summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorGeir Storli <geirst@verizonmedia.com>2019-03-01 12:36:55 +0000
committerGeir Storli <geirst@verizonmedia.com>2019-03-01 12:36:55 +0000
commit9b7a751309080c04f593aaec0dbc162a30d1225b (patch)
treebd1b8f52bbab169b6efab56a927e0e271bc5d60b /document
parent635eab7943e37d2e2e6b126c01831ab36633047d (diff)
Migrate unit test from cppunit to gtest.
Diffstat (limited to 'document')
-rw-r--r--document/src/tests/CMakeLists.txt2
-rw-r--r--document/src/tests/documentcalculatortestcase.cpp125
2 files changed, 33 insertions, 94 deletions
diff --git a/document/src/tests/CMakeLists.txt b/document/src/tests/CMakeLists.txt
index 2fff6722a8c..ccf25b17061 100644
--- a/document/src/tests/CMakeLists.txt
+++ b/document/src/tests/CMakeLists.txt
@@ -4,6 +4,7 @@
# 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
@@ -25,7 +26,6 @@ vespa_add_executable(document_testrunner_app TEST
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..e5d75f1bd46 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)));
}
}