summaryrefslogtreecommitdiffstats
path: root/document/src
diff options
context:
space:
mode:
authorGeir Storli <geirst@verizonmedia.com>2019-03-01 14:43:55 +0000
committerGeir Storli <geirst@verizonmedia.com>2019-03-01 14:47:21 +0000
commit87b9b1c1fde62b9e62c17dba45564a1f80ee4655 (patch)
tree54bdaa8a7511cb14513ebd9a1090bbd5008f1e54 /document/src
parent9b7a751309080c04f593aaec0dbc162a30d1225b (diff)
Migrate unit test from cppunit to gtest.
Diffstat (limited to 'document/src')
-rw-r--r--document/src/tests/CMakeLists.txt2
-rw-r--r--document/src/tests/teststringutil.cpp80
-rw-r--r--document/src/tests/teststringutil.h24
3 files changed, 32 insertions, 74 deletions
diff --git a/document/src/tests/CMakeLists.txt b/document/src/tests/CMakeLists.txt
index ccf25b17061..b78fd66b687 100644
--- a/document/src/tests/CMakeLists.txt
+++ b/document/src/tests/CMakeLists.txt
@@ -8,6 +8,7 @@ vespa_add_executable(document_gtest_runner_app TEST
documentidtest.cpp
documentupdatetestcase.cpp
gtest_runner.cpp
+ teststringutil.cpp
DEPENDS
document
gtest
@@ -23,7 +24,6 @@ vespa_add_test(
# Runner for unit tests written in CppUnit (DEPRECATED).
vespa_add_executable(document_testrunner_app TEST
SOURCES
- teststringutil.cpp
testbytebuffer.cpp
stringtokenizertest.cpp
buckettest.cpp
diff --git a/document/src/tests/teststringutil.cpp b/document/src/tests/teststringutil.cpp
index 3d741d4827f..ad57c18488d 100644
--- a/document/src/tests/teststringutil.cpp
+++ b/document/src/tests/teststringutil.cpp
@@ -1,63 +1,45 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-/**
- * Test program for StringUtil methods
- *
- * @version $Id$
- */
-#include <stdio.h>
-#include <string.h>
-#include <stdint.h>
#include <vespa/document/util/stringutil.h>
-#include "heapdebugger.h"
-#include "teststringutil.h"
-#include <cppunit/TestFixture.h>
-#include <cppunit/extensions/HelperMacros.h>
-
-CPPUNIT_TEST_SUITE_REGISTRATION( StringUtil_Test );
+#include <gtest/gtest.h>
using namespace document;
using vespalib::string;
-void StringUtil_Test::setUp()
-{
- enableHeapUsageMonitor();
-}
-
-void StringUtil_Test::test_escape()
+TEST(StringUtilTest, test_escape)
{
- CPPUNIT_ASSERT_EQUAL(string("abz019ABZ"), StringUtil::escape("abz019ABZ"));
- CPPUNIT_ASSERT_EQUAL(string("\\t"), StringUtil::escape("\t"));
- CPPUNIT_ASSERT_EQUAL(string("\\n"), StringUtil::escape("\n"));
- CPPUNIT_ASSERT_EQUAL(string("\\r"), StringUtil::escape("\r"));
- CPPUNIT_ASSERT_EQUAL(string("\\\""), StringUtil::escape("\""));
- CPPUNIT_ASSERT_EQUAL(string("\\f"), StringUtil::escape("\f"));
- CPPUNIT_ASSERT_EQUAL(string("\\\\"), StringUtil::escape("\\"));
- CPPUNIT_ASSERT_EQUAL(string("\\x05"), StringUtil::escape("\x05"));
- CPPUNIT_ASSERT_EQUAL(string("\\tA\\ncombined\\r\\x055test"),
- StringUtil::escape("\tA\ncombined\r\x05""5test"));
- CPPUNIT_ASSERT_EQUAL(string("A\\x20space\\x20separated\\x20string"),
- StringUtil::escape("A space separated string", ' '));
+ EXPECT_EQ(string("abz019ABZ"), StringUtil::escape("abz019ABZ"));
+ EXPECT_EQ(string("\\t"), StringUtil::escape("\t"));
+ EXPECT_EQ(string("\\n"), StringUtil::escape("\n"));
+ EXPECT_EQ(string("\\r"), StringUtil::escape("\r"));
+ EXPECT_EQ(string("\\\""), StringUtil::escape("\""));
+ EXPECT_EQ(string("\\f"), StringUtil::escape("\f"));
+ EXPECT_EQ(string("\\\\"), StringUtil::escape("\\"));
+ EXPECT_EQ(string("\\x05"), StringUtil::escape("\x05"));
+ EXPECT_EQ(string("\\tA\\ncombined\\r\\x055test"),
+ StringUtil::escape("\tA\ncombined\r\x05""5test"));
+ EXPECT_EQ(string("A\\x20space\\x20separated\\x20string"),
+ StringUtil::escape("A space separated string", ' '));
}
-void StringUtil_Test::test_unescape()
+TEST(StringUtilTest, test_unescape)
{
- CPPUNIT_ASSERT_EQUAL(string("abz019ABZ"),
- StringUtil::unescape("abz019ABZ"));
- CPPUNIT_ASSERT_EQUAL(string("\t"), StringUtil::unescape("\\t"));
- CPPUNIT_ASSERT_EQUAL(string("\n"), StringUtil::unescape("\\n"));
- CPPUNIT_ASSERT_EQUAL(string("\r"), StringUtil::unescape("\\r"));
- CPPUNIT_ASSERT_EQUAL(string("\""), StringUtil::unescape("\\\""));
- CPPUNIT_ASSERT_EQUAL(string("\f"), StringUtil::unescape("\\f"));
- CPPUNIT_ASSERT_EQUAL(string("\\"), StringUtil::unescape("\\\\"));
- CPPUNIT_ASSERT_EQUAL(string("\x05"), StringUtil::unescape("\\x05"));
- CPPUNIT_ASSERT_EQUAL(string("\tA\ncombined\r\x05""5test"),
- StringUtil::unescape("\\tA\\ncombined\\r\\x055test"));
- CPPUNIT_ASSERT_EQUAL(string("A space separated string"),
- StringUtil::unescape("A\\x20space\\x20separated\\x20string"));
+ EXPECT_EQ(string("abz019ABZ"),
+ StringUtil::unescape("abz019ABZ"));
+ EXPECT_EQ(string("\t"), StringUtil::unescape("\\t"));
+ EXPECT_EQ(string("\n"), StringUtil::unescape("\\n"));
+ EXPECT_EQ(string("\r"), StringUtil::unescape("\\r"));
+ EXPECT_EQ(string("\""), StringUtil::unescape("\\\""));
+ EXPECT_EQ(string("\f"), StringUtil::unescape("\\f"));
+ EXPECT_EQ(string("\\"), StringUtil::unescape("\\\\"));
+ EXPECT_EQ(string("\x05"), StringUtil::unescape("\\x05"));
+ EXPECT_EQ(string("\tA\ncombined\r\x05""5test"),
+ StringUtil::unescape("\\tA\\ncombined\\r\\x055test"));
+ EXPECT_EQ(string("A space separated string"),
+ StringUtil::unescape("A\\x20space\\x20separated\\x20string"));
}
-void StringUtil_Test::test_printAsHex()
+TEST(StringUtilTest, test_printAsHex)
{
std::vector<char> asciitable(256);
for (uint32_t i=0; i<256; ++i) asciitable[i] = i;
@@ -82,7 +64,7 @@ void StringUtil_Test::test_printAsHex()
" 208: d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df\n"
" 224: e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef\n"
" 240: f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff");
- CPPUNIT_ASSERT_EQUAL(expected, ost.str());
+ EXPECT_EQ(expected, ost.str());
ost.str("");
ost << "\n";
@@ -107,5 +89,5 @@ void StringUtil_Test::test_printAsHex()
"225: e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef ...............\n"
"240: f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ...............\n"
"255: ff .";
- CPPUNIT_ASSERT_EQUAL(expected, ost.str());
+ EXPECT_EQ(expected, ost.str());
}
diff --git a/document/src/tests/teststringutil.h b/document/src/tests/teststringutil.h
deleted file mode 100644
index bcc7617d1d4..00000000000
--- a/document/src/tests/teststringutil.h
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#pragma once
-
-#include <cppunit/extensions/HelperMacros.h>
-
-class StringUtil_Test : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE( StringUtil_Test);
- CPPUNIT_TEST(test_escape);
- CPPUNIT_TEST(test_unescape);
- CPPUNIT_TEST(test_printAsHex);
- CPPUNIT_TEST_SUITE_END();
-
-public:
- void setUp() override;
-
-protected:
- void test_escape();
- void test_unescape();
- void test_printAsHex();
-
-};
-
-