add boost url unit test for learn.

This commit is contained in:
amass 2023-12-30 22:51:20 +08:00
parent 0edab61c09
commit b8c3ed6b7d
4 changed files with 30 additions and 1 deletions

3
.gitignore vendored
View File

@ -41,4 +41,5 @@ target_wrapper.*
# QtCreator CMake
CMakeLists.txt.user*
build
build
logs

View File

@ -27,6 +27,9 @@ add_executable(UnitTest main.cpp
DataStructure/StaticQueueTest.cpp
DataStructure/StaticStackTest.cpp
DataStructure/StringTest.cpp
HttpProxy/BoostUrlTest.cpp
Universal/BoostLogTest.cpp
)
@ -37,5 +40,6 @@ target_compile_definitions(UnitTest
target_link_libraries(UnitTest
PRIVATE Boost::unit_test_framework
PRIVATE DataStructure
PRIVATE HttpProxy
PRIVATE Universal
)

View File

@ -0,0 +1,19 @@
#include "BoostLog.h"
#include <boost/test/unit_test.hpp>
#include <boost/url/parse_path.hpp>
#include <boost/url/url_view.hpp>
BOOST_AUTO_TEST_CASE(BoostUrlTest) {
boost::urls::url_view u("https://user:pass@example.com:443/%E5%B7%A5%E4%BD%9C%E7%AC%94%E8%AE%B0/path/to/"
"my%2dfile.txt?id=42&name=John%20Doe%20Jingleheimer%2DSchmidt#page%20anchor");
BOOST_CHECK_EQUAL(u.scheme(), "https");
BOOST_CHECK_EQUAL(u.authority().buffer(), "user:pass@example.com:443");
BOOST_CHECK_EQUAL(u.userinfo(), "user:pass");
BOOST_CHECK_EQUAL(u.user(), "user");
BOOST_CHECK_EQUAL(u.password(), "pass");
BOOST_CHECK_EQUAL(u.host(), "example.com");
BOOST_CHECK_EQUAL(u.port(), "443");
BOOST_CHECK_EQUAL(u.path(), "/工作笔记/path/to/my-file.txt");
BOOST_CHECK_EQUAL(u.query(), "id=42&name=John Doe Jingleheimer-Schmidt");
BOOST_CHECK_EQUAL(u.fragment(), "page anchor");
}

View File

@ -47,6 +47,7 @@ function cmake_scan() {
-S ${base_path} \
-B ${build_path} \
-DCMAKE_BUILD_TYPE=Debug \
-DUNIT_TEST=ON \
-DBOOST_ROOT=${libraries_root}/boost_1_84_0 \
-DZeroMQ_ROOT=${libraries_root}/zeromq-4.3.4_debug \
${cmake_qt_parameters}
@ -62,6 +63,10 @@ function build() {
/opt/Qt/Tools/CMake/bin/cmake \
--build ${build_path} \
--target all
if [ $? -ne 0 ]; then
exit 1
fi
build/UnitTest/UnitTest
}
function main() {