summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@broadpark.no>2019-04-16 08:56:00 +0200
committerTor Egge <Tor.Egge@broadpark.no>2019-04-16 11:08:52 +0200
commit7dd0e264a2778660ec22fdcad98e0118acf39d9e (patch)
tree44030a97fb7e947bf968cd2f87e77974609fda76 /document
parent5ab193575090efa10cc5aa07744ad457e1af973f (diff)
Migrate document unit tests from cppunit to gtest.
Diffstat (limited to 'document')
-rw-r--r--document/src/tests/CMakeLists.txt24
-rw-r--r--document/src/tests/arrayfieldvaluetest.cpp138
-rw-r--r--document/src/tests/arrayfieldvaluetest.h29
-rw-r--r--document/src/tests/bucketselectortest.cpp28
-rw-r--r--document/src/tests/buckettest.cpp220
-rw-r--r--document/src/tests/documentselectparsertest.cpp264
-rw-r--r--document/src/tests/documentselecttest.h34
-rw-r--r--document/src/tests/documenttestcase.cpp459
-rw-r--r--document/src/tests/documenttypetestcase.cpp138
-rw-r--r--document/src/tests/fieldpathupdatetestcase.cpp429
-rw-r--r--document/src/tests/fieldsettest.cpp176
-rw-r--r--document/src/tests/fixed_bucket_spaces_test.cpp56
-rw-r--r--document/src/tests/forcelinktest.cpp15
-rw-r--r--document/src/tests/gid_filter_test.cpp282
-rw-r--r--document/src/tests/globalidtest.cpp145
15 files changed, 977 insertions, 1460 deletions
diff --git a/document/src/tests/CMakeLists.txt b/document/src/tests/CMakeLists.txt
index bb668287a8c..9de4e8cc7d0 100644
--- a/document/src/tests/CMakeLists.txt
+++ b/document/src/tests/CMakeLists.txt
@@ -4,9 +4,21 @@
# NOTE: All new test classes should be added here.
vespa_add_executable(document_gtest_runner_app TEST
SOURCES
+ arrayfieldvaluetest.cpp
+ bucketselectortest.cpp
+ buckettest.cpp
documentcalculatortestcase.cpp
documentidtest.cpp
+ documentselectparsertest.cpp
+ documenttestcase.cpp
+ documenttypetestcase.cpp
documentupdatetestcase.cpp
+ fieldpathupdatetestcase.cpp
+ fieldsettest.cpp
+ fixed_bucket_spaces_test.cpp
+ forcelinktest.cpp
+ gid_filter_test.cpp
+ globalidtest.cpp
gtest_runner.cpp
teststringutil.cpp
DEPENDS
@@ -26,28 +38,16 @@ vespa_add_executable(document_testrunner_app TEST
SOURCES
testbytebuffer.cpp
stringtokenizertest.cpp
- buckettest.cpp
- globalidtest.cpp
- documenttypetestcase.cpp
primitivefieldvaluetest.cpp
- arrayfieldvaluetest.cpp
weightedsetfieldvaluetest.cpp
structfieldvaluetest.cpp
- documenttestcase.cpp
testdocmantest.cpp
- fieldpathupdatetestcase.cpp
- documentselectparsertest.cpp
- bucketselectortest.cpp
testxml.cpp
- forcelinktest.cpp
orderingselectortest.cpp
testrunner.cpp
heapdebuggerother.cpp
positiontypetest.cpp
urltypetest.cpp
- fieldsettest.cpp
- gid_filter_test.cpp
- fixed_bucket_spaces_test.cpp
DEPENDS
document
AFTER
diff --git a/document/src/tests/arrayfieldvaluetest.cpp b/document/src/tests/arrayfieldvaluetest.cpp
index 74243ab1511..014884e44cd 100644
--- a/document/src/tests/arrayfieldvaluetest.cpp
+++ b/document/src/tests/arrayfieldvaluetest.cpp
@@ -2,26 +2,17 @@
#include <vespa/document/fieldvalue/fieldvalues.h>
#include <vespa/document/serialization/vespadocumentdeserializer.h>
-#include <vespa/vdstestlib/cppunit/macros.h>
#include <vespa/vespalib/objects/nbostream.h>
#include <vespa/document/util/bytebuffer.h>
#include <vespa/document/repo/documenttyperepo.h>
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
using vespalib::nbostream;
+using namespace ::testing;
namespace document {
-struct ArrayFieldValueTest : public CppUnit::TestFixture {
- void testArray();
-
- CPPUNIT_TEST_SUITE(ArrayFieldValueTest);
- CPPUNIT_TEST(testArray);
- CPPUNIT_TEST_SUITE_END();
-
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(ArrayFieldValueTest);
-
namespace {
template <typename T>
void deserialize(const ByteBuffer &buffer, T &value) {
@@ -33,41 +24,41 @@ void deserialize(const ByteBuffer &buffer, T &value) {
}
} // namespace
-void ArrayFieldValueTest::testArray()
+TEST(ArrayFieldValueTest, testArray)
{
ArrayDataType type(*DataType::INT);
ArrayFieldValue value(type);
// Initially empty
- CPPUNIT_ASSERT_EQUAL(size_t(0), value.size());
- CPPUNIT_ASSERT(value.isEmpty());
- CPPUNIT_ASSERT(!value.contains(IntFieldValue(1)));
+ EXPECT_EQ(size_t(0), value.size());
+ EXPECT_TRUE(value.isEmpty());
+ EXPECT_TRUE(!value.contains(IntFieldValue(1)));
- CPPUNIT_ASSERT(value.add(IntFieldValue(1)));
+ EXPECT_TRUE(value.add(IntFieldValue(1)));
// Not empty
- CPPUNIT_ASSERT_EQUAL(size_t(1), value.size());
- CPPUNIT_ASSERT(!value.isEmpty());
- CPPUNIT_ASSERT(value.contains(IntFieldValue(1)));
+ EXPECT_EQ(size_t(1), value.size());
+ EXPECT_TRUE(!value.isEmpty());
+ EXPECT_TRUE(value.contains(IntFieldValue(1)));
// Adding some more
- CPPUNIT_ASSERT(value.add(IntFieldValue(2)));
- CPPUNIT_ASSERT(value.add(IntFieldValue(3)));
+ EXPECT_TRUE(value.add(IntFieldValue(2)));
+ EXPECT_TRUE(value.add(IntFieldValue(3)));
// Not empty
- CPPUNIT_ASSERT_EQUAL(size_t(3), value.size());
- CPPUNIT_ASSERT(!value.isEmpty());
- CPPUNIT_ASSERT_EQUAL(IntFieldValue(1), (IntFieldValue&) value[0]);
- CPPUNIT_ASSERT_EQUAL(IntFieldValue(2), (IntFieldValue&) value[1]);
- CPPUNIT_ASSERT_EQUAL(IntFieldValue(3), (IntFieldValue&) value[2]);
+ ASSERT_EQ(size_t(3), value.size());
+ EXPECT_TRUE(!value.isEmpty());
+ EXPECT_EQ(IntFieldValue(1), (IntFieldValue&) value[0]);
+ EXPECT_EQ(IntFieldValue(2), (IntFieldValue&) value[1]);
+ EXPECT_EQ(IntFieldValue(3), (IntFieldValue&) value[2]);
// Serialize & equality
std::unique_ptr<ByteBuffer> buffer(value.serialize());
buffer->flip();
ArrayFieldValue value2(type);
- CPPUNIT_ASSERT(value != value2);
+ EXPECT_TRUE(value != value2);
deserialize(*buffer, value2);
- CPPUNIT_ASSERT_EQUAL(value, value2);
+ EXPECT_EQ(value, value2);
// Various ways of removing
{
@@ -75,44 +66,44 @@ void ArrayFieldValueTest::testArray()
buffer->setPos(0);
deserialize(*buffer, value2);
value2.remove(1);
- CPPUNIT_ASSERT(!value2.contains(IntFieldValue(2)));
- CPPUNIT_ASSERT_EQUAL(size_t(2), value2.size());
+ EXPECT_TRUE(!value2.contains(IntFieldValue(2)));
+ EXPECT_EQ(size_t(2), value2.size());
// By value
buffer->setPos(0);
deserialize(*buffer, value2);
- CPPUNIT_ASSERT(value2.remove(IntFieldValue(1)));
- CPPUNIT_ASSERT(!value2.contains(IntFieldValue(1)));
- CPPUNIT_ASSERT_EQUAL(size_t(2), value2.size());
+ EXPECT_TRUE(value2.remove(IntFieldValue(1)));
+ EXPECT_TRUE(!value2.contains(IntFieldValue(1)));
+ EXPECT_EQ(size_t(2), value2.size());
// By value with multiple present
buffer->setPos(0);
deserialize(*buffer, value2);
value2.add(IntFieldValue(1));
- CPPUNIT_ASSERT(value2.remove(IntFieldValue(1)));
- CPPUNIT_ASSERT(!value2.contains(IntFieldValue(1)));
- CPPUNIT_ASSERT_EQUAL(size_t(2), value2.size());
+ EXPECT_TRUE(value2.remove(IntFieldValue(1)));
+ EXPECT_TRUE(!value2.contains(IntFieldValue(1)));
+ EXPECT_EQ(size_t(2), value2.size());
// Clearing all
buffer->setPos(0);
deserialize(*buffer, value2);
value2.clear();
- CPPUNIT_ASSERT(!value2.contains(IntFieldValue(1)));
- CPPUNIT_ASSERT_EQUAL(size_t(0), value2.size());
- CPPUNIT_ASSERT(value2.isEmpty());
+ EXPECT_TRUE(!value2.contains(IntFieldValue(1)));
+ EXPECT_EQ(size_t(0), value2.size());
+ EXPECT_TRUE(value2.isEmpty());
}
// Updating
value2 = value;
- CPPUNIT_ASSERT_EQUAL(value, value2);
+ EXPECT_EQ(value, value2);
value2[1].assign(IntFieldValue(5));
- CPPUNIT_ASSERT(!value2.contains(IntFieldValue(2)));
- CPPUNIT_ASSERT_EQUAL(IntFieldValue(5), (IntFieldValue&) value2[1]);
- CPPUNIT_ASSERT(value != value2);
+ EXPECT_TRUE(!value2.contains(IntFieldValue(2)));
+ EXPECT_EQ(IntFieldValue(5), (IntFieldValue&) value2[1]);
+ EXPECT_TRUE(value != value2);
value2.assign(value);
- CPPUNIT_ASSERT_EQUAL(value, value2);
+ EXPECT_EQ(value, value2);
ArrayFieldValue::UP valuePtr(value2.clone());
- CPPUNIT_ASSERT_EQUAL(value, *valuePtr);
+ EXPECT_EQ(value, *valuePtr);
// Iterating
const ArrayFieldValue& constVal(value);
@@ -121,7 +112,7 @@ void ArrayFieldValueTest::testArray()
{
const FieldValue& fval1(*it);
(void) fval1;
- CPPUNIT_ASSERT_EQUAL((uint32_t) IntFieldValue::classId,
+ EXPECT_EQ((uint32_t) IntFieldValue::classId,
it->getClass().id());
}
value2 = value;
@@ -130,28 +121,28 @@ void ArrayFieldValueTest::testArray()
(*it).assign(IntFieldValue(7));
it->assign(IntFieldValue(7));
}
- CPPUNIT_ASSERT(value != value2);
- CPPUNIT_ASSERT(value2.contains(IntFieldValue(7)));
- CPPUNIT_ASSERT(value2.remove(IntFieldValue(7)));
- CPPUNIT_ASSERT(value2.isEmpty());
+ EXPECT_TRUE(value != value2);
+ EXPECT_TRUE(value2.contains(IntFieldValue(7)));
+ EXPECT_TRUE(value2.remove(IntFieldValue(7)));
+ EXPECT_TRUE(value2.isEmpty());
// Comparison
value2 = value;
- CPPUNIT_ASSERT_EQUAL(0, value.compare(value2));
+ EXPECT_EQ(0, value.compare(value2));
value2.remove(1);
- CPPUNIT_ASSERT(value.compare(value2) > 0);
- CPPUNIT_ASSERT(value2.compare(value) < 0);
+ EXPECT_TRUE(value.compare(value2) > 0);
+ EXPECT_TRUE(value2.compare(value) < 0);
value2 = value;
value2[1].assign(IntFieldValue(5));
- CPPUNIT_ASSERT(value.compare(value2) < 0);
- CPPUNIT_ASSERT(value2.compare(value) > 0);
+ EXPECT_TRUE(value.compare(value2) < 0);
+ EXPECT_TRUE(value2.compare(value) > 0);
// Output
- CPPUNIT_ASSERT_EQUAL(std::string("Array(size: 3,\n 1,\n 2,\n 3\n)"),
+ EXPECT_EQ(std::string("Array(size: 3,\n 1,\n 2,\n 3\n)"),
value.toString(false));
- CPPUNIT_ASSERT_EQUAL(std::string("Array(size: 3,\n. 1,\n. 2,\n. 3\n.)"),
+ EXPECT_EQ(std::string("Array(size: 3,\n. 1,\n. 2,\n. 3\n.)"),
value.toString(true, "."));
- CPPUNIT_ASSERT_EQUAL(std::string(
+ EXPECT_EQ(std::string(
"<value>\n"
" <item>1</item>\n"
" <item>2</item>\n"
@@ -172,39 +163,39 @@ void ArrayFieldValueTest::testArray()
ArrayFieldValue value4(type4);
try{
value3 = value4;
- CPPUNIT_FAIL("Failed to check type equality in operator=");
+ FAIL() << "Failed to check type equality in operator=";
} catch (std::exception& e) {
- CPPUNIT_ASSERT_CONTAIN("Cannot assign value of type", e.what());
+ EXPECT_THAT(e.what(), HasSubstr("Cannot assign value of type"));
}
try{
value3.assign(value4);
- CPPUNIT_FAIL("Failed to check type equality in assign()");
+ FAIL() << "Failed to check type equality in assign()";
} catch (std::exception& e) {
- CPPUNIT_ASSERT_CONTAIN("Cannot assign value of type", e.what());
+ EXPECT_THAT(e.what(), HasSubstr("Cannot assign value of type"));
}
try{
ArrayFieldValue subValue(type2);
subValue.add(LongFieldValue(4));
value3.add(subValue);
- CPPUNIT_FAIL("Failed to check type equality in add()");
+ FAIL() << "Failed to check type equality in add()";
} catch (std::exception& e) {
- CPPUNIT_ASSERT_CONTAIN("Cannot add value of type",e.what());
+ EXPECT_THAT(e.what(), HasSubstr("Cannot add value of type"));
}
try{
ArrayFieldValue subValue(type2);
subValue.add(LongFieldValue(4));
value3.contains(subValue);
- CPPUNIT_FAIL("Failed to check type equality in contains()");
+ FAIL() << "Failed to check type equality in contains()";
} catch (std::exception& e) {
- CPPUNIT_ASSERT_CONTAIN("can't possibly be in array of type", e.what());
+ EXPECT_THAT(e.what(), HasSubstr("can't possibly be in array of type"));
}
try{
ArrayFieldValue subValue(type2);
subValue.add(LongFieldValue(4));
value3.remove(subValue);
- CPPUNIT_FAIL("Failed to check type equality in remove()");
+ FAIL() << "Failed to check type equality in remove()";
} catch (std::exception& e) {
- CPPUNIT_ASSERT_CONTAIN("can't possibly be in array of type", e.what());
+ EXPECT_THAT(e.what(), HasSubstr("can't possibly be in array of type"));
}
// Verify that compare sees difference
{
@@ -216,19 +207,18 @@ void ArrayFieldValueTest::testArray()
value4.clear();
value3.add(subValue1);
value4.add(subValue2);
- CPPUNIT_ASSERT(value3.compare(value4) != 0);
+ EXPECT_TRUE(value3.compare(value4) != 0);
}
// Removing non-existing element
value2 = value;
try{
value2.remove(5);
- CPPUNIT_FAIL("Failed to throw out of bounds exception on remove(int)");
+ FAIL() << "Failed to throw out of bounds exception on remove(int)";
} catch (std::exception& e) {
- CPPUNIT_ASSERT_CONTAIN("Cannot remove index 5 from an array of size 3",
- e.what());
+ EXPECT_THAT(e.what(), HasSubstr("Cannot remove index 5 from an array of size 3"));
}
- CPPUNIT_ASSERT(!value2.remove(IntFieldValue(15)));
+ EXPECT_TRUE(!value2.remove(IntFieldValue(15)));
}
} // document
diff --git a/document/src/tests/arrayfieldvaluetest.h b/document/src/tests/arrayfieldvaluetest.h
deleted file mode 100644
index b8ae6a20b8d..00000000000
--- a/document/src/tests/arrayfieldvaluetest.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-/* $Id$*/
-
-#pragma once
-
-#include <cppunit/extensions/HelperMacros.h>
-
-class ArrayFieldValue_Test : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE( ArrayFieldValue_Test);
- CPPUNIT_TEST(testArray);
- CPPUNIT_TEST(testArray2);
- CPPUNIT_TEST(testArrayRaw);
- CPPUNIT_TEST(testTextSerialize);
- CPPUNIT_TEST(testArrayRemove);
- CPPUNIT_TEST_SUITE_END();
-
-public:
- void setUp();
-
- void tearDown();
-protected:
- void testArray();
- void testArray2();
- void testArrayRaw();
- void testTextSerialize();
- void testArrayRemove();
-};
-
-
diff --git a/document/src/tests/bucketselectortest.cpp b/document/src/tests/bucketselectortest.cpp
index e0857a32dba..fcd254a9fc6 100644
--- a/document/src/tests/bucketselectortest.cpp
+++ b/document/src/tests/bucketselectortest.cpp
@@ -3,26 +3,18 @@
#include <vespa/document/bucket/bucketselector.h>
#include <vespa/document/bucket/bucketid.h>
-#include <vespa/vdstestlib/cppunit/macros.h>
#include <vespa/document/select/parser.h>
#include <vespa/document/base/testdocrepo.h>
+#include <vespa/vespalib/test/insertion_operators.h>
#include <algorithm>
+#include <iostream>
+#include <gtest/gtest.h>
using document::select::Node;
using document::select::Parser;
namespace document {
-struct BucketSelectorTest : public CppUnit::TestFixture {
- void testSimple();
-
- CPPUNIT_TEST_SUITE(BucketSelectorTest);
- CPPUNIT_TEST(testSimple);
- CPPUNIT_TEST_SUITE_END();
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(BucketSelectorTest);
-
#define ASSERT_BUCKET_COUNT(expression, count) \
{ \
TestDocRepo testRepo; \
@@ -30,14 +22,14 @@ CPPUNIT_TEST_SUITE_REGISTRATION(BucketSelectorTest);
BucketSelector selector(idfactory); \
Parser parser(testRepo.getTypeRepo(), idfactory); \
std::unique_ptr<Node> node(parser.parse(expression)); \
- CPPUNIT_ASSERT(node.get() != 0); \
+ ASSERT_TRUE(node.get() != 0); \
std::unique_ptr<BucketSelector::BucketVector> buckets( \
selector.select(*node)); \
size_t bcount(buckets.get() ? buckets->size() : 0); \
std::ostringstream ost; \
ost << "Expression " << expression << " did not contain " << count \
<< " buckets as expected"; \
- CPPUNIT_ASSERT_EQUAL_MSG(ost.str(), (size_t) count, bcount); \
+ EXPECT_EQ((size_t) count, bcount) << ost.str(); \
}
#define ASSERT_BUCKET(expression, bucket) \
@@ -47,7 +39,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(BucketSelectorTest);
BucketSelector selector(idfactory); \
Parser parser(testRepo.getTypeRepo(), idfactory); \
std::unique_ptr<Node> node(parser.parse(expression)); \
- CPPUNIT_ASSERT(node.get() != 0); \
+ ASSERT_TRUE(node.get() != 0); \
std::unique_ptr<BucketSelector::BucketVector> buckets( \
selector.select(*node)); \
std::ostringstream ost; \
@@ -58,12 +50,12 @@ CPPUNIT_TEST_SUITE_REGISTRATION(BucketSelectorTest);
} else { \
ost << ". Matches all buckets"; \
} \
- CPPUNIT_ASSERT_MSG(ost.str(), buckets.get() && \
- std::find(buckets->begin(), buckets->end(), \
- bucket) != buckets->end()); \
+ EXPECT_TRUE(buckets.get() && \
+ std::find(buckets->begin(), buckets->end(), \
+ bucket) != buckets->end()) << ost.str(); \
}
-void BucketSelectorTest::testSimple()
+TEST(BucketSelectorTest, testSimple)
{
ASSERT_BUCKET_COUNT("id = \"userdoc:ns:123:foobar\"", 1u);
ASSERT_BUCKET_COUNT("id = \"userdoc:ns:123:foo*\"", 0u);
diff --git a/document/src/tests/buckettest.cpp b/document/src/tests/buckettest.cpp
index 2aae0c87102..3de6d02b4b3 100644
--- a/document/src/tests/buckettest.cpp
+++ b/document/src/tests/buckettest.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/document/bucket/bucketidfactory.h>
#include <vespa/document/base/documentid.h>
#include <vespa/vespalib/util/random.h>
#include <vespa/document/bucket/bucketspace.h>
#include <vespa/document/bucket/bucket.h>
+#include <gtest/gtest.h>
namespace document {
-class BucketTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(BucketTest);
- CPPUNIT_TEST(testBucketId);
- CPPUNIT_TEST(testBucketGeneration);
- CPPUNIT_TEST(testBucketSerialization);
- CPPUNIT_TEST(testReverseBucket);
- CPPUNIT_TEST(testContains);
- CPPUNIT_TEST(testGetBit);
- CPPUNIT_TEST(testToString);
- CPPUNIT_TEST(testOperators);
- CPPUNIT_TEST_SUITE_END();
-
-public:
- void testBucketId();
- void testBucketGeneration();
- void testBucketSerialization();
- void testReverseBucket();
- void testContains();
- void testGetBit();
- void testToString();
- void testOperators();
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(BucketTest);
-
struct Hex {
BucketId::Type val;
@@ -46,62 +21,62 @@ inline std::ostream& operator<<(std::ostream& out, const Hex& h) {
return out;
}
-void BucketTest::testBucketId()
+TEST(BucketTest, testBucketId)
{
// Test empty (invalid) buckets
BucketId id1;
BucketId id2;
- CPPUNIT_ASSERT_EQUAL(id1, id2);
- CPPUNIT_ASSERT(!(id1 < id2) && !(id2 < id1));
- CPPUNIT_ASSERT_EQUAL(Hex(0), Hex(id1.getId()));
- CPPUNIT_ASSERT_EQUAL(Hex(0), Hex(id1.getRawId()));
- CPPUNIT_ASSERT_EQUAL(vespalib::string("BucketId(0x0000000000000000)"),
+ EXPECT_EQ(id1, id2);
+ EXPECT_TRUE(!(id1 < id2) && !(id2 < id1));
+ EXPECT_EQ(Hex(0), Hex(id1.getId()));
+ EXPECT_EQ(Hex(0), Hex(id1.getRawId()));
+ EXPECT_EQ(vespalib::string("BucketId(0x0000000000000000)"),
id1.toString());
- CPPUNIT_ASSERT_EQUAL(0u, id1.getUsedBits());
+ EXPECT_EQ(0u, id1.getUsedBits());
// Test bucket with a value
id2 = BucketId((BucketId::Type(16) << 58) | 0x123);
- CPPUNIT_ASSERT(id1 != id2);
- CPPUNIT_ASSERT((id1 < id2) && !(id2 < id1));
- CPPUNIT_ASSERT_EQUAL(Hex(0x4000000000000123ull), Hex(id2.getId()));
- CPPUNIT_ASSERT_EQUAL(Hex(0x4000000000000123ull), Hex(id2.getRawId()));
- CPPUNIT_ASSERT_EQUAL(vespalib::string("BucketId(0x4000000000000123)"),
- id2.toString());
- CPPUNIT_ASSERT_EQUAL(16u, id2.getUsedBits());
+ EXPECT_TRUE(id1 != id2);
+ EXPECT_TRUE((id1 < id2) && !(id2 < id1));
+ EXPECT_EQ(Hex(0x4000000000000123ull), Hex(id2.getId()));
+ EXPECT_EQ(Hex(0x4000000000000123ull), Hex(id2.getRawId()));
+ EXPECT_EQ(vespalib::string("BucketId(0x4000000000000123)"),
+ id2.toString());
+ EXPECT_EQ(16u, id2.getUsedBits());
// Test copy constructor and operator=
BucketId id3(id2);
- CPPUNIT_ASSERT_EQUAL(id2, id3);
+ EXPECT_EQ(id2, id3);
id3 = id1;
- CPPUNIT_ASSERT(!(id2 == id3));
+ EXPECT_TRUE(!(id2 == id3));
id3 = id2;
- CPPUNIT_ASSERT_EQUAL(id2, id3);
+ EXPECT_EQ(id2, id3);
}
-void BucketTest::testGetBit()
+TEST(BucketTest, testGetBit)
{
for (uint32_t i = 0; i < 58; ++i) {
- CPPUNIT_ASSERT_EQUAL(0, (int)document::BucketId(16, 0).getBit(i));
+ EXPECT_EQ(0, (int)document::BucketId(16, 0).getBit(i));
}
for (uint32_t i = 0; i < 4; ++i) {
- CPPUNIT_ASSERT_EQUAL(0, (int)document::BucketId(16, 16).getBit(i));
+ EXPECT_EQ(0, (int)document::BucketId(16, 16).getBit(i));
}
- CPPUNIT_ASSERT_EQUAL(1, (int)document::BucketId(16, 16).getBit(4));
+ EXPECT_EQ(1, (int)document::BucketId(16, 16).getBit(4));
for (uint32_t i = 5; i < 59; ++i) {
- CPPUNIT_ASSERT_EQUAL(0, (int)document::BucketId(16, 16).getBit(i));
+ EXPECT_EQ(0, (int)document::BucketId(16, 16).getBit(i));
}
- CPPUNIT_ASSERT_EQUAL(0, (int)document::BucketId(17, 0x0ffff).getBit(16));
+ EXPECT_EQ(0, (int)document::BucketId(17, 0x0ffff).getBit(16));
for (uint32_t i = 0; i < 16; ++i) {
- CPPUNIT_ASSERT_EQUAL(1, (int)document::BucketId(17, 0x0ffff).getBit(i));
+ EXPECT_EQ(1, (int)document::BucketId(17, 0x0ffff).getBit(i));
}
}
-void BucketTest::testBucketGeneration()
+TEST(BucketTest, testBucketGeneration)
{
BucketIdFactory factory;
DocumentId doc1("doc:ns:spec");
@@ -136,49 +111,49 @@ void BucketTest::testBucketGeneration()
BucketId orderDocBucket5(factory.getBucketId(orderDoc5));
BucketId orderDocBucket6(factory.getBucketId(orderDoc6));
- CPPUNIT_ASSERT_EQUAL(Hex(0xe99703f200000012ull), Hex(userDocBucket1.getRawId()));
- CPPUNIT_ASSERT_EQUAL(Hex(0xebfa518a00000012ull), Hex(userDocBucket2.getRawId()));
- CPPUNIT_ASSERT_EQUAL(Hex(0xeac1850800000013ull), Hex(userDocBucket3.getRawId()));
+ EXPECT_EQ(Hex(0xe99703f200000012ull), Hex(userDocBucket1.getRawId()));
+ EXPECT_EQ(Hex(0xebfa518a00000012ull), Hex(userDocBucket2.getRawId()));
+ EXPECT_EQ(Hex(0xeac1850800000013ull), Hex(userDocBucket3.getRawId()));
- CPPUNIT_ASSERT_EQUAL(Hex(0xeae764e90000000dull), Hex(orderDocBucket1.getRawId()));
- CPPUNIT_ASSERT_EQUAL(Hex(0xeacb85f10000000dull), Hex(orderDocBucket2.getRawId()));
- CPPUNIT_ASSERT_EQUAL(Hex(0xea68ddf10000000dull), Hex(orderDocBucket3.getRawId()));
+ EXPECT_EQ(Hex(0xeae764e90000000dull), Hex(orderDocBucket1.getRawId()));
+ EXPECT_EQ(Hex(0xeacb85f10000000dull), Hex(orderDocBucket2.getRawId()));
+ EXPECT_EQ(Hex(0xea68ddf10000000dull), Hex(orderDocBucket3.getRawId()));
- CPPUNIT_ASSERT_EQUAL(Hex(0xe87526540000000dull), Hex(orderDocBucket4.getRawId()));
- CPPUNIT_ASSERT_EQUAL(Hex(0xea59f8f20000000dull), Hex(orderDocBucket5.getRawId()));
- CPPUNIT_ASSERT_EQUAL(Hex(0xe9eb703d0000000dull), Hex(orderDocBucket6.getRawId()));
+ EXPECT_EQ(Hex(0xe87526540000000dull), Hex(orderDocBucket4.getRawId()));
+ EXPECT_EQ(Hex(0xea59f8f20000000dull), Hex(orderDocBucket5.getRawId()));
+ EXPECT_EQ(Hex(0xe9eb703d0000000dull), Hex(orderDocBucket6.getRawId()));
userDocBucket1.setUsedBits(16);
- CPPUNIT_ASSERT_EQUAL(Hex(0x4000000000000012ull), Hex(userDocBucket1.getId()));
+ EXPECT_EQ(Hex(0x4000000000000012ull), Hex(userDocBucket1.getId()));
userDocBucket2.setUsedBits(16);
- CPPUNIT_ASSERT_EQUAL(Hex(0x4000000000000012ull), Hex(userDocBucket2.getId()));
+ EXPECT_EQ(Hex(0x4000000000000012ull), Hex(userDocBucket2.getId()));
userDocBucket3.setUsedBits(16);
- CPPUNIT_ASSERT_EQUAL(Hex(0x4000000000000013ull), Hex(userDocBucket3.getId()));
+ EXPECT_EQ(Hex(0x4000000000000013ull), Hex(userDocBucket3.getId()));
- CPPUNIT_ASSERT_EQUAL(Hex(0xe90ce4b09a1acd50ull), Hex(groupDocBucket1.getRawId()));
- CPPUNIT_ASSERT_EQUAL(Hex(0xe9cedaa49a1acd50ull), Hex(groupDocBucket2.getRawId()));
- CPPUNIT_ASSERT_EQUAL(Hex(0xe8cdb18bafe81f24ull), Hex(groupDocBucket3.getRawId()));
+ EXPECT_EQ(Hex(0xe90ce4b09a1acd50ull), Hex(groupDocBucket1.getRawId()));
+ EXPECT_EQ(Hex(0xe9cedaa49a1acd50ull), Hex(groupDocBucket2.getRawId()));
+ EXPECT_EQ(Hex(0xe8cdb18bafe81f24ull), Hex(groupDocBucket3.getRawId()));
groupDocBucket1.setUsedBits(16);
- CPPUNIT_ASSERT_EQUAL(Hex(0x400000000000cd50ull), Hex(groupDocBucket1.getId()));
+ EXPECT_EQ(Hex(0x400000000000cd50ull), Hex(groupDocBucket1.getId()));
groupDocBucket2.setUsedBits(16);
- CPPUNIT_ASSERT_EQUAL(Hex(0x400000000000cd50ull), Hex(groupDocBucket2.getId()));
+ EXPECT_EQ(Hex(0x400000000000cd50ull), Hex(groupDocBucket2.getId()));
groupDocBucket3.setUsedBits(16);
- CPPUNIT_ASSERT_EQUAL(Hex(0x4000000000001f24ull), Hex(groupDocBucket3.getId()));
+ EXPECT_EQ(Hex(0x4000000000001f24ull), Hex(groupDocBucket3.getId()));
- CPPUNIT_ASSERT_EQUAL(Hex(0xe980c9abd5fd8d11ull), Hex(docBucket1.getRawId()));
- CPPUNIT_ASSERT_EQUAL(Hex(0xeafe870c5f9c37b9ull), Hex(docBucket2.getRawId()));
- CPPUNIT_ASSERT_EQUAL(Hex(0xeaebe9473ecbcd69ull), Hex(docBucket3.getRawId()));
+ EXPECT_EQ(Hex(0xe980c9abd5fd8d11ull), Hex(docBucket1.getRawId()));
+ EXPECT_EQ(Hex(0xeafe870c5f9c37b9ull), Hex(docBucket2.getRawId()));
+ EXPECT_EQ(Hex(0xeaebe9473ecbcd69ull), Hex(docBucket3.getRawId()));
docBucket1.setUsedBits(16);
- CPPUNIT_ASSERT_EQUAL(Hex(0x4000000000008d11ull), Hex(docBucket1.getId()));
+ EXPECT_EQ(Hex(0x4000000000008d11ull), Hex(docBucket1.getId()));
docBucket2.setUsedBits(16);
- CPPUNIT_ASSERT_EQUAL(Hex(0x40000000000037b9ull), Hex(docBucket2.getId()));
+ EXPECT_EQ(Hex(0x40000000000037b9ull), Hex(docBucket2.getId()));
docBucket3.setUsedBits(16);
- CPPUNIT_ASSERT_EQUAL(Hex(0x400000000000cd69ull), Hex(docBucket3.getId()));
+ EXPECT_EQ(Hex(0x400000000000cd69ull), Hex(docBucket3.getId()));
}
-void BucketTest::testBucketSerialization()
+TEST(BucketTest, testBucketSerialization)
{
BucketIdFactory factory;
DocumentId doc(DocIdString("ns", "spec"));
@@ -186,7 +161,7 @@ void BucketTest::testBucketSerialization()
std::ostringstream ost;
ost << bucket.getRawId();
- CPPUNIT_ASSERT_EQUAL(std::string("16825669947722927377"),
+ EXPECT_EQ(std::string("16825669947722927377"),
ost.str());
BucketId::Type id;
@@ -194,96 +169,99 @@ void BucketTest::testBucketSerialization()
ist >> id;
BucketId bucket2(id);
- CPPUNIT_ASSERT_EQUAL(bucket, bucket2);
+ EXPECT_EQ(bucket, bucket2);
}
-void BucketTest::testReverseBucket()
+TEST(BucketTest, testReverseBucket)
{
{
BucketId id(0x3000000000000012ull);
- CPPUNIT_ASSERT_EQUAL(Hex(0x480000000000000cull), Hex(id.toKey()));
- CPPUNIT_ASSERT_EQUAL(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
+ EXPECT_EQ(Hex(0x480000000000000cull), Hex(id.toKey()));
+ EXPECT_EQ(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
}
{
BucketId id(0x4000000000000012ull);
- CPPUNIT_ASSERT_EQUAL(Hex(0x4800000000000010ull), Hex(id.toKey()));
- CPPUNIT_ASSERT_EQUAL(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
+ EXPECT_EQ(Hex(0x4800000000000010ull), Hex(id.toKey()));
+ EXPECT_EQ(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
}
{
BucketId id(0x600000000000ffffull);
- CPPUNIT_ASSERT_EQUAL(Hex(0xffff000000000018ull), Hex(id.toKey()));
- CPPUNIT_ASSERT_EQUAL(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
+ EXPECT_EQ(Hex(0xffff000000000018ull), Hex(id.toKey()));
+ EXPECT_EQ(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
}
{
BucketId id(0x540000000001ffffull);
- CPPUNIT_ASSERT_EQUAL(Hex(0xffff800000000015ull), Hex(id.toKey()));
- CPPUNIT_ASSERT_EQUAL(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
+ EXPECT_EQ(Hex(0xffff800000000015ull), Hex(id.toKey()));
+ EXPECT_EQ(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
}
{
BucketId id(0xa80000000003ffffull);
- CPPUNIT_ASSERT_EQUAL(Hex(0xffffc0000000002aull), Hex(id.toKey()));
- CPPUNIT_ASSERT_EQUAL(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
+ EXPECT_EQ(Hex(0xffffc0000000002aull), Hex(id.toKey()));
+ EXPECT_EQ(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
}
{
BucketId id(0xbc0000000007ffffull);
- CPPUNIT_ASSERT_EQUAL(Hex(0xffffe0000000002full), Hex(id.toKey()));
- CPPUNIT_ASSERT_EQUAL(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
+ EXPECT_EQ(Hex(0xffffe0000000002full), Hex(id.toKey()));
+ EXPECT_EQ(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
}
{
BucketId id(0xcc0000000002ffffull);
- CPPUNIT_ASSERT_EQUAL(Hex(0xffff400000000033ull), Hex(id.toKey()));
- CPPUNIT_ASSERT_EQUAL(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
+ EXPECT_EQ(Hex(0xffff400000000033ull), Hex(id.toKey()));
+ EXPECT_EQ(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
}
{
BucketId id(0xebffffffffffffffull);
- CPPUNIT_ASSERT_EQUAL(Hex(0xfffffffffffffffaull), Hex(id.toKey()));
- CPPUNIT_ASSERT_EQUAL(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
+ EXPECT_EQ(Hex(0xfffffffffffffffaull), Hex(id.toKey()));
+ EXPECT_EQ(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
}
{
BucketId id(0xeaaaaaaaaaaaaaaaull);
- CPPUNIT_ASSERT_EQUAL(Hex(0x555555555555557aull), Hex(id.toKey()));
- CPPUNIT_ASSERT_EQUAL(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
+ EXPECT_EQ(Hex(0x555555555555557aull), Hex(id.toKey()));
+ EXPECT_EQ(Hex(id.getId()), Hex(document::BucketId::keyToBucketId(id.stripUnused().toKey())));
}
}
-void BucketTest::testContains() {
+TEST(BucketTest, testContains)
+{
BucketId id(18, 0x123456789ULL);
- CPPUNIT_ASSERT(id.contains(BucketId(20, 0x123456789ULL)));
- CPPUNIT_ASSERT(id.contains(BucketId(18, 0x888f56789ULL)));
- CPPUNIT_ASSERT(id.contains(BucketId(24, 0x888456789ULL)));
- CPPUNIT_ASSERT(!id.contains(BucketId(24, 0x888886789ULL)));
- CPPUNIT_ASSERT(!id.contains(BucketId(16, 0x123456789ULL)));
+ EXPECT_TRUE(id.contains(BucketId(20, 0x123456789ULL)));
+ EXPECT_TRUE(id.contains(BucketId(18, 0x888f56789ULL)));
+ EXPECT_TRUE(id.contains(BucketId(24, 0x888456789ULL)));
+ EXPECT_TRUE(!id.contains(BucketId(24, 0x888886789ULL)));
+ EXPECT_TRUE(!id.contains(BucketId(16, 0x123456789ULL)));
}
-void BucketTest::testToString() {
+TEST(BucketTest, testToString)
+{
BucketSpace bucketSpace(0x123450006789ULL);
- CPPUNIT_ASSERT_EQUAL(vespalib::string("BucketSpace(0x0000123450006789)"), bucketSpace.toString());
+ EXPECT_EQ(vespalib::string("BucketSpace(0x0000123450006789)"), bucketSpace.toString());
Bucket bucket(bucketSpace, BucketId(0x123456789ULL));
- CPPUNIT_ASSERT_EQUAL(
+ EXPECT_EQ(
vespalib::string("Bucket(BucketSpace(0x0000123450006789), BucketId(0x0000000123456789))"),
bucket.toString());
}
-void BucketTest::testOperators() {
- CPPUNIT_ASSERT(BucketSpace(0x1) == BucketSpace(0x1));
- CPPUNIT_ASSERT(BucketSpace(0x1) != BucketSpace(0x2));
- CPPUNIT_ASSERT(BucketSpace(0x1) < BucketSpace(0x2));
-
- CPPUNIT_ASSERT(Bucket(BucketSpace(0x1), BucketId(0x123456789ULL)) ==
- Bucket(BucketSpace(0x1), BucketId(0x123456789ULL)));
- CPPUNIT_ASSERT(Bucket(BucketSpace(0x1), BucketId(0x123456789ULL)) !=
- Bucket(BucketSpace(0x2), BucketId(0x123456789ULL)));
- CPPUNIT_ASSERT(Bucket(BucketSpace(0x1), BucketId(0x123456789ULL)) !=
- Bucket(BucketSpace(0x1), BucketId(0x987654321ULL)));
- CPPUNIT_ASSERT(Bucket(BucketSpace(0x1), BucketId(0x123456789ULL)) <
- Bucket(BucketSpace(0x1), BucketId(0x987654321ULL)));
- CPPUNIT_ASSERT(Bucket(BucketSpace(0x1), BucketId(0x123456789ULL)) <
- Bucket(BucketSpace(0x2), BucketId(0x123456789ULL)));
+TEST(BucketTest, testOperators)
+{
+ EXPECT_TRUE(BucketSpace(0x1) == BucketSpace(0x1));
+ EXPECT_TRUE(BucketSpace(0x1) != BucketSpace(0x2));
+ EXPECT_TRUE(BucketSpace(0x1) < BucketSpace(0x2));
+
+ EXPECT_TRUE(Bucket(BucketSpace(0x1), BucketId(0x123456789ULL)) ==
+ Bucket(BucketSpace(0x1), BucketId(0x123456789ULL)));
+ EXPECT_TRUE(Bucket(BucketSpace(0x1), BucketId(0x123456789ULL)) !=
+ Bucket(BucketSpace(0x2), BucketId(0x123456789ULL)));
+ EXPECT_TRUE(Bucket(BucketSpace(0x1), BucketId(0x123456789ULL)) !=
+ Bucket(BucketSpace(0x1), BucketId(0x987654321ULL)));
+ EXPECT_TRUE(Bucket(BucketSpace(0x1), BucketId(0x123456789ULL)) <
+ Bucket(BucketSpace(0x1), BucketId(0x987654321ULL)));
+ EXPECT_TRUE(Bucket(BucketSpace(0x1), BucketId(0x123456789ULL)) <
+ Bucket(BucketSpace(0x2), BucketId(0x123456789ULL)));
}
} // document
diff --git a/document/src/tests/documentselectparsertest.cpp b/document/src/tests/documentselectparsertest.cpp
index 93b2eadaa0d..9ba38f5ca6b 100644
--- a/document/src/tests/documentselectparsertest.cpp
+++ b/document/src/tests/documentselectparsertest.cpp
@@ -1,7 +1,5 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <cppunit/TestFixture.h>
-#include <cppunit/extensions/HelperMacros.h>
#include <vespa/document/repo/configbuilder.h>
#include <vespa/document/repo/documenttyperepo.h>
#include <vespa/document/update/assignvalueupdate.h>
@@ -21,34 +19,14 @@
#include <vespa/document/select/parse_utils.h>
#include <vespa/vespalib/util/exceptions.h>
#include <limits>
+#include <gtest/gtest.h>
using namespace document::config_builder;
namespace document {
-class DocumentSelectParserTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(DocumentSelectParserTest);
- CPPUNIT_TEST(testParseTerminals);
- CPPUNIT_TEST(testParseBranches);
- CPPUNIT_TEST(testOperators);
- CPPUNIT_TEST(testVisitor);
- CPPUNIT_TEST(testUtf8);
- CPPUNIT_TEST(testThatSimpleFieldValuesHaveCorrectFieldName);
- CPPUNIT_TEST(testThatComplexFieldValuesHaveCorrectFieldNames);
- CPPUNIT_TEST(testBodyFieldDetection);
- CPPUNIT_TEST(testDocumentUpdates);
- CPPUNIT_TEST(testDocumentIdsInRemoves);
- CPPUNIT_TEST(test_syntax_error_reporting);
- CPPUNIT_TEST(test_operator_precedence);
- CPPUNIT_TEST(test_token_used_as_ident_preserves_casing);
- CPPUNIT_TEST(test_ambiguous_field_spec_expression_is_handled_correctly);
- CPPUNIT_TEST(test_can_build_field_value_from_field_expr_node);
- CPPUNIT_TEST(test_can_build_function_call_from_field_expr_node);
- CPPUNIT_TEST(test_function_call_on_doctype_throws_exception);
- CPPUNIT_TEST(test_parse_utilities_handle_well_formed_input);
- CPPUNIT_TEST(test_parse_utilities_handle_malformed_input);
- CPPUNIT_TEST_SUITE_END();
-
+class DocumentSelectParserTest : public ::testing::Test {
+protected:
BucketIdFactory _bucketIdFactory;
std::unique_ptr<select::Parser> _parser;
std::vector<Document::SP > _doc;
@@ -71,17 +49,13 @@ class DocumentSelectParserTest : public CppUnit::TestFixture {
const ContainsType& t);
std::string parse_to_tree(const std::string& str);
-public:
DocumentSelectParserTest()
: _bucketIdFactory() {}
- void setUp() override;
+ void SetUp() override;
void createDocs();
- void testParseTerminals();
- void testParseBranches();
- void testOperators();
void testOperators0();
void testOperators1();
void testOperators2();
@@ -92,36 +66,19 @@ public:
void testOperators7();
void testOperators8();
void testOperators9();
- void testVisitor();
- void testUtf8();
- void testThatSimpleFieldValuesHaveCorrectFieldName();
- void testThatComplexFieldValuesHaveCorrectFieldNames();
- void testBodyFieldDetection();
- void testDocumentUpdates();
void testDocumentUpdates0();
void testDocumentUpdates1();
void testDocumentUpdates2();
void testDocumentUpdates3();
void testDocumentUpdates4();
- void testDocumentIdsInRemoves();
- void test_syntax_error_reporting();
- void test_operator_precedence();
- void test_token_used_as_ident_preserves_casing();
- void test_ambiguous_field_spec_expression_is_handled_correctly();
- void test_can_build_field_value_from_field_expr_node();
- void test_can_build_function_call_from_field_expr_node();
- void test_function_call_on_doctype_throws_exception();
- void test_parse_utilities_handle_well_formed_input();
- void test_parse_utilities_handle_malformed_input();
};
-CPPUNIT_TEST_SUITE_REGISTRATION(DocumentSelectParserTest);
namespace {
std::shared_ptr<const DocumentTypeRepo> _repo;
}
-void DocumentSelectParserTest::setUp()
+void DocumentSelectParserTest::SetUp()
{
DocumenttypesConfigBuilderHelper builder(TestDocRepo::getDefaultConfig());
builder.document(535424777, "notandor",
@@ -295,24 +252,24 @@ DocumentSelectParserTest::createDocs()
namespace {
void doVerifyParse(select::Node *node, const std::string &query, const char *expected) {
std::string message("Query "+query+" failed to parse.");
- CPPUNIT_ASSERT_MESSAGE(message, node != 0);
+ ASSERT_TRUE(node != nullptr) << message;
std::ostringstream actual;
actual << *node;
- std::string exp(expected != 0 ? std::string(expected) : query);
- CPPUNIT_ASSERT_EQUAL(exp, actual.str());
+ std::string exp(expected != nullptr ? std::string(expected) : query);
+ EXPECT_EQ(exp, actual.str());
// Test that cloning gives the same result
std::unique_ptr<select::Node> clonedNode(node->clone());
std::ostringstream clonedStr;
clonedStr << *clonedNode;
- CPPUNIT_ASSERT_EQUAL(exp, clonedStr.str());
+ EXPECT_EQ(exp, clonedStr.str());
}
void verifySimpleParse(const std::string& query, const char* expected = 0) {
BucketIdFactory factory;
select::simple::SelectionParser parser(factory);
std::string message("Query "+query+" failed to parse.");
- CPPUNIT_ASSERT_MESSAGE(message, parser.parse(query));
+ EXPECT_TRUE(parser.parse(query)) << message;
std::unique_ptr<select::Node> node(parser.getNode());
doVerifyParse(node.get(), query, expected);
}
@@ -330,19 +287,20 @@ void verifyParse(const std::string& query, const char* expected = 0) {
TestDocRepo test_repo;
select::Parser parser(test_repo.getTypeRepo(), factory);
std::unique_ptr<select::Node> node(parser.parse(query));
- CPPUNIT_FAIL("Expected exception parsing query '"+query+"'");
+ FAIL() << "Expected exception parsing query '" << query << "'";
} catch (select::ParsingFailedException& e) {
std::string message(e.what());
if (message.size() > error.size())
message = message.substr(0, error.size());
std::string failure("Expected: " + error + "\n- Actual : "
+ std::string(e.what()));
- CPPUNIT_ASSERT_MESSAGE(failure, error == message);
+ EXPECT_EQ(error, message) << failure;
}
}
}
-void DocumentSelectParserTest::test_syntax_error_reporting() {
+TEST_F(DocumentSelectParserTest, test_syntax_error_reporting)
+{
createDocs();
verifyFailedParse("testdoctype1.headerval == aaa", "ParsingFailedException: "
@@ -376,7 +334,7 @@ void DocumentSelectParserTest::test_syntax_error_reporting() {
"doctype, bool or comparison at column 1 when parsing selection '(1 + 2)'");
}
-void DocumentSelectParserTest::testParseTerminals()
+TEST_F(DocumentSelectParserTest, testParseTerminals)
{
createDocs();
@@ -401,8 +359,8 @@ void DocumentSelectParserTest::testParseTerminals()
const select::StringValueNode& vnode(
dynamic_cast<const select::StringValueNode&>(compnode.getRight()));
- CPPUNIT_ASSERT_EQUAL(vespalib::string("headerval"), fnode.getFieldName());
- CPPUNIT_ASSERT_EQUAL(vespalib::string("test"), vnode.getValue());
+ EXPECT_EQ(vespalib::string("headerval"), fnode.getFieldName());
+ EXPECT_EQ(vespalib::string("test"), vnode.getValue());
// Test whitespace
verifyParse("testdoctype1.headerval == \"te st \"");
verifyParse(" \t testdoctype1.headerval\t== \t \"test\"\t",
@@ -416,7 +374,7 @@ void DocumentSelectParserTest::testParseTerminals()
select::Compare& escapednode(dynamic_cast<select::Compare&>(*node));
const select::StringValueNode& escval(
dynamic_cast<const select::StringValueNode&>(escapednode.getRight()));
- CPPUNIT_ASSERT_EQUAL(vespalib::string("\ttH \n"), escval.getValue());
+ EXPECT_EQ(vespalib::string("\ttH \n"), escval.getValue());
// Test <= <, > >=
verifyParse("testdoctype1.headerval >= 123");
verifyParse("testdoctype1.headerval > 123");
@@ -503,7 +461,7 @@ void DocumentSelectParserTest::testParseTerminals()
verifyParse("usergroup");
}
-void DocumentSelectParserTest::testParseBranches()
+TEST_F(DocumentSelectParserTest, testParseBranches)
{
createDocs();
@@ -540,25 +498,23 @@ DocumentSelectParserTest::doParse(vespalib::stringref expr,
oss << "for expr: " << expr << "\n";
select::ResultList tracedResult(root->trace(t, oss));
- CPPUNIT_ASSERT_EQUAL_MESSAGE(expr, result, clonedResult);
- CPPUNIT_ASSERT_EQUAL_MESSAGE(oss.str(), result, tracedResult);
+ EXPECT_EQ(result, clonedResult) << expr;
+ EXPECT_EQ(result, tracedResult) << oss.str();
return result;
}
#define PARSE(expr, doc, result) \
- CPPUNIT_ASSERT_EQUAL_MESSAGE(expr, select::ResultList(select::Result::result), \
- doParse(expr, (doc)));
+ EXPECT_EQ(select::ResultList(select::Result::result), \
+ doParse(expr, (doc))) << expr;
#define PARSEI(expr, doc, result) \
- CPPUNIT_ASSERT_EQUAL_MESSAGE(std::string("Doc: ") + expr, \
- select::ResultList(select::Result::result), \
- doParse(expr, (doc))); \
- CPPUNIT_ASSERT_EQUAL_MESSAGE(std::string("Doc id: ") + expr, \
- select::ResultList(select::Result::result), \
- doParse(expr, (doc).getId()));
-
-void DocumentSelectParserTest::testOperators()
+ EXPECT_EQ(select::ResultList(select::Result::result), \
+ doParse(expr, (doc))) << (std::string("Doc: ") + expr); \
+ EXPECT_EQ(select::ResultList(select::Result::result), \
+ doParse(expr, (doc).getId())) << (std::string("Doc id: ") + expr);
+
+TEST_F(DocumentSelectParserTest, testOperators)
{
testOperators0();
testOperators1();
@@ -1000,7 +956,7 @@ namespace {
}
-void DocumentSelectParserTest::testVisitor()
+TEST_F(DocumentSelectParserTest, testVisitor)
{
createDocs();
@@ -1018,10 +974,10 @@ void DocumentSelectParserTest::testVisitor()
"COMPARE(testdoctype1.hstringval = \"ola\"))), "
"COMPARE(testdoctype1.headerval != null)))";
- CPPUNIT_ASSERT_EQUAL(expected, v.getVisitString());
+ EXPECT_EQ(expected, v.getVisitString());
}
-void DocumentSelectParserTest::testBodyFieldDetection()
+TEST_F(DocumentSelectParserTest, testBodyFieldDetection)
{
{
@@ -1029,8 +985,8 @@ void DocumentSelectParserTest::testBodyFieldDetection()
select::BodyFieldDetector detector(*_repo);
root->visit(detector);
- CPPUNIT_ASSERT(!detector.foundBodyField);
- CPPUNIT_ASSERT(detector.foundHeaderField);
+ EXPECT_TRUE(!detector.foundBodyField);
+ EXPECT_TRUE(detector.foundHeaderField);
}
{
@@ -1038,8 +994,8 @@ void DocumentSelectParserTest::testBodyFieldDetection()
select::BodyFieldDetector detector(*_repo);
root->visit(detector);
- CPPUNIT_ASSERT(!detector.foundBodyField);
- CPPUNIT_ASSERT(detector.foundHeaderField);
+ EXPECT_TRUE(!detector.foundBodyField);
+ EXPECT_TRUE(detector.foundHeaderField);
}
{
@@ -1047,8 +1003,8 @@ void DocumentSelectParserTest::testBodyFieldDetection()
select::BodyFieldDetector detector(*_repo);
root->visit(detector);
- CPPUNIT_ASSERT(!detector.foundBodyField);
- CPPUNIT_ASSERT(detector.foundHeaderField);
+ EXPECT_TRUE(!detector.foundBodyField);
+ EXPECT_TRUE(detector.foundHeaderField);
}
{
@@ -1056,7 +1012,7 @@ void DocumentSelectParserTest::testBodyFieldDetection()
select::BodyFieldDetector detector(*_repo);
root->visit(detector);
- CPPUNIT_ASSERT(detector.foundBodyField);
+ EXPECT_TRUE(detector.foundBodyField);
}
{
@@ -1067,12 +1023,12 @@ void DocumentSelectParserTest::testBodyFieldDetection()
select::BodyFieldDetector detector(*_repo);
root->visit(detector);
- CPPUNIT_ASSERT(!detector.foundBodyField);
+ EXPECT_TRUE(!detector.foundBodyField);
}
}
-void DocumentSelectParserTest::testDocumentUpdates()
+TEST_F(DocumentSelectParserTest, testDocumentUpdates)
{
testDocumentUpdates0();
testDocumentUpdates1();
@@ -1239,7 +1195,7 @@ void DocumentSelectParserTest::testDocumentUpdates4()
PARSEI("-6 % 10 = -6", *_update[0], True);
}
-void DocumentSelectParserTest::testDocumentIdsInRemoves()
+TEST_F(DocumentSelectParserTest, testDocumentIdsInRemoves)
{
PARSE("testdoctype1", DocumentId("id:ns:testdoctype1::1"), True);
PARSE("testdoctype1", DocumentId("id:ns:null::1"), False);
@@ -1252,15 +1208,15 @@ void DocumentSelectParserTest::testDocumentIdsInRemoves()
PARSE("testdoctype1 and testdoctype1.headerval == 0", DocumentId("id:ns:testdoctype1::1"), Invalid);
}
-void DocumentSelectParserTest::testUtf8()
+TEST_F(DocumentSelectParserTest, testUtf8)
{
createDocs();
std::string utf8name(u8"H\u00e5kon");
- CPPUNIT_ASSERT_EQUAL(size_t(6), utf8name.size());
+ EXPECT_EQ(size_t(6), utf8name.size());
/// \todo TODO (was warning): UTF8 test for glob/regex support in selection language disabled. Known not to work
// boost::u32regex rx = boost::make_u32regex("H.kon");
-// CPPUNIT_ASSERT_EQUAL(true, boost::u32regex_match(utf8name, rx));
+// EXPECT_EQ(true, boost::u32regex_match(utf8name, rx));
_doc.push_back(createDoc(
"testdoctype1", "doc:myspace:utf8doc", 24, 2.0, utf8name, "bar"));
@@ -1274,22 +1230,24 @@ DocumentSelectParserTest::parseFieldValue(const std::string& expression) {
dynamic_cast<const select::Compare &>(*_parser->parse(expression)).getLeft().clone().release()));
}
-void DocumentSelectParserTest::testThatSimpleFieldValuesHaveCorrectFieldName() {
- CPPUNIT_ASSERT_EQUAL(
+TEST_F(DocumentSelectParserTest, testThatSimpleFieldValuesHaveCorrectFieldName)
+{
+ EXPECT_EQ(
vespalib::string("headerval"),
parseFieldValue("testdoctype1.headerval")->getRealFieldName());
}
-void DocumentSelectParserTest::testThatComplexFieldValuesHaveCorrectFieldNames() {
- CPPUNIT_ASSERT_EQUAL(
+TEST_F(DocumentSelectParserTest, testThatComplexFieldValuesHaveCorrectFieldNames)
+{
+ EXPECT_EQ(
vespalib::string("headerval"),
parseFieldValue("testdoctype1.headerval{test}")->getRealFieldName());
- CPPUNIT_ASSERT_EQUAL(
+ EXPECT_EQ(
vespalib::string("headerval"),
parseFieldValue("testdoctype1.headerval[42]")->getRealFieldName());
- CPPUNIT_ASSERT_EQUAL(
+ EXPECT_EQ(
vespalib::string("headerval"),
parseFieldValue("testdoctype1.headerval.meow.meow{test}")->getRealFieldName());
}
@@ -1399,84 +1357,88 @@ std::string DocumentSelectParserTest::parse_to_tree(const std::string& str) {
return node_to_string(*root);
}
-void DocumentSelectParserTest::test_operator_precedence() {
+TEST_F(DocumentSelectParserTest, test_operator_precedence)
+{
createDocs();
using namespace std::string_literals;
- CPPUNIT_ASSERT_EQUAL("(AND true false)"s, parse_to_tree("true and false"));
- CPPUNIT_ASSERT_EQUAL("(AND (NOT false) true)"s, parse_to_tree("not false and true"));
- CPPUNIT_ASSERT_EQUAL("(NOT (AND false true))"s, parse_to_tree("not (false and true)"));
- CPPUNIT_ASSERT_EQUAL("(NOT (DOCTYPE testdoctype1))"s, parse_to_tree("not testdoctype1"));
- CPPUNIT_ASSERT_EQUAL("(NOT (DOCTYPE (testdoctype1)))"s, parse_to_tree("not (testdoctype1)"));
- CPPUNIT_ASSERT_EQUAL("(NOT (DOCTYPE (testdoctype1)))"s, parse_to_tree("(not (testdoctype1))"));
- CPPUNIT_ASSERT_EQUAL("(OR (== 1 2) (== 3 4))"s, parse_to_tree("1==2 or 3==4"));
- CPPUNIT_ASSERT_EQUAL("(!= (+ (+ 1 2) 3) 0)"s, parse_to_tree("1+2+3 != 0"));
- CPPUNIT_ASSERT_EQUAL("(!= (+ (+ 1.1 2.2) 3.3) 4.4)"s, parse_to_tree("1.1+2.2+3.3 != 4.4"));
- CPPUNIT_ASSERT_EQUAL("(!= (- (- 1 2) 3) 0)"s, parse_to_tree("1-2-3 != 0"));
- CPPUNIT_ASSERT_EQUAL("(!= (+ (+ 1 2) 3) 0)"s, parse_to_tree("1 + 2 + 3 != 0"));
- CPPUNIT_ASSERT_EQUAL("(!= (+ 1 (* 2 3)) 0)"s, parse_to_tree("1 + 2 * 3 != 0"));
- CPPUNIT_ASSERT_EQUAL("(!= (- (/ (* 1 2) 3) 4) 0)"s, parse_to_tree("1 * 2 / 3 - 4 != 0"));
- CPPUNIT_ASSERT_EQUAL("(!= (/ (* 1 2) (- 3 4)) 0)"s, parse_to_tree("1 * 2 / (3 - 4) != 0"));
- CPPUNIT_ASSERT_EQUAL("(OR (AND true (NOT (== 1 2))) false)"s,
+ EXPECT_EQ("(AND true false)"s, parse_to_tree("true and false"));
+ EXPECT_EQ("(AND (NOT false) true)"s, parse_to_tree("not false and true"));
+ EXPECT_EQ("(NOT (AND false true))"s, parse_to_tree("not (false and true)"));
+ EXPECT_EQ("(NOT (DOCTYPE testdoctype1))"s, parse_to_tree("not testdoctype1"));
+ EXPECT_EQ("(NOT (DOCTYPE (testdoctype1)))"s, parse_to_tree("not (testdoctype1)"));
+ EXPECT_EQ("(NOT (DOCTYPE (testdoctype1)))"s, parse_to_tree("(not (testdoctype1))"));
+ EXPECT_EQ("(OR (== 1 2) (== 3 4))"s, parse_to_tree("1==2 or 3==4"));
+ EXPECT_EQ("(!= (+ (+ 1 2) 3) 0)"s, parse_to_tree("1+2+3 != 0"));
+ EXPECT_EQ("(!= (+ (+ 1.1 2.2) 3.3) 4.4)"s, parse_to_tree("1.1+2.2+3.3 != 4.4"));
+ EXPECT_EQ("(!= (- (- 1 2) 3) 0)"s, parse_to_tree("1-2-3 != 0"));
+ EXPECT_EQ("(!= (+ (+ 1 2) 3) 0)"s, parse_to_tree("1 + 2 + 3 != 0"));
+ EXPECT_EQ("(!= (+ 1 (* 2 3)) 0)"s, parse_to_tree("1 + 2 * 3 != 0"));
+ EXPECT_EQ("(!= (- (/ (* 1 2) 3) 4) 0)"s, parse_to_tree("1 * 2 / 3 - 4 != 0"));
+ EXPECT_EQ("(!= (/ (* 1 2) (- 3 4)) 0)"s, parse_to_tree("1 * 2 / (3 - 4) != 0"));
+ EXPECT_EQ("(OR (AND true (NOT (== 1 2))) false)"s,
parse_to_tree("true and not 1 == 2 or false"));
- CPPUNIT_ASSERT_EQUAL("(AND (AND (AND (< 1 2) (> 3 4)) (<= 5 6)) (>= 7 8))"s,
+ EXPECT_EQ("(AND (AND (AND (< 1 2) (> 3 4)) (<= 5 6)) (>= 7 8))"s,
parse_to_tree("1 < 2 and 3 > 4 and 5 <= 6 and 7 >= 8"));
- CPPUNIT_ASSERT_EQUAL("(OR (AND (AND (< 1 2) (> 3 4)) (<= 5 6)) (>= 7 8))"s,
+ EXPECT_EQ("(OR (AND (AND (< 1 2) (> 3 4)) (<= 5 6)) (>= 7 8))"s,
parse_to_tree("1 < 2 and 3 > 4 and 5 <= 6 or 7 >= 8"));
- CPPUNIT_ASSERT_EQUAL("(OR (AND (< 1 2) (> 3 4)) (AND (<= 5 6) (>= 7 8)))"s,
+ EXPECT_EQ("(OR (AND (< 1 2) (> 3 4)) (AND (<= 5 6) (>= 7 8)))"s,
parse_to_tree("1 < 2 and 3 > 4 or 5 <= 6 and 7 >= 8"));
// Unary plus is simply ignored by the parser.
- CPPUNIT_ASSERT_EQUAL("(== 1 -2)"s, parse_to_tree("+1==-2"));
- CPPUNIT_ASSERT_EQUAL("(== 1.23 -2.56)"s, parse_to_tree("+1.23==-2.56"));
- CPPUNIT_ASSERT_EQUAL("(== (+ 1 2) (- 3 -4))"s, parse_to_tree("1 + +2==3 - -4"));
- CPPUNIT_ASSERT_EQUAL("(== (+ 1 2) (- 3 -4))"s, parse_to_tree("1++2==3--4"));
+ EXPECT_EQ("(== 1 -2)"s, parse_to_tree("+1==-2"));
+ EXPECT_EQ("(== 1.23 -2.56)"s, parse_to_tree("+1.23==-2.56"));
+ EXPECT_EQ("(== (+ 1 2) (- 3 -4))"s, parse_to_tree("1 + +2==3 - -4"));
+ EXPECT_EQ("(== (+ 1 2) (- 3 -4))"s, parse_to_tree("1++2==3--4"));
// Due to the way parentheses are handled by the AST, ((foo)) always gets
// reduced down to (foo).
- CPPUNIT_ASSERT_EQUAL("(DOCTYPE (testdoctype1))"s, parse_to_tree("(((testdoctype1)))"));
- CPPUNIT_ASSERT_EQUAL("(AND (DOCTYPE (testdoctype1)) (DOCTYPE (testdoctype2)))"s,
+ EXPECT_EQ("(DOCTYPE (testdoctype1))"s, parse_to_tree("(((testdoctype1)))"));
+ EXPECT_EQ("(AND (DOCTYPE (testdoctype1)) (DOCTYPE (testdoctype2)))"s,
parse_to_tree("((((testdoctype1))) and ((testdoctype2)))"));
- CPPUNIT_ASSERT_EQUAL("(== (ID id) \"foo\")"s, parse_to_tree("id == 'foo'"));
- CPPUNIT_ASSERT_EQUAL("(== (ID id.group) \"foo\")"s, parse_to_tree("id.group == 'foo'"));
+ EXPECT_EQ("(== (ID id) \"foo\")"s, parse_to_tree("id == 'foo'"));
+ EXPECT_EQ("(== (ID id.group) \"foo\")"s, parse_to_tree("id.group == 'foo'"));
// id_spec function apply
- CPPUNIT_ASSERT_EQUAL("(== (hash (ID id)) 12345)"s, parse_to_tree("id.hash() == 12345"));
+ EXPECT_EQ("(== (hash (ID id)) 12345)"s, parse_to_tree("id.hash() == 12345"));
// Combination of id_spec function apply and arith_expr function apply
- CPPUNIT_ASSERT_EQUAL("(== (abs (hash (ID id))) 12345)"s, parse_to_tree("id.hash().abs() == 12345"));
+ EXPECT_EQ("(== (abs (hash (ID id))) 12345)"s, parse_to_tree("id.hash().abs() == 12345"));
}
-void DocumentSelectParserTest::test_token_used_as_ident_preserves_casing() {
+TEST_F(DocumentSelectParserTest, test_token_used_as_ident_preserves_casing)
+{
createDocs();
using namespace std::string_literals;
// TYPE, SCHEME, ORDER etc are tokens that may also be used as identifiers
// without introducing parsing ambiguities. In this context their original
// casing should be preserved.
- CPPUNIT_ASSERT_EQUAL("(== (VAR Type) 123)"s, parse_to_tree("$Type == 123"));
- CPPUNIT_ASSERT_EQUAL("(== (VAR giD) 123)"s, parse_to_tree("$giD == 123"));
- CPPUNIT_ASSERT_EQUAL("(== (VAR ORDER) 123)"s, parse_to_tree("$ORDER == 123"));
+ EXPECT_EQ("(== (VAR Type) 123)"s, parse_to_tree("$Type == 123"));
+ EXPECT_EQ("(== (VAR giD) 123)"s, parse_to_tree("$giD == 123"));
+ EXPECT_EQ("(== (VAR ORDER) 123)"s, parse_to_tree("$ORDER == 123"));
}
-void DocumentSelectParserTest::test_ambiguous_field_spec_expression_is_handled_correctly() {
+TEST_F(DocumentSelectParserTest, test_ambiguous_field_spec_expression_is_handled_correctly)
+{
createDocs();
using namespace std::string_literals;
// In earlier revisions of LR(1)-grammar, this triggered a reduce/reduce conflict between
// logical_expr and arith_expr for the sequence '(' field_spec ')', which failed to
// parse in an expected manner. Test that we don't get regressions here.
- CPPUNIT_ASSERT_EQUAL("(!= (FIELD testdoctype1 foo) null)"s, parse_to_tree("(testdoctype1.foo)"));
- CPPUNIT_ASSERT_EQUAL("(AND (!= (FIELD testdoctype1 foo) null) (!= (FIELD testdoctype1 bar) null))"s,
+ EXPECT_EQ("(!= (FIELD testdoctype1 foo) null)"s, parse_to_tree("(testdoctype1.foo)"));
+ EXPECT_EQ("(AND (!= (FIELD testdoctype1 foo) null) (!= (FIELD testdoctype1 bar) null))"s,
parse_to_tree("(testdoctype1.foo) AND (testdoctype1.bar)"));
}
-void DocumentSelectParserTest::test_can_build_field_value_from_field_expr_node() {
+TEST_F(DocumentSelectParserTest, test_can_build_field_value_from_field_expr_node)
+{
using select::FieldExprNode;
{
// Simple field expression
auto lhs = std::make_unique<FieldExprNode>("mydoctype");
auto root = std::make_unique<FieldExprNode>(std::move(lhs), "foo");
auto fv = root->convert_to_field_value();
- CPPUNIT_ASSERT_EQUAL(vespalib::string("mydoctype"), fv->getDocType());
- CPPUNIT_ASSERT_EQUAL(vespalib::string("foo"), fv->getFieldName());
+ EXPECT_EQ(vespalib::string("mydoctype"), fv->getDocType());
+ EXPECT_EQ(vespalib::string("foo"), fv->getFieldName());
}
{
// Nested field expression
@@ -1484,12 +1446,13 @@ void DocumentSelectParserTest::test_can_build_field_value_from_field_expr_node()
auto lhs2 = std::make_unique<FieldExprNode>(std::move(lhs1), "foo");
auto root = std::make_unique<FieldExprNode>(std::move(lhs2), "bar");
auto fv = root->convert_to_field_value();
- CPPUNIT_ASSERT_EQUAL(vespalib::string("mydoctype"), fv->getDocType());
- CPPUNIT_ASSERT_EQUAL(vespalib::string("foo.bar"), fv->getFieldName());
+ EXPECT_EQ(vespalib::string("mydoctype"), fv->getDocType());
+ EXPECT_EQ(vespalib::string("foo.bar"), fv->getFieldName());
}
}
-void DocumentSelectParserTest::test_can_build_function_call_from_field_expr_node() {
+TEST_F(DocumentSelectParserTest, test_can_build_function_call_from_field_expr_node)
+{
using select::FieldExprNode;
{
// doctype.foo.lowercase()
@@ -1499,20 +1462,21 @@ void DocumentSelectParserTest::test_can_build_function_call_from_field_expr_node
auto lhs2 = std::make_unique<FieldExprNode>(std::move(lhs1), "foo");
auto root = std::make_unique<FieldExprNode>(std::move(lhs2), "lowercase");
auto func = root->convert_to_function_call();
- CPPUNIT_ASSERT_EQUAL(vespalib::string("lowercase"), func->getFunctionName());
+ EXPECT_EQ(vespalib::string("lowercase"), func->getFunctionName());
// TODO vespalib::string?
- CPPUNIT_ASSERT_EQUAL(std::string("(FIELD mydoctype foo)"), node_to_string(func->getChild()));
+ EXPECT_EQ(std::string("(FIELD mydoctype foo)"), node_to_string(func->getChild()));
}
}
-void DocumentSelectParserTest::test_function_call_on_doctype_throws_exception() {
+TEST_F(DocumentSelectParserTest, test_function_call_on_doctype_throws_exception)
+{
using select::FieldExprNode;
auto lhs = std::make_unique<FieldExprNode>("mydoctype");
auto root = std::make_unique<FieldExprNode>(std::move(lhs), "lowercase");
try {
root->convert_to_function_call();
} catch (const vespalib::IllegalArgumentException& e) {
- CPPUNIT_ASSERT_EQUAL(vespalib::string("Cannot call function 'lowercase' directly on document type"),
+ EXPECT_EQ(vespalib::string("Cannot call function 'lowercase' directly on document type"),
e.getMessage());
}
}
@@ -1522,33 +1486,34 @@ namespace {
void check_parse_i64(vespalib::stringref str, bool expect_ok, int64_t expected_output) {
int64_t out = 0;
bool ok = select::util::parse_i64(str.data(), str.size(), out);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Parsing did not returned expected success status for i64 input " + str, expect_ok, ok);
+ EXPECT_EQ(expect_ok, ok) << "Parsing did not returned expected success status for i64 input " << str;
if (expect_ok) {
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Parse output not as expected for i64 input " + str, expected_output, out);
+ EXPECT_EQ(expected_output, out) << "Parse output not as expected for i64 input " << str;
}
}
void check_parse_hex_i64(vespalib::stringref str, bool expect_ok, int64_t expected_output) {
int64_t out = 0;
bool ok = select::util::parse_hex_i64(str.data(), str.size(), out);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Parsing did not returned expected success status for hex i64 input " + str, expect_ok, ok);
+ EXPECT_EQ(expect_ok, ok) << "Parsing did not returned expected success status for hex i64 input " << str;
if (expect_ok) {
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Parse output not as expected for hex i64 input " + str, expected_output, out);
+ EXPECT_EQ(expected_output, out) << "Parse output not as expected for hex i64 input " << str;
}
}
void check_parse_double(vespalib::stringref str, bool expect_ok, double expected_output) {
double out = 0;
bool ok = select::util::parse_double(str.data(), str.size(), out);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Parsing did not returned expected success status for hex i64 input " + str, expect_ok, ok);
+ EXPECT_EQ(expect_ok, ok) << "Parsing did not returned expected success status for hex i64 input " << str;
if (expect_ok) {
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Parse output not as expected for double input " + str, expected_output, out);
+ EXPECT_EQ(expected_output, out) << "Parse output not as expected for double input " << str;
}
}
}
-void DocumentSelectParserTest::test_parse_utilities_handle_well_formed_input() {
+TEST_F(DocumentSelectParserTest, test_parse_utilities_handle_well_formed_input)
+{
check_parse_i64("0", true, 0);
check_parse_i64("1", true, 1);
check_parse_i64("9223372036854775807", true, INT64_MAX);
@@ -1568,7 +1533,8 @@ void DocumentSelectParserTest::test_parse_utilities_handle_well_formed_input() {
check_parse_double("1.79769e+308", true, 1.79769e+308); // DBL_MAX
}
-void DocumentSelectParserTest::test_parse_utilities_handle_malformed_input() {
+TEST_F(DocumentSelectParserTest, test_parse_utilities_handle_malformed_input)
+{
check_parse_i64("9223372036854775808", false, 0); // INT64_MAX + 1
check_parse_i64("18446744073709551615", false, 0); // UINT64_MAX
check_parse_i64("", false, 0);
diff --git a/document/src/tests/documentselecttest.h b/document/src/tests/documentselecttest.h
deleted file mode 100644
index e50dd984b65..00000000000
--- a/document/src/tests/documentselecttest.h
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-/* $Id$*/
-#pragma once
-
-#include <cppunit/extensions/HelperMacros.h>
-
-class DocumentSelect_Test : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE( DocumentSelect_Test);
- CPPUNIT_TEST(testEquals);
- CPPUNIT_TEST(testLt);
- CPPUNIT_TEST(testGt);
- CPPUNIT_TEST(testAnd);
- CPPUNIT_TEST(testOr);
- CPPUNIT_TEST(testNot);
- CPPUNIT_TEST(testConfig1);
- CPPUNIT_TEST(testConfig2);
- CPPUNIT_TEST_SUITE_END();
-
-public:
- void setUp();
-
- void tearDown();
-protected:
- void testEquals();
- void testLt();
- void testGt();
- void testAnd();
- void testOr();
- void testNot();
- void testConfig1();
- void testConfig2();
-};
-
-
diff --git a/document/src/tests/documenttestcase.cpp b/document/src/tests/documenttestcase.cpp
index ee49259e982..bb07f63a83b 100644
--- a/document/src/tests/documenttestcase.cpp
+++ b/document/src/tests/documenttestcase.cpp
@@ -2,8 +2,6 @@
#include <vespa/document/base/testdocman.h>
#include <vespa/vespalib/io/fileutil.h>
-#include <vespa/vdstestlib/cppunit/macros.h>
-
#include <vespa/document/datatype/annotationreferencedatatype.h>
#include <vespa/document/fieldvalue/iteratorhandler.h>
#include <vespa/document/repo/configbuilder.h>
@@ -15,9 +13,12 @@
#include <vespa/document/util/serializableexceptions.h>
#include <vespa/document/util/bytebuffer.h>
#include <fcntl.h>
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
using vespalib::nbostream;
using vespalib::compression::CompressionConfig;
+using namespace ::testing;
using namespace document::config_builder;
@@ -25,67 +26,15 @@ namespace document {
using namespace fieldvalue;
-struct DocumentTest : public CppUnit::TestFixture {
- void testTraversing();
- void testFieldPath();
- void testModifyDocument();
- void testVariables();
- void testSimpleUsage();
- void testReadSerializedFile();
- void testReadSerializedFileCompressed();
- void testReadSerializedAllVersions();
- void testGenerateSerializedFile();
- void testGetURIFromSerialized();
- void testBogusserialize();
- void testCRC32();
- void testHasChanged();
- void testSplitSerialization();
- void testSliceSerialize();
- void testCompression();
- void testCompressionConfigured();
- void testUnknownEntries();
- void testAnnotationDeserialization();
- void testGetSerializedSize();
- void testDeserializeMultiple();
- void testSizeOf();
-
- CPPUNIT_TEST_SUITE(DocumentTest);
- CPPUNIT_TEST(testFieldPath);
- CPPUNIT_TEST(testTraversing);
- CPPUNIT_TEST(testModifyDocument);
- CPPUNIT_TEST(testVariables);
- CPPUNIT_TEST(testSimpleUsage);
- CPPUNIT_TEST(testReadSerializedFile);
- CPPUNIT_TEST(testReadSerializedFileCompressed);
- CPPUNIT_TEST(testReadSerializedAllVersions);
- CPPUNIT_TEST(testGenerateSerializedFile);
- CPPUNIT_TEST(testGetURIFromSerialized);
- CPPUNIT_TEST(testBogusserialize);
- CPPUNIT_TEST(testCRC32);
- CPPUNIT_TEST(testHasChanged);
- CPPUNIT_TEST(testSplitSerialization);
- CPPUNIT_TEST(testSliceSerialize);
- CPPUNIT_TEST(testCompression);
- CPPUNIT_TEST(testCompressionConfigured);
- CPPUNIT_TEST(testUnknownEntries);
- CPPUNIT_TEST(testAnnotationDeserialization);
- CPPUNIT_TEST(testGetSerializedSize);
- CPPUNIT_TEST(testDeserializeMultiple);
- CPPUNIT_TEST(testSizeOf);
- CPPUNIT_TEST_SUITE_END();
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(DocumentTest);
-
-void DocumentTest::testSizeOf()
+TEST(DocumentTest, testSizeOf)
{
- CPPUNIT_ASSERT_EQUAL(136ul, sizeof(Document));
- CPPUNIT_ASSERT_EQUAL(72ul, sizeof(StructFieldValue));
- CPPUNIT_ASSERT_EQUAL(24ul, sizeof(StructuredFieldValue));
- CPPUNIT_ASSERT_EQUAL(64ul, sizeof(SerializableArray));
+ EXPECT_EQ(136ul, sizeof(Document));
+ EXPECT_EQ(72ul, sizeof(StructFieldValue));
+ EXPECT_EQ(24ul, sizeof(StructuredFieldValue));
+ EXPECT_EQ(64ul, sizeof(SerializableArray));
}
-void DocumentTest::testFieldPath()
+TEST(DocumentTest, testFieldPath)
{
const vespalib::string testValues[] = { "{}", "", "",
"{}r", "", "r",
@@ -104,8 +53,8 @@ void DocumentTest::testFieldPath()
for (size_t i(0); i < sizeof(testValues)/sizeof(testValues[0]); i+=3) {
vespalib::stringref tmp = testValues[i];
vespalib::string key = FieldPathEntry::parseKey(tmp);
- CPPUNIT_ASSERT_EQUAL(testValues[i+1], key);
- CPPUNIT_ASSERT_EQUAL(testValues[i+2], vespalib::string(tmp));
+ EXPECT_EQ(testValues[i+1], key);
+ EXPECT_EQ(testValues[i+2], vespalib::string(tmp));
}
}
@@ -133,7 +82,7 @@ Handler::Handler() = default;
Handler::~Handler() = default;
-void DocumentTest::testTraversing()
+TEST(DocumentTest, testTraversing)
{
Field primitive1("primitive1", 1, *DataType::INT, true);
Field primitive2("primitive2", 2, *DataType::INT, true);
@@ -191,7 +140,7 @@ void DocumentTest::testTraversing()
Handler fullTraverser;
FieldPath empty;
doc.iterateNested(empty.getFullRange(), fullTraverser);
- CPPUNIT_ASSERT_EQUAL(fullTraverser.getResult(),
+ EXPECT_EQ(fullTraverser.getResult(),
std::string("<0:P-0<0:P-0<0:P-0P-0[P-0P-1P-2][<0:P-0P-0><1:P-1P-1>]>>>"));
}
@@ -212,8 +161,7 @@ public:
VariableIteratorHandler::VariableIteratorHandler() {}
VariableIteratorHandler::~VariableIteratorHandler() {}
-void
-DocumentTest::testVariables()
+TEST(DocumentTest, testVariables)
{
ArrayDataType iarr(*DataType::INT);
ArrayDataType iiarr(static_cast<DataType &>(iarr));
@@ -274,7 +222,7 @@ DocumentTest::testVariables()
"x: 2,y: 2,z: 1, - 18\n"
"x: 2,y: 2,z: 2, - 27\n";
- CPPUNIT_ASSERT_EQUAL(fasit, handler.retVal);
+ EXPECT_EQ(fasit, handler.retVal);
}
}
@@ -296,8 +244,7 @@ public:
}
};
-void
-DocumentTest::testModifyDocument()
+TEST(DocumentTest, testModifyDocument)
{
// Create test document type and content
Field primitive1("primitive1", 1, *DataType::INT, true);
@@ -405,7 +352,7 @@ DocumentTest::testModifyDocument()
doc->print(std::cerr, true, "");
}
-void DocumentTest::testSimpleUsage()
+TEST(DocumentTest, testSimpleUsage)
{
DocumentType::SP type(new DocumentType("test"));
Field intF("int", 1, *DataType::INT, true);
@@ -420,33 +367,33 @@ void DocumentTest::testSimpleUsage()
Document value(*repo.getDocumentType("test"), DocumentId("doc::testdoc"));
// Initially empty
- CPPUNIT_ASSERT_EQUAL(size_t(0), value.getSetFieldCount());
- CPPUNIT_ASSERT(!value.hasValue(intF));
+ EXPECT_EQ(size_t(0), value.getSetFieldCount());
+ EXPECT_TRUE(!value.hasValue(intF));
value.setValue(intF, IntFieldValue(1));
// Not empty
- CPPUNIT_ASSERT_EQUAL(size_t(1), value.getSetFieldCount());
- CPPUNIT_ASSERT(value.hasValue(intF));
+ EXPECT_EQ(size_t(1), value.getSetFieldCount());
+ EXPECT_TRUE(value.hasValue(intF));
// Adding some more
value.setValue(longF, LongFieldValue(2));
// Not empty
- CPPUNIT_ASSERT_EQUAL(size_t(2), value.getSetFieldCount());
- CPPUNIT_ASSERT_EQUAL(1, value.getValue(intF)->getAsInt());
- CPPUNIT_ASSERT_EQUAL(2, value.getValue(longF)->getAsInt());
+ EXPECT_EQ(size_t(2), value.getSetFieldCount());
+ EXPECT_EQ(1, value.getValue(intF)->getAsInt());
+ EXPECT_EQ(2, value.getValue(longF)->getAsInt());
// Serialize & equality
std::unique_ptr<ByteBuffer> buffer(value.serialize());
buffer->flip();
Document value2(*repo.getDocumentType("test"),
DocumentId("userdoc::3:foo"));
- CPPUNIT_ASSERT(value != value2);
+ EXPECT_TRUE(value != value2);
value2.deserialize(repo, *buffer);
- CPPUNIT_ASSERT(value2.hasValue(intF));
- CPPUNIT_ASSERT_EQUAL(value, value2);
- CPPUNIT_ASSERT_EQUAL(DocumentId("doc::testdoc"), value2.getId());
+ EXPECT_TRUE(value2.hasValue(intF));
+ EXPECT_EQ(value, value2);
+ EXPECT_EQ(DocumentId("doc::testdoc"), value2.getId());
// Various ways of removing
{
@@ -454,29 +401,29 @@ void DocumentTest::testSimpleUsage()
buffer->setPos(0);
value2.deserialize(repo, *buffer);
value2.remove(intF);
- CPPUNIT_ASSERT(!value2.hasValue(intF));
- CPPUNIT_ASSERT_EQUAL(size_t(1), value2.getSetFieldCount());
+ EXPECT_TRUE(!value2.hasValue(intF));
+ EXPECT_EQ(size_t(1), value2.getSetFieldCount());
// Clearing all
buffer->setPos(0);
value2.deserialize(repo, *buffer);
value2.clear();
- CPPUNIT_ASSERT(!value2.hasValue(intF));
- CPPUNIT_ASSERT_EQUAL(size_t(0), value2.getSetFieldCount());
+ EXPECT_TRUE(!value2.hasValue(intF));
+ EXPECT_EQ(size_t(0), value2.getSetFieldCount());
}
// Updating
value2 = value;
- CPPUNIT_ASSERT_EQUAL(value, value2);
+ EXPECT_EQ(value, value2);
value2.setValue(strF, StringFieldValue("foo"));
- CPPUNIT_ASSERT(value2.hasValue(strF));
- CPPUNIT_ASSERT_EQUAL(vespalib::string("foo"),
+ EXPECT_TRUE(value2.hasValue(strF));
+ EXPECT_EQ(vespalib::string("foo"),
value2.getValue(strF)->getAsString());
- CPPUNIT_ASSERT(value != value2);
+ EXPECT_TRUE(value != value2);
value2.assign(value);
- CPPUNIT_ASSERT_EQUAL(value, value2);
+ EXPECT_EQ(value, value2);
Document::UP valuePtr(value2.clone());
- CPPUNIT_ASSERT_EQUAL(value, *valuePtr);
+ EXPECT_EQ(value, *valuePtr);
// Iterating
const Document& constVal(value);
@@ -488,20 +435,20 @@ void DocumentTest::testSimpleUsage()
// Comparison
value2 = value;
- CPPUNIT_ASSERT_EQUAL(0, value.compare(value2));
+ EXPECT_EQ(0, value.compare(value2));
value2.remove(intF);
- CPPUNIT_ASSERT(value.compare(value2) < 0);
- CPPUNIT_ASSERT(value2.compare(value) > 0);
+ EXPECT_TRUE(value.compare(value2) < 0);
+ EXPECT_TRUE(value2.compare(value) > 0);
value2 = value;
value2.setValue(intF, IntFieldValue(5));
- CPPUNIT_ASSERT(value.compare(value2) < 0);
- CPPUNIT_ASSERT(value2.compare(value) > 0);
+ EXPECT_TRUE(value.compare(value2) < 0);
+ EXPECT_TRUE(value2.compare(value) > 0);
// Output
- CPPUNIT_ASSERT_EQUAL(
+ EXPECT_EQ(
std::string("Document(doc::testdoc, DocumentType(test))"),
value.toString(false));
- CPPUNIT_ASSERT_EQUAL(
+ EXPECT_EQ(
std::string(
" Document(doc::testdoc\n"
" DocumentType(test, id -877171244)\n"
@@ -516,7 +463,7 @@ void DocumentTest::testSimpleUsage()
" long: 2\n"
" )"),
" " + value.toString(true, " "));
- CPPUNIT_ASSERT_EQUAL(
+ EXPECT_EQ(
std::string(
"<document documenttype=\"test\" documentid=\"doc::testdoc\">\n"
" <int>1</int>\n"
@@ -530,81 +477,81 @@ void DocumentTest::testSimpleUsage()
// (Would be nice if this failed, but whole idea to fetch by field
// objects is to improve performance.)
Field anotherIntF("int", 17, *DataType::INT, true);
- CPPUNIT_ASSERT(!value.hasValue(anotherIntF));
- CPPUNIT_ASSERT(value.getValue(anotherIntF).get() == 0);
+ EXPECT_TRUE(!value.hasValue(anotherIntF));
+ EXPECT_TRUE(!value.getValue(anotherIntF));
// Refuse to accept non-document types
try{
StructDataType otherType("foo", 4);
Document value6(otherType, DocumentId("doc::"));
- CPPUNIT_FAIL("Didn't complain about non-document type");
+ FAIL() << "Didn't complain about non-document type";
} catch (std::exception& e) {
- CPPUNIT_ASSERT_CONTAIN("Cannot generate a document with "
- "non-document type", e.what());
+ EXPECT_THAT(e.what(), HasSubstr("Cannot generate a document with "
+ "non-document type"));
}
// Refuse to set wrong types
try{
value2.setValue(intF, StringFieldValue("bar"));
- CPPUNIT_FAIL("Failed to check type equality in setValue");
+ FAIL() << "Failed to check type equality in setValue";
} catch (std::exception& e) {
- CPPUNIT_ASSERT_CONTAIN("Cannot assign value of type", e.what());
+ EXPECT_THAT(e.what(), HasSubstr("Cannot assign value of type"));
}
}
void verifyJavaDocument(Document& doc)
{
IntFieldValue intVal;
- CPPUNIT_ASSERT(doc.getValue(doc.getField("intfield"), intVal));
- CPPUNIT_ASSERT_EQUAL(5, intVal.getAsInt());
+ EXPECT_TRUE(doc.getValue(doc.getField("intfield"), intVal));
+ EXPECT_EQ(5, intVal.getAsInt());
FloatFieldValue floatVal;
- CPPUNIT_ASSERT(doc.getValue(doc.getField("floatfield"), floatVal));
- CPPUNIT_ASSERT(floatVal.getAsFloat() == (float) -9.23);
+ EXPECT_TRUE(doc.getValue(doc.getField("floatfield"), floatVal));
+ EXPECT_TRUE(floatVal.getAsFloat() == (float) -9.23);
StringFieldValue stringVal("");
- CPPUNIT_ASSERT(doc.getValue(doc.getField("stringfield"), stringVal));
- CPPUNIT_ASSERT_EQUAL(vespalib::string("This is a string."),
+ EXPECT_TRUE(doc.getValue(doc.getField("stringfield"), stringVal));
+ EXPECT_EQ(vespalib::string("This is a string."),
stringVal.getAsString());
LongFieldValue longVal;
- CPPUNIT_ASSERT(doc.getValue(doc.getField("longfield"), longVal));
- CPPUNIT_ASSERT_EQUAL((int64_t)398420092938472983LL, longVal.getAsLong());
+ EXPECT_TRUE(doc.getValue(doc.getField("longfield"), longVal));
+ EXPECT_EQ((int64_t)398420092938472983LL, longVal.getAsLong());
DoubleFieldValue doubleVal;
- CPPUNIT_ASSERT(doc.getValue(doc.getField("doublefield"), doubleVal));
- CPPUNIT_ASSERT_EQUAL(doubleVal.getAsDouble(), 98374532.398820);
+ EXPECT_TRUE(doc.getValue(doc.getField("doublefield"), doubleVal));
+ EXPECT_EQ(doubleVal.getAsDouble(), 98374532.398820);
ByteFieldValue byteVal;
- CPPUNIT_ASSERT(doc.getValue(doc.getField("bytefield"), byteVal));
- CPPUNIT_ASSERT_EQUAL(-2, byteVal.getAsInt());
+ EXPECT_TRUE(doc.getValue(doc.getField("bytefield"), byteVal));
+ EXPECT_EQ(-2, byteVal.getAsInt());
RawFieldValue rawVal;
- CPPUNIT_ASSERT(doc.getValue(doc.getField("rawfield"), rawVal));
- CPPUNIT_ASSERT(memcmp(rawVal.getAsRaw().first, "RAW DATA", 8) == 0);
+ EXPECT_TRUE(doc.getValue(doc.getField("rawfield"), rawVal));
+ EXPECT_TRUE(memcmp(rawVal.getAsRaw().first, "RAW DATA", 8) == 0);
Document embedDocVal;
- CPPUNIT_ASSERT(doc.getValue(doc.getField("docfield"), embedDocVal));
+ EXPECT_TRUE(doc.getValue(doc.getField("docfield"), embedDocVal));
ArrayFieldValue array(doc.getField("arrayoffloatfield").getDataType());
- CPPUNIT_ASSERT(doc.getValue(doc.getField("arrayoffloatfield"), array));
- CPPUNIT_ASSERT_EQUAL((float)1.0, array[0].getAsFloat());
- CPPUNIT_ASSERT_EQUAL((float)2.0, array[1].getAsFloat());
+ EXPECT_TRUE(doc.getValue(doc.getField("arrayoffloatfield"), array));
+ EXPECT_EQ((float)1.0, array[0].getAsFloat());
+ EXPECT_EQ((float)2.0, array[1].getAsFloat());
WeightedSetFieldValue wset(doc.getField("wsfield").getDataType());
- CPPUNIT_ASSERT(doc.getValue(doc.getField("wsfield"), wset));
- CPPUNIT_ASSERT_EQUAL(50, wset.get(StringFieldValue("Weighted 0")));
- CPPUNIT_ASSERT_EQUAL(199, wset.get(StringFieldValue("Weighted 1")));
+ EXPECT_TRUE(doc.getValue(doc.getField("wsfield"), wset));
+ EXPECT_EQ(50, wset.get(StringFieldValue("Weighted 0")));
+ EXPECT_EQ(199, wset.get(StringFieldValue("Weighted 1")));
MapFieldValue map(doc.getField("mapfield").getDataType());
- CPPUNIT_ASSERT(doc.getValue(doc.getField("mapfield"), map));
- CPPUNIT_ASSERT(map.get(StringFieldValue("foo1")).get());
- CPPUNIT_ASSERT(map.get(StringFieldValue("foo2")).get());
- CPPUNIT_ASSERT_EQUAL(StringFieldValue("bar1"), dynamic_cast<StringFieldValue&>(*map.get(StringFieldValue("foo1"))));
- CPPUNIT_ASSERT_EQUAL(StringFieldValue("bar2"), dynamic_cast<StringFieldValue&>(*map.get(StringFieldValue("foo2"))));
+ EXPECT_TRUE(doc.getValue(doc.getField("mapfield"), map));
+ EXPECT_TRUE(map.get(StringFieldValue("foo1")).get());
+ EXPECT_TRUE(map.get(StringFieldValue("foo2")).get());
+ EXPECT_EQ(StringFieldValue("bar1"), dynamic_cast<StringFieldValue&>(*map.get(StringFieldValue("foo1"))));
+ EXPECT_EQ(StringFieldValue("bar2"), dynamic_cast<StringFieldValue&>(*map.get(StringFieldValue("foo2"))));
}
-void DocumentTest::testReadSerializedFile()
+TEST(DocumentTest, testReadSerializedFile)
{
// Reads a file serialized from java
const std::string file_name = TEST_PATH("data/crossplatform-java-cpp-doctypes.cfg");
@@ -629,16 +576,16 @@ void DocumentTest::testReadSerializedFile()
Document doc2(repo, *buf2);
verifyJavaDocument(doc2);
- CPPUNIT_ASSERT_EQUAL(len, buf2->getPos());
- CPPUNIT_ASSERT(memcmp(buf2->getBuffer(), buf.getBuffer(), buf2->getPos()) == 0);
+ EXPECT_EQ(len, buf2->getPos());
+ EXPECT_TRUE(memcmp(buf2->getBuffer(), buf.getBuffer(), buf2->getPos()) == 0);
doc2.setValue("stringfield", StringFieldValue("hei"));
std::unique_ptr<ByteBuffer> buf3 = doc2.serialize();
- CPPUNIT_ASSERT(len != buf3->getPos());
+ EXPECT_TRUE(len != buf3->getPos());
}
-void DocumentTest::testReadSerializedFileCompressed()
+TEST(DocumentTest, testReadSerializedFileCompressed)
{
// Reads a file serialized from java
const std::string file_name = TEST_PATH("data/crossplatform-java-cpp-doctypes.cfg");
@@ -698,7 +645,7 @@ namespace {
* When adding new fields to the documents, use the version tagged with each
* file to ignore these field for old types.
*/
-void DocumentTest::testReadSerializedAllVersions()
+TEST(DocumentTest,testReadSerializedAllVersions)
{
const int array_id = 1650586661;
const int wset_id = 1328286588;
@@ -760,12 +707,12 @@ void DocumentTest::testReadSerializedAllVersions()
{
//doc.setCompression(CompressionConfig(CompressionConfig::NONE, 0, 0));
std::unique_ptr<ByteBuffer> buf = doc.serialize();
- CPPUNIT_ASSERT_EQUAL(buf->getLength(), buf->getPos());
+ EXPECT_EQ(buf->getLength(), buf->getPos());
int fd = open(TEST_PATH("data/document-cpp-currentversion-uncompressed.dat").c_str(),
O_WRONLY | O_CREAT | O_TRUNC, 0644);
- CPPUNIT_ASSERT(fd > 0);
+ EXPECT_TRUE(fd > 0);
size_t len = write(fd, buf->getBuffer(), buf->getPos());
- CPPUNIT_ASSERT_EQUAL(buf->getPos(), len);
+ EXPECT_EQ(buf->getPos(), len);
close(fd);
}
{
@@ -773,12 +720,12 @@ void DocumentTest::testReadSerializedAllVersions()
CompressionConfig newCfg(CompressionConfig::LZ4, 9, 95);
const_cast<StructDataType &>(doc.getType().getFieldsType()).setCompressionConfig(newCfg);
std::unique_ptr<ByteBuffer> buf = doc.serialize();
- CPPUNIT_ASSERT(buf->getPos() <= buf->getLength());
+ EXPECT_TRUE(buf->getPos() <= buf->getLength());
int fd = open(TEST_PATH("data/document-cpp-currentversion-lz4-9.dat").c_str(),
O_WRONLY | O_CREAT | O_TRUNC, 0644);
- CPPUNIT_ASSERT(fd > 0);
+ EXPECT_TRUE(fd > 0);
size_t len = write(fd, buf->getBuffer(), buf->getPos());
- CPPUNIT_ASSERT_EQUAL(buf->getPos(), len);
+ EXPECT_EQ(buf->getPos(), len);
close(fd);
const_cast<StructDataType &>(doc.getType().getFieldsType()).setCompressionConfig(oldCfg);
}
@@ -795,7 +742,7 @@ void DocumentTest::testReadSerializedAllVersions()
std::string name = tests[i]._dataFile;
std::cerr << name << std::endl;
if (!vespalib::fileExists(name)) {
- CPPUNIT_FAIL("File " + name + " does not exist.");
+ FAIL() << "File " << name << " does not exist.";
}
int fd = open(tests[i]._dataFile.c_str(), O_RDONLY);
int len = lseek(fd,0,SEEK_END);
@@ -809,54 +756,54 @@ void DocumentTest::testReadSerializedAllVersions()
Document doc(repo, buf);
IntFieldValue intVal;
- CPPUNIT_ASSERT(doc.getValue(doc.getField("intfield"), intVal));
- CPPUNIT_ASSERT_EQUAL(5, intVal.getAsInt());
+ EXPECT_TRUE(doc.getValue(doc.getField("intfield"), intVal));
+ EXPECT_EQ(5, intVal.getAsInt());
FloatFieldValue floatVal;
- CPPUNIT_ASSERT(doc.getValue(doc.getField("floatfield"), floatVal));
- CPPUNIT_ASSERT(floatVal.getAsFloat() == (float) -9.23);
+ EXPECT_TRUE(doc.getValue(doc.getField("floatfield"), floatVal));
+ EXPECT_TRUE(floatVal.getAsFloat() == (float) -9.23);
StringFieldValue stringVal("");
- CPPUNIT_ASSERT(doc.getValue(doc.getField("stringfield"), stringVal));
- CPPUNIT_ASSERT_EQUAL(vespalib::string("This is a string."),
+ EXPECT_TRUE(doc.getValue(doc.getField("stringfield"), stringVal));
+ EXPECT_EQ(vespalib::string("This is a string."),
stringVal.getAsString());
LongFieldValue longVal;
- CPPUNIT_ASSERT(doc.getValue(doc.getField("longfield"), longVal));
- CPPUNIT_ASSERT_EQUAL(static_cast<int64_t>(398420092938472983LL),
+ EXPECT_TRUE(doc.getValue(doc.getField("longfield"), longVal));
+ EXPECT_EQ(static_cast<int64_t>(398420092938472983LL),
longVal.getAsLong());
DoubleFieldValue doubleVal;
- CPPUNIT_ASSERT(doc.getValue(doc.getField("doublefield"), doubleVal));
- CPPUNIT_ASSERT_EQUAL(doubleVal.getAsDouble(), 98374532.398820);
+ EXPECT_TRUE(doc.getValue(doc.getField("doublefield"), doubleVal));
+ EXPECT_EQ(doubleVal.getAsDouble(), 98374532.398820);
ByteFieldValue byteVal;
- CPPUNIT_ASSERT(doc.getValue(doc.getField("bytefield"), byteVal));
- CPPUNIT_ASSERT_EQUAL(-2, byteVal.getAsInt());
+ EXPECT_TRUE(doc.getValue(doc.getField("bytefield"), byteVal));
+ EXPECT_EQ(-2, byteVal.getAsInt());
RawFieldValue rawVal;
- CPPUNIT_ASSERT(doc.getValue(doc.getField("rawfield"), rawVal));
- CPPUNIT_ASSERT(memcmp(rawVal.getAsRaw().first, "RAW DATA", 8) == 0);
+ EXPECT_TRUE(doc.getValue(doc.getField("rawfield"), rawVal));
+ EXPECT_TRUE(memcmp(rawVal.getAsRaw().first, "RAW DATA", 8) == 0);
if (version > 6) {
Document docInDoc;
- CPPUNIT_ASSERT(doc.getValue(doc.getField("docfield"), docInDoc));
+ EXPECT_TRUE(doc.getValue(doc.getField("docfield"), docInDoc));
- CPPUNIT_ASSERT(docInDoc.getValue(
+ EXPECT_TRUE(docInDoc.getValue(
docInDoc.getField("stringindocfield"), stringVal));
- CPPUNIT_ASSERT_EQUAL(vespalib::string("Elvis is dead"),
+ EXPECT_EQ(vespalib::string("Elvis is dead"),
stringVal.getAsString());
}
ArrayFieldValue array(doc.getField("arrayoffloatfield").getDataType());
- CPPUNIT_ASSERT(doc.getValue(doc.getField("arrayoffloatfield"), array));
- CPPUNIT_ASSERT_EQUAL((float)1.0, array[0].getAsFloat());
- CPPUNIT_ASSERT_EQUAL((float)2.0, array[1].getAsFloat());
+ EXPECT_TRUE(doc.getValue(doc.getField("arrayoffloatfield"), array));
+ EXPECT_EQ((float)1.0, array[0].getAsFloat());
+ EXPECT_EQ((float)2.0, array[1].getAsFloat());
WeightedSetFieldValue wset(doc.getField("wsfield").getDataType());
- CPPUNIT_ASSERT(doc.getValue(doc.getField("wsfield"), wset));
- CPPUNIT_ASSERT_EQUAL(50, wset.get(StringFieldValue("Weighted 0")));
- CPPUNIT_ASSERT_EQUAL(199, wset.get(StringFieldValue("Weighted 1")));
+ EXPECT_TRUE(doc.getValue(doc.getField("wsfield"), wset));
+ EXPECT_EQ(50, wset.get(StringFieldValue("Weighted 0")));
+ EXPECT_EQ(199, wset.get(StringFieldValue("Weighted 1")));
// Check that serialization doesn't cause any problems.
std::unique_ptr<ByteBuffer> buf2 = doc.serialize();
@@ -882,7 +829,7 @@ size_t getSerializedSizeBody(const Document &doc) {
return stream.size();
}
-void DocumentTest::testGenerateSerializedFile()
+TEST(DocumentTest, testGenerateSerializedFile)
{
const std::string file_name = TEST_PATH("data/crossplatform-java-cpp-doctypes.cfg");
DocumentTypeRepo repo(readDocumenttypesConfig(file_name));
@@ -900,7 +847,7 @@ void DocumentTest::testGenerateSerializedFile()
doc.set("rawfield", "RAW DATA");
const DocumentType *docindoc_type = repo.getDocumentType("docindoc");
- CPPUNIT_ASSERT(docindoc_type);
+ EXPECT_TRUE(docindoc_type);
Document embedDoc(*docindoc_type,
DocumentId(DocIdString("docindoc", "http://embedded")));
@@ -964,7 +911,8 @@ void DocumentTest::testGenerateSerializedFile()
}
close(fd);
}
-void DocumentTest::testGetURIFromSerialized()
+
+TEST(DocumentTest, testGetURIFromSerialized)
{
TestDocRepo test_repo;
Document doc(*test_repo.getDocumentType("testdoctype1"),
@@ -974,11 +922,11 @@ void DocumentTest::testGetURIFromSerialized()
std::unique_ptr<ByteBuffer> serialized = doc.serialize();
serialized->flip();
- CPPUNIT_ASSERT_EQUAL(
+ EXPECT_EQ(
vespalib::string(DocIdString("ns", "testdoc").toString()),
Document::getIdFromSerialized(*serialized).toString());
- CPPUNIT_ASSERT_EQUAL(vespalib::string("testdoctype1"),
+ EXPECT_EQ(vespalib::string("testdoctype1"),
Document::getDocTypeFromSerialized(
test_repo.getTypeRepo(),
*serialized)->getName());
@@ -989,34 +937,34 @@ void DocumentTest::testGetURIFromSerialized()
serialized->flip();
Document doc2(test_repo.getTypeRepo(), *serialized, false, NULL);
- CPPUNIT_ASSERT_EQUAL(
+ EXPECT_EQ(
vespalib::string(DocIdString("ns", "testdoc").toString()), doc2.getId().toString());
- CPPUNIT_ASSERT_EQUAL(vespalib::string("testdoctype1"), doc2.getType().getName());
+ EXPECT_EQ(vespalib::string("testdoctype1"), doc2.getType().getName());
}
-};
+}
-void DocumentTest::testBogusserialize()
+TEST(DocumentTest, testBogusserialize)
{
TestDocRepo test_repo;
try {
std::unique_ptr<ByteBuffer> buf(
new ByteBuffer("aoifjweprjwoejr203r+2+4r823++!",100));
Document doc(test_repo.getTypeRepo(), *buf);
- CPPUNIT_ASSERT(false);
+ FAIL() << "Failed to throw exception deserializing bogus data";
} catch (DeserializeException& e) {
- CPPUNIT_ASSERT_CONTAIN("Unrecognized serialization version", e.what());
+ EXPECT_THAT(e.what(), HasSubstr("Unrecognized serialization version"));
}
try {
std::unique_ptr<ByteBuffer> buf(new ByteBuffer("",0));
Document doc(test_repo.getTypeRepo(), *buf);
- CPPUNIT_ASSERT(false);
+ FAIL() << "Failed to throw exception deserializing empty buffer";
} catch (DeserializeException& e) {
- CPPUNIT_ASSERT_CONTAIN("Buffer out of bounds", e.what());
+ EXPECT_THAT(e.what(), HasSubstr("Buffer out of bounds"));
}
}
-void DocumentTest::testCRC32()
+TEST(DocumentTest, testCRC32)
{
TestDocRepo test_repo;
Document doc(*test_repo.getDocumentType("testdoctype1"),
@@ -1026,7 +974,7 @@ void DocumentTest::testCRC32()
StringFieldValue("bla bla bla bla bla"));
uint32_t crc = doc.calculateChecksum();
- CPPUNIT_ASSERT_EQUAL(277496115u, crc);
+ EXPECT_EQ(277496115u, crc);
std::unique_ptr<ByteBuffer> buf = doc.serialize();
buf->flip();
@@ -1040,9 +988,9 @@ void DocumentTest::testCRC32()
try {
Document doc2(test_repo.getTypeRepo(), *buf);
buf->setPos(0);
- CPPUNIT_ASSERT(crc != doc2.calculateChecksum());
+ EXPECT_TRUE(crc != doc2.calculateChecksum());
} catch (document::DeserializeException& e) {
- CPPUNIT_ASSERT(false);
+ EXPECT_TRUE(false);
}
// Return original value and retry
buf->getBuffer()[pos] ^= 72;
@@ -1050,19 +998,18 @@ void DocumentTest::testCRC32()
/// \todo TODO (was warning): Cannot test for in memory representation altered, as there is no syntax for getting internal refs to data from document. Add test when this is added.
}
-void
-DocumentTest::testHasChanged()
+TEST(DocumentTest, testHasChanged)
{
TestDocRepo test_repo;
Document doc(*test_repo.getDocumentType("testdoctype1"),
DocumentId(DocIdString("crawler", "http://www.ntnu.no/")));
// Before deserialization we are changed.
- CPPUNIT_ASSERT(doc.hasChanged());
+ EXPECT_TRUE(doc.hasChanged());
doc.setValue(doc.getField("hstringval"),
StringFieldValue("bla bla bla bla bla"));
// Still changed after setting a value of course.
- CPPUNIT_ASSERT(doc.hasChanged());
+ EXPECT_TRUE(doc.hasChanged());
std::unique_ptr<ByteBuffer> buf = doc.serialize();
buf->flip();
@@ -1071,10 +1018,10 @@ DocumentTest::testHasChanged()
{
buf->setPos(0);
Document doc2(test_repo.getTypeRepo(), *buf);
- CPPUNIT_ASSERT(!doc2.hasChanged());
+ EXPECT_TRUE(!doc2.hasChanged());
doc2.set("headerval", 13);
- CPPUNIT_ASSERT(doc2.hasChanged());
+ EXPECT_TRUE(doc2.hasChanged());
}
// Overwriting a value in doc tags us changed.
{
@@ -1082,7 +1029,7 @@ DocumentTest::testHasChanged()
Document doc2(test_repo.getTypeRepo(), *buf);
doc2.set("hstringval", "bla bla bla bla bla");
- CPPUNIT_ASSERT(doc2.hasChanged());
+ EXPECT_TRUE(doc2.hasChanged());
}
// Clearing value tags us changed.
{
@@ -1090,13 +1037,12 @@ DocumentTest::testHasChanged()
Document doc2(test_repo.getTypeRepo(), *buf);
doc2.clear();
- CPPUNIT_ASSERT(doc2.hasChanged());
+ EXPECT_TRUE(doc2.hasChanged());
}
// Add more tests here when we allow non-const refs to internals
}
-void
-DocumentTest::testSplitSerialization()
+TEST(DocumentTest, testSplitSerialization)
{
TestDocMan testDocMan;
Document::UP doc = testDocMan.createDocument();
@@ -1110,22 +1056,22 @@ DocumentTest::testSplitSerialization()
doc->serializeBody(buf2);
buf2.flip();
- CPPUNIT_ASSERT_EQUAL(size_t(65), buf.getLength());
- CPPUNIT_ASSERT_EQUAL(size_t(73), buf2.getLength());
+ EXPECT_EQ(size_t(65), buf.getLength());
+ EXPECT_EQ(size_t(73), buf2.getLength());
Document headerDoc(testDocMan.getTypeRepo(), buf);
- CPPUNIT_ASSERT(headerDoc.hasValue("headerval"));
- CPPUNIT_ASSERT(!headerDoc.hasValue("content"));
+ EXPECT_TRUE(headerDoc.hasValue("headerval"));
+ EXPECT_TRUE(!headerDoc.hasValue("content"));
buf.setPos(0);
Document fullDoc(testDocMan.getTypeRepo(), buf, buf2);
- CPPUNIT_ASSERT(fullDoc.hasValue("headerval"));
- CPPUNIT_ASSERT(fullDoc.hasValue("content"));
+ EXPECT_TRUE(fullDoc.hasValue("headerval"));
+ EXPECT_TRUE(fullDoc.hasValue("content"));
- CPPUNIT_ASSERT_EQUAL(*doc, fullDoc);
+ EXPECT_EQ(*doc, fullDoc);
}
-void DocumentTest::testSliceSerialize()
+TEST(DocumentTest, testSliceSerialize)
{
// Test that document doesn't need its own bytebuffer, such that we
// can serialize multiple documents after each other in the same
@@ -1143,23 +1089,23 @@ void DocumentTest::testSliceSerialize()
ByteBuffer buf(getSerializedSize(*doc) + getSerializedSize(*doc2));
doc->serialize(buf);
- CPPUNIT_ASSERT_EQUAL(getSerializedSize(*doc), buf.getPos());
+ EXPECT_EQ(getSerializedSize(*doc), buf.getPos());
doc2->serialize(buf);
- CPPUNIT_ASSERT_EQUAL(getSerializedSize(*doc) + getSerializedSize(*doc2),
+ EXPECT_EQ(getSerializedSize(*doc) + getSerializedSize(*doc2),
buf.getPos());
buf.flip();
Document doc3(testDocMan.getTypeRepo(), buf);
- CPPUNIT_ASSERT_EQUAL(getSerializedSize(*doc), buf.getPos());
+ EXPECT_EQ(getSerializedSize(*doc), buf.getPos());
Document doc4(testDocMan.getTypeRepo(), buf);
- CPPUNIT_ASSERT_EQUAL(getSerializedSize(*doc) + getSerializedSize(*doc2),
+ EXPECT_EQ(getSerializedSize(*doc) + getSerializedSize(*doc2),
buf.getPos());
- CPPUNIT_ASSERT_EQUAL(*doc, doc3);
- CPPUNIT_ASSERT_EQUAL(*doc2, doc4);
+ EXPECT_EQ(*doc, doc3);
+ EXPECT_EQ(*doc2, doc4);
}
-void DocumentTest::testCompression()
+TEST(DocumentTest, testCompression)
{
TestDocMan testDocMan;
Document::UP doc = testDocMan.createDocument();
@@ -1181,14 +1127,14 @@ void DocumentTest::testCompression()
const_cast<StructDataType &>(doc->getType().getFieldsType()).setCompressionConfig(oldCfg);
- CPPUNIT_ASSERT(buf_lz4->getRemaining() < buf_uncompressed->getRemaining());
+ EXPECT_TRUE(buf_lz4->getRemaining() < buf_uncompressed->getRemaining());
Document doc_lz4(testDocMan.getTypeRepo(), *buf_lz4);
- CPPUNIT_ASSERT_EQUAL(*doc, doc_lz4);
+ EXPECT_EQ(*doc, doc_lz4);
}
-void DocumentTest::testCompressionConfigured()
+TEST(DocumentTest, testCompressionConfigured)
{
DocumenttypesConfigBuilderHelper builder;
builder.document(43, "serializetest",
@@ -1225,23 +1171,22 @@ void DocumentTest::testCompressionConfigured()
buf_compressed->flip();
size_t compressedSize = buf_compressed->getRemaining();
- CPPUNIT_ASSERT(compressedSize < uncompressedSize);
+ EXPECT_TRUE(compressedSize < uncompressedSize);
Document doc2(repo2, *buf_compressed);
std::unique_ptr<ByteBuffer> buf_compressed2 = doc2.serialize();
buf_compressed2->flip();
- CPPUNIT_ASSERT_EQUAL(compressedSize, buf_compressed2->getRemaining());
+ EXPECT_EQ(compressedSize, buf_compressed2->getRemaining());
Document doc3(repo2, *buf_compressed2);
- CPPUNIT_ASSERT_EQUAL(doc2, doc_uncompressed);
- CPPUNIT_ASSERT_EQUAL(doc2, doc3);
+ EXPECT_EQ(doc2, doc_uncompressed);
+ EXPECT_EQ(doc2, doc3);
}
-void
-DocumentTest::testUnknownEntries()
+TEST(DocumentTest, testUnknownEntries)
{
// We should be able to deserialize a document with unknown values in it.
DocumentType type1("test", 0);
@@ -1289,40 +1234,40 @@ DocumentTest::testUnknownEntries()
doc3.deserializeHeader(repo, header);
doc3.deserializeBody(repo, body);
- CPPUNIT_ASSERT_EQUAL(std::string(
+ EXPECT_EQ(std::string(
"<document documenttype=\"test\" documentid=\"doc::testdoc\">\n"
"<int3>3</int3>\n"
"<int4>4</int4>\n"
"</document>"), doc2.toXml());
- CPPUNIT_ASSERT_EQUAL(std::string(
+ EXPECT_EQ(std::string(
"<document documenttype=\"test\" documentid=\"doc::testdoc\">\n"
"<int3>3</int3>\n"
"<int4>4</int4>\n"
"</document>"), doc3.toXml());
- CPPUNIT_ASSERT_EQUAL(3, doc2.getValue(field3)->getAsInt());
- CPPUNIT_ASSERT_EQUAL(4, doc2.getValue(field4)->getAsInt());
- CPPUNIT_ASSERT_EQUAL(3, doc3.getValue(field3)->getAsInt());
- CPPUNIT_ASSERT_EQUAL(4, doc3.getValue(field4)->getAsInt());
+ EXPECT_EQ(3, doc2.getValue(field3)->getAsInt());
+ EXPECT_EQ(4, doc2.getValue(field4)->getAsInt());
+ EXPECT_EQ(3, doc3.getValue(field3)->getAsInt());
+ EXPECT_EQ(4, doc3.getValue(field4)->getAsInt());
// The fields are actually accessible as long as you ask with field of
// correct type.
- CPPUNIT_ASSERT(doc2.hasValue(field1));
- CPPUNIT_ASSERT(doc2.hasValue(field2));
- CPPUNIT_ASSERT(doc3.hasValue(field1));
- CPPUNIT_ASSERT(doc3.hasValue(field2));
+ EXPECT_TRUE(doc2.hasValue(field1));
+ EXPECT_TRUE(doc2.hasValue(field2));
+ EXPECT_TRUE(doc3.hasValue(field1));
+ EXPECT_TRUE(doc3.hasValue(field2));
- CPPUNIT_ASSERT_EQUAL(1, doc2.getValue(field1)->getAsInt());
- CPPUNIT_ASSERT_EQUAL(2, doc2.getValue(field2)->getAsInt());
- CPPUNIT_ASSERT_EQUAL(1, doc3.getValue(field1)->getAsInt());
- CPPUNIT_ASSERT_EQUAL(2, doc3.getValue(field2)->getAsInt());
+ EXPECT_EQ(1, doc2.getValue(field1)->getAsInt());
+ EXPECT_EQ(2, doc2.getValue(field2)->getAsInt());
+ EXPECT_EQ(1, doc3.getValue(field1)->getAsInt());
+ EXPECT_EQ(2, doc3.getValue(field2)->getAsInt());
- CPPUNIT_ASSERT_EQUAL(size_t(2), doc2.getSetFieldCount());
- CPPUNIT_ASSERT_EQUAL(size_t(2), doc3.getSetFieldCount());
+ EXPECT_EQ(size_t(2), doc2.getSetFieldCount());
+ EXPECT_EQ(size_t(2), doc3.getSetFieldCount());
}
-void DocumentTest::testAnnotationDeserialization()
+TEST(DocumentTest, testAnnotationDeserialization)
{
DocumenttypesConfigBuilderHelper builder;
builder.document(-1326249427, "dokk", Struct("dokk.header"),
@@ -1358,7 +1303,7 @@ void DocumentTest::testAnnotationDeserialization()
Document doc(repo, buf);
StringFieldValue strVal;
- CPPUNIT_ASSERT(doc.getValue(doc.getField("story"), strVal));
+ EXPECT_TRUE(doc.getValue(doc.getField("story"), strVal));
vespalib::nbostream stream;
VespaDocumentSerializer serializer(stream);
@@ -1368,49 +1313,47 @@ void DocumentTest::testAnnotationDeserialization()
VespaDocumentDeserializer deserializer(fixedRepo, stream, 8);
StringFieldValue strVal2;
deserializer.read(strVal2);
- CPPUNIT_ASSERT_EQUAL(strVal.toString(), strVal2.toString());
- CPPUNIT_ASSERT_EQUAL(strVal.toString(true), strVal2.toString(true));
+ EXPECT_EQ(strVal.toString(), strVal2.toString());
+ EXPECT_EQ(strVal.toString(true), strVal2.toString(true));
- CPPUNIT_ASSERT_EQUAL(vespalib::string("help me help me i'm stuck inside a computer!"),
+ EXPECT_EQ(vespalib::string("help me help me i'm stuck inside a computer!"),
strVal.getAsString());
StringFieldValue::SpanTrees trees = strVal.getSpanTrees();
const SpanTree *span_tree = StringFieldValue::findTree(trees, "fruits");
- CPPUNIT_ASSERT(span_tree);
- CPPUNIT_ASSERT_EQUAL(size_t(8), span_tree->numAnnotations());
+ EXPECT_TRUE(span_tree);
+ EXPECT_EQ(size_t(8), span_tree->numAnnotations());
span_tree = StringFieldValue::findTree(trees, "ballooo");
- CPPUNIT_ASSERT(span_tree);
- CPPUNIT_ASSERT_EQUAL(size_t(8), span_tree->numAnnotations());
+ EXPECT_TRUE(span_tree);
+ EXPECT_EQ(size_t(8), span_tree->numAnnotations());
ByteFieldValue byteVal;
- CPPUNIT_ASSERT(doc.getValue(doc.getField("age"), byteVal));
- CPPUNIT_ASSERT_EQUAL( 123, byteVal.getAsInt());
+ EXPECT_TRUE(doc.getValue(doc.getField("age"), byteVal));
+ EXPECT_EQ( 123, byteVal.getAsInt());
IntFieldValue intVal;
- CPPUNIT_ASSERT(doc.getValue(doc.getField("date"), intVal));
- CPPUNIT_ASSERT_EQUAL(13829297, intVal.getAsInt());
+ EXPECT_TRUE(doc.getValue(doc.getField("date"), intVal));
+ EXPECT_EQ(13829297, intVal.getAsInt());
LongFieldValue longVal;
- CPPUNIT_ASSERT(doc.getValue(doc.getField("friend"), longVal));
- CPPUNIT_ASSERT_EQUAL((int64_t)2384LL, longVal.getAsLong());
+ EXPECT_TRUE(doc.getValue(doc.getField("friend"), longVal));
+ EXPECT_EQ((int64_t)2384LL, longVal.getAsLong());
}
-void
-DocumentTest::testGetSerializedSize()
+TEST(DocumentTest, testGetSerializedSize)
{
TestDocMan testDocMan;
Document::UP doc = testDocMan.createDocument();
- CPPUNIT_ASSERT_EQUAL(getSerializedSize(*doc), doc->getSerializedSize());
+ EXPECT_EQ(getSerializedSize(*doc), doc->getSerializedSize());
}
-void
-DocumentTest::testDeserializeMultiple()
+TEST(DocumentTest, testDeserializeMultiple)
{
TestDocRepo testDocRepo;
const DocumentTypeRepo& repo(testDocRepo.getTypeRepo());
const DocumentType* docTypePtr(repo.getDocumentType("testdoctype1"));
- CPPUNIT_ASSERT(docTypePtr != 0);
+ EXPECT_TRUE(docTypePtr != nullptr);
const DocumentType & docType = *docTypePtr;
StructFieldValue sv1(docType.getField("mystruct").getDataType());
@@ -1435,7 +1378,7 @@ DocumentTest::testDeserializeMultiple()
correct.setValue(correct.getField("key"), IntFieldValue(1234));
correct.setValue(correct.getField("value"), StringFieldValue("badger"));
- CPPUNIT_ASSERT_EQUAL(correct, sv3);
+ EXPECT_EQ(correct, sv3);
}
-} // document
+}
diff --git a/document/src/tests/documenttypetestcase.cpp b/document/src/tests/documenttypetestcase.cpp
index d6707bc610a..649367d76f3 100644
--- a/document/src/tests/documenttypetestcase.cpp
+++ b/document/src/tests/documenttypetestcase.cpp
@@ -4,70 +4,40 @@
#include <vespa/document/fieldvalue/fieldvalues.h>
#include <vespa/document/repo/configbuilder.h>
#include <vespa/document/repo/documenttyperepo.h>
-#include <vespa/vdstestlib/cppunit/macros.h>
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/vespalib/util/exceptions.h>
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
using document::config_builder::Struct;
using document::config_builder::Wset;
using document::config_builder::Array;
using document::config_builder::Map;
+using namespace ::testing;
namespace document {
-struct DocumentTypeTest : public CppUnit::TestFixture {
- void setUp() override;
- void tearDown() override;
-
- void testSetGet();
- void testHeaderContent();
- void testFieldSetCanContainFieldsNotInDocType();
- void testInheritance();
- void testInheritanceConfig();
- void testMultipleInheritance();
- void testOutputOperator();
-
- CPPUNIT_TEST_SUITE( DocumentTypeTest);
- CPPUNIT_TEST(testSetGet);
- CPPUNIT_TEST(testFieldSetCanContainFieldsNotInDocType);
- CPPUNIT_TEST(testInheritance);
- CPPUNIT_TEST(testInheritanceConfig);
- CPPUNIT_TEST(testMultipleInheritance);
- CPPUNIT_TEST(testOutputOperator);
- CPPUNIT_TEST(testHeaderContent);
- CPPUNIT_TEST_SUITE_END();
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(DocumentTypeTest);
-
-void DocumentTypeTest::setUp()
+TEST(DocumentTypeTest, testSetGet)
{
-}
-
-void DocumentTypeTest::tearDown()
-{
-}
-
-void DocumentTypeTest::testSetGet() {
DocumentType docType("doctypetestdoc", 0);
docType.addField(Field("stringattr", 3, *DataType::STRING, true));
docType.addField(Field("nalle", 0, *DataType::INT, false));
- const Field& fetch1=docType.getField("stringattr");
- const Field& fetch2=docType.getField("stringattr");
+ const Field& fetch1 = docType.getField("stringattr");
+ const Field& fetch2 = docType.getField("stringattr");
- CPPUNIT_ASSERT(fetch1==fetch2);
- CPPUNIT_ASSERT(fetch1.getName() == "stringattr");
+ EXPECT_TRUE(fetch1 == fetch2);
+ EXPECT_TRUE(fetch1.getName() == "stringattr");
const Field& fetch3 = docType.getField(3);
- CPPUNIT_ASSERT(fetch1==fetch3);
+ EXPECT_TRUE(fetch1 == fetch3);
- const Field& fetch4=docType.getField(0);
+ const Field& fetch4 = docType.getField(0);
- CPPUNIT_ASSERT(fetch4!=fetch1);
+ EXPECT_TRUE(fetch4 != fetch1);
}
void
@@ -86,24 +56,22 @@ categorizeFields(const Field::Set& fields,
}
}
-void
-DocumentTypeTest::testInheritanceConfig()
+TEST(DocumentTypeTest, testInheritanceConfig)
{
DocumentTypeRepo
repo(readDocumenttypesConfig(TEST_PATH("data/inheritancetest.cfg")));
{
const DocumentType* type(repo.getDocumentType("music"));
- CPPUNIT_ASSERT(type != NULL);
+ EXPECT_TRUE(type != NULL);
}
{
const DocumentType* type(repo.getDocumentType("books"));
- CPPUNIT_ASSERT(type != NULL);
+ EXPECT_TRUE(type != NULL);
}
}
-void
-DocumentTypeTest::testHeaderContent()
+TEST(DocumentTypeTest, testHeaderContent)
{
DocumentTypeRepo
repo(readDocumenttypesConfig(TEST_PATH("data/doctypesconfigtest.cfg")));
@@ -116,18 +84,18 @@ DocumentTypeTest::testHeaderContent()
std::vector<const Field*> bodies;
categorizeFields(fields, headers, bodies);
- CPPUNIT_ASSERT(headers.size() == 4);
- CPPUNIT_ASSERT(headers[0]->getName() == "field1");
- CPPUNIT_ASSERT(headers[1]->getName() == "field2");
- CPPUNIT_ASSERT(headers[2]->getName() == "field4");
- CPPUNIT_ASSERT(headers[3]->getName() == "fieldarray1");
+ EXPECT_TRUE(headers.size() == 4);
+ EXPECT_TRUE(headers[0]->getName() == "field1");
+ EXPECT_TRUE(headers[1]->getName() == "field2");
+ EXPECT_TRUE(headers[2]->getName() == "field4");
+ EXPECT_TRUE(headers[3]->getName() == "fieldarray1");
- CPPUNIT_ASSERT(bodies.size() == 2);
- CPPUNIT_ASSERT(bodies[0]->getName() == "field3");
- CPPUNIT_ASSERT(bodies[1]->getName() == "field5");
+ EXPECT_TRUE(bodies.size() == 2);
+ EXPECT_TRUE(bodies[0]->getName() == "field3");
+ EXPECT_TRUE(bodies[1]->getName() == "field5");
}
-void DocumentTypeTest::testMultipleInheritance()
+TEST(DocumentTypeTest, testMultipleInheritance)
{
config_builder::DocumenttypesConfigBuilderHelper builder;
builder.document(42, "test1", Struct("test1.header"),
@@ -145,10 +113,10 @@ void DocumentTypeTest::testMultipleInheritance()
DocumentTypeRepo repo(builder.config());
const DocumentType* docType3(repo.getDocumentType("test3"));
- CPPUNIT_ASSERT(docType3->hasField("stringattr"));
- CPPUNIT_ASSERT(docType3->hasField("nalle"));
- CPPUNIT_ASSERT(docType3->hasField("tmp"));
- CPPUNIT_ASSERT(docType3->hasField("tall"));
+ EXPECT_TRUE(docType3->hasField("stringattr"));
+ EXPECT_TRUE(docType3->hasField("nalle"));
+ EXPECT_TRUE(docType3->hasField("tmp"));
+ EXPECT_TRUE(docType3->hasField("tall"));
Document doc(*docType3, DocumentId(DocIdString("test", "test")));
@@ -158,9 +126,9 @@ void DocumentTypeTest::testMultipleInheritance()
StringFieldValue stringVal("tmp");
doc.setValue(doc.getField("tmp"), stringVal);
- CPPUNIT_ASSERT(doc.getValue(doc.getField("nalle"))->getAsInt()==3);
- CPPUNIT_ASSERT_EQUAL(vespalib::string("tmp"),
- doc.getValue(doc.getField("tmp"))->getAsString());
+ EXPECT_TRUE(doc.getValue(doc.getField("nalle"))->getAsInt()==3);
+ EXPECT_EQ(vespalib::string("tmp"),
+ doc.getValue(doc.getField("tmp"))->getAsString());
}
namespace {
@@ -171,7 +139,8 @@ bool containsField(const DocumentType::FieldSet &fieldSet, const vespalib::strin
}
-void DocumentTypeTest::testFieldSetCanContainFieldsNotInDocType() {
+TEST(DocumentTypeTest, testFieldSetCanContainFieldsNotInDocType)
+{
DocumentType docType("test1");
docType.addField(Field("stringattr", 3, *DataType::STRING, false));
docType.addField(Field("nalle", 0, *DataType::INT, false));
@@ -182,12 +151,12 @@ void DocumentTypeTest::testFieldSetCanContainFieldsNotInDocType() {
docType.addFieldSet("a", tmp);
}
auto fieldSet = docType.getFieldSet("a");
- CPPUNIT_ASSERT_EQUAL((size_t)2, fieldSet->getFields().size());
- CPPUNIT_ASSERT(containsField(*fieldSet, "nalle"));
- CPPUNIT_ASSERT(containsField(*fieldSet, "nulle"));
+ EXPECT_EQ((size_t)2, fieldSet->getFields().size());
+ EXPECT_TRUE(containsField(*fieldSet, "nalle"));
+ EXPECT_TRUE(containsField(*fieldSet, "nulle"));
}
-void DocumentTypeTest::testInheritance()
+TEST(DocumentTypeTest, testInheritance)
{
// Inheritance of conflicting but equal datatype ok
DocumentType docType("test1");
@@ -200,10 +169,10 @@ void DocumentTypeTest::testInheritance()
docType2.addField(Field("tall", 10, *DataType::INT, false));
docType.inherit(docType2);
- CPPUNIT_ASSERT(docType.hasField("stringattr"));
- CPPUNIT_ASSERT(docType.hasField("nalle"));
- CPPUNIT_ASSERT(docType.hasField("tmp"));
- CPPUNIT_ASSERT(docType.hasField("tall"));
+ EXPECT_TRUE(docType.hasField("stringattr"));
+ EXPECT_TRUE(docType.hasField("nalle"));
+ EXPECT_TRUE(docType.hasField("tmp"));
+ EXPECT_TRUE(docType.hasField("tall"));
DocumentType docType3("test3");
docType3.addField(Field("stringattr", 3, *DataType::RAW, false));
@@ -211,29 +180,29 @@ void DocumentTypeTest::testInheritance()
try{
docType2.inherit(docType3);
- //CPPUNIT_FAIL("Supposed to fail");
+ // FAIL() << "Supposed to fail";
} catch (std::exception& e) {
- CPPUNIT_ASSERT_EQUAL(std::string("foo"), std::string(e.what()));
+ EXPECT_EQ(std::string("foo"), std::string(e.what()));
}
try{
docType.inherit(docType3);
- //CPPUNIT_FAIL("Supposed to fail");
+ // FAIL() << "Supposed to fail";
} catch (std::exception& e) {
- CPPUNIT_ASSERT_EQUAL(std::string("foo"), std::string(e.what()));
+ EXPECT_EQ(std::string("foo"), std::string(e.what()));
}
DocumentType docType4("test4");
docType4.inherit(docType3);
- CPPUNIT_ASSERT(docType4.hasField("stringattr"));
- CPPUNIT_ASSERT(docType4.hasField("tall"));
+ EXPECT_TRUE(docType4.hasField("stringattr"));
+ EXPECT_TRUE(docType4.hasField("tall"));
try{
docType3.inherit(docType4);
- CPPUNIT_FAIL("Accepted cyclic inheritance");
+ FAIL() << "Accepted cyclic inheritance";
} catch (std::exception& e) {
- CPPUNIT_ASSERT_CONTAIN("Cannot add cyclic dependencies", e.what());
+ EXPECT_THAT(e.what(), HasSubstr("Cannot add cyclic dependencies"));
}
DocumentType docType5("test5");
@@ -241,18 +210,19 @@ void DocumentTypeTest::testInheritance()
try{
docType4.inherit(docType5);
- //CPPUNIT_FAIL("Supposed to fail");
+ // FAIL() << "Supposed to fail";
} catch (std::exception& e) {
- CPPUNIT_ASSERT_EQUAL(std::string("foo"), std::string(e.what()));
+ EXPECT_EQ(std::string("foo"), std::string(e.what()));
}
}
-void DocumentTypeTest::testOutputOperator() {
+TEST(DocumentTypeTest,testOutputOperator)
+{
DocumentType docType("test1");
std::ostringstream ost;
ost << docType;
std::string expected("DocumentType(test1)");
- CPPUNIT_ASSERT_EQUAL(expected, ost.str());
+ EXPECT_EQ(expected, ost.str());
}
} // document
diff --git a/document/src/tests/fieldpathupdatetestcase.cpp b/document/src/tests/fieldpathupdatetestcase.cpp
index 35b851ca895..74e2c20ad86 100644
--- a/document/src/tests/fieldpathupdatetestcase.cpp
+++ b/document/src/tests/fieldpathupdatetestcase.cpp
@@ -5,7 +5,6 @@
#include <vespa/document/base/exceptions.h>
#include <vespa/vespalib/io/fileutil.h>
-#include <vespa/vdstestlib/cppunit/macros.h>
#include <vespa/document/update/fieldpathupdates.h>
#include <vespa/document/update/documentupdate.h>
@@ -17,6 +16,7 @@
#include <vespa/document/serialization/vespadocumentserializer.h>
#include <vespa/vespalib/objects/nbostream.h>
#include <fcntl.h>
+#include <gtest/gtest.h>
using vespalib::Identifiable;
using namespace document::config_builder;
@@ -25,103 +25,19 @@ namespace document {
using namespace fieldvalue;
-struct FieldPathUpdateTestCase : public CppUnit::TestFixture {
+class FieldPathUpdateTestCase : public ::testing::Test {
+protected:
std::shared_ptr<const DocumentTypeRepo> _repo;
DocumentType _foobar_type;
+ ~FieldPathUpdateTestCase();
+
+ void SetUp() override;
+ void TearDown() override;
- void setUp() override;
- void tearDown() override;
-
- void testWhereClause();
- void testBrokenWhereClause();
- void testNoIterateMapValues();
- void testRemoveField();
- void testApplyRemoveEntireListField();
- void testApplyRemoveMultiList();
- void testApplyRemoveMultiList2();
- void testApplyRemoveMultiWset();
- void testApplyAssignSingle();
- void testApplyAssignMath();
- void testApplyAssignMathDivZero();
- void testApplyAssignMathByteToZero();
- void testApplyAssignMathNotModifiedOnUnderflow();
- void testApplyAssignMathNotModifiedOnOverflow();
- void testApplyAssignFieldNotExistingInExpression();
- void testApplyAssignFieldNotExistingInPath();
- void testApplyAssignTargetNotExisting();
- void testAssignSimpleMapValueWithVariable();
- void testApplyAssignMathRemoveIfZero();
- void testApplyAssignMultiList();
- void testApplyAssignMultiWset();
- void testAssignWsetRemoveIfZero();
- void testApplyAddMultiList();
- void testAddAndAssignList();
- void testAssignMap();
- void testAssignMapStruct();
- void testAssignMapStructVariable();
- void testAssignMapNoExist();
- void testAssignMapNoExistNoCreate();
- void testQuotedStringKey();
- void testEqualityComparison();
- void testAffectsDocumentBody();
- void testIncompatibleDataTypeFails();
- void testSerializeAssign();
- void testSerializeAdd();
- void testSerializeRemove();
- void testSerializeAssignMath();
- void testReadSerializedFile();
- void testGenerateSerializedFile();
- void array_element_update_for_invalid_index_is_ignored();
-
- CPPUNIT_TEST_SUITE(FieldPathUpdateTestCase);
- CPPUNIT_TEST(testWhereClause);
- CPPUNIT_TEST(testBrokenWhereClause);
- CPPUNIT_TEST(testNoIterateMapValues);
- CPPUNIT_TEST(testRemoveField);
- CPPUNIT_TEST(testApplyRemoveEntireListField);
- CPPUNIT_TEST(testApplyRemoveMultiList);
- CPPUNIT_TEST(testApplyRemoveMultiList2);
- CPPUNIT_TEST(testApplyRemoveMultiWset);
- CPPUNIT_TEST(testApplyAssignSingle);
- CPPUNIT_TEST(testApplyAssignMath);
- CPPUNIT_TEST(testApplyAssignMathDivZero);
- CPPUNIT_TEST(testApplyAssignMathByteToZero);
- CPPUNIT_TEST(testApplyAssignMathNotModifiedOnUnderflow);
- CPPUNIT_TEST(testApplyAssignMathNotModifiedOnOverflow);
- CPPUNIT_TEST(testApplyAssignFieldNotExistingInExpression);
- CPPUNIT_TEST(testApplyAssignFieldNotExistingInPath);
- CPPUNIT_TEST(testApplyAssignTargetNotExisting);
- CPPUNIT_TEST(testAssignSimpleMapValueWithVariable);
- CPPUNIT_TEST(testApplyAssignMathRemoveIfZero);
- CPPUNIT_TEST(testApplyAssignMultiList);
- CPPUNIT_TEST(testApplyAssignMultiWset);
- CPPUNIT_TEST(testAssignWsetRemoveIfZero);
- CPPUNIT_TEST(testApplyAddMultiList);
- CPPUNIT_TEST(testAddAndAssignList);
- CPPUNIT_TEST(testAssignMap);
- CPPUNIT_TEST(testAssignMapStruct);
- CPPUNIT_TEST(testAssignMapStructVariable);
- CPPUNIT_TEST(testAssignMapNoExist);
- CPPUNIT_TEST(testAssignMapNoExistNoCreate);
- CPPUNIT_TEST(testQuotedStringKey);
- CPPUNIT_TEST(testEqualityComparison);
- CPPUNIT_TEST(testAffectsDocumentBody);
- CPPUNIT_TEST(testIncompatibleDataTypeFails);
- CPPUNIT_TEST(testSerializeAssign);
- CPPUNIT_TEST(testSerializeAdd);
- CPPUNIT_TEST(testSerializeRemove);
- CPPUNIT_TEST(testSerializeAssignMath);
- CPPUNIT_TEST(testReadSerializedFile);
- CPPUNIT_TEST(testGenerateSerializedFile);
- CPPUNIT_TEST(array_element_update_for_invalid_index_is_ignored);
- CPPUNIT_TEST_SUITE_END();
-private:
DocumentUpdate::UP
createDocumentUpdateForSerialization(const DocumentTypeRepo& repo);
};
-CPPUNIT_TEST_SUITE_REGISTRATION(FieldPathUpdateTestCase);
-
namespace {
document::DocumenttypesConfig getRepoConfig() {
@@ -233,29 +149,28 @@ void testSerialize(const DocumentTypeRepo& repo, const DocumentUpdate& a) {
bb->flip();
DocumentUpdate::UP b(DocumentUpdate::createHEAD(repo, *bb));
- CPPUNIT_ASSERT_EQUAL(size_t(0), bb->getRemaining());
- CPPUNIT_ASSERT_EQUAL(a.getId().toString(), b->getId().toString());
- CPPUNIT_ASSERT_EQUAL(a.getUpdates().size(), b->getUpdates().size());
+ EXPECT_EQ(size_t(0), bb->getRemaining());
+ EXPECT_EQ(a.getId().toString(), b->getId().toString());
+ EXPECT_EQ(a.getUpdates().size(), b->getUpdates().size());
for (size_t i(0); i < a.getUpdates().size(); i++) {
const FieldUpdate & ua = a.getUpdates()[i];
const FieldUpdate & ub = b->getUpdates()[i];
- CPPUNIT_ASSERT_EQUAL(&ua.getField(), &ub.getField());
- CPPUNIT_ASSERT_EQUAL(ua.getUpdates().size(),
+ EXPECT_EQ(&ua.getField(), &ub.getField());
+ EXPECT_EQ(ua.getUpdates().size(),
ub.getUpdates().size());
for (size_t j(0); j < ua.getUpdates().size(); j++) {
- CPPUNIT_ASSERT_EQUAL(ua.getUpdates()[j]->getType(),
- ub.getUpdates()[j]->getType());
+ EXPECT_EQ(ua.getUpdates()[j]->getType(), ub.getUpdates()[j]->getType());
}
}
- CPPUNIT_ASSERT_EQUAL(a.getFieldPathUpdates().size(), b->getFieldPathUpdates().size());
+ EXPECT_EQ(a.getFieldPathUpdates().size(), b->getFieldPathUpdates().size());
for (size_t i(0); i < a.getFieldPathUpdates().size(); i++) {
const FieldPathUpdate::CP& ua = a.getFieldPathUpdates()[i];
const FieldPathUpdate::CP& ub = b->getFieldPathUpdates()[i];
- CPPUNIT_ASSERT_EQUAL(*ua, *ub);
+ EXPECT_EQ(*ua, *ub);
}
- CPPUNIT_ASSERT_EQUAL(a, *b);
+ EXPECT_EQ(a, *b);
} catch (std::exception& e) {
std::cerr << "Failed while testing document field path update:\n"
<< a.toString(true) << "\n";
@@ -320,8 +235,10 @@ TestFieldPathUpdate::TestFieldPathUpdate(const TestFieldPathUpdate& other)
{
}
+FieldPathUpdateTestCase::~FieldPathUpdateTestCase() = default;
+
void
-FieldPathUpdateTestCase::setUp()
+FieldPathUpdateTestCase::SetUp()
{
DocumenttypesConfigBuilderHelper builder;
builder.document(42, "foobar",
@@ -344,62 +261,57 @@ FieldPathUpdateTestCase::setUp()
}
void
-FieldPathUpdateTestCase::tearDown()
+FieldPathUpdateTestCase::TearDown()
{
}
-void
-FieldPathUpdateTestCase::testWhereClause()
+TEST_F(FieldPathUpdateTestCase, testWhereClause)
{
DocumentTypeRepo repo(getRepoConfig());
Document::UP doc(createTestDocument(repo));
std::string where = "test.l1s1.structmap.value.smap{$x} == \"dicaprio\"";
TestFieldPathUpdate update("l1s1.structmap.value.smap{$x}", where);
update.applyTo(*doc);
- CPPUNIT_ASSERT_EQUAL(std::string("dicaprio"), update._str);
+ EXPECT_EQ(std::string("dicaprio"), update._str);
}
-void
-FieldPathUpdateTestCase::testBrokenWhereClause()
+TEST_F(FieldPathUpdateTestCase, testBrokenWhereClause)
{
DocumentTypeRepo repo(getRepoConfig());
Document::UP doc(createTestDocument(repo));
std::string where = "l1s1.structmap.value.smap{$x} == \"dicaprio\"";
TestFieldPathUpdate update("l1s1.structmap.value.smap{$x}", where);
update.applyTo(*doc);
- CPPUNIT_ASSERT_EQUAL(std::string(""), update._str);
+ EXPECT_EQ(std::string(""), update._str);
}
-void
-FieldPathUpdateTestCase::testNoIterateMapValues()
+TEST_F(FieldPathUpdateTestCase, testNoIterateMapValues)
{
DocumentTypeRepo repo(getRepoConfig());
Document::UP doc(createTestDocument(repo));
TestFieldPathUpdate update("l1s1.structwset.primitive1", "true");
update.applyTo(*doc);
- CPPUNIT_ASSERT_EQUAL(std::string("3;5"), update._str);
+ EXPECT_EQ(std::string("3;5"), update._str);
}
-void
-FieldPathUpdateTestCase::testRemoveField()
+TEST_F(FieldPathUpdateTestCase, testRemoveField)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:things:thangs")));
- CPPUNIT_ASSERT(doc->hasValue("strfoo") == false);
+ EXPECT_TRUE(doc->hasValue("strfoo") == false);
doc->setValue("strfoo", StringFieldValue("cocacola"));
- CPPUNIT_ASSERT_EQUAL(vespalib::string("cocacola"), doc->getValue("strfoo")->getAsString());
+ EXPECT_EQ(vespalib::string("cocacola"), doc->getValue("strfoo")->getAsString());
//doc->print(std::cerr, true, "");
DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("doc:barbar:foofoo"));
docUp.addFieldPathUpdate(FieldPathUpdate::CP(new RemoveFieldPathUpdate("strfoo")));
docUp.applyTo(*doc);
- CPPUNIT_ASSERT(doc->hasValue("strfoo") == false);
+ EXPECT_TRUE(doc->hasValue("strfoo") == false);
}
-void
-FieldPathUpdateTestCase::testApplyRemoveMultiList()
+TEST_F(FieldPathUpdateTestCase, testApplyRemoveMultiList)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:things:thangs")));
doc->setRepo(*_repo);
- CPPUNIT_ASSERT(doc->hasValue("strarray") == false);
+ EXPECT_TRUE(doc->hasValue("strarray") == false);
{
ArrayFieldValue strArray(doc->getType().getField("strarray").getDataType());
strArray.add(StringFieldValue("crouching tiger, hidden field"));
@@ -407,7 +319,7 @@ FieldPathUpdateTestCase::testApplyRemoveMultiList()
strArray.add(StringFieldValue("hello hello"));
doc->setValue("strarray", strArray);
}
- CPPUNIT_ASSERT(doc->hasValue("strarray"));
+ EXPECT_TRUE(doc->hasValue("strarray"));
//doc->print(std::cerr, true, "");
DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("doc:barbar:foofoo"));
docUp.addFieldPathUpdate(FieldPathUpdate::CP(
@@ -415,18 +327,17 @@ FieldPathUpdateTestCase::testApplyRemoveMultiList()
docUp.applyTo(*doc);
{
std::unique_ptr<ArrayFieldValue> strArray = doc->getAs<ArrayFieldValue>(doc->getField("strarray"));
- CPPUNIT_ASSERT_EQUAL(std::size_t(2), strArray->size());
- CPPUNIT_ASSERT_EQUAL(vespalib::string("crouching tiger, hidden field"), (*strArray)[0].getAsString());
- CPPUNIT_ASSERT_EQUAL(vespalib::string("hello hello"), (*strArray)[1].getAsString());
+ ASSERT_EQ(std::size_t(2), strArray->size());
+ EXPECT_EQ(vespalib::string("crouching tiger, hidden field"), (*strArray)[0].getAsString());
+ EXPECT_EQ(vespalib::string("hello hello"), (*strArray)[1].getAsString());
}
}
-void
-FieldPathUpdateTestCase::testApplyRemoveMultiList2()
+TEST_F(FieldPathUpdateTestCase, testApplyRemoveMultiList2)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:things:thangs")));
doc->setRepo(*_repo);
- CPPUNIT_ASSERT(doc->hasValue("strarray") == false);
+ EXPECT_TRUE(doc->hasValue("strarray") == false);
{
ArrayFieldValue strArray(doc->getType().getField("strarray").getDataType());
strArray.add(StringFieldValue("remove val 1"));
@@ -434,7 +345,7 @@ FieldPathUpdateTestCase::testApplyRemoveMultiList2()
strArray.add(StringFieldValue("hello hello"));
doc->setValue("strarray", strArray);
}
- CPPUNIT_ASSERT(doc->hasValue("strarray"));
+ EXPECT_TRUE(doc->hasValue("strarray"));
//doc->print(std::cerr, true, "");
DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("doc:barbar:foofoo"));
docUp.addFieldPathUpdate(FieldPathUpdate::CP(
@@ -442,16 +353,15 @@ FieldPathUpdateTestCase::testApplyRemoveMultiList2()
docUp.applyTo(*doc);
{
std::unique_ptr<ArrayFieldValue> strArray = doc->getAs<ArrayFieldValue>(doc->getField("strarray"));
- CPPUNIT_ASSERT_EQUAL(std::size_t(1), strArray->size());
- CPPUNIT_ASSERT_EQUAL(vespalib::string("hello hello"), (*strArray)[0].getAsString());
+ ASSERT_EQ(std::size_t(1), strArray->size());
+ EXPECT_EQ(vespalib::string("hello hello"), (*strArray)[0].getAsString());
}
}
-void
-FieldPathUpdateTestCase::testApplyRemoveEntireListField()
+TEST_F(FieldPathUpdateTestCase, testApplyRemoveEntireListField)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:things:thangs")));
- CPPUNIT_ASSERT(doc->hasValue("strarray") == false);
+ EXPECT_TRUE(doc->hasValue("strarray") == false);
{
ArrayFieldValue strArray(doc->getType().getField("strarray").getDataType());
strArray.add(StringFieldValue("this list"));
@@ -463,54 +373,51 @@ FieldPathUpdateTestCase::testApplyRemoveEntireListField()
DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("doc:barbar:foofoo"));
docUp.addFieldPathUpdate(FieldPathUpdate::CP(new RemoveFieldPathUpdate("strarray", "")));
docUp.applyTo(*doc);
- CPPUNIT_ASSERT(!doc->hasValue("strarray"));
+ EXPECT_TRUE(!doc->hasValue("strarray"));
}
-void
-FieldPathUpdateTestCase::testApplyRemoveMultiWset()
+TEST_F(FieldPathUpdateTestCase, testApplyRemoveMultiWset)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:helan:halvan")));
- CPPUNIT_ASSERT(doc->hasValue("strwset") == false);
+ EXPECT_TRUE(doc->hasValue("strwset") == false);
{
WeightedSetFieldValue strWset(doc->getType().getField("strwset").getDataType());
strWset.add(StringFieldValue("hello hello"), 10);
strWset.add(StringFieldValue("remove val 1"), 20);
doc->setValue("strwset", strWset);
}
- CPPUNIT_ASSERT(doc->hasValue("strwset"));
+ EXPECT_TRUE(doc->hasValue("strwset"));
//doc->print(std::cerr, true, "");
DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("doc:barbar:foofoo"));
docUp.addFieldPathUpdate(FieldPathUpdate::CP(new RemoveFieldPathUpdate("strwset{remove val 1}")));
docUp.applyTo(*doc);
{
std::unique_ptr<WeightedSetFieldValue> strWset = doc->getAs<WeightedSetFieldValue>(doc->getField("strwset"));
- CPPUNIT_ASSERT_EQUAL(std::size_t(1), strWset->size());
- CPPUNIT_ASSERT_EQUAL(10, strWset->get(StringFieldValue("hello hello")));
+ ASSERT_EQ(std::size_t(1), strWset->size());
+ EXPECT_EQ(10, strWset->get(StringFieldValue("hello hello")));
}
}
-void
-FieldPathUpdateTestCase::testApplyAssignSingle()
+TEST_F(FieldPathUpdateTestCase, testApplyAssignSingle)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:drekka:karsk")));
- CPPUNIT_ASSERT(doc->hasValue("strfoo") == false);
+ EXPECT_TRUE(doc->hasValue("strfoo") == false);
// Test assignment of non-existing
DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("doc:barbar:foofoo"));
docUp.addFieldPathUpdate(FieldPathUpdate::CP(
new AssignFieldPathUpdate(*doc->getDataType(), "strfoo", std::string(), StringFieldValue("himert"))));
docUp.applyTo(*doc);
- CPPUNIT_ASSERT(doc->hasValue("strfoo"));
- CPPUNIT_ASSERT_EQUAL(vespalib::string("himert"), doc->getValue("strfoo")->getAsString());
+ EXPECT_TRUE(doc->hasValue("strfoo"));
+ EXPECT_EQ(vespalib::string("himert"), doc->getValue("strfoo")->getAsString());
// Test overwriting existing
DocumentUpdate docUp2(*_repo, _foobar_type, DocumentId("doc:barbar:foofoo"));
docUp2.addFieldPathUpdate(FieldPathUpdate::CP(
new AssignFieldPathUpdate(*doc->getDataType(), "strfoo", std::string(), StringFieldValue("wunderbaum"))));
docUp2.applyTo(*doc);
- CPPUNIT_ASSERT_EQUAL(vespalib::string("wunderbaum"), doc->getValue("strfoo")->getAsString());
+ EXPECT_EQ(vespalib::string("wunderbaum"), doc->getValue("strfoo")->getAsString());
}
-void
-FieldPathUpdateTestCase::testApplyAssignMath()
+TEST_F(FieldPathUpdateTestCase, testApplyAssignMath)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:bat:man")));
doc->setValue("num", IntFieldValue(34));
@@ -518,11 +425,10 @@ FieldPathUpdateTestCase::testApplyAssignMath()
DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("doc:barbar:foofoo"));
docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("num", "", "($value * 2) / $value")));
docUp.applyTo(*doc);
- CPPUNIT_ASSERT_EQUAL(static_cast<const FieldValue&>(IntFieldValue(2)), *doc->getValue("num"));
+ EXPECT_EQ(static_cast<const FieldValue&>(IntFieldValue(2)), *doc->getValue("num"));
}
-void
-FieldPathUpdateTestCase::testApplyAssignMathByteToZero()
+TEST_F(FieldPathUpdateTestCase, testApplyAssignMathByteToZero)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:bat:man")));
doc->setValue("byteval", ByteFieldValue(3));
@@ -530,11 +436,10 @@ FieldPathUpdateTestCase::testApplyAssignMathByteToZero()
DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("doc:barbar:foofoo"));
docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("byteval", "", "$value - 3")));
docUp.applyTo(*doc);
- CPPUNIT_ASSERT_EQUAL(static_cast<const FieldValue&>(ByteFieldValue(0)), *doc->getValue("byteval"));
+ EXPECT_EQ(static_cast<const FieldValue&>(ByteFieldValue(0)), *doc->getValue("byteval"));
}
-void
-FieldPathUpdateTestCase::testApplyAssignMathNotModifiedOnUnderflow()
+TEST_F(FieldPathUpdateTestCase, testApplyAssignMathNotModifiedOnUnderflow)
{
int low_value = -126;
Document::UP doc(new Document(_foobar_type, DocumentId("doc:bat:man")));
@@ -544,11 +449,10 @@ FieldPathUpdateTestCase::testApplyAssignMathNotModifiedOnUnderflow()
docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("byteval", "", "$value - 4")));
docUp.applyTo(*doc);
// Over/underflow will happen. You must have control of your data types.
- CPPUNIT_ASSERT_EQUAL(static_cast<const FieldValue&>(ByteFieldValue((char)(low_value - 4))), *doc->getValue("byteval"));
+ EXPECT_EQ(static_cast<const FieldValue&>(ByteFieldValue((char)(low_value - 4))), *doc->getValue("byteval"));
}
-void
-FieldPathUpdateTestCase::testApplyAssignMathNotModifiedOnOverflow()
+TEST_F(FieldPathUpdateTestCase, testApplyAssignMathNotModifiedOnOverflow)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:bat:man")));
doc->setValue("byteval", ByteFieldValue(127));
@@ -557,38 +461,35 @@ FieldPathUpdateTestCase::testApplyAssignMathNotModifiedOnOverflow()
docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("byteval", "", "$value + 200")));
docUp.applyTo(*doc);
// Over/underflow will happen. You must have control of your data types.
- CPPUNIT_ASSERT_EQUAL(static_cast<const FieldValue&>(ByteFieldValue(static_cast<char>(static_cast<int>(127+200)))), *doc->getValue("byteval"));
+ EXPECT_EQ(static_cast<const FieldValue&>(ByteFieldValue(static_cast<char>(static_cast<int>(127+200)))), *doc->getValue("byteval"));
}
-void
-FieldPathUpdateTestCase::testApplyAssignMathDivZero()
+TEST_F(FieldPathUpdateTestCase, testApplyAssignMathDivZero)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:bat:man")));
- CPPUNIT_ASSERT(doc->hasValue("num") == false);
+ EXPECT_TRUE(doc->hasValue("num") == false);
doc->setValue("num", IntFieldValue(10));
DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("doc:barbar:foofoo"));
docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("num", "", "$value / ($value - 10)")));
docUp.applyTo(*doc);
- CPPUNIT_ASSERT_EQUAL(static_cast<const FieldValue&>(IntFieldValue(10)), *doc->getValue("num"));
+ EXPECT_EQ(static_cast<const FieldValue&>(IntFieldValue(10)), *doc->getValue("num"));
}
-void
-FieldPathUpdateTestCase::testApplyAssignFieldNotExistingInExpression()
+TEST_F(FieldPathUpdateTestCase, testApplyAssignFieldNotExistingInExpression)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:bat:man")));
doc->setRepo(*_repo);
- CPPUNIT_ASSERT(doc->hasValue("num") == false);
+ EXPECT_TRUE(doc->hasValue("num") == false);
doc->setValue("num", IntFieldValue(10));
DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("doc:barbar:foofoo"));
docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("num", "", "foobar.num2 + $value")));
docUp.applyTo(*doc);
- CPPUNIT_ASSERT_EQUAL(static_cast<const FieldValue&>(IntFieldValue(10)), *doc->getValue("num"));
+ EXPECT_EQ(static_cast<const FieldValue&>(IntFieldValue(10)), *doc->getValue("num"));
}
-void
-FieldPathUpdateTestCase::testApplyAssignFieldNotExistingInPath()
+TEST_F(FieldPathUpdateTestCase, testApplyAssignFieldNotExistingInPath)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:bat:man")));
doc->setRepo(*_repo);
@@ -597,25 +498,23 @@ FieldPathUpdateTestCase::testApplyAssignFieldNotExistingInPath()
try {
docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("nosuchnum", "", "foobar.num + $value")));
docUp.applyTo(*doc);
- CPPUNIT_ASSERT(false);
+ EXPECT_TRUE(false);
} catch (const FieldNotFoundException&) {
}
}
-void
-FieldPathUpdateTestCase::testApplyAssignTargetNotExisting()
+TEST_F(FieldPathUpdateTestCase, testApplyAssignTargetNotExisting)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:bat:man")));
- CPPUNIT_ASSERT(doc->hasValue("num") == false);
+ EXPECT_TRUE(doc->hasValue("num") == false);
DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("doc:barbar:foofoo"));
docUp.addFieldPathUpdate(FieldPathUpdate::CP(new AssignFieldPathUpdate("num", "", "$value + 5")));
docUp.applyTo(*doc);
- CPPUNIT_ASSERT_EQUAL(static_cast<const FieldValue&>(IntFieldValue(5)), *doc->getValue("num"));
+ EXPECT_EQ(static_cast<const FieldValue&>(IntFieldValue(5)), *doc->getValue("num"));
}
-void
-FieldPathUpdateTestCase::testAssignSimpleMapValueWithVariable()
+TEST_F(FieldPathUpdateTestCase, testAssignSimpleMapValueWithVariable)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:bug:hunter")));
doc->setRepo(*_repo);
@@ -634,22 +533,21 @@ FieldPathUpdateTestCase::testAssignSimpleMapValueWithVariable()
std::unique_ptr<MapFieldValue> valueNow(doc->getAs<MapFieldValue>(doc->getField("strmap")));
- CPPUNIT_ASSERT_EQUAL(std::size_t(2), valueNow->size());
- CPPUNIT_ASSERT_EQUAL(
+ ASSERT_EQ(std::size_t(2), valueNow->size());
+ EXPECT_EQ(
static_cast<const FieldValue&>(StringFieldValue("shinyvalue")),
*valueNow->get(StringFieldValue("foo")));
- CPPUNIT_ASSERT_EQUAL(
+ EXPECT_EQ(
static_cast<const FieldValue&>(StringFieldValue("bananas")),
*valueNow->get(StringFieldValue("baz")));
}
-void
-FieldPathUpdateTestCase::testApplyAssignMathRemoveIfZero()
+TEST_F(FieldPathUpdateTestCase, testApplyAssignMathRemoveIfZero)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:bat:man")));
- CPPUNIT_ASSERT(doc->hasValue("num") == false);
+ EXPECT_TRUE(doc->hasValue("num") == false);
doc->setValue("num", IntFieldValue(34));
- CPPUNIT_ASSERT(doc->hasValue("num") == true);
+ EXPECT_TRUE(doc->hasValue("num") == true);
DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("doc:barbar:foofoo"));
FieldPathUpdate::CP up1(new AssignFieldPathUpdate("num", "", "($value * 2) / $value - 2"));
@@ -657,21 +555,20 @@ FieldPathUpdateTestCase::testApplyAssignMathRemoveIfZero()
docUp.addFieldPathUpdate(up1);
docUp.applyTo(*doc);
- CPPUNIT_ASSERT(doc->hasValue("num") == false);
+ EXPECT_TRUE(doc->hasValue("num") == false);
}
-void
-FieldPathUpdateTestCase::testApplyAssignMultiList()
+TEST_F(FieldPathUpdateTestCase, testApplyAssignMultiList)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:fest:skinnvest")));
- CPPUNIT_ASSERT(doc->hasValue("strarray") == false);
+ EXPECT_TRUE(doc->hasValue("strarray") == false);
{
ArrayFieldValue strArray(doc->getType().getField("strarray").getDataType());
strArray.add(StringFieldValue("hello hello"));
strArray.add(StringFieldValue("blah blargh"));
doc->setValue("strarray", strArray);
- CPPUNIT_ASSERT(doc->hasValue("strarray"));
+ EXPECT_TRUE(doc->hasValue("strarray"));
}
ArrayFieldValue updateArray(doc->getType().getField("strarray").getDataType());
@@ -685,25 +582,24 @@ FieldPathUpdateTestCase::testApplyAssignMultiList()
{
std::unique_ptr<ArrayFieldValue> strArray =
doc->getAs<ArrayFieldValue>(doc->getField("strarray"));
- CPPUNIT_ASSERT_EQUAL(std::size_t(2), strArray->size());
- CPPUNIT_ASSERT_EQUAL(vespalib::string("assigned val 0"), (*strArray)[0].getAsString());
- CPPUNIT_ASSERT_EQUAL(vespalib::string("assigned val 1"), (*strArray)[1].getAsString());
+ ASSERT_EQ(std::size_t(2), strArray->size());
+ EXPECT_EQ(vespalib::string("assigned val 0"), (*strArray)[0].getAsString());
+ EXPECT_EQ(vespalib::string("assigned val 1"), (*strArray)[1].getAsString());
}
}
-void
-FieldPathUpdateTestCase::testApplyAssignMultiWset()
+TEST_F(FieldPathUpdateTestCase, testApplyAssignMultiWset)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:fest:skinnvest")));
- CPPUNIT_ASSERT(doc->hasValue("strarray") == false);
+ EXPECT_TRUE(doc->hasValue("strarray") == false);
{
WeightedSetFieldValue strWset(doc->getType().getField("strwset").getDataType());
strWset.add(StringFieldValue("hello gentlemen"), 10);
strWset.add(StringFieldValue("what you say"), 20);
doc->setValue("strwset", strWset);
- CPPUNIT_ASSERT(doc->hasValue("strwset"));
+ EXPECT_TRUE(doc->hasValue("strwset"));
}
WeightedSetFieldValue assignWset(doc->getType().getField("strwset").getDataType());
@@ -718,24 +614,23 @@ FieldPathUpdateTestCase::testApplyAssignMultiWset()
//doc->print(std::cerr, true, "");
{
std::unique_ptr<WeightedSetFieldValue> strWset = doc->getAs<WeightedSetFieldValue>(doc->getField("strwset"));
- CPPUNIT_ASSERT_EQUAL(std::size_t(2), strWset->size());
- CPPUNIT_ASSERT_EQUAL(5, strWset->get(StringFieldValue("assigned val 0")));
- CPPUNIT_ASSERT_EQUAL(10, strWset->get(StringFieldValue("assigned val 1")));
+ ASSERT_EQ(std::size_t(2), strWset->size());
+ EXPECT_EQ(5, strWset->get(StringFieldValue("assigned val 0")));
+ EXPECT_EQ(10, strWset->get(StringFieldValue("assigned val 1")));
}
}
-void
-FieldPathUpdateTestCase::testAssignWsetRemoveIfZero()
+TEST_F(FieldPathUpdateTestCase, testAssignWsetRemoveIfZero)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:tronder:bataljon")));
- CPPUNIT_ASSERT(doc->hasValue("strarray") == false);
+ EXPECT_TRUE(doc->hasValue("strarray") == false);
{
WeightedSetFieldValue strWset(doc->getType().getField("strwset").getDataType());
strWset.add(StringFieldValue("you say goodbye"), 164);
strWset.add(StringFieldValue("but i say hello"), 243);
doc->setValue("strwset", strWset);
- CPPUNIT_ASSERT(doc->hasValue("strwset"));
+ EXPECT_TRUE(doc->hasValue("strwset"));
}
{
@@ -750,17 +645,16 @@ FieldPathUpdateTestCase::testAssignWsetRemoveIfZero()
//doc->print(std::cerr, true, "");
{
std::unique_ptr<WeightedSetFieldValue> strWset = doc->getAs<WeightedSetFieldValue>(doc->getField("strwset"));
- CPPUNIT_ASSERT_EQUAL(std::size_t(1), strWset->size());
- CPPUNIT_ASSERT_EQUAL(243, strWset->get(StringFieldValue("but i say hello")));
+ ASSERT_EQ(std::size_t(1), strWset->size());
+ EXPECT_EQ(243, strWset->get(StringFieldValue("but i say hello")));
}
}
}
-void
-FieldPathUpdateTestCase::testApplyAddMultiList()
+TEST_F(FieldPathUpdateTestCase, testApplyAddMultiList)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:george:costanza")));
- CPPUNIT_ASSERT(doc->hasValue("strarray") == false);
+ EXPECT_TRUE(doc->hasValue("strarray") == false);
ArrayFieldValue adds(doc->getType().getField("strarray").getDataType());
adds.add(StringFieldValue("serenity now"));
@@ -773,21 +667,20 @@ FieldPathUpdateTestCase::testApplyAddMultiList()
//doc->print(std::cerr, true, "");
docUp.applyTo(*doc);
//doc->print(std::cerr, true, "");
- CPPUNIT_ASSERT(doc->hasValue("strarray"));
+ EXPECT_TRUE(doc->hasValue("strarray"));
}
-void
-FieldPathUpdateTestCase::testAddAndAssignList()
+TEST_F(FieldPathUpdateTestCase, testAddAndAssignList)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:fancy:pants")));
- CPPUNIT_ASSERT(doc->hasValue("strarray") == false);
+ EXPECT_TRUE(doc->hasValue("strarray") == false);
{
ArrayFieldValue strArray(doc->getType().getField("strarray").getDataType());
strArray.add(StringFieldValue("hello hello"));
strArray.add(StringFieldValue("blah blargh"));
doc->setValue("strarray", strArray);
- CPPUNIT_ASSERT(doc->hasValue("strarray"));
+ EXPECT_TRUE(doc->hasValue("strarray"));
}
DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("doc:barbar:foofoo"));
@@ -805,10 +698,10 @@ FieldPathUpdateTestCase::testAddAndAssignList()
//doc->print(std::cerr, true, "");
{
std::unique_ptr<ArrayFieldValue> strArray = doc->getAs<ArrayFieldValue>(doc->getField("strarray"));
- CPPUNIT_ASSERT_EQUAL(std::size_t(3), strArray->size());
- CPPUNIT_ASSERT_EQUAL(vespalib::string("hello hello"), (*strArray)[0].getAsString());
- CPPUNIT_ASSERT_EQUAL(vespalib::string("assigned val 1"), (*strArray)[1].getAsString());
- CPPUNIT_ASSERT_EQUAL(vespalib::string("new value"), (*strArray)[2].getAsString());
+ ASSERT_EQ(std::size_t(3), strArray->size());
+ EXPECT_EQ(vespalib::string("hello hello"), (*strArray)[0].getAsString());
+ EXPECT_EQ(vespalib::string("assigned val 1"), (*strArray)[1].getAsString());
+ EXPECT_EQ(vespalib::string("new value"), (*strArray)[2].getAsString());
}
}
@@ -866,8 +759,7 @@ Fixture::Fixture(const DocumentType &doc_type, const Keys &k)
} // namespace
-void
-FieldPathUpdateTestCase::testAssignMap()
+TEST_F(FieldPathUpdateTestCase, testAssignMap)
{
Keys k;
Fixture f(_foobar_type, k);
@@ -878,17 +770,16 @@ FieldPathUpdateTestCase::testAssignMap()
docUp.applyTo(*f.doc);
std::unique_ptr<MapFieldValue> valueNow = f.doc->getAs<MapFieldValue>(f.doc->getField("structmap"));
- CPPUNIT_ASSERT_EQUAL(std::size_t(3), valueNow->size());
- CPPUNIT_ASSERT_EQUAL(static_cast<FieldValue&>(f.fv1),
+ ASSERT_EQ(std::size_t(3), valueNow->size());
+ EXPECT_EQ(static_cast<FieldValue&>(f.fv1),
*valueNow->get(StringFieldValue(k.key1)));
- CPPUNIT_ASSERT_EQUAL(static_cast<FieldValue&>(f.fv4),
+ EXPECT_EQ(static_cast<FieldValue&>(f.fv4),
*valueNow->get(StringFieldValue(k.key2)));
- CPPUNIT_ASSERT_EQUAL(static_cast<FieldValue&>(f.fv3),
+ EXPECT_EQ(static_cast<FieldValue&>(f.fv3),
*valueNow->get(StringFieldValue(k.key3)));
}
-void
-FieldPathUpdateTestCase::testAssignMapStruct()
+TEST_F(FieldPathUpdateTestCase, testAssignMapStruct)
{
Keys k;
Fixture f(_foobar_type, k);
@@ -900,17 +791,16 @@ FieldPathUpdateTestCase::testAssignMapStruct()
docUp.applyTo(*f.doc);
std::unique_ptr<MapFieldValue> valueNow = f.doc->getAs<MapFieldValue>(f.doc->getField("structmap"));
- CPPUNIT_ASSERT_EQUAL(std::size_t(3), valueNow->size());
- CPPUNIT_ASSERT_EQUAL(static_cast<FieldValue&>(f.fv1),
+ ASSERT_EQ(std::size_t(3), valueNow->size());
+ EXPECT_EQ(static_cast<FieldValue&>(f.fv1),
*valueNow->get(StringFieldValue(k.key1)));
- CPPUNIT_ASSERT_EQUAL(static_cast<FieldValue&>(f.fv4),
+ EXPECT_EQ(static_cast<FieldValue&>(f.fv4),
*valueNow->get(StringFieldValue(k.key2)));
- CPPUNIT_ASSERT_EQUAL(static_cast<FieldValue&>(f.fv3),
+ EXPECT_EQ(static_cast<FieldValue&>(f.fv3),
*valueNow->get(StringFieldValue(k.key3)));
}
-void
-FieldPathUpdateTestCase::testAssignMapStructVariable()
+TEST_F(FieldPathUpdateTestCase, testAssignMapStructVariable)
{
Keys k;
Fixture f(_foobar_type, k);
@@ -923,17 +813,16 @@ FieldPathUpdateTestCase::testAssignMapStructVariable()
docUp.applyTo(*f.doc);
std::unique_ptr<MapFieldValue> valueNow = f.doc->getAs<MapFieldValue>(f.doc->getField("structmap"));
- CPPUNIT_ASSERT_EQUAL(std::size_t(3), valueNow->size());
- CPPUNIT_ASSERT_EQUAL(static_cast<FieldValue&>(f.fv1),
+ ASSERT_EQ(std::size_t(3), valueNow->size());
+ EXPECT_EQ(static_cast<FieldValue&>(f.fv1),
*valueNow->get(StringFieldValue(k.key1)));
- CPPUNIT_ASSERT_EQUAL(static_cast<FieldValue&>(f.fv4),
+ EXPECT_EQ(static_cast<FieldValue&>(f.fv4),
*valueNow->get(StringFieldValue(k.key2)));
- CPPUNIT_ASSERT_EQUAL(static_cast<FieldValue&>(f.fv3),
+ EXPECT_EQ(static_cast<FieldValue&>(f.fv3),
*valueNow->get(StringFieldValue(k.key3)));
}
-void
-FieldPathUpdateTestCase::testAssignMapNoExist()
+TEST_F(FieldPathUpdateTestCase, testAssignMapNoExist)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:planet:express")));
MapFieldValue mfv(doc->getType().getField("structmap").getDataType());
@@ -951,12 +840,11 @@ FieldPathUpdateTestCase::testAssignMapNoExist()
std::unique_ptr<MapFieldValue> valueNow =
doc->getAs<MapFieldValue>(doc->getField("structmap"));
- CPPUNIT_ASSERT_EQUAL(std::size_t(1), valueNow->size());
- CPPUNIT_ASSERT_EQUAL(static_cast<FieldValue&>(fv1), *valueNow->get(StringFieldValue("foo")));
+ ASSERT_EQ(std::size_t(1), valueNow->size());
+ EXPECT_EQ(static_cast<FieldValue&>(fv1), *valueNow->get(StringFieldValue("foo")));
}
-void
-FieldPathUpdateTestCase::testAssignMapNoExistNoCreate()
+TEST_F(FieldPathUpdateTestCase, testAssignMapNoExistNoCreate)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:planet:express")));
MapFieldValue mfv(doc->getType().getField("structmap").getDataType());
@@ -976,11 +864,10 @@ FieldPathUpdateTestCase::testAssignMapNoExistNoCreate()
//doc->print(std::cerr, true, "");
std::unique_ptr<MapFieldValue> valueNow = doc->getAs<MapFieldValue>(doc->getField("structmap"));
- CPPUNIT_ASSERT(valueNow.get() == 0);
+ EXPECT_TRUE(valueNow.get() == 0);
}
-void
-FieldPathUpdateTestCase::testQuotedStringKey()
+TEST_F(FieldPathUpdateTestCase, testQuotedStringKey)
{
Keys k;
k.key2 = "here is a \"fancy\" 'map' :-} key :-{";
@@ -993,17 +880,16 @@ FieldPathUpdateTestCase::testQuotedStringKey()
docUp.applyTo(*f.doc);
std::unique_ptr<MapFieldValue> valueNow = f.doc->getAs<MapFieldValue>(f.doc->getField("structmap"));
- CPPUNIT_ASSERT_EQUAL(std::size_t(3), valueNow->size());
- CPPUNIT_ASSERT_EQUAL(static_cast<FieldValue&>(f.fv1),
+ ASSERT_EQ(std::size_t(3), valueNow->size());
+ EXPECT_EQ(static_cast<FieldValue&>(f.fv1),
*valueNow->get(StringFieldValue(k.key1)));
- CPPUNIT_ASSERT_EQUAL(static_cast<FieldValue&>(f.fv4),
+ EXPECT_EQ(static_cast<FieldValue&>(f.fv4),
*valueNow->get(StringFieldValue(k.key2)));
- CPPUNIT_ASSERT_EQUAL(static_cast<FieldValue&>(f.fv3),
+ EXPECT_EQ(static_cast<FieldValue&>(f.fv3),
*valueNow->get(StringFieldValue(k.key3)));
}
-void
-FieldPathUpdateTestCase::testEqualityComparison()
+TEST_F(FieldPathUpdateTestCase, testEqualityComparison)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:foo:zoo")));
MapFieldValue mfv(doc->getType().getField("structmap").getDataType());
@@ -1015,14 +901,14 @@ FieldPathUpdateTestCase::testEqualityComparison()
{
DocumentUpdate docUp1(*_repo, _foobar_type, DocumentId("doc:barbar:foofoo"));
DocumentUpdate docUp2(*_repo, _foobar_type, DocumentId("doc:barbar:foofoo"));
- CPPUNIT_ASSERT(docUp1 == docUp2);
+ EXPECT_TRUE(docUp1 == docUp2);
FieldPathUpdate::CP assignUp1(new AssignFieldPathUpdate(*doc->getDataType(),
"structmap{here be dragons}", std::string(), fv4));
docUp1.addFieldPathUpdate(assignUp1);
- CPPUNIT_ASSERT(docUp1 != docUp2);
+ EXPECT_TRUE(docUp1 != docUp2);
docUp2.addFieldPathUpdate(assignUp1);
- CPPUNIT_ASSERT(docUp1 == docUp2);
+ EXPECT_TRUE(docUp1 == docUp2);
}
{
DocumentUpdate docUp1(*_repo, _foobar_type, DocumentId("doc:barbar:foofoo"));
@@ -1034,7 +920,7 @@ FieldPathUpdateTestCase::testEqualityComparison()
"structmap{here be dragons}", "false", fv4));
docUp1.addFieldPathUpdate(assignUp1);
docUp2.addFieldPathUpdate(assignUp2);
- CPPUNIT_ASSERT(docUp1 != docUp2);
+ EXPECT_TRUE(docUp1 != docUp2);
}
{
DocumentUpdate docUp1(*_repo, _foobar_type, DocumentId("doc:barbar:foofoo"));
@@ -1046,13 +932,12 @@ FieldPathUpdateTestCase::testEqualityComparison()
"structmap{here be kittens}", std::string(), fv4));
docUp1.addFieldPathUpdate(assignUp1);
docUp2.addFieldPathUpdate(assignUp2);
- CPPUNIT_ASSERT(docUp1 != docUp2);
+ EXPECT_TRUE(docUp1 != docUp2);
}
}
-void
-FieldPathUpdateTestCase::testAffectsDocumentBody()
+TEST_F(FieldPathUpdateTestCase, testAffectsDocumentBody)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:things:stuff")));
MapFieldValue mfv(doc->getType().getField("structmap").getDataType());
@@ -1082,8 +967,7 @@ FieldPathUpdateTestCase::testAffectsDocumentBody()
}
-void
-FieldPathUpdateTestCase::testIncompatibleDataTypeFails()
+TEST_F(FieldPathUpdateTestCase, testIncompatibleDataTypeFails)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:things:stuff")));
MapFieldValue mfv(doc->getType().getField("structmap").getDataType());
@@ -1093,14 +977,13 @@ FieldPathUpdateTestCase::testIncompatibleDataTypeFails()
try {
FieldPathUpdate::CP update1(new AssignFieldPathUpdate(*doc->getDataType(), "structmap{foo}",
std::string(), StringFieldValue("bad things")));
- CPPUNIT_ASSERT(false);
+ EXPECT_TRUE(false);
} catch (const vespalib::IllegalArgumentException& e) {
// OK
}
}
-void
-FieldPathUpdateTestCase::testSerializeAssign()
+TEST_F(FieldPathUpdateTestCase, testSerializeAssign)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:weloveto:serializestuff")));
MapFieldValue mfv(doc->getType().getField("structmap").getDataType());
@@ -1118,11 +1001,10 @@ FieldPathUpdateTestCase::testSerializeAssign()
testSerialize(*_repo, docUp);
}
-void
-FieldPathUpdateTestCase::testSerializeAdd()
+TEST_F(FieldPathUpdateTestCase, testSerializeAdd)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:george:costanza")));
- CPPUNIT_ASSERT(doc->hasValue("strarray") == false);
+ EXPECT_TRUE(doc->hasValue("strarray") == false);
ArrayFieldValue adds(doc->getType().getField("strarray").getDataType());
adds.add(StringFieldValue("serenity now"));
@@ -1137,8 +1019,7 @@ FieldPathUpdateTestCase::testSerializeAdd()
testSerialize(*_repo, docUp);
}
-void
-FieldPathUpdateTestCase::testSerializeRemove()
+TEST_F(FieldPathUpdateTestCase, testSerializeRemove)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:weloveto:serializestuff")));
MapFieldValue mfv(doc->getType().getField("structmap").getDataType());
@@ -1151,11 +1032,10 @@ FieldPathUpdateTestCase::testSerializeRemove()
testSerialize(*_repo, docUp);
}
-void
-FieldPathUpdateTestCase::testSerializeAssignMath()
+TEST_F(FieldPathUpdateTestCase, testSerializeAssignMath)
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:bat:man")));
- CPPUNIT_ASSERT(doc->hasValue("num") == false);
+ EXPECT_TRUE(doc->hasValue("num") == false);
doc->setValue("num", IntFieldValue(34));
DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("doc:barbar:foofoo"));
@@ -1184,8 +1064,7 @@ FieldPathUpdateTestCase::createDocumentUpdateForSerialization(const DocumentType
return docUp;
}
-void
-FieldPathUpdateTestCase::testReadSerializedFile()
+TEST_F(FieldPathUpdateTestCase, testReadSerializedFile)
{
// Reads a file serialized from java
const std::string cfg_file_name = TEST_PATH("data/crossplatform-java-cpp-doctypes.cfg");
@@ -1205,11 +1084,10 @@ FieldPathUpdateTestCase::testReadSerializedFile()
DocumentUpdate& upd(*updp);
DocumentUpdate::UP compare(createDocumentUpdateForSerialization(repo));
- CPPUNIT_ASSERT_EQUAL(*compare, upd);
+ EXPECT_EQ(*compare, upd);
}
-void
-FieldPathUpdateTestCase::testGenerateSerializedFile()
+TEST_F(FieldPathUpdateTestCase, testGenerateSerializedFile)
{
const std::string cfg_file_name = TEST_PATH("data/crossplatform-java-cpp-doctypes.cfg");
DocumentTypeRepo repo(readDocumenttypesConfig(cfg_file_name));
@@ -1226,7 +1104,8 @@ FieldPathUpdateTestCase::testGenerateSerializedFile()
close(fd);
}
-void FieldPathUpdateTestCase::array_element_update_for_invalid_index_is_ignored() {
+TEST_F(FieldPathUpdateTestCase, array_element_update_for_invalid_index_is_ignored)
+{
auto doc = std::make_unique<Document>(_foobar_type, DocumentId("id::foobar::1"));
doc->setRepo(*_repo);
auto& field = doc->getType().getField("strarray");
@@ -1242,7 +1121,7 @@ void FieldPathUpdateTestCase::array_element_update_for_invalid_index_is_ignored(
// Doc is unmodified.
auto new_arr = doc->getAs<ArrayFieldValue>(field);
- CPPUNIT_ASSERT_EQUAL(str_array, *new_arr);
+ EXPECT_EQ(str_array, *new_arr);
}
}
diff --git a/document/src/tests/fieldsettest.cpp b/document/src/tests/fieldsettest.cpp
index f3bc2a03bc5..0297e7bdda4 100644
--- a/document/src/tests/fieldsettest.cpp
+++ b/document/src/tests/fieldsettest.cpp
@@ -3,13 +3,12 @@
#include <vespa/document/base/testdocman.h>
#include <vespa/document/fieldset/fieldsetrepo.h>
#include <vespa/vespalib/io/fileutil.h>
-#include <vespa/vdstestlib/cppunit/macros.h>
-
#include <vespa/document/datatype/annotationreferencedatatype.h>
#include <vespa/document/repo/configbuilder.h>
#include <vespa/document/repo/documenttyperepo.h>
#include <vespa/vespalib/objects/nbostream.h>
#include <algorithm>
+#include <gtest/gtest.h>
using vespalib::nbostream;
@@ -17,23 +16,9 @@ using namespace document::config_builder;
namespace document {
-struct FieldSetTest : public CppUnit::TestFixture {
- void testParsing();
- void testContains();
- void testCopyDocumentFields();
- void testDocumentSubsetCopy();
- void testStripFields();
- void testSerialize();
-
- CPPUNIT_TEST_SUITE(FieldSetTest);
- CPPUNIT_TEST(testParsing);
- CPPUNIT_TEST(testSerialize);
- CPPUNIT_TEST(testContains);
- CPPUNIT_TEST(testCopyDocumentFields);
- CPPUNIT_TEST(testDocumentSubsetCopy);
- CPPUNIT_TEST(testStripFields);
- CPPUNIT_TEST_SUITE_END();
+class FieldSetTest : public ::testing::Test {
+protected:
std::string stringifyFields(const Document& doc) const;
std::string doCopyFields(const Document& src,
const DocumentTypeRepo& docRepo,
@@ -48,9 +33,7 @@ struct FieldSetTest : public CppUnit::TestFixture {
Document::UP createTestDocument(const TestDocMan& testDocMan) const;
};
-CPPUNIT_TEST_SUITE_REGISTRATION(FieldSetTest);
-
-void FieldSetTest::testParsing()
+TEST_F(FieldSetTest, testParsing)
{
TestDocMan testDocMan;
const DocumentTypeRepo& docRepo = testDocMan.getTypeRepo();
@@ -73,7 +56,7 @@ void FieldSetTest::testParsing()
ost << (*iter)->getName() << " ";
}
- CPPUNIT_ASSERT_EQUAL(std::string("content headerval "), ost.str());
+ EXPECT_EQ(std::string("content headerval "), ost.str());
}
namespace {
@@ -98,7 +81,7 @@ bool checkError(FieldSetRepo& r, const DocumentTypeRepo& repo,
}
-void FieldSetTest::testContains()
+TEST_F(FieldSetTest, testContains)
{
TestDocMan testDocMan;
const DocumentTypeRepo& repo = testDocMan.getTypeRepo();
@@ -113,45 +96,44 @@ void FieldSetTest::testContains()
HeaderFields h;
BodyFields b;
- CPPUNIT_ASSERT_EQUAL(false, headerField.contains(
- type.getField("headerlongval")));
- CPPUNIT_ASSERT_EQUAL(true, headerField.contains(headerField));
- CPPUNIT_ASSERT_EQUAL(true, headerField.contains(id));
- CPPUNIT_ASSERT_EQUAL(false, headerField.contains(all));
- CPPUNIT_ASSERT_EQUAL(true, headerField.contains(none));
- CPPUNIT_ASSERT_EQUAL(false, none.contains(headerField));
- CPPUNIT_ASSERT_EQUAL(true, all.contains(headerField));
- CPPUNIT_ASSERT_EQUAL(true, all.contains(none));
- CPPUNIT_ASSERT_EQUAL(false, none.contains(all));
- CPPUNIT_ASSERT_EQUAL(true, all.contains(id));
- CPPUNIT_ASSERT_EQUAL(false, none.contains(id));
- CPPUNIT_ASSERT_EQUAL(true, id.contains(none));
-
- CPPUNIT_ASSERT_EQUAL(true, h.contains(headerField));
- CPPUNIT_ASSERT_EQUAL(false, h.contains(bodyField));
-
- CPPUNIT_ASSERT_EQUAL(false, b.contains(headerField));
- CPPUNIT_ASSERT_EQUAL(true, b.contains(bodyField));
+ EXPECT_EQ(false, headerField.contains(type.getField("headerlongval")));
+ EXPECT_EQ(true, headerField.contains(headerField));
+ EXPECT_EQ(true, headerField.contains(id));
+ EXPECT_EQ(false, headerField.contains(all));
+ EXPECT_EQ(true, headerField.contains(none));
+ EXPECT_EQ(false, none.contains(headerField));
+ EXPECT_EQ(true, all.contains(headerField));
+ EXPECT_EQ(true, all.contains(none));
+ EXPECT_EQ(false, none.contains(all));
+ EXPECT_EQ(true, all.contains(id));
+ EXPECT_EQ(false, none.contains(id));
+ EXPECT_EQ(true, id.contains(none));
+
+ EXPECT_EQ(true, h.contains(headerField));
+ EXPECT_EQ(false, h.contains(bodyField));
+
+ EXPECT_EQ(false, b.contains(headerField));
+ EXPECT_EQ(true, b.contains(bodyField));
FieldSetRepo r;
- CPPUNIT_ASSERT_EQUAL(true, checkContains(r, repo, "[body]",
+ EXPECT_EQ(true, checkContains(r, repo, "[body]",
"testdoctype1:content"));
- CPPUNIT_ASSERT_EQUAL(false, checkContains(r, repo, "[header]",
+ EXPECT_EQ(false, checkContains(r, repo, "[header]",
"testdoctype1:content"));
- CPPUNIT_ASSERT_EQUAL(true, checkContains(r, repo,
+ EXPECT_EQ(true, checkContains(r, repo,
"testdoctype1:content,headerval",
"testdoctype1:content"));
- CPPUNIT_ASSERT_EQUAL(false, checkContains(r, repo,
+ EXPECT_EQ(false, checkContains(r, repo,
"testdoctype1:content",
"testdoctype1:content,headerval"));
- CPPUNIT_ASSERT_EQUAL(true, checkContains(r, repo,
+ EXPECT_EQ(true, checkContains(r, repo,
"testdoctype1:headerval,content",
"testdoctype1:content,headerval"));
- CPPUNIT_ASSERT(checkError(r, repo, "nodoctype"));
- CPPUNIT_ASSERT(checkError(r, repo, "unknowndoctype:foo"));
- CPPUNIT_ASSERT(checkError(r, repo, "testdoctype1:unknownfield"));
- CPPUNIT_ASSERT(checkError(r, repo, "[badid]"));
+ EXPECT_TRUE(checkError(r, repo, "nodoctype"));
+ EXPECT_TRUE(checkError(r, repo, "unknowndoctype:foo"));
+ EXPECT_TRUE(checkError(r, repo, "testdoctype1:unknownfield"));
+ EXPECT_TRUE(checkError(r, repo, "[badid]"));
}
std::string
@@ -221,33 +203,32 @@ FieldSetTest::createTestDocument(const TestDocMan& testDocMan) const
return doc;
}
-void
-FieldSetTest::testCopyDocumentFields()
+TEST_F(FieldSetTest, testCopyDocumentFields)
{
TestDocMan testDocMan;
const DocumentTypeRepo& repo = testDocMan.getTypeRepo();
Document::UP src(createTestDocument(testDocMan));
- CPPUNIT_ASSERT_EQUAL(std::string("content: megafoo megabar\n"),
- doCopyFields(*src, repo, "[body]"));
- CPPUNIT_ASSERT_EQUAL(std::string(""),
- doCopyFields(*src, repo, "[none]"));
- CPPUNIT_ASSERT_EQUAL(std::string("headerval: 5678\n"
- "hstringval: hello fantastic world\n"),
- doCopyFields(*src, repo, "[header]"));
- CPPUNIT_ASSERT_EQUAL(std::string("content: megafoo megabar\n"
- "headerval: 5678\n"
- "hstringval: hello fantastic world\n"),
- doCopyFields(*src, repo, "[all]"));
- CPPUNIT_ASSERT_EQUAL(std::string("content: megafoo megabar\n"
- "hstringval: hello fantastic world\n"),
- doCopyFields(*src, repo, "testdoctype1:hstringval,content"));
+ EXPECT_EQ(std::string("content: megafoo megabar\n"),
+ doCopyFields(*src, repo, "[body]"));
+ EXPECT_EQ(std::string(""),
+ doCopyFields(*src, repo, "[none]"));
+ EXPECT_EQ(std::string("headerval: 5678\n"
+ "hstringval: hello fantastic world\n"),
+ doCopyFields(*src, repo, "[header]"));
+ EXPECT_EQ(std::string("content: megafoo megabar\n"
+ "headerval: 5678\n"
+ "hstringval: hello fantastic world\n"),
+ doCopyFields(*src, repo, "[all]"));
+ EXPECT_EQ(std::string("content: megafoo megabar\n"
+ "hstringval: hello fantastic world\n"),
+ doCopyFields(*src, repo, "testdoctype1:hstringval,content"));
// Test that we overwrite already set fields in destination document
{
Document dest(src->getType(), DocumentId("doc:foo:bar"));
dest.setValue(dest.getField("content"), StringFieldValue("overwriteme"));
- CPPUNIT_ASSERT_EQUAL(std::string("content: megafoo megabar\n"),
- doCopyFields(*src, repo, "[body]", &dest));
+ EXPECT_EQ(std::string("content: megafoo megabar\n"),
+ doCopyFields(*src, repo, "[body]", &dest));
}
}
@@ -263,8 +244,7 @@ FieldSetTest::doCopyDocument(const Document& src,
}
-void
-FieldSetTest::testDocumentSubsetCopy()
+TEST_F(FieldSetTest, testDocumentSubsetCopy)
{
TestDocMan testDocMan;
const DocumentTypeRepo& repo = testDocMan.getTypeRepo();
@@ -273,11 +253,11 @@ FieldSetTest::testDocumentSubsetCopy()
{
Document::UP doc(FieldSet::createDocumentSubsetCopy(*src, AllFields()));
// Test that document id and type are copied correctly.
- CPPUNIT_ASSERT(doc.get());
- CPPUNIT_ASSERT_EQUAL(src->getId(), doc->getId());
- CPPUNIT_ASSERT_EQUAL(src->getType(), doc->getType());
- CPPUNIT_ASSERT_EQUAL(doCopyFields(*src, repo, "[all]"),
- stringifyFields(*doc));
+ EXPECT_TRUE(doc.get());
+ EXPECT_EQ(src->getId(), doc->getId());
+ EXPECT_EQ(src->getType(), doc->getType());
+ EXPECT_EQ(doCopyFields(*src, repo, "[all]"),
+ stringifyFields(*doc));
}
const char* fieldSets[] = {
@@ -288,13 +268,12 @@ FieldSetTest::testDocumentSubsetCopy()
"testdoctype1:hstringval,content"
};
for (size_t i = 0; i < sizeof(fieldSets) / sizeof(fieldSets[0]); ++i) {
- CPPUNIT_ASSERT_EQUAL(doCopyFields(*src, repo, fieldSets[i]),
- doCopyDocument(*src, repo, fieldSets[i]));
+ EXPECT_EQ(doCopyFields(*src, repo, fieldSets[i]),
+ doCopyDocument(*src, repo, fieldSets[i]));
}
}
-void
-FieldSetTest::testSerialize()
+TEST_F(FieldSetTest, testSerialize)
{
TestDocMan testDocMan;
const DocumentTypeRepo& docRepo = testDocMan.getTypeRepo();
@@ -312,33 +291,32 @@ FieldSetTest::testSerialize()
FieldSetRepo repo;
for (size_t i = 0; i < sizeof(fieldSets) / sizeof(fieldSets[0]); ++i) {
FieldSet::UP fs = repo.parse(docRepo, fieldSets[i]);
- CPPUNIT_ASSERT_EQUAL(vespalib::string(fieldSets[i]), repo.serialize(*fs));
+ EXPECT_EQ(vespalib::string(fieldSets[i]), repo.serialize(*fs));
}
}
-void
-FieldSetTest::testStripFields()
+TEST_F(FieldSetTest, testStripFields)
{
TestDocMan testDocMan;
const DocumentTypeRepo& repo = testDocMan.getTypeRepo();
Document::UP src(createTestDocument(testDocMan));
- CPPUNIT_ASSERT_EQUAL(std::string("content: megafoo megabar\n"),
- doStripFields(*src, repo, "[body]"));
- CPPUNIT_ASSERT_EQUAL(std::string(""),
- doStripFields(*src, repo, "[none]"));
- CPPUNIT_ASSERT_EQUAL(std::string(""),
- doStripFields(*src, repo, "[id]"));
- CPPUNIT_ASSERT_EQUAL(std::string("headerval: 5678\n"
- "hstringval: hello fantastic world\n"),
- doStripFields(*src, repo, "[header]"));
- CPPUNIT_ASSERT_EQUAL(std::string("content: megafoo megabar\n"
- "headerval: 5678\n"
- "hstringval: hello fantastic world\n"),
- doStripFields(*src, repo, "[all]"));
- CPPUNIT_ASSERT_EQUAL(std::string("content: megafoo megabar\n"
- "hstringval: hello fantastic world\n"),
- doStripFields(*src, repo, "testdoctype1:hstringval,content"));
+ EXPECT_EQ(std::string("content: megafoo megabar\n"),
+ doStripFields(*src, repo, "[body]"));
+ EXPECT_EQ(std::string(""),
+ doStripFields(*src, repo, "[none]"));
+ EXPECT_EQ(std::string(""),
+ doStripFields(*src, repo, "[id]"));
+ EXPECT_EQ(std::string("headerval: 5678\n"
+ "hstringval: hello fantastic world\n"),
+ doStripFields(*src, repo, "[header]"));
+ EXPECT_EQ(std::string("content: megafoo megabar\n"
+ "headerval: 5678\n"
+ "hstringval: hello fantastic world\n"),
+ doStripFields(*src, repo, "[all]"));
+ EXPECT_EQ(std::string("content: megafoo megabar\n"
+ "hstringval: hello fantastic world\n"),
+ doStripFields(*src, repo, "testdoctype1:hstringval,content"));
}
} // document
diff --git a/document/src/tests/fixed_bucket_spaces_test.cpp b/document/src/tests/fixed_bucket_spaces_test.cpp
index 12c248adf37..87903281c46 100644
--- a/document/src/tests/fixed_bucket_spaces_test.cpp
+++ b/document/src/tests/fixed_bucket_spaces_test.cpp
@@ -1,62 +1,48 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/document/bucket/fixed_bucket_spaces.h>
-#include <cppunit/extensions/HelperMacros.h>
+#include <gtest/gtest.h>
namespace document {
-struct FixedBucketSpacesTest : CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(FixedBucketSpacesTest);
- CPPUNIT_TEST(bucket_space_from_name_is_defined_for_default_space);
- CPPUNIT_TEST(bucket_space_from_name_is_defined_for_global_space);
- CPPUNIT_TEST(bucket_space_from_name_throws_exception_for_unknown_space);
- CPPUNIT_TEST(name_from_bucket_space_is_defined_for_default_space);
- CPPUNIT_TEST(name_from_bucket_space_is_defined_for_global_space);
- CPPUNIT_TEST(name_from_bucket_space_throws_exception_for_unknown_space);
- CPPUNIT_TEST_SUITE_END();
-
- void bucket_space_from_name_is_defined_for_default_space();
- void bucket_space_from_name_is_defined_for_global_space();
- void bucket_space_from_name_throws_exception_for_unknown_space();
- void name_from_bucket_space_is_defined_for_default_space();
- void name_from_bucket_space_is_defined_for_global_space();
- void name_from_bucket_space_throws_exception_for_unknown_space();
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(FixedBucketSpacesTest);
-
-void FixedBucketSpacesTest::bucket_space_from_name_is_defined_for_default_space() {
- CPPUNIT_ASSERT_EQUAL(FixedBucketSpaces::default_space(), FixedBucketSpaces::from_string("default"));
+TEST(FixedBucketSpacesTest, bucket_space_from_name_is_defined_for_default_space)
+{
+ EXPECT_EQ(FixedBucketSpaces::default_space(), FixedBucketSpaces::from_string("default"));
}
-void FixedBucketSpacesTest::bucket_space_from_name_is_defined_for_global_space() {
- CPPUNIT_ASSERT_EQUAL(FixedBucketSpaces::global_space(), FixedBucketSpaces::from_string("global"));
+TEST(FixedBucketSpacesTest, bucket_space_from_name_is_defined_for_global_space)
+{
+ EXPECT_EQ(FixedBucketSpaces::global_space(), FixedBucketSpaces::from_string("global"));
}
-void FixedBucketSpacesTest::bucket_space_from_name_throws_exception_for_unknown_space() {
+TEST(FixedBucketSpacesTest, bucket_space_from_name_throws_exception_for_unknown_space)
+{
try {
FixedBucketSpaces::from_string("banana");
- CPPUNIT_FAIL("Expected exception on unknown bucket space name");
+ FAIL() << "Expected exception on unknown bucket space name";
} catch (document::UnknownBucketSpaceException& e) {
}
}
-void FixedBucketSpacesTest::name_from_bucket_space_is_defined_for_default_space() {
- CPPUNIT_ASSERT_EQUAL(vespalib::stringref("default"),
+TEST(FixedBucketSpacesTest, name_from_bucket_space_is_defined_for_default_space)
+{
+ EXPECT_EQ(vespalib::stringref("default"),
FixedBucketSpaces::to_string(FixedBucketSpaces::default_space()));
- CPPUNIT_ASSERT_EQUAL(vespalib::stringref("default"), FixedBucketSpaces::default_space_name());
+ EXPECT_EQ(vespalib::stringref("default"), FixedBucketSpaces::default_space_name());
}
-void FixedBucketSpacesTest::name_from_bucket_space_is_defined_for_global_space() {
- CPPUNIT_ASSERT_EQUAL(vespalib::stringref("global"),
+TEST(FixedBucketSpacesTest, name_from_bucket_space_is_defined_for_global_space)
+{
+ EXPECT_EQ(vespalib::stringref("global"),
FixedBucketSpaces::to_string(FixedBucketSpaces::global_space()));
- CPPUNIT_ASSERT_EQUAL(vespalib::stringref("global"), FixedBucketSpaces::global_space_name());
+ EXPECT_EQ(vespalib::stringref("global"), FixedBucketSpaces::global_space_name());
}
-void FixedBucketSpacesTest::name_from_bucket_space_throws_exception_for_unknown_space() {
+TEST(FixedBucketSpacesTest, name_from_bucket_space_throws_exception_for_unknown_space)
+{
try {
FixedBucketSpaces::to_string(BucketSpace(4567));
- CPPUNIT_FAIL("Expected exception on unknown bucket space value");
+ FAIL() << "Expected exception on unknown bucket space value";
} catch (document::UnknownBucketSpaceException& e) {
}
}
diff --git a/document/src/tests/forcelinktest.cpp b/document/src/tests/forcelinktest.cpp
index 6839843c7aa..421138f34cf 100644
--- a/document/src/tests/forcelinktest.cpp
+++ b/document/src/tests/forcelinktest.cpp
@@ -1,22 +1,11 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/document/base/forcelink.h>
-#include <cppunit/extensions/HelperMacros.h>
+#include <gtest/gtest.h>
namespace document {
-struct ForceLinkTest : public CppUnit::TestFixture {
- void testUsage();
-
- CPPUNIT_TEST_SUITE(ForceLinkTest);
- CPPUNIT_TEST(testUsage);
- CPPUNIT_TEST_SUITE_END();
-
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(ForceLinkTest);
-
-void ForceLinkTest::testUsage()
+TEST(ForceLinkTest, testUsage)
{
ForceLink link;
}
diff --git a/document/src/tests/gid_filter_test.cpp b/document/src/tests/gid_filter_test.cpp
index 7519c8f29dd..dcfafb56b99 100644
--- a/document/src/tests/gid_filter_test.cpp
+++ b/document/src/tests/gid_filter_test.cpp
@@ -1,16 +1,16 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <cppunit/TestFixture.h>
-#include <cppunit/extensions/HelperMacros.h>
#include <vespa/document/select/gid_filter.h>
#include <vespa/document/select/parser.h>
#include <vespa/document/base/documentid.h>
#include <vespa/document/base/testdocrepo.h>
+#include <gtest/gtest.h>
-namespace document {
-namespace select {
+namespace document::select {
-class GidFilterTest : public CppUnit::TestFixture {
+class GidFilterTest : public ::testing::Test {
+
+protected:
struct Fixture {
TestDocRepo _repo;
BucketIdFactory _id_factory;
@@ -38,48 +38,6 @@ class GidFilterTest : public CppUnit::TestFixture {
auto filter = GidFilter::for_selection_root_node(*f._root);
return filter.gid_might_match_selection(id_to_gid(id_string));
}
-
- CPPUNIT_TEST_SUITE(GidFilterTest);
- CPPUNIT_TEST(same_user_for_selection_and_gid_returns_match);
- CPPUNIT_TEST(differing_user_for_selection_and_gid_returns_mismatch);
- CPPUNIT_TEST(user_location_constraint_is_order_invariant);
- CPPUNIT_TEST(non_location_selection_always_matches);
- CPPUNIT_TEST(location_selection_does_not_match_non_location_id);
- CPPUNIT_TEST(simple_conjunctive_location_expressions_are_filtered);
- CPPUNIT_TEST(complex_conjunctive_location_expressions_are_filtered);
- CPPUNIT_TEST(simple_disjunctive_location_expressions_are_not_filtered);
- CPPUNIT_TEST(complex_disjunctive_location_expressions_are_not_filtered);
- CPPUNIT_TEST(non_location_id_comparisons_are_not_filtered);
- CPPUNIT_TEST(unsupported_location_comparison_operands_not_filtered);
- CPPUNIT_TEST(default_constructed_filter_always_matches);
- CPPUNIT_TEST(most_significant_32_bits_are_ignored);
- CPPUNIT_TEST(gid_filters_may_be_copy_constructed);
- CPPUNIT_TEST(gid_filters_may_be_copy_assigned);
- CPPUNIT_TEST(same_group_for_selection_and_gid_returns_match);
- CPPUNIT_TEST(differing_group_for_selection_and_gid_returns_mismatch);
- CPPUNIT_TEST(composite_user_comparison_sub_expressions_not_supported);
- CPPUNIT_TEST(composite_group_comparison_sub_expressions_not_supported);
- CPPUNIT_TEST_SUITE_END();
-public:
- void same_user_for_selection_and_gid_returns_match();
- void differing_user_for_selection_and_gid_returns_mismatch();
- void user_location_constraint_is_order_invariant();
- void non_location_selection_always_matches();
- void location_selection_does_not_match_non_location_id();
- void simple_conjunctive_location_expressions_are_filtered();
- void complex_conjunctive_location_expressions_are_filtered();
- void simple_disjunctive_location_expressions_are_not_filtered();
- void complex_disjunctive_location_expressions_are_not_filtered();
- void non_location_id_comparisons_are_not_filtered();
- void unsupported_location_comparison_operands_not_filtered();
- void default_constructed_filter_always_matches();
- void most_significant_32_bits_are_ignored();
- void gid_filters_may_be_copy_constructed();
- void gid_filters_may_be_copy_assigned();
- void same_group_for_selection_and_gid_returns_match();
- void differing_group_for_selection_and_gid_returns_mismatch();
- void composite_user_comparison_sub_expressions_not_supported();
- void composite_group_comparison_sub_expressions_not_supported();
};
GidFilterTest::Fixture::Fixture(vespalib::stringref selection)
@@ -89,157 +47,142 @@ GidFilterTest::Fixture::Fixture(vespalib::stringref selection)
{ }
GidFilterTest::Fixture::~Fixture() { }
-CPPUNIT_TEST_SUITE_REGISTRATION(GidFilterTest);
-
-void
-GidFilterTest::same_user_for_selection_and_gid_returns_match()
+TEST_F(GidFilterTest, same_user_for_selection_and_gid_returns_match)
{
- CPPUNIT_ASSERT(might_match("id.user == 12345",
- "id::testdoctype1:n=12345:foo"));
+ EXPECT_TRUE(might_match("id.user == 12345",
+ "id::testdoctype1:n=12345:foo"));
// User locations are defined over [0, 2**63-1]
- CPPUNIT_ASSERT(might_match("id.user == 0",
- "id::testdoctype1:n=0:foo"));
- CPPUNIT_ASSERT(might_match("id.user == 9223372036854775807" ,
- "id::testdoctype1:n=9223372036854775807:foo"));
+ EXPECT_TRUE(might_match("id.user == 0",
+ "id::testdoctype1:n=0:foo"));
+ EXPECT_TRUE(might_match("id.user == 9223372036854775807" ,
+ "id::testdoctype1:n=9223372036854775807:foo"));
}
-void
-GidFilterTest::differing_user_for_selection_and_gid_returns_mismatch()
+TEST_F(GidFilterTest, differing_user_for_selection_and_gid_returns_mismatch)
{
- CPPUNIT_ASSERT(!might_match("id.user == 1", "id::testdoctype1:n=2000:foo"));
+ EXPECT_TRUE(!might_match("id.user == 1", "id::testdoctype1:n=2000:foo"));
// Similar, but non-identical, bit patterns
- CPPUNIT_ASSERT(!might_match("id.user == 12345",
- "id::testdoctype1:n=12346:foo"));
- CPPUNIT_ASSERT(!might_match("id.user == 12345",
- "id::testdoctype1:n=12344:foo"));
+ EXPECT_TRUE(!might_match("id.user == 12345",
+ "id::testdoctype1:n=12346:foo"));
+ EXPECT_TRUE(!might_match("id.user == 12345",
+ "id::testdoctype1:n=12344:foo"));
}
-void
-GidFilterTest::user_location_constraint_is_order_invariant()
+TEST_F(GidFilterTest, user_location_constraint_is_order_invariant)
{
- CPPUNIT_ASSERT(might_match("12345 == id.user",
- "id::testdoctype1:n=12345:foo"));
- CPPUNIT_ASSERT(!might_match("12345 == id.user",
- "id::testdoctype1:n=12346:foo"));
+ EXPECT_TRUE(might_match("12345 == id.user",
+ "id::testdoctype1:n=12345:foo"));
+ EXPECT_TRUE(!might_match("12345 == id.user",
+ "id::testdoctype1:n=12346:foo"));
}
-void
-GidFilterTest::non_location_selection_always_matches()
+TEST_F(GidFilterTest, non_location_selection_always_matches)
{
- CPPUNIT_ASSERT(might_match("testdoctype1.headerval == 67890",
- "id::testdoctype1:n=12345:foo"));
+ EXPECT_TRUE(might_match("testdoctype1.headerval == 67890",
+ "id::testdoctype1:n=12345:foo"));
}
-void
-GidFilterTest::location_selection_does_not_match_non_location_id()
+TEST_F(GidFilterTest, location_selection_does_not_match_non_location_id)
{
// Test name is a half-truth; the MD5-derived ID _will_ give a false
// positive every 2**32 or so document ID when the stars and their bit
// patterns align :)
- CPPUNIT_ASSERT(!might_match("id.user == 987654321",
- "id::testdoctype1::foo"));
+ EXPECT_TRUE(!might_match("id.user == 987654321",
+ "id::testdoctype1::foo"));
- CPPUNIT_ASSERT(!might_match("id.group == 'snusmumrikk'",
- "id::testdoctype1::foo"));
+ EXPECT_TRUE(!might_match("id.group == 'snusmumrikk'",
+ "id::testdoctype1::foo"));
}
-void
-GidFilterTest::simple_conjunctive_location_expressions_are_filtered()
+TEST_F(GidFilterTest, simple_conjunctive_location_expressions_are_filtered)
{
// A conjunctive expression in this context is one where there exist a
// location predicate and the result of the entire expression can only
// be true iff the location predicate matches.
- CPPUNIT_ASSERT(might_match("id.user == 12345 and true",
- "id::testdoctype1:n=12345:bar"));
- CPPUNIT_ASSERT(might_match("true and id.user == 12345",
- "id::testdoctype1:n=12345:bar"));
+ EXPECT_TRUE(might_match("id.user == 12345 and true",
+ "id::testdoctype1:n=12345:bar"));
+ EXPECT_TRUE(might_match("true and id.user == 12345",
+ "id::testdoctype1:n=12345:bar"));
- CPPUNIT_ASSERT(!might_match("id.user == 123456 and true",
- "id::testdoctype1:n=12345:bar"));
- CPPUNIT_ASSERT(!might_match("true and id.user == 123456",
- "id::testdoctype1:n=12345:bar"));
+ EXPECT_TRUE(!might_match("id.user == 123456 and true",
+ "id::testdoctype1:n=12345:bar"));
+ EXPECT_TRUE(!might_match("true and id.user == 123456",
+ "id::testdoctype1:n=12345:bar"));
}
-void
-GidFilterTest::complex_conjunctive_location_expressions_are_filtered()
+TEST_F(GidFilterTest, complex_conjunctive_location_expressions_are_filtered)
{
- CPPUNIT_ASSERT(might_match("(((testdoctype1.headerval < 5) and (1 != 2)) "
- "and id.user == 12345)",
+ EXPECT_TRUE(might_match("(((testdoctype1.headerval < 5) and (1 != 2)) "
+ "and id.user == 12345)",
"id::testdoctype1:n=12345:bar"));
- CPPUNIT_ASSERT(!might_match("(((1 != 2) and (id.user==12345)) and "
- "(2 != 3)) and (testdoctype1.headerval < 5)",
- "id::testdoctype1:n=23456:bar"));
+ EXPECT_TRUE(!might_match("(((1 != 2) and (id.user==12345)) and "
+ "(2 != 3)) and (testdoctype1.headerval < 5)",
+ "id::testdoctype1:n=23456:bar"));
// In this case the expression contains a disjunction but the outcome
// of evaluating it still strongly depends on the location predicate.
- CPPUNIT_ASSERT(might_match("((id.user == 12345 and true) and "
- "(true or false))",
- "id::testdoctype1:n=12345:bar"));
- CPPUNIT_ASSERT(!might_match("((id.user == 12345 and true) and "
- "(true or false))",
- "id::testdoctype1:n=23456:bar"));
+ EXPECT_TRUE(might_match("((id.user == 12345 and true) and "
+ "(true or false))",
+ "id::testdoctype1:n=12345:bar"));
+ EXPECT_TRUE(!might_match("((id.user == 12345 and true) and "
+ "(true or false))",
+ "id::testdoctype1:n=23456:bar"));
}
-void
-GidFilterTest::simple_disjunctive_location_expressions_are_not_filtered()
+TEST_F(GidFilterTest, simple_disjunctive_location_expressions_are_not_filtered)
{
// Documents mismatch location but match selection as a whole.
- CPPUNIT_ASSERT(might_match("id.user == 12345 or true",
- "id::testdoctype1:n=12345678:bar"));
- CPPUNIT_ASSERT(might_match("true or id.user == 12345",
- "id::testdoctype1:n=12345678:bar"));
+ EXPECT_TRUE(might_match("id.user == 12345 or true",
+ "id::testdoctype1:n=12345678:bar"));
+ EXPECT_TRUE(might_match("true or id.user == 12345",
+ "id::testdoctype1:n=12345678:bar"));
}
-void
-GidFilterTest::complex_disjunctive_location_expressions_are_not_filtered()
+TEST_F(GidFilterTest, complex_disjunctive_location_expressions_are_not_filtered)
{
- CPPUNIT_ASSERT(might_match("((id.user == 12345) and true) or false",
- "id::testdoctype1:n=12345678:bar"));
- CPPUNIT_ASSERT(might_match("((id.user == 12345) or false) and true",
- "id::testdoctype1:n=12345678:bar"));
+ EXPECT_TRUE(might_match("((id.user == 12345) and true) or false",
+ "id::testdoctype1:n=12345678:bar"));
+ EXPECT_TRUE(might_match("((id.user == 12345) or false) and true",
+ "id::testdoctype1:n=12345678:bar"));
}
-void
-GidFilterTest::non_location_id_comparisons_are_not_filtered()
+TEST_F(GidFilterTest, non_location_id_comparisons_are_not_filtered)
{
// Note: these selections are syntactically valid but semantically
// invalid (comparing strings to integers), but are used to catch any
// logic holes where an id node is indiscriminately treated as something
// from which we should derive a GID-related integer.
- CPPUNIT_ASSERT(might_match("id.namespace == 123456",
- "id::testdoctype1:n=12345678:bar"));
- CPPUNIT_ASSERT(might_match("id.type == 1234",
- "id::testdoctype1:n=12345678:bar"));
- CPPUNIT_ASSERT(might_match("id.scheme == 555",
- "id::testdoctype1:n=12345678:bar"));
- CPPUNIT_ASSERT(might_match("id.specific == 7654",
- "id::testdoctype1:n=12345678:bar"));
+ EXPECT_TRUE(might_match("id.namespace == 123456",
+ "id::testdoctype1:n=12345678:bar"));
+ EXPECT_TRUE(might_match("id.type == 1234",
+ "id::testdoctype1:n=12345678:bar"));
+ EXPECT_TRUE(might_match("id.scheme == 555",
+ "id::testdoctype1:n=12345678:bar"));
+ EXPECT_TRUE(might_match("id.specific == 7654",
+ "id::testdoctype1:n=12345678:bar"));
}
-void
-GidFilterTest::unsupported_location_comparison_operands_not_filtered()
+TEST_F(GidFilterTest, unsupported_location_comparison_operands_not_filtered)
{
- CPPUNIT_ASSERT(might_match("id.user == 'rick & morty'",
- "id::testdoctype1:n=12345678:bar"));
- CPPUNIT_ASSERT(might_match("id.group == 56789",
- "id::testdoctype1:n=12345678:bar"));
- CPPUNIT_ASSERT(might_match("id.user == testdoctype1.headervalue",
- "id::testdoctype1:n=12345678:bar"));
- CPPUNIT_ASSERT(might_match("id.group == testdoctype1.headervalue",
- "id::testdoctype1:g=helloworld:bar"));
+ EXPECT_TRUE(might_match("id.user == 'rick & morty'",
+ "id::testdoctype1:n=12345678:bar"));
+ EXPECT_TRUE(might_match("id.group == 56789",
+ "id::testdoctype1:n=12345678:bar"));
+ EXPECT_TRUE(might_match("id.user == testdoctype1.headervalue",
+ "id::testdoctype1:n=12345678:bar"));
+ EXPECT_TRUE(might_match("id.group == testdoctype1.headervalue",
+ "id::testdoctype1:g=helloworld:bar"));
}
-void
-GidFilterTest::default_constructed_filter_always_matches()
+TEST_F(GidFilterTest, default_constructed_filter_always_matches)
{
GidFilter filter;
- CPPUNIT_ASSERT(filter.gid_might_match_selection(
+ EXPECT_TRUE(filter.gid_might_match_selection(
DocumentId("id::testdoctype1:n=12345678:bar").getGlobalId()));
- CPPUNIT_ASSERT(filter.gid_might_match_selection(
+ EXPECT_TRUE(filter.gid_might_match_selection(
DocumentId("id::testdoctype1::foo").getGlobalId()));
}
-void
-GidFilterTest::most_significant_32_bits_are_ignored()
+TEST_F(GidFilterTest, most_significant_32_bits_are_ignored)
{
// The fact that the 32 MSB are effectively ignored is an artifact of
// how the GID location extraction is historically performed and is not
@@ -248,26 +191,24 @@ GidFilterTest::most_significant_32_bits_are_ignored()
// behavior currently is and should thus be tested.
// The following locations have the same 32 LSB:
- CPPUNIT_ASSERT(might_match("id.user == 12345678901",
- "id::testdoctype1:n=29525548085:bar"));
+ EXPECT_TRUE(might_match("id.user == 12345678901",
+ "id::testdoctype1:n=29525548085:bar"));
}
-void
-GidFilterTest::gid_filters_may_be_copy_constructed()
+TEST_F(GidFilterTest, gid_filters_may_be_copy_constructed)
{
Fixture f("id.user == 1337");
GidFilter filter = GidFilter::for_selection_root_node(*f._root);
GidFilter copy_constructed(filter);
- CPPUNIT_ASSERT(copy_constructed.gid_might_match_selection(
+ EXPECT_TRUE(copy_constructed.gid_might_match_selection(
id_to_gid("id::testdoctype1:n=1337:zoid")));
- CPPUNIT_ASSERT(!copy_constructed.gid_might_match_selection(
+ EXPECT_TRUE(!copy_constructed.gid_might_match_selection(
id_to_gid("id::testdoctype1:n=555:zoid")));
}
-void
-GidFilterTest::gid_filters_may_be_copy_assigned()
+TEST_F(GidFilterTest, gid_filters_may_be_copy_assigned)
{
Fixture f("id.user == 1337");
GidFilter filter = GidFilter::for_selection_root_node(*f._root);
@@ -275,45 +216,40 @@ GidFilterTest::gid_filters_may_be_copy_assigned()
GidFilter copy_assigned;
copy_assigned = filter;
- CPPUNIT_ASSERT(copy_assigned.gid_might_match_selection(
+ EXPECT_TRUE(copy_assigned.gid_might_match_selection(
id_to_gid("id::testdoctype1:n=1337:zoid")));
- CPPUNIT_ASSERT(!copy_assigned.gid_might_match_selection(
+ EXPECT_TRUE(!copy_assigned.gid_might_match_selection(
id_to_gid("id::testdoctype1:n=555:zoid")));
}
-void
-GidFilterTest::same_group_for_selection_and_gid_returns_match()
+TEST_F(GidFilterTest, same_group_for_selection_and_gid_returns_match)
{
- CPPUNIT_ASSERT(might_match("id.group == 'bjarne'",
- "id::testdoctype1:g=bjarne:foo"));
- CPPUNIT_ASSERT(might_match("id.group == 'andrei'",
- "id::testdoctype1:g=andrei:bar"));
+ EXPECT_TRUE(might_match("id.group == 'bjarne'",
+ "id::testdoctype1:g=bjarne:foo"));
+ EXPECT_TRUE(might_match("id.group == 'andrei'",
+ "id::testdoctype1:g=andrei:bar"));
}
-void
-GidFilterTest::differing_group_for_selection_and_gid_returns_mismatch()
+TEST_F(GidFilterTest, differing_group_for_selection_and_gid_returns_mismatch)
{
- CPPUNIT_ASSERT(!might_match("id.group == 'cult of bjarne'",
- "id::testdoctype1:g=stl:foo"));
- CPPUNIT_ASSERT(!might_match("id.group == 'sutters mill'",
- "id::testdoctype1:g=andrei:bar"));
+ EXPECT_TRUE(!might_match("id.group == 'cult of bjarne'",
+ "id::testdoctype1:g=stl:foo"));
+ EXPECT_TRUE(!might_match("id.group == 'sutters mill'",
+ "id::testdoctype1:g=andrei:bar"));
}
-void
-GidFilterTest::composite_user_comparison_sub_expressions_not_supported()
+TEST_F(GidFilterTest, composite_user_comparison_sub_expressions_not_supported)
{
// Technically this is a mismatch, but we currently only want to support
// the simple, obvious cases since this is not an expected use case.
- CPPUNIT_ASSERT(might_match("id.user == (1 + 2)",
- "id::testdoctype1:n=20:foo"));
+ EXPECT_TRUE(might_match("id.user == (1 + 2)",
+ "id::testdoctype1:n=20:foo"));
}
-void
-GidFilterTest::composite_group_comparison_sub_expressions_not_supported()
+TEST_F(GidFilterTest, composite_group_comparison_sub_expressions_not_supported)
{
- CPPUNIT_ASSERT(might_match("id.group == 'foo'+'bar'",
- "id::testdoctype1:g=sputnik_hits:foo"));
+ EXPECT_TRUE(might_match("id.group == 'foo'+'bar'",
+ "id::testdoctype1:g=sputnik_hits:foo"));
}
-} // select
-} // document
+}
diff --git a/document/src/tests/globalidtest.cpp b/document/src/tests/globalidtest.cpp
index c72ede2f20e..c6c974011ce 100644
--- a/document/src/tests/globalidtest.cpp
+++ b/document/src/tests/globalidtest.cpp
@@ -1,80 +1,66 @@
// 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/document/bucket/bucketidfactory.h>
#include <vespa/document/base/documentid.h>
#include <vespa/document/base/globalid.h>
#include <vespa/vespalib/util/random.h>
#include <vespa/vespalib/stllike/asciistream.h>
+#include <gtest/gtest.h>
namespace document {
-struct GlobalIdTest : public CppUnit::TestFixture {
- void testNormalUsage();
- void testBucketIdConversion();
- void testGidRangeConversion();
- void testBucketOrderCmp();
+class GlobalIdTest : public ::testing::Test {
+protected:
void verifyGlobalIdRange(const std::vector<DocumentId>& ids,
uint32_t countBits);
-
- CPPUNIT_TEST_SUITE(GlobalIdTest);
- CPPUNIT_TEST(testNormalUsage);
- CPPUNIT_TEST(testBucketIdConversion);
- CPPUNIT_TEST(testGidRangeConversion);
- CPPUNIT_TEST(testBucketOrderCmp);
- CPPUNIT_TEST_SUITE_END();
};
-CPPUNIT_TEST_SUITE_REGISTRATION(GlobalIdTest);
-
-void
-GlobalIdTest::testNormalUsage()
+TEST_F(GlobalIdTest, testNormalUsage)
{
const char* emptystring = "\0\0\0\0\0\0\0\0\0\0\0\0";
const char* teststring = "1234567890ABCDEF";
- CPPUNIT_ASSERT(strlen(teststring) > GlobalId::LENGTH);
+ EXPECT_TRUE(strlen(teststring) > GlobalId::LENGTH);
{ // Test empty global id
GlobalId id;
for (uint32_t i=0; i<GlobalId::LENGTH; ++i) {
- CPPUNIT_ASSERT_EQUAL((unsigned char) '\0', id.get()[i]);
+ EXPECT_EQ((unsigned char) '\0', id.get()[i]);
}
GlobalId id2(emptystring);
- CPPUNIT_ASSERT_EQUAL(id, id2);
- CPPUNIT_ASSERT(!(id != id2));
- CPPUNIT_ASSERT(!(id < id2) && !(id2 < id));
- CPPUNIT_ASSERT_EQUAL(std::string(emptystring, GlobalId::LENGTH),
- std::string((const char*) id.get(),
- GlobalId::LENGTH));
+ EXPECT_EQ(id, id2);
+ EXPECT_TRUE(!(id != id2));
+ EXPECT_TRUE(!(id < id2) && !(id2 < id));
+ EXPECT_EQ(std::string(emptystring, GlobalId::LENGTH),
+ std::string((const char*) id.get(), GlobalId::LENGTH));
}
{ // Test non-empty global id
GlobalId empty;
GlobalId initialempty;
initialempty.set(teststring);
GlobalId id(teststring);
- CPPUNIT_ASSERT_EQUAL(id, initialempty);
- CPPUNIT_ASSERT(!(id != initialempty));
- CPPUNIT_ASSERT(!(id < initialempty) && !(initialempty < id));
+ EXPECT_EQ(id, initialempty);
+ EXPECT_TRUE(!(id != initialempty));
+ EXPECT_TRUE(!(id < initialempty) && !(initialempty < id));
- CPPUNIT_ASSERT(id != empty);
- CPPUNIT_ASSERT(!(id == empty));
- CPPUNIT_ASSERT(!(id < empty) && (empty < id));
+ EXPECT_TRUE(id != empty);
+ EXPECT_TRUE(!(id == empty));
+ EXPECT_TRUE(!(id < empty) && (empty < id));
- CPPUNIT_ASSERT_EQUAL(
+ EXPECT_EQ(
std::string(teststring, GlobalId::LENGTH),
std::string((const char*) id.get(), GlobalId::LENGTH));
- CPPUNIT_ASSERT_EQUAL(std::string(teststring, GlobalId::LENGTH),
+ EXPECT_EQ(std::string(teststring, GlobalId::LENGTH),
std::string((const char*) initialempty.get(),
GlobalId::LENGTH));
}
{ // Test printing and parsing
GlobalId id1("LIN!#LNKASD#!MYL#&NK");
- CPPUNIT_ASSERT_EQUAL(vespalib::string("gid(0x4c494e21234c4e4b41534423)"),
+ EXPECT_EQ(vespalib::string("gid(0x4c494e21234c4e4b41534423)"),
id1.toString());
GlobalId id2 = GlobalId::parse(id1.toString());
- CPPUNIT_ASSERT_EQUAL(id1, id2);
+ EXPECT_EQ(id1, id2);
// Verify string representation too, to verify that operator== works
- CPPUNIT_ASSERT_EQUAL(vespalib::string("gid(0x4c494e21234c4e4b41534423)"),
+ EXPECT_EQ(vespalib::string("gid(0x4c494e21234c4e4b41534423)"),
id2.toString());
}
}
@@ -88,18 +74,15 @@ namespace {
BucketId generated = gid.convertToBucketId();
//std::cerr << bid << ", " << generated << "\n";
if (bid != generated) {
- std::ostringstream ost;
- ost << "Document id " << s << " with gid " << gid
- << " belongs to bucket " << bid
- << ", but globalid convert function generated bucketid "
- << generated;
- CPPUNIT_FAIL(ost.str());
+ FAIL() << "Document id " << s << " with gid " << gid
+ << " belongs to bucket " << bid
+ << ", but globalid convert function generated bucketid "
+ << generated;
}
}
}
-void
-GlobalIdTest::testBucketIdConversion()
+TEST_F(GlobalIdTest, testBucketIdConversion)
{
verifyDocumentId("userdoc:ns:1:abc");
verifyDocumentId("userdoc:ns:1000:abc");
@@ -144,32 +127,23 @@ GlobalIdTest::verifyGlobalIdRange(const std::vector<DocumentId>& ids,
<< " should be in the range "
<< first.convertToBucketId().toKey() << " - "
<< last.convertToBucketId().toKey() << "\n";
- CPPUNIT_ASSERT_MESSAGE(msg.str(),
- gid.convertToBucketId().toKey() >=
- first.convertToBucketId().toKey());
- CPPUNIT_ASSERT_MESSAGE(msg.str(),
- gid.convertToBucketId().toKey() <=
- last.convertToBucketId().toKey());
+ EXPECT_TRUE(gid.convertToBucketId().toKey() >= first.convertToBucketId().toKey()) << msg.str();
+ EXPECT_TRUE(gid.convertToBucketId().toKey() <= last.convertToBucketId().toKey()) << msg.str();
}
} else {
if ((gidKey >= first.convertToBucketId().toKey()) && (gidKey <= last.convertToBucketId().toKey())) {
std::ostringstream msg;
msg << gid << " should not be in the range " << first
<< " - " << last;
- CPPUNIT_ASSERT_MESSAGE(msg.str(),
- (gid.convertToBucketId().toKey() <
- first.convertToBucketId().toKey())
- ||
- (gid.convertToBucketId().toKey() >
- last.convertToBucketId().toKey()));
+ EXPECT_TRUE((gid.convertToBucketId().toKey() < first.convertToBucketId().toKey()) ||
+ (gid.convertToBucketId().toKey() > last.convertToBucketId().toKey())) << msg.str();
}
}
}
}
}
-void
-GlobalIdTest::testGidRangeConversion()
+TEST_F(GlobalIdTest, testGidRangeConversion)
{
// Generate a lot of random document ids used for test
std::vector<DocumentId> docIds;
@@ -194,7 +168,7 @@ GlobalIdTest::testGidRangeConversion()
}
ost << ":";
break;
- default: CPPUNIT_ASSERT(false);
+ default: EXPECT_TRUE(false);
}
ost << "http://";
for (uint32_t i=0, n=randomizer.nextUint32(1, 20); i<n; ++i) {
@@ -210,19 +184,18 @@ GlobalIdTest::testGidRangeConversion()
}
}
-void
-GlobalIdTest::testBucketOrderCmp()
+TEST_F(GlobalIdTest, testBucketOrderCmp)
{
typedef GlobalId::BucketOrderCmp C;
- CPPUNIT_ASSERT(C::compareRaw(0, 0) == 0);
- CPPUNIT_ASSERT(C::compareRaw(0, 1) == -1);
- CPPUNIT_ASSERT(C::compareRaw(1, 0) == 1);
- CPPUNIT_ASSERT(C::compareRaw(255, 255) == 0);
- CPPUNIT_ASSERT(C::compareRaw(0, 255) == -255);
- CPPUNIT_ASSERT(C::compareRaw(255, 0) == 255);
- CPPUNIT_ASSERT(C::compareRaw(254, 254) == 0);
- CPPUNIT_ASSERT(C::compareRaw(254, 255) == -1);
- CPPUNIT_ASSERT(C::compareRaw(255, 254) == 1);
+ EXPECT_TRUE(C::compareRaw(0, 0) == 0);
+ EXPECT_TRUE(C::compareRaw(0, 1) == -1);
+ EXPECT_TRUE(C::compareRaw(1, 0) == 1);
+ EXPECT_TRUE(C::compareRaw(255, 255) == 0);
+ EXPECT_TRUE(C::compareRaw(0, 255) == -255);
+ EXPECT_TRUE(C::compareRaw(255, 0) == 255);
+ EXPECT_TRUE(C::compareRaw(254, 254) == 0);
+ EXPECT_TRUE(C::compareRaw(254, 255) == -1);
+ EXPECT_TRUE(C::compareRaw(255, 254) == 1);
{
// Test raw comparator object.
GlobalId foo = GlobalId::parse("gid(0x000001103330333077700000)");
@@ -230,15 +203,15 @@ GlobalIdTest::testBucketOrderCmp()
GlobalId baz = GlobalId::parse("gid(0x000000103330333000700000)");
GlobalId::BucketOrderCmp cmp;
- CPPUNIT_ASSERT(!cmp(foo, foo));
- CPPUNIT_ASSERT(!cmp(bar, bar));
- CPPUNIT_ASSERT(!cmp(baz, baz));
- CPPUNIT_ASSERT(!cmp(foo, bar));
- CPPUNIT_ASSERT( cmp(bar, foo));
- CPPUNIT_ASSERT(!cmp(foo, baz));
- CPPUNIT_ASSERT( cmp(baz, foo));
- CPPUNIT_ASSERT(!cmp(baz, bar));
- CPPUNIT_ASSERT( cmp(bar, baz));
+ EXPECT_TRUE(!cmp(foo, foo));
+ EXPECT_TRUE(!cmp(bar, bar));
+ EXPECT_TRUE(!cmp(baz, baz));
+ EXPECT_TRUE(!cmp(foo, bar));
+ EXPECT_TRUE( cmp(bar, foo));
+ EXPECT_TRUE(!cmp(foo, baz));
+ EXPECT_TRUE( cmp(baz, foo));
+ EXPECT_TRUE(!cmp(baz, bar));
+ EXPECT_TRUE( cmp(bar, baz));
}
{
// Test sorting by bucket.
@@ -253,15 +226,15 @@ GlobalIdTest::testBucketOrderCmp()
gidMap[baz] = 888;
GidMap::iterator it = gidMap.begin();
- CPPUNIT_ASSERT(it->first == bar);
- CPPUNIT_ASSERT(it->second == 777);
+ EXPECT_TRUE(it->first == bar);
+ EXPECT_TRUE(it->second == 777);
++it;
- CPPUNIT_ASSERT(it->first == baz);
- CPPUNIT_ASSERT(it->second == 888);
+ EXPECT_TRUE(it->first == baz);
+ EXPECT_TRUE(it->second == 888);
++it;
- CPPUNIT_ASSERT(it->first == foo);
- CPPUNIT_ASSERT(it->second == 666);
+ EXPECT_TRUE(it->first == foo);
+ EXPECT_TRUE(it->second == 666);
}
}
-} // document
+}