From b8c3ed6b7d58473796373c1d9a302758d24713f3 Mon Sep 17 00:00:00 2001 From: amass <168062547@qq.com> Date: Sat, 30 Dec 2023 22:51:20 +0800 Subject: [PATCH] add boost url unit test for learn. --- .gitignore | 3 ++- UnitTest/CMakeLists.txt | 4 ++++ UnitTest/HttpProxy/BoostUrlTest.cpp | 19 +++++++++++++++++++ resource/deploy.sh | 5 +++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 UnitTest/HttpProxy/BoostUrlTest.cpp diff --git a/.gitignore b/.gitignore index 72c48ef..2500e85 100644 --- a/.gitignore +++ b/.gitignore @@ -41,4 +41,5 @@ target_wrapper.* # QtCreator CMake CMakeLists.txt.user* -build \ No newline at end of file +build +logs \ No newline at end of file diff --git a/UnitTest/CMakeLists.txt b/UnitTest/CMakeLists.txt index 06d30c4..b2142fb 100644 --- a/UnitTest/CMakeLists.txt +++ b/UnitTest/CMakeLists.txt @@ -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 ) diff --git a/UnitTest/HttpProxy/BoostUrlTest.cpp b/UnitTest/HttpProxy/BoostUrlTest.cpp new file mode 100644 index 0000000..f4b9954 --- /dev/null +++ b/UnitTest/HttpProxy/BoostUrlTest.cpp @@ -0,0 +1,19 @@ +#include "BoostLog.h" +#include +#include +#include + +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"); +} diff --git a/resource/deploy.sh b/resource/deploy.sh index 304e089..f172dc2 100755 --- a/resource/deploy.sh +++ b/resource/deploy.sh @@ -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() {