summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorGeir Storli <geirst@verizonmedia.com>2019-02-15 15:06:45 +0000
committerGeir Storli <geirst@verizonmedia.com>2019-02-18 11:56:22 +0000
commitfcdb5bfcfe230ebc83d2efdf6fd6feecfedabaaf (patch)
treea7c9c16136bc3c2934e8eb04c9e7297f08c4755a /document
parentd15559afb0e5ba06bf9f33bd6f25ed02a90273a9 (diff)
Add gtest runner and migrate documentidtest from CppUnit to gtest.
Diffstat (limited to 'document')
-rw-r--r--document/src/tests/.gitignore1
-rw-r--r--document/src/tests/CMakeLists.txt22
-rw-r--r--document/src/tests/documentidtest.cpp79
-rw-r--r--document/src/tests/gtest_runner.cpp14
4 files changed, 58 insertions, 58 deletions
diff --git a/document/src/tests/.gitignore b/document/src/tests/.gitignore
index 0a157447e4b..4d5d93dd093 100644
--- a/document/src/tests/.gitignore
+++ b/document/src/tests/.gitignore
@@ -13,6 +13,7 @@ mytestfile_clear
test.vlog
testrunner
*_test
+document_gtest_runner_app
document_testrunner_app
/serializecpp-lz4-level9.dat
/serializecppsplit_body.dat
diff --git a/document/src/tests/CMakeLists.txt b/document/src/tests/CMakeLists.txt
index 6edd113f17b..2561265d361 100644
--- a/document/src/tests/CMakeLists.txt
+++ b/document/src/tests/CMakeLists.txt
@@ -1,4 +1,25 @@
# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+# Runner for unit tests written in gtest.
+# NOTE: All new test classes should be added here.
+vespa_add_executable(document_gtest_runner_app TEST
+ SOURCES
+ documentidtest.cpp
+ gtest_runner.cpp
+ DEPENDS
+ document
+ gtest
+ AFTER
+ document_documentconfig
+)
+
+vespa_add_test(
+ NAME document_gtest_runner_app
+ COMMAND $<TARGET_FILE:document_gtest_runner_app>
+ DEPENDS document_gtest_runner_app
+)
+
+# Runner for unit tests written in CppUnit (DEPRECATED).
vespa_add_executable(document_testrunner_app TEST
SOURCES
teststringutil.cpp
@@ -7,7 +28,6 @@ vespa_add_executable(document_testrunner_app TEST
documentcalculatortestcase.cpp
buckettest.cpp
globalidtest.cpp
- documentidtest.cpp
documenttypetestcase.cpp
primitivefieldvaluetest.cpp
arrayfieldvaluetest.cpp
diff --git a/document/src/tests/documentidtest.cpp b/document/src/tests/documentidtest.cpp
index ae5c25a22ef..198a8ce5e15 100644
--- a/document/src/tests/documentidtest.cpp
+++ b/document/src/tests/documentidtest.cpp
@@ -1,39 +1,14 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <cppunit/extensions/HelperMacros.h>
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/document/bucket/bucketidfactory.h>
#include <vespa/document/base/documentid.h>
#include <vespa/vespalib/util/md5.h>
#include <vespa/fastos/file.h>
+#include <gtest/gtest.h>
namespace document {
-struct DocumentIdTest : public CppUnit::TestFixture {
- void generateJavaComplianceFile();
- void testOutput();
- void testEqualityOperator();
- void testCopying();
- void testParseId();
- void checkNtnuGlobalId();
- void testDocGlobalId();
- void freestandingLocationFromGroupNameFuncMatchesIdLocation();
-
- CPPUNIT_TEST_SUITE(DocumentIdTest);
- CPPUNIT_TEST(testEqualityOperator);
- CPPUNIT_TEST(testOutput);
- CPPUNIT_TEST(testCopying);
- CPPUNIT_TEST(generateJavaComplianceFile);
- CPPUNIT_TEST(testParseId);
- CPPUNIT_TEST(checkNtnuGlobalId);
- CPPUNIT_TEST(testDocGlobalId);
- CPPUNIT_TEST(freestandingLocationFromGroupNameFuncMatchesIdLocation);
- CPPUNIT_TEST_SUITE_END();
-
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(DocumentIdTest);
-
namespace {
void writeGlobalIdBucketId(std::ostream& out, const std::string& id) {
BucketIdFactory factory;
@@ -43,7 +18,7 @@ namespace {
}
}
-void DocumentIdTest::generateJavaComplianceFile()
+TEST(DocumentIdTest, generateJavaComplianceFile)
{
{ // Generate file with globalids and bucket ID of various document ids,
// which java will use to ensure equal implementations.
@@ -72,28 +47,28 @@ void DocumentIdTest::generateJavaComplianceFile()
writeGlobalIdBucketId(ost, "id:np:type:g=agroup:another");
writeGlobalIdBucketId(ost, "id:ns:type:g=another:specific");
FastOS_File file;
- CPPUNIT_ASSERT(file.OpenWriteOnlyTruncate(TEST_PATH("cpp-globalidbucketids.txt").c_str()));
+ ASSERT_TRUE(file.OpenWriteOnlyTruncate(TEST_PATH("cpp-globalidbucketids.txt").c_str()));
std::string content(ost.str());
- CPPUNIT_ASSERT(file.CheckedWrite(content.c_str(), content.size()));
- CPPUNIT_ASSERT(file.Close());
+ ASSERT_TRUE(file.CheckedWrite(content.c_str(), content.size()));
+ ASSERT_TRUE(file.Close());
}
}
-void DocumentIdTest::testOutput()
+TEST(DocumentIdTest, testOutput)
{
DocumentId id(DocIdString("crawler", "http://www.yahoo.com"));
std::ostringstream ost;
ost << id;
std::string expected("doc:crawler:http://www.yahoo.com");
- CPPUNIT_ASSERT_EQUAL(expected, ost.str());
+ EXPECT_EQ(expected, ost.str());
- CPPUNIT_ASSERT_EQUAL(vespalib::string(expected), id.toString());
+ EXPECT_EQ(vespalib::string(expected), id.toString());
expected = "DocumentId(id = doc:crawler:http://www.yahoo.com, "
"gid(0x928baffb39cf32004542fb60))";
- CPPUNIT_ASSERT_EQUAL(expected, static_cast<Printable&>(id).toString(true));
+ EXPECT_EQ(expected, static_cast<Printable&>(id).toString(true));
}
namespace {
@@ -106,7 +81,7 @@ namespace {
}
}
-void DocumentIdTest::testEqualityOperator()
+TEST(DocumentIdTest, testEqualityOperator)
{
std::string uri(DocIdString("crawler", "http://www.yahoo.com").toString());
@@ -114,11 +89,11 @@ void DocumentIdTest::testEqualityOperator()
DocumentId id2(uri);
DocumentId id3("doc:crawler:http://www.yahoo.no/");
- CPPUNIT_ASSERT_EQUAL(id1, id2);
- CPPUNIT_ASSERT_MESSAGE(getNotEqualMessage(id1, id3), !(id1 == id3));
+ EXPECT_EQ(id1, id2);
+ EXPECT_NE(id1, id3);
}
-void DocumentIdTest::testCopying()
+TEST(DocumentIdTest, testCopying)
{
std::string uri(DocIdString("crawler", "http://www.yahoo.com/").toString());
@@ -127,26 +102,17 @@ void DocumentIdTest::testCopying()
DocumentId id3("doc:ns:foo");
id3 = id2;
- CPPUNIT_ASSERT_EQUAL(id1, id2);
- CPPUNIT_ASSERT_EQUAL(id1, id3);
-}
-
-void
-DocumentIdTest::testParseId()
-{
- // Moved to base/documentid_test.cpp
+ EXPECT_EQ(id1, id2);
+ EXPECT_EQ(id1, id3);
}
-void
-DocumentIdTest::checkNtnuGlobalId()
+TEST(DocumentIdTest, checkNtnuGlobalId)
{
DocumentId id("doc:crawler:http://www.ntnu.no/");
- CPPUNIT_ASSERT_EQUAL(vespalib::string("gid(0xb8863740be14221c0ac77896)"),
- id.getGlobalId().toString());
+ EXPECT_EQ(vespalib::string("gid(0xb8863740be14221c0ac77896)"), id.getGlobalId().toString());
}
-void
-DocumentIdTest::testDocGlobalId()
+TEST(DocumentIdTest, testDocGlobalId)
{
// Test that location of doc scheme documents are set correctly, such
// that the location is the first bytes of the original GID.
@@ -157,16 +123,15 @@ DocumentIdTest::testDocGlobalId()
fastc_md5sum(reinterpret_cast<const unsigned char*>(id.c_str()),
id.size(), key);
- CPPUNIT_ASSERT_EQUAL(GlobalId(key), did.getGlobalId());
+ EXPECT_EQ(GlobalId(key), did.getGlobalId());
}
-void
-DocumentIdTest::freestandingLocationFromGroupNameFuncMatchesIdLocation()
+TEST(DocumentIdTest, freestandingLocationFromGroupNameFuncMatchesIdLocation)
{
- CPPUNIT_ASSERT_EQUAL(
+ EXPECT_EQ(
DocumentId("id::foo:g=zoid:bar").getScheme().getLocation(),
GroupDocIdString::locationFromGroupName("zoid"));
- CPPUNIT_ASSERT_EQUAL(
+ EXPECT_EQ(
DocumentId("id::bar:g=doink:baz").getScheme().getLocation(),
GroupDocIdString::locationFromGroupName("doink"));
}
diff --git a/document/src/tests/gtest_runner.cpp b/document/src/tests/gtest_runner.cpp
new file mode 100644
index 00000000000..efe108c2042
--- /dev/null
+++ b/document/src/tests/gtest_runner.cpp
@@ -0,0 +1,14 @@
+// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include <gtest/gtest.h>
+
+#include <vespa/log/log.h>
+LOG_SETUP("document_gtest_runner");
+
+int
+main(int argc, char* argv[])
+{
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
+