aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/tests/documentupdatetestcase.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'document/src/tests/documentupdatetestcase.cpp')
-rw-r--r--document/src/tests/documentupdatetestcase.cpp275
1 files changed, 105 insertions, 170 deletions
diff --git a/document/src/tests/documentupdatetestcase.cpp b/document/src/tests/documentupdatetestcase.cpp
index 9ba17d95264..2a77d610420 100644
--- a/document/src/tests/documentupdatetestcase.cpp
+++ b/document/src/tests/documentupdatetestcase.cpp
@@ -191,16 +191,15 @@ DocumentUpdateTest::testSimpleUsage() {
fieldUpdate.addUpdate(AssignValueUpdate(IntFieldValue(1)));
ByteBuffer::UP fieldBuf = serialize(fieldUpdate);
fieldBuf->flip();
- FieldUpdate fieldUpdateCopy(repo, *docType, *fieldBuf,
- Document::getNewestSerializationVersion());
+ FieldUpdate fieldUpdateCopy(repo, *docType, *fieldBuf, Document::getNewestSerializationVersion());
CPPUNIT_ASSERT_EQUAL(fieldUpdate, fieldUpdateCopy);
// Test that a document update can be serialized
- DocumentUpdate docUpdate(*docType, DocumentId("doc::testdoc"));
+ DocumentUpdate docUpdate(repo, *docType, DocumentId("doc::testdoc"));
docUpdate.addUpdate(fieldUpdateCopy);
- ByteBuffer::UP docBuf = serialize42(docUpdate);
+ ByteBuffer::UP docBuf = serializeHEAD(docUpdate);
docBuf->flip();
- DocumentUpdate::UP docUpdateCopy(DocumentUpdate::create42(repo, *docBuf));
+ auto docUpdateCopy(DocumentUpdate::createHEAD(repo, nbostream(docBuf->getBufferAtPos(), docBuf->getRemaining())));
// Create a test document
Document doc(*docType, DocumentId("doc::testdoc"));
@@ -214,62 +213,53 @@ DocumentUpdateTest::testSimpleUsage() {
// Verify that we can apply simple updates to it
{
Document updated(doc);
- DocumentUpdate upd(*docType, DocumentId("doc::testdoc"));
- upd.addUpdate(FieldUpdate(docType->getField("intf"))
- .addUpdate(ClearValueUpdate()));
+ DocumentUpdate upd(repo, *docType, DocumentId("doc::testdoc"));
+ upd.addUpdate(FieldUpdate(docType->getField("intf")).addUpdate(ClearValueUpdate()));
upd.applyTo(updated);
CPPUNIT_ASSERT(doc != updated);
CPPUNIT_ASSERT(! updated.getValue("intf"));
}
{
Document updated(doc);
- DocumentUpdate upd(*docType, DocumentId("doc::testdoc"));
- upd.addUpdate(FieldUpdate(docType->getField("intf"))
- .addUpdate(AssignValueUpdate(IntFieldValue(15))));
+ DocumentUpdate upd(repo, *docType, DocumentId("doc::testdoc"));
+ upd.addUpdate(FieldUpdate(docType->getField("intf")).addUpdate(AssignValueUpdate(IntFieldValue(15))));
upd.applyTo(updated);
CPPUNIT_ASSERT(doc != updated);
CPPUNIT_ASSERT_EQUAL(15, updated.getValue("intf")->getAsInt());
}
{
Document updated(doc);
- DocumentUpdate upd(*docType, DocumentId("doc::testdoc"));
- upd.addUpdate(FieldUpdate(docType->getField("intf"))
- .addUpdate(ArithmeticValueUpdate(
- ArithmeticValueUpdate::Add, 15)));
+ DocumentUpdate upd(repo, *docType, DocumentId("doc::testdoc"));
+ upd.addUpdate(FieldUpdate(docType->getField("intf")).addUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 15)));
upd.applyTo(updated);
CPPUNIT_ASSERT(doc != updated);
CPPUNIT_ASSERT_EQUAL(20, updated.getValue("intf")->getAsInt());
}
{
Document updated(doc);
- DocumentUpdate upd(*docType, DocumentId("doc::testdoc"));
- upd.addUpdate(FieldUpdate(docType->getField("intarr"))
- .addUpdate(AddValueUpdate(IntFieldValue(4))));
+ DocumentUpdate upd(repo, *docType, DocumentId("doc::testdoc"));
+ upd.addUpdate(FieldUpdate(docType->getField("intarr")).addUpdate(AddValueUpdate(IntFieldValue(4))));
upd.applyTo(updated);
CPPUNIT_ASSERT(doc != updated);
- std::unique_ptr<ArrayFieldValue> val(dynamic_cast<ArrayFieldValue*>(
- updated.getValue("intarr").release()));
+ std::unique_ptr<ArrayFieldValue> val(dynamic_cast<ArrayFieldValue*>(updated.getValue("intarr").release()));
CPPUNIT_ASSERT_EQUAL(size_t(3), val->size());
CPPUNIT_ASSERT_EQUAL(4, (*val)[2].getAsInt());
}
{
Document updated(doc);
- DocumentUpdate upd(*docType, DocumentId("doc::testdoc"));
- upd.addUpdate(FieldUpdate(docType->getField("intarr"))
- .addUpdate(RemoveValueUpdate(IntFieldValue(3))));
+ DocumentUpdate upd(repo, *docType, DocumentId("doc::testdoc"));
+ upd.addUpdate(FieldUpdate(docType->getField("intarr")).addUpdate(RemoveValueUpdate(IntFieldValue(3))));
upd.applyTo(updated);
CPPUNIT_ASSERT(doc != updated);
- std::unique_ptr<ArrayFieldValue> val(dynamic_cast<ArrayFieldValue*>(
- updated.getValue("intarr").release()));
+ std::unique_ptr<ArrayFieldValue> val(dynamic_cast<ArrayFieldValue*>(updated.getValue("intarr").release()));
CPPUNIT_ASSERT_EQUAL(size_t(1), val->size());
CPPUNIT_ASSERT_EQUAL(7, (*val)[0].getAsInt());
}
{
Document updated(doc);
- DocumentUpdate upd(*docType, DocumentId("doc::testdoc"));
+ DocumentUpdate upd(repo, *docType, DocumentId("doc::testdoc"));
upd.addUpdate(FieldUpdate(docType->getField("bytef"))
- .addUpdate(ArithmeticValueUpdate(
- ArithmeticValueUpdate::Add, 15)));
+ .addUpdate(ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 15)));
upd.applyTo(updated);
CPPUNIT_ASSERT(doc != updated);
CPPUNIT_ASSERT_EQUAL(15, (int) updated.getValue("bytef")->getAsByte());
@@ -286,9 +276,8 @@ DocumentUpdateTest::testClearField()
CPPUNIT_ASSERT_EQUAL(4, doc->getValue("headerval")->getAsInt());
// Apply an update.
- DocumentUpdate(*doc->getDataType(), doc->getId())
- .addUpdate(FieldUpdate(doc->getField("headerval"))
- .addUpdate(AssignValueUpdate()))
+ DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId())
+ .addUpdate(FieldUpdate(doc->getField("headerval")).addUpdate(AssignValueUpdate()))
.applyTo(*doc);
CPPUNIT_ASSERT(!doc->getValue("headerval"));
}
@@ -303,9 +292,8 @@ DocumentUpdateTest::testUpdateApplySingleValue()
CPPUNIT_ASSERT_EQUAL(4, doc->getValue("headerval")->getAsInt());
// Apply an update.
- DocumentUpdate(*doc->getDataType(), doc->getId())
- .addUpdate(FieldUpdate(doc->getField("headerval"))
- .addUpdate(AssignValueUpdate(IntFieldValue(9))))
+ DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId())
+ .addUpdate(FieldUpdate(doc->getField("headerval")).addUpdate(AssignValueUpdate(IntFieldValue(9))))
.applyTo(*doc);
CPPUNIT_ASSERT_EQUAL(9, doc->getValue("headerval")->getAsInt());
}
@@ -316,28 +304,23 @@ DocumentUpdateTest::testUpdateArray()
// Create a document.
TestDocMan docMan;
Document::UP doc(docMan.createDocument());
- CPPUNIT_ASSERT_EQUAL((document::FieldValue*)NULL,
- doc->getValue(doc->getField("tags")).get());
+ CPPUNIT_ASSERT_EQUAL((document::FieldValue*)NULL, doc->getValue(doc->getField("tags")).get());
// Assign array field.
ArrayFieldValue myarray(doc->getType().getField("tags").getDataType());
myarray.add(StringFieldValue("foo"));
myarray.add(StringFieldValue("bar"));
- DocumentUpdate(*doc->getDataType(), doc->getId())
- .addUpdate(FieldUpdate(doc->getField("tags"))
- .addUpdate(AssignValueUpdate(myarray)))
+ DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId())
+ .addUpdate(FieldUpdate(doc->getField("tags")).addUpdate(AssignValueUpdate(myarray)))
.applyTo(*doc);
- std::unique_ptr<ArrayFieldValue>
- fval1(doc->getAs<ArrayFieldValue>(doc->getField("tags")));
+ auto fval1(doc->getAs<ArrayFieldValue>(doc->getField("tags")));
CPPUNIT_ASSERT_EQUAL((size_t) 2, fval1->size());
- CPPUNIT_ASSERT_EQUAL(std::string("foo"),
- std::string((*fval1)[0].getAsString()));
- CPPUNIT_ASSERT_EQUAL(std::string("bar"),
- std::string((*fval1)[1].getAsString()));
+ CPPUNIT_ASSERT_EQUAL(std::string("foo"), std::string((*fval1)[0].getAsString()));
+ CPPUNIT_ASSERT_EQUAL(std::string("bar"), std::string((*fval1)[1].getAsString()));
// Append array field
- DocumentUpdate(*doc->getDataType(), doc->getId())
+ DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId())
.addUpdate(FieldUpdate(doc->getField("tags"))
.addUpdate(AddValueUpdate(StringFieldValue("another")))
.addUpdate(AddValueUpdate(StringFieldValue("tag"))))
@@ -345,21 +328,16 @@ DocumentUpdateTest::testUpdateArray()
std::unique_ptr<ArrayFieldValue>
fval2(doc->getAs<ArrayFieldValue>(doc->getField("tags")));
CPPUNIT_ASSERT_EQUAL((size_t) 4, fval2->size());
- CPPUNIT_ASSERT_EQUAL(std::string("foo"),
- std::string((*fval2)[0].getAsString()));
- CPPUNIT_ASSERT_EQUAL(std::string("bar"),
- std::string((*fval2)[1].getAsString()));
- CPPUNIT_ASSERT_EQUAL(std::string("another"),
- std::string((*fval2)[2].getAsString()));
- CPPUNIT_ASSERT_EQUAL(std::string("tag"),
- std::string((*fval2)[3].getAsString()));
+ CPPUNIT_ASSERT_EQUAL(std::string("foo"), std::string((*fval2)[0].getAsString()));
+ CPPUNIT_ASSERT_EQUAL(std::string("bar"), std::string((*fval2)[1].getAsString()));
+ CPPUNIT_ASSERT_EQUAL(std::string("another"), std::string((*fval2)[2].getAsString()));
+ CPPUNIT_ASSERT_EQUAL(std::string("tag"), std::string((*fval2)[3].getAsString()));
// Append single value.
try {
- DocumentUpdate(*doc->getDataType(), doc->getId())
+ DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId())
.addUpdate(FieldUpdate(doc->getField("tags"))
- .addUpdate(AssignValueUpdate(
- StringFieldValue("THROW MEH!"))))
+ .addUpdate(AssignValueUpdate(StringFieldValue("THROW MEH!"))))
.applyTo(*doc);
CPPUNIT_FAIL("Expected exception when assinging a string value to an "
"array field.");
@@ -369,25 +347,22 @@ DocumentUpdateTest::testUpdateArray()
}
// Remove array field.
- DocumentUpdate(*doc->getDataType(), doc->getId())
+ DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId())
.addUpdate(FieldUpdate(doc->getField("tags"))
.addUpdate(RemoveValueUpdate(StringFieldValue("foo")))
.addUpdate(RemoveValueUpdate(StringFieldValue("tag"))))
.applyTo(*doc);
- std::unique_ptr<ArrayFieldValue>
- fval3(doc->getAs<ArrayFieldValue>(doc->getField("tags")));
+ auto fval3(doc->getAs<ArrayFieldValue>(doc->getField("tags")));
CPPUNIT_ASSERT_EQUAL((size_t) 2, fval3->size());
- CPPUNIT_ASSERT_EQUAL(std::string("bar"),
- std::string((*fval3)[0].getAsString()));
- CPPUNIT_ASSERT_EQUAL(std::string("another"),
- std::string((*fval3)[1].getAsString()));
+ CPPUNIT_ASSERT_EQUAL(std::string("bar"), std::string((*fval3)[0].getAsString()));
+ CPPUNIT_ASSERT_EQUAL(std::string("another"), std::string((*fval3)[1].getAsString()));
// Remove array from array.
ArrayFieldValue myarray2(doc->getType().getField("tags").getDataType());
myarray2.add(StringFieldValue("foo"));
myarray2.add(StringFieldValue("bar"));
try {
- DocumentUpdate(*doc->getDataType(), doc->getId())
+ DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId())
.addUpdate(FieldUpdate(doc->getField("tags"))
.addUpdate(RemoveValueUpdate(myarray2)))
.applyTo(*doc);
@@ -412,12 +387,10 @@ DocumentUpdateTest::testUpdateWeightedSet()
WeightedSetFieldValue wset(field.getDataType());
wset.add(StringFieldValue("foo"), 3);
wset.add(StringFieldValue("bar"), 14);
- DocumentUpdate(*doc->getDataType(), doc->getId())
- .addUpdate(FieldUpdate(field)
- .addUpdate(AssignValueUpdate(wset)))
+ DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId())
+ .addUpdate(FieldUpdate(field).addUpdate(AssignValueUpdate(wset)))
.applyTo(*doc);
- std::unique_ptr<WeightedSetFieldValue>
- fval1(doc->getAs<WeightedSetFieldValue>(field));
+ auto fval1(doc->getAs<WeightedSetFieldValue>(field));
CPPUNIT_ASSERT_EQUAL((size_t) 2, fval1->size());
CPPUNIT_ASSERT(fval1->contains(StringFieldValue("foo")));
CPPUNIT_ASSERT(fval1->find(StringFieldValue("foo")) != fval1->end());
@@ -430,12 +403,11 @@ DocumentUpdateTest::testUpdateWeightedSet()
WeightedSetFieldValue wset2(field.getDataType());
wset2.add(StringFieldValue("foo"), 16);
wset2.add(StringFieldValue("bar"), 24);
- DocumentUpdate(*doc->getDataType(), doc->getId())
+ DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId())
.addUpdate(FieldUpdate(field)
.addUpdate(AssignValueUpdate(wset2)))
.applyTo(*doc);
- std::unique_ptr<WeightedSetFieldValue>
- fval2(doc->getAs<WeightedSetFieldValue>(field));
+ auto fval2(doc->getAs<WeightedSetFieldValue>(field));
CPPUNIT_ASSERT_EQUAL((size_t) 2, fval2->size());
CPPUNIT_ASSERT(fval2->contains(StringFieldValue("foo")));
CPPUNIT_ASSERT(fval2->find(StringFieldValue("foo")) != fval1->end());
@@ -445,12 +417,10 @@ DocumentUpdateTest::testUpdateWeightedSet()
CPPUNIT_ASSERT_EQUAL(24, fval2->get(StringFieldValue("bar"), 0));
// Append weighted field
- DocumentUpdate(*doc->getDataType(), doc->getId())
+ DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId())
.addUpdate(FieldUpdate(field)
- .addUpdate(AddValueUpdate(StringFieldValue("foo"))
- .setWeight(3))
- .addUpdate(AddValueUpdate(StringFieldValue("too"))
- .setWeight(14)))
+ .addUpdate(AddValueUpdate(StringFieldValue("foo")).setWeight(3))
+ .addUpdate(AddValueUpdate(StringFieldValue("too")).setWeight(14)))
.applyTo(*doc);
std::unique_ptr<WeightedSetFieldValue>
fval3(doc->getAs<WeightedSetFieldValue>(field));
@@ -463,13 +433,12 @@ DocumentUpdateTest::testUpdateWeightedSet()
CPPUNIT_ASSERT_EQUAL(14, fval3->get(StringFieldValue("too"), 0));
// Remove weighted field
- DocumentUpdate(*doc->getDataType(), doc->getId())
+ DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId())
.addUpdate(FieldUpdate(field)
.addUpdate(RemoveValueUpdate(StringFieldValue("foo")))
.addUpdate(RemoveValueUpdate(StringFieldValue("too"))))
.applyTo(*doc);
- std::unique_ptr<WeightedSetFieldValue>
- fval4(doc->getAs<WeightedSetFieldValue>(field));
+ auto fval4(doc->getAs<WeightedSetFieldValue>(field));
CPPUNIT_ASSERT_EQUAL((size_t) 1, fval4->size());
CPPUNIT_ASSERT(!fval4->contains(StringFieldValue("foo")));
CPPUNIT_ASSERT(fval4->contains(StringFieldValue("bar")));
@@ -500,21 +469,18 @@ struct WeightedSetAutoCreateFixture
// and remove-if-zero attributes set. Attempting to explicitly create
// a field matching those characteristics will in fact fail with a
// redefinition error.
- builder.document(42, "test",
- Struct("test.header")
- .addField("strwset", DataType::T_TAG),
- Struct("test.body"));
+ builder.document(42, "test", Struct("test.header").addField("strwset", DataType::T_TAG), Struct("test.body"));
return builder.config();
}
};
-WeightedSetAutoCreateFixture::~WeightedSetAutoCreateFixture() {}
+WeightedSetAutoCreateFixture::~WeightedSetAutoCreateFixture() = default;
WeightedSetAutoCreateFixture::WeightedSetAutoCreateFixture()
: repo(makeConfig()),
docType(repo.getDocumentType("test")),
doc(*docType, DocumentId("doc::testdoc")),
field(docType->getField("strwset")),
- update(*docType, DocumentId("doc::testdoc"))
+ update(repo, *docType, DocumentId("doc::testdoc"))
{
update.addUpdate(FieldUpdate(field)
.addUpdate(MapValueUpdate(StringFieldValue("foo"),
@@ -585,7 +551,8 @@ void DocumentUpdateTest::testReadSerializedFile()
}
close(fd);
- DocumentUpdate::UP updp(DocumentUpdate::create42(repo, buf));
+ nbostream is(buf.getBufferAtPos(), buf.getRemaining());
+ DocumentUpdate::UP updp(DocumentUpdate::create42(repo, is));
DocumentUpdate& upd(*updp);
const DocumentType *type = repo.getDocumentType("serializetest");
@@ -647,7 +614,7 @@ void DocumentUpdateTest::testGenerateSerializedFile()
DocumentTypeRepo repo(readDocumenttypesConfig(file_name));
const DocumentType *type(repo.getDocumentType("serializetest"));
- DocumentUpdate upd(*type, DocumentId(DocIdString("update", "test")));
+ DocumentUpdate upd(repo, *type, DocumentId(DocIdString("update", "test")));
upd.addUpdate(FieldUpdate(type->getField("intfield"))
.addUpdate(AssignValueUpdate(IntFieldValue(4))));
upd.addUpdate(FieldUpdate(type->getField("floatfield"))
@@ -678,11 +645,10 @@ void DocumentUpdateTest::testSetBadFieldTypes()
// Create a test document
TestDocMan docMan;
Document::UP doc(docMan.createDocument());
- CPPUNIT_ASSERT_EQUAL((document::FieldValue*)NULL,
- doc->getValue(doc->getField("headerval")).get());
+ CPPUNIT_ASSERT_EQUAL((document::FieldValue*)NULL, doc->getValue(doc->getField("headerval")).get());
// Assign a float value to an int field.
- DocumentUpdate update(*doc->getDataType(), doc->getId());
+ DocumentUpdate update(docMan.getTypeRepo(), *doc->getDataType(), doc->getId());
try {
update.addUpdate(FieldUpdate(doc->getField("headerval"))
.addUpdate(AssignValueUpdate(FloatFieldValue(4.00f))));
@@ -701,23 +667,19 @@ void DocumentUpdateTest::testSetBadFieldTypes()
void
DocumentUpdateTest::testUpdateApplyNoParams()
{
- // Create a test document
TestDocMan docMan;
Document::UP doc(docMan.createDocument());
- CPPUNIT_ASSERT_EQUAL((document::FieldValue*)NULL,
- doc->getValue(doc->getField("tags")).get());
+ CPPUNIT_ASSERT_EQUAL((document::FieldValue*)NULL, doc->getValue(doc->getField("tags")).get());
// Assign array field with no parameters - illegal.
- DocumentUpdate update(*doc->getDataType(), doc->getId());
+ DocumentUpdate update(docMan.getTypeRepo(), *doc->getDataType(), doc->getId());
try {
- update.addUpdate(FieldUpdate(doc->getField("tags"))
- .addUpdate(AssignValueUpdate()));
+ update.addUpdate(FieldUpdate(doc->getField("tags")).addUpdate(AssignValueUpdate()));
CPPUNIT_FAIL("Expected exception when assign a NULL value.");
} catch (std::exception& e) {
; // fprintf(stderr, "Got exception => OK: %s\n", e.what());
}
- // Apply update
update.applyTo(*doc);
// Verify that the field was cleared in the document.
@@ -727,20 +689,16 @@ DocumentUpdateTest::testUpdateApplyNoParams()
void
DocumentUpdateTest::testUpdateApplyNoArrayValues()
{
- // Create a test document
TestDocMan docMan;
Document::UP doc(docMan.createDocument());
const Field &field(doc->getType().getField("tags"));
- CPPUNIT_ASSERT_EQUAL((document::FieldValue*) 0,
- doc->getValue(field).get());
+ CPPUNIT_ASSERT_EQUAL((document::FieldValue*) 0, doc->getValue(field).get());
// Assign array field with no array values = empty array
- DocumentUpdate update(*doc->getDataType(), doc->getId());
+ DocumentUpdate update(docMan.getTypeRepo(), *doc->getDataType(), doc->getId());
update.addUpdate(FieldUpdate(field)
- .addUpdate(AssignValueUpdate(
- ArrayFieldValue(field.getDataType()))));
+ .addUpdate(AssignValueUpdate(ArrayFieldValue(field.getDataType()))));
- // Apply update
update.applyTo(*doc);
// Verify that the field was set in the document
@@ -759,7 +717,7 @@ DocumentUpdateTest::testUpdateArrayEmptyParamValue()
CPPUNIT_ASSERT_EQUAL((document::FieldValue*) 0, doc->getValue(field).get());
// Assign array field with no array values = empty array.
- DocumentUpdate update(*doc->getDataType(), doc->getId());
+ DocumentUpdate update(docMan.getTypeRepo(), *doc->getDataType(), doc->getId());
update.addUpdate(FieldUpdate(field).addUpdate(AssignValueUpdate(ArrayFieldValue(field.getDataType()))));
update.applyTo(*doc);
@@ -769,7 +727,7 @@ DocumentUpdateTest::testUpdateArrayEmptyParamValue()
CPPUNIT_ASSERT_EQUAL((size_t) 0, fval1->size());
// Remove array field.
- DocumentUpdate update2(*doc->getDataType(), doc->getId());
+ DocumentUpdate update2(docMan.getTypeRepo(), *doc->getDataType(), doc->getId());
update2.addUpdate(FieldUpdate(field).addUpdate(ClearValueUpdate()));
update2.applyTo(*doc);
@@ -788,7 +746,7 @@ DocumentUpdateTest::testUpdateWeightedSetEmptyParamValue()
CPPUNIT_ASSERT_EQUAL((document::FieldValue*) 0, doc->getValue(field).get());
// Assign weighted set with no items = empty set.
- DocumentUpdate update(*doc->getDataType(), doc->getId());
+ DocumentUpdate update(docMan.getTypeRepo(), *doc->getDataType(), doc->getId());
update.addUpdate(FieldUpdate(field).addUpdate(AssignValueUpdate(WeightedSetFieldValue(field.getDataType()))));
update.applyTo(*doc);
@@ -798,7 +756,7 @@ DocumentUpdateTest::testUpdateWeightedSetEmptyParamValue()
CPPUNIT_ASSERT_EQUAL((size_t) 0, fval1->size());
// Remove weighted set field.
- DocumentUpdate update2(*doc->getDataType(), doc->getId());
+ DocumentUpdate update2(docMan.getTypeRepo(), *doc->getDataType(), doc->getId());
update2.addUpdate(FieldUpdate(field).addUpdate(ClearValueUpdate()));
update2.applyTo(*doc);
@@ -817,7 +775,7 @@ DocumentUpdateTest::testUpdateArrayWrongSubtype()
CPPUNIT_ASSERT_EQUAL((document::FieldValue*) 0, doc->getValue(field).get());
// Assign int values to string array.
- DocumentUpdate update(*doc->getDataType(), doc->getId());
+ DocumentUpdate update(docMan.getTypeRepo(), *doc->getDataType(), doc->getId());
try {
update.addUpdate(FieldUpdate(field)
.addUpdate(AddValueUpdate(IntFieldValue(123)))
@@ -842,17 +800,14 @@ DocumentUpdateTest::testUpdateWeightedSetWrongSubtype()
TestDocMan docMan;
Document::UP doc(docMan.createDocument());
const Field &field(doc->getType().getField("stringweightedset"));
- CPPUNIT_ASSERT_EQUAL((document::FieldValue*) 0,
- doc->getValue(field).get());
+ CPPUNIT_ASSERT_EQUAL((document::FieldValue*) 0, doc->getValue(field).get());
// Assign int values to string array.
- DocumentUpdate update(*doc->getDataType(), doc->getId());
+ DocumentUpdate update(docMan.getTypeRepo(), *doc->getDataType(), doc->getId());
try {
update.addUpdate(FieldUpdate(field)
- .addUpdate(AddValueUpdate(IntFieldValue(123))
- .setWeight(1000))
- .addUpdate(AddValueUpdate(IntFieldValue(456))
- .setWeight(2000)));
+ .addUpdate(AddValueUpdate(IntFieldValue(123)).setWeight(1000))
+ .addUpdate(AddValueUpdate(IntFieldValue(456)).setWeight(2000)));
CPPUNIT_FAIL("Expected exception when adding wrong type.");
} catch (std::exception& e) {
; // fprintf(stderr, "Got exception => OK: %s\n", e.what());
@@ -879,79 +834,61 @@ DocumentUpdateTest::testMapValueUpdate()
doc->setValue(field1, wsval1);
doc->setValue(field2, wsval2);
- DocumentUpdate(*doc->getDataType(), doc->getId())
+ DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId())
.addUpdate(FieldUpdate(field1)
- .addUpdate(MapValueUpdate(
- StringFieldValue("banana"),
- ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 1.0)
- )))
+ .addUpdate(MapValueUpdate(StringFieldValue("banana"),
+ ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 1.0))))
.applyTo(*doc);
std::unique_ptr<WeightedSetFieldValue> fv1 =
doc->getAs<WeightedSetFieldValue>(field1);
CPPUNIT_ASSERT(fv1->size() == 0);
- DocumentUpdate(*doc->getDataType(), doc->getId())
+ DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId())
.addUpdate(FieldUpdate(field2)
- .addUpdate(MapValueUpdate(
- StringFieldValue("banana"),
- ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 1.0)
- )))
+ .addUpdate(MapValueUpdate(StringFieldValue("banana"),
+ ArithmeticValueUpdate(ArithmeticValueUpdate::Add, 1.0))))
.applyTo(*doc);
- std::unique_ptr<WeightedSetFieldValue> fv2 =
- doc->getAs<WeightedSetFieldValue>(field2);
+ auto fv2 = doc->getAs<WeightedSetFieldValue>(field2);
CPPUNIT_ASSERT(fv2->size() == 1);
CPPUNIT_ASSERT(fv1->find(StringFieldValue("apple")) == fv1->end());
- DocumentUpdate(*doc->getDataType(), doc->getId())
- .addUpdate(FieldUpdate(field1)
- .addUpdate(ClearValueUpdate()))
+ DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId())
+ .addUpdate(FieldUpdate(field1).addUpdate(ClearValueUpdate()))
.applyTo(*doc);
- DocumentUpdate(*doc->getDataType(), doc->getId())
- .addUpdate(FieldUpdate(field1)
- .addUpdate(AddValueUpdate(StringFieldValue("apple"))
- .setWeight(1)))
+ DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId())
+ .addUpdate(FieldUpdate(field1).addUpdate(AddValueUpdate(StringFieldValue("apple")).setWeight(1)))
.applyTo(*doc);
- std::unique_ptr<WeightedSetFieldValue>
- fval3(doc->getAs<WeightedSetFieldValue>(field1));
+ auto fval3(doc->getAs<WeightedSetFieldValue>(field1));
CPPUNIT_ASSERT(fval3->find(StringFieldValue("apple")) != fval3->end());
CPPUNIT_ASSERT_EQUAL(1, fval3->get(StringFieldValue("apple")));
- DocumentUpdate(*doc->getDataType(), doc->getId())
- .addUpdate(FieldUpdate(field2)
- .addUpdate(AddValueUpdate(StringFieldValue("apple"))
- .setWeight(1)))
+ DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId())
+ .addUpdate(FieldUpdate(field2).addUpdate(AddValueUpdate(StringFieldValue("apple")).setWeight(1)))
.applyTo(*doc);
- std::unique_ptr<WeightedSetFieldValue>
- fval3b(doc->getAs<WeightedSetFieldValue>(field2));
+ auto fval3b(doc->getAs<WeightedSetFieldValue>(field2));
CPPUNIT_ASSERT(fval3b->find(StringFieldValue("apple")) != fval3b->end());
CPPUNIT_ASSERT_EQUAL(1, fval3b->get(StringFieldValue("apple")));
- DocumentUpdate(*doc->getDataType(), doc->getId())
+ DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId())
.addUpdate(FieldUpdate(field1)
- .addUpdate(MapValueUpdate(
- StringFieldValue("apple"),
- ArithmeticValueUpdate(ArithmeticValueUpdate::Sub, 1.0)
- )))
+ .addUpdate(MapValueUpdate(StringFieldValue("apple"),
+ ArithmeticValueUpdate(ArithmeticValueUpdate::Sub, 1.0))))
.applyTo(*doc);
- std::unique_ptr<WeightedSetFieldValue> fv3 =
- doc->getAs<WeightedSetFieldValue>(field1);
+ auto fv3 = doc->getAs<WeightedSetFieldValue>(field1);
CPPUNIT_ASSERT(fv3->find(StringFieldValue("apple")) != fv3->end());
CPPUNIT_ASSERT_EQUAL(0, fv3->get(StringFieldValue("apple")));
- DocumentUpdate(*doc->getDataType(), doc->getId())
+ DocumentUpdate(docMan.getTypeRepo(), *doc->getDataType(), doc->getId())
.addUpdate(FieldUpdate(field2)
- .addUpdate(MapValueUpdate(
- StringFieldValue("apple"),
- ArithmeticValueUpdate(ArithmeticValueUpdate::Sub, 1.0)
- )))
+ .addUpdate(MapValueUpdate(StringFieldValue("apple"),
+ ArithmeticValueUpdate(ArithmeticValueUpdate::Sub, 1.0))))
.applyTo(*doc);
- std::unique_ptr<WeightedSetFieldValue> fv4 =
- doc->getAs<WeightedSetFieldValue>(field2);
+ auto fv4 = doc->getAs<WeightedSetFieldValue>(field2);
CPPUNIT_ASSERT(fv4->find(StringFieldValue("apple")) == fv4->end());
}
@@ -965,9 +902,8 @@ DocumentUpdateTest::testTensorAssignUpdate()
Document updated(*doc);
FieldValue::UP new_value(createTensorFieldValue());
testValueUpdate(AssignValueUpdate(*new_value), *DataType::TENSOR);
- DocumentUpdate upd(*doc->getDataType(), doc->getId());
- upd.addUpdate(FieldUpdate(upd.getType().getField("tensor")).
- addUpdate(AssignValueUpdate(*new_value)));
+ DocumentUpdate upd(docMan.getTypeRepo(), *doc->getDataType(), doc->getId());
+ upd.addUpdate(FieldUpdate(upd.getType().getField("tensor")).addUpdate(AssignValueUpdate(*new_value)));
upd.applyTo(updated);
FieldValue::UP fval(updated.getValue("tensor"));
CPPUNIT_ASSERT(fval);
@@ -983,9 +919,8 @@ DocumentUpdateTest::testTensorClearUpdate()
Document updated(*doc);
updated.setValue(updated.getField("tensor"), *createTensorFieldValue());
CPPUNIT_ASSERT(*doc != updated);
- DocumentUpdate upd(*doc->getDataType(), doc->getId());
- upd.addUpdate(FieldUpdate(upd.getType().getField("tensor")).
- addUpdate(ClearValueUpdate()));
+ DocumentUpdate upd(docMan.getTypeRepo(), *doc->getDataType(), doc->getId());
+ upd.addUpdate(FieldUpdate(upd.getType().getField("tensor")).addUpdate(ClearValueUpdate()));
upd.applyTo(updated);
CPPUNIT_ASSERT(!updated.getValue("tensor"));
CPPUNIT_ASSERT(*doc == updated);
@@ -1036,12 +971,11 @@ struct CreateIfNonExistentFixture
CreateIfNonExistentFixture();
};
-CreateIfNonExistentFixture::~CreateIfNonExistentFixture() {}
+CreateIfNonExistentFixture::~CreateIfNonExistentFixture() = default;
CreateIfNonExistentFixture::CreateIfNonExistentFixture()
: docMan(),
document(docMan.createDocument()),
- update(new DocumentUpdate(*document->getDataType(),
- document->getId()))
+ update(new DocumentUpdate(docMan.getTypeRepo(), *document->getDataType(), document->getId()))
{
update->addUpdate(FieldUpdate(document->getField("headerval"))
.addUpdate(AssignValueUpdate(IntFieldValue(1))));
@@ -1069,7 +1003,8 @@ DocumentUpdateTest::testThatCreateIfNonExistentFlagIsSerializedAndDeserialized()
ByteBuffer::UP buf(serialize42(*f.update));
buf->flip();
- DocumentUpdate::UP deserialized = DocumentUpdate::create42(f.docMan.getTypeRepo(), *buf);
+ nbostream is(buf->getBufferAtPos(), buf->getRemaining());
+ auto deserialized = DocumentUpdate::create42(f.docMan.getTypeRepo(), is);
CPPUNIT_ASSERT_EQUAL(*f.update, *deserialized);
CPPUNIT_ASSERT(deserialized->getCreateIfNonExistent());
}
@@ -1089,7 +1024,7 @@ ArrayUpdateFixture::ArrayUpdateFixture()
doc(doc_man.createDocument()),
array_field(doc->getType().getField("tags")) // of type array<string>
{
- update = std::make_unique<DocumentUpdate>(*doc->getDataType(), doc->getId());
+ update = std::make_unique<DocumentUpdate>(doc_man.getTypeRepo(), *doc->getDataType(), doc->getId());
update->addUpdate(FieldUpdate(array_field)
.addUpdate(MapValueUpdate(IntFieldValue(1),
AssignValueUpdate(StringFieldValue("bar")))));