summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorGeir Storli <geirst@verizonmedia.com>2019-03-04 08:42:50 +0100
committerGitHub <noreply@github.com>2019-03-04 08:42:50 +0100
commit1e0ae2265c676e0dcf8ecc08102579379f3ccd85 (patch)
treed0093a673dace2186d86be8bcce786758a75c442 /document
parent866e0944565acc0fbd1fd24ee8ec76db192a86f0 (diff)
parentca15266fb4cf9e045fd9e86d768ad032ea66bd41 (diff)
Merge pull request #8653 from vespa-engine/geirst/migrate-tests-from-cppunit-to-gtest-1
Geirst/migrate tests from cppunit to gtest 1
Diffstat (limited to 'document')
-rw-r--r--document/src/tests/CMakeLists.txt5
-rw-r--r--document/src/tests/documentcalculatortestcase.cpp125
-rw-r--r--document/src/tests/gtest_runner.cpp2
-rw-r--r--document/src/tests/teststringutil.cpp80
-rw-r--r--document/src/tests/teststringutil.h24
5 files changed, 66 insertions, 170 deletions
diff --git a/document/src/tests/CMakeLists.txt b/document/src/tests/CMakeLists.txt
index c0b46d7ccd4..b78fd66b687 100644
--- a/document/src/tests/CMakeLists.txt
+++ b/document/src/tests/CMakeLists.txt
@@ -4,9 +4,11 @@
# NOTE: All new test classes should be added here.
vespa_add_executable(document_gtest_runner_app TEST
SOURCES
+ documentcalculatortestcase.cpp
documentidtest.cpp
documentupdatetestcase.cpp
gtest_runner.cpp
+ teststringutil.cpp
DEPENDS
document
gtest
@@ -17,16 +19,13 @@ vespa_add_executable(document_gtest_runner_app TEST
vespa_add_test(
NAME document_gtest_runner_app
COMMAND 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
testbytebuffer.cpp
stringtokenizertest.cpp
- documentcalculatortestcase.cpp
buckettest.cpp
globalidtest.cpp
documenttypetestcase.cpp
diff --git a/document/src/tests/documentcalculatortestcase.cpp b/document/src/tests/documentcalculatortestcase.cpp
index e313f3f33b5..744a7556f1b 100644
--- a/document/src/tests/documentcalculatortestcase.cpp
+++ b/document/src/tests/documentcalculatortestcase.cpp
@@ -1,87 +1,52 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/document/base/testdocrepo.h>
-#include <vespa/vespalib/io/fileutil.h>
-#include <vespa/vdstestlib/cppunit/macros.h>
#include <vespa/document/base/documentcalculator.h>
-#include <vespa/document/fieldvalue/document.h>
+#include <vespa/document/base/testdocrepo.h>
#include <vespa/document/fieldvalue/bytefieldvalue.h>
+#include <vespa/document/fieldvalue/document.h>
+#include <vespa/document/fieldvalue/floatfieldvalue.h>
#include <vespa/document/fieldvalue/intfieldvalue.h>
#include <vespa/document/fieldvalue/longfieldvalue.h>
-#include <vespa/document/fieldvalue/floatfieldvalue.h>
#include <vespa/document/select/variablemap.h>
+#include <vespa/vespalib/gtest/gtest.h>
+#include <vespa/vespalib/io/fileutil.h>
#include <vespa/vespalib/util/exceptions.h>
namespace document {
-class DocumentCalculatorTest : public CppUnit::TestFixture {
- TestDocRepo _testRepo;
-
+class DocumentCalculatorTest : public ::testing::Test {
public:
+ TestDocRepo _testRepo;
const DocumentTypeRepo &getRepo() { return _testRepo.getTypeRepo(); }
-
- void setUp() override {}
- void tearDown() override {}
-
- void testConstant();
- void testSimple();
- void testVariables();
- void testFields();
- void testDivideByZero();
- void testModByZero();
- void testFieldsDivZero();
- void testFieldNotSet();
- void testFieldNotFound();
- void testByteSubtractionZeroResult();
-
- CPPUNIT_TEST_SUITE(DocumentCalculatorTest);
- CPPUNIT_TEST(testConstant);
- CPPUNIT_TEST(testSimple);
- CPPUNIT_TEST(testVariables);
- CPPUNIT_TEST(testFields);
- CPPUNIT_TEST(testDivideByZero);
- CPPUNIT_TEST(testModByZero);
- CPPUNIT_TEST(testFieldsDivZero);
- CPPUNIT_TEST(testFieldNotSet);
- CPPUNIT_TEST(testFieldNotFound);
- CPPUNIT_TEST(testByteSubtractionZeroResult);
- CPPUNIT_TEST_SUITE_END();
};
-CPPUNIT_TEST_SUITE_REGISTRATION(DocumentCalculatorTest);
-
-
-void
-DocumentCalculatorTest::testConstant() {
+TEST_F(DocumentCalculatorTest, testConstant) {
auto variables = std::make_unique<select::VariableMap>();
DocumentCalculator calc(getRepo(), "4.0");
Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("doc:test:foo"));
- CPPUNIT_ASSERT_EQUAL(4.0, calc.evaluate(doc, std::move(variables)));
+ EXPECT_EQ(4.0, calc.evaluate(doc, std::move(variables)));
}
-void
-DocumentCalculatorTest::testSimple() {
+TEST_F(DocumentCalculatorTest, testSimple) {
auto variables = std::make_unique<select::VariableMap>();
DocumentCalculator calc(getRepo(), "(3 + 5) / 2");
Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("doc:test:foo"));
- CPPUNIT_ASSERT_EQUAL(4.0, calc.evaluate(doc, std::move(variables)));
+ EXPECT_EQ(4.0, calc.evaluate(doc, std::move(variables)));
}
-void
-DocumentCalculatorTest::testVariables() {
+TEST_F(DocumentCalculatorTest, testVariables) {
auto variables = std::make_unique<select::VariableMap>();
(*variables)["x"] = 3.0;
(*variables)["y"] = 5.0;
DocumentCalculator calc(getRepo(), "($x + $y) / 2");
Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("doc:test:foo"));
- CPPUNIT_ASSERT_EQUAL(4.0, calc.evaluate(doc, std::move(variables)));
+ EXPECT_EQ(4.0, calc.evaluate(doc, std::move(variables)));
}
-void
-DocumentCalculatorTest::testFields() {
+TEST_F(DocumentCalculatorTest, testFields) {
auto variables = std::make_unique<select::VariableMap>();
(*variables)["x"] = 3.0;
(*variables)["y"] = 5.0;
@@ -92,11 +57,10 @@ DocumentCalculatorTest::testFields() {
doc.setValue(doc.getField("headerval"), IntFieldValue(5));
doc.setValue(doc.getField("hfloatval"), FloatFieldValue(3.0));
doc.setValue(doc.getField("headerlongval"), LongFieldValue(2));
- CPPUNIT_ASSERT_EQUAL(4.0, calc.evaluate(doc, std::move(variables)));
+ EXPECT_EQ(4.0, calc.evaluate(doc, std::move(variables)));
}
-void
-DocumentCalculatorTest::testFieldsDivZero() {
+TEST_F(DocumentCalculatorTest, testFieldsDivZero) {
auto variables = std::make_unique<select::VariableMap>();
(*variables)["x"] = 3.0;
(*variables)["y"] = 5.0;
@@ -107,44 +71,29 @@ DocumentCalculatorTest::testFieldsDivZero() {
doc.setValue(doc.getField("headerval"), IntFieldValue(5));
doc.setValue(doc.getField("hfloatval"), FloatFieldValue(3.0));
doc.setValue(doc.getField("headerlongval"), LongFieldValue(0));
- try {
- calc.evaluate(doc, std::move(variables));
- CPPUNIT_ASSERT(false);
- } catch (const vespalib::IllegalArgumentException& e) {
- // OK
- }
+ EXPECT_THROW(calc.evaluate(doc, std::move(variables)),
+ vespalib::IllegalArgumentException);
}
-void
-DocumentCalculatorTest::testDivideByZero() {
+TEST_F(DocumentCalculatorTest, testDivideByZero) {
auto variables = std::make_unique<select::VariableMap>();
DocumentCalculator calc(getRepo(), "(3 + 5) / 0");
Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("doc:test:foo"));
- try {
- calc.evaluate(doc, std::move(variables));
- CPPUNIT_ASSERT(false);
- } catch (const vespalib::IllegalArgumentException& e) {
- // OK
- }
+ EXPECT_THROW(calc.evaluate(doc, std::move(variables)),
+ vespalib::IllegalArgumentException);
}
-void
-DocumentCalculatorTest::testModByZero() {
+TEST_F(DocumentCalculatorTest, testModByZero) {
auto variables = std::make_unique<select::VariableMap>();
DocumentCalculator calc(getRepo(), "(3 + 5) % 0");
Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("doc:test:foo"));
- try {
- calc.evaluate(doc, std::move(variables));
- CPPUNIT_ASSERT(false);
- } catch (const vespalib::IllegalArgumentException& e) {
- // OK
- }
+ EXPECT_THROW(calc.evaluate(doc, std::move(variables)),
+ vespalib::IllegalArgumentException);
}
-void
-DocumentCalculatorTest::testFieldNotSet() {
+TEST_F(DocumentCalculatorTest, testFieldNotSet) {
auto variables = std::make_unique<select::VariableMap>();
DocumentCalculator calc(getRepo(), "(testdoctype1.headerval + testdoctype1"
".hfloatval) / testdoctype1.headerlongval");
@@ -152,16 +101,11 @@ DocumentCalculatorTest::testFieldNotSet() {
Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("doc:test:foo"));
doc.setValue(doc.getField("hfloatval"), FloatFieldValue(3.0));
doc.setValue(doc.getField("headerlongval"), LongFieldValue(2));
- try {
- calc.evaluate(doc, std::move(variables));
- CPPUNIT_ASSERT(false);
- } catch (const vespalib::IllegalArgumentException&) {
- // OK
- }
+ EXPECT_THROW(calc.evaluate(doc, std::move(variables)),
+ vespalib::IllegalArgumentException);
}
-void
-DocumentCalculatorTest::testFieldNotFound() {
+TEST_F(DocumentCalculatorTest, testFieldNotFound) {
auto variables = std::make_unique<select::VariableMap>();
DocumentCalculator calc(getRepo(),
"(testdoctype1.mynotfoundfield + testdoctype1"
@@ -170,22 +114,17 @@ DocumentCalculatorTest::testFieldNotFound() {
Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("doc:test:foo"));
doc.setValue(doc.getField("hfloatval"), FloatFieldValue(3.0));
doc.setValue(doc.getField("headerlongval"), LongFieldValue(2));
- try {
- calc.evaluate(doc, std::move(variables));
- CPPUNIT_ASSERT(false);
- } catch (const vespalib::IllegalArgumentException&) {
- // OK
- }
+ EXPECT_THROW(calc.evaluate(doc, std::move(variables)),
+ vespalib::IllegalArgumentException);
}
-void
-DocumentCalculatorTest::testByteSubtractionZeroResult() {
+TEST_F(DocumentCalculatorTest, testByteSubtractionZeroResult) {
auto variables = std::make_unique<select::VariableMap>();
DocumentCalculator calc(getRepo(), "testdoctype1.byteval - 3");
Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("doc:test:foo"));
doc.setValue(doc.getField("byteval"), ByteFieldValue(3));
- CPPUNIT_ASSERT_EQUAL(0.0, calc.evaluate(doc, std::move(variables)));
+ EXPECT_EQ(0.0, calc.evaluate(doc, std::move(variables)));
}
}
diff --git a/document/src/tests/gtest_runner.cpp b/document/src/tests/gtest_runner.cpp
index fed042acceb..7a55e8a098e 100644
--- a/document/src/tests/gtest_runner.cpp
+++ b/document/src/tests/gtest_runner.cpp
@@ -5,4 +5,4 @@
#include <vespa/log/log.h>
LOG_SETUP("document_gtest_runner");
-GTEST_MAIN_RUN_ALL_TESTS
+GTEST_MAIN_RUN_ALL_TESTS()
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();
-
-};
-
-