diff options
author | Geir Storli <geirst@yahooinc.com> | 2024-02-26 15:00:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-26 15:00:26 +0100 |
commit | 39114a8d8d85dc2a3f2732f79bf7c69004229a07 (patch) | |
tree | 108dcbaaaf501f743538e7770de879444f5dac8c /vespalib | |
parent | 58d08a0d4f97630b9e048375a75b4a6e2c40c528 (diff) | |
parent | 9a4d13d6954890413f77b96a307aaf678777d331 (diff) |
Merge pull request #30395 from vespa-engine/toregge/rewrite-crc-unit-test-to-gtest
Rewrite crc unit test to gtest.
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/tests/crc/CMakeLists.txt | 1 | ||||
-rw-r--r-- | vespalib/src/tests/crc/crc_test.cpp | 35 |
2 files changed, 10 insertions, 26 deletions
diff --git a/vespalib/src/tests/crc/CMakeLists.txt b/vespalib/src/tests/crc/CMakeLists.txt index 49907cb36fb..a7de5d1fa7a 100644 --- a/vespalib/src/tests/crc/CMakeLists.txt +++ b/vespalib/src/tests/crc/CMakeLists.txt @@ -4,5 +4,6 @@ vespa_add_executable(vespalib_crc_test_app TEST crc_test.cpp DEPENDS vespalib + GTest::gtest ) vespa_add_test(NAME vespalib_crc_test_app COMMAND vespalib_crc_test_app boost) diff --git a/vespalib/src/tests/crc/crc_test.cpp b/vespalib/src/tests/crc/crc_test.cpp index 180cd8934dc..82ad8b4c013 100644 --- a/vespalib/src/tests/crc/crc_test.cpp +++ b/vespalib/src/tests/crc/crc_test.cpp @@ -1,51 +1,34 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vespalib/testkit/testapp.h> #include <vespa/vespalib/util/crc.h> +#include <vespa/vespalib/gtest/gtest.h> #include <vector> using namespace vespalib; -class Test : public TestApp -{ -public: - int Main() override; - void testCorrectNess(); - void testBenchmark(size_t bufSz, size_t numRep); -}; - -int -Test::Main() -{ - TEST_INIT("crc_test"); - testCorrectNess(); - testBenchmark(1024, 1000*1000); - TEST_DONE(); -} - -void -Test::testCorrectNess() +TEST(FCrcTest, test_correctness) { const char *a[7] = { "", "a", "ab", "abc", "abcd", "abcde", "doc:crawler:http://www.ntnu.no/" }; uint32_t expected[7] = {0, 0xe8b7be43, 0x9e83486d, 0x352441c2, 0xed82cd11, 0x8587d865, 0x86287fc5}; for (size_t i(0); i < sizeof(a)/sizeof(a[0]); i++) { uint32_t vespaCrc32 = crc_32_type::crc(a[i], strlen(a[i])); - EXPECT_EQUAL(vespaCrc32, expected[i]); + EXPECT_EQ(vespaCrc32, expected[i]); vespalib::crc_32_type calculator2; calculator2.process_bytes(a[i], strlen(a[i])); - EXPECT_EQUAL(vespaCrc32, calculator2.checksum()); + EXPECT_EQ(vespaCrc32, calculator2.checksum()); } vespalib::crc_32_type calculator; uint32_t accum_expected[7] = {0, 0xe8b7be43, 0x690e2297, 0x8d7284f9, 0x7ed0c389, 0x61bc2a26, 0x1816e339}; for (size_t i(0); i < sizeof(a)/sizeof(a[0]); i++) { calculator.process_bytes(a[i], strlen(a[i])); - EXPECT_EQUAL(calculator.checksum(), accum_expected[i]); + EXPECT_EQ(calculator.checksum(), accum_expected[i]); } } -void -Test::testBenchmark(size_t bufSz, size_t numRep) +TEST(CrcTest, benchmark) { + constexpr size_t bufSz = 1024; + constexpr size_t numRep = 1000 * 1000; std::vector<char> a(numRep+bufSz); for(size_t i(0), m(a.size()); i < m; i++) { a[i] = i&0xff; @@ -60,4 +43,4 @@ Test::testBenchmark(size_t bufSz, size_t numRep) printf("sum = %x\n", sum); } -TEST_APPHOOK(Test) +GTEST_MAIN_RUN_ALL_TESTS() |