diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fd4591..5779a57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.17) option(ENABLE_ICONV "Use libiconv to convert encoding" ON) option(ENABLE_STANDALONE "Build utils standalone" OFF) -option(ENABLE_CXX17 "Enable C++ 17" OFF) option(INSTALL_DEP_FILES "Install a file with dependences." OFF) option(ENABLE_SSL "Enable SSL" OFF) option(ENABLE_ZLIB "Use Zlib to uncompress http data." OFF) @@ -186,9 +185,7 @@ endif() if (ENABLE_ZLIB) target_link_libraries(utils ZLIB::ZLIB) endif() -if (ENABLE_CXX17) - target_compile_features(utils PRIVATE cxx_std_17) -endif() +target_compile_features(utils PRIVATE cxx_std_17) if (ENABLE_STANDALONE) install(TARGETS utils) endif() diff --git a/meson.build b/meson.build index f4839fd..e472270 100644 --- a/meson.build +++ b/meson.build @@ -1,4 +1,4 @@ -project('utils') +project('utils', default_options: ['cpp_std=c++17']) add_languages('c', 'cpp', required: true) cc = meson.get_compiler('c') @@ -181,3 +181,19 @@ utils_dep = declare_dependency(include_directories: include_directories('.'), li if get_option('utils_standalone') install_headers(source_file_headers) endif + +if get_option('test') + gtest = subproject('gtest') + gtest_main_dep = gtest.get_variable('gtest_main_dep') + test_exe = executable('unittest', + files( + 'test/stack_test.cpp', + 'test/queue_test.cpp', + 'test/binary_tree_test.cpp', + 'test/hash_map_test.cpp', + 'test/hash_lib_test.cpp', + ), + dependencies: [utils_dep, gtest_main_dep], + ) + test('unittest', test_exe, args: ['-v'], timeout: 60) +endif diff --git a/meson_options.txt b/meson_options.txt index d9b8768..ed0c79b 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -2,3 +2,4 @@ option('utils_iconv', type: 'feature', value: 'auto', description: 'Enable iconv option('utils_standalone', type: 'boolean', value: false, description: 'Build standalone utils') option('utils_ssl', type: 'feature', value: 'disabled', description: 'Enable SSL support') option('utils_zlib', type: 'feature', value: 'disabled', description: 'Enable zlib support for uncompress http data.') +option('test', type: 'boolean', value: false, description: 'Enable test') diff --git a/subprojects/.gitignore b/subprojects/.gitignore new file mode 100644 index 0000000..355164c --- /dev/null +++ b/subprojects/.gitignore @@ -0,0 +1 @@ +*/ diff --git a/subprojects/gtest.wrap b/subprojects/gtest.wrap new file mode 100644 index 0000000..ba73d96 --- /dev/null +++ b/subprojects/gtest.wrap @@ -0,0 +1,16 @@ +[wrap-file] +directory = googletest-1.15.2 +source_url = https://github.com/google/googletest/archive/refs/tags/v1.15.2.tar.gz +source_filename = gtest-1.15.2.tar.gz +source_hash = 7b42b4d6ed48810c5362c265a17faebe90dc2373c885e5216439d37927f02926 +patch_filename = gtest_1.15.2-4_patch.zip +patch_url = https://wrapdb.mesonbuild.com/v2/gtest_1.15.2-4/get_patch +patch_hash = a5151324b97e6a98fa7a0e8095523e6d5c4bb3431210d6ac4ad9800c345acf40 +source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/gtest_1.15.2-4/gtest-1.15.2.tar.gz +wrapdb_version = 1.15.2-4 + +[provide] +gtest = gtest_dep +gtest_main = gtest_main_dep +gmock = gmock_dep +gmock_main = gmock_main_dep diff --git a/test/hash_lib_test.cpp b/test/hash_lib_test.cpp index d4b2261..53bf4dc 100644 --- a/test/hash_lib_test.cpp +++ b/test/hash_lib_test.cpp @@ -12,6 +12,7 @@ TEST(HashLibTest, SHA512ClassTest) { GTEST_ASSERT_EQ(re, sha512.digest()); auto hexRe = hashHex("Hello, World!"); GTEST_ASSERT_EQ(hexRe, sha512.hexDigest()); + GTEST_ASSERT_EQ(hashHex("Hello, World!Hello, World!"), hashHex("Hello, World!", another)); another.update("Hello, World!"); GTEST_ASSERT_EQ(hashHex("Hello, World!Hello, World!"), another.hexDigest()); sha512.update("Hello, World!");