summaryrefslogtreecommitdiffstats
path: root/document/src/tests/fieldpathupdatetestcase.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'document/src/tests/fieldpathupdatetestcase.cpp')
-rw-r--r--document/src/tests/fieldpathupdatetestcase.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/document/src/tests/fieldpathupdatetestcase.cpp b/document/src/tests/fieldpathupdatetestcase.cpp
index 80a63a86b92..f5db5831912 100644
--- a/document/src/tests/fieldpathupdatetestcase.cpp
+++ b/document/src/tests/fieldpathupdatetestcase.cpp
@@ -33,6 +33,7 @@ struct FieldPathUpdateTestCase : public CppUnit::TestFixture {
void tearDown() override;
void testWhereClause();
+ void testBrokenWhereClause();
void testNoIterateMapValues();
void testRemoveField();
void testApplyRemoveEntireListField();
@@ -69,9 +70,11 @@ struct FieldPathUpdateTestCase : public CppUnit::TestFixture {
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);
@@ -108,6 +111,7 @@ struct FieldPathUpdateTestCase : public CppUnit::TestFixture {
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
@@ -354,6 +358,17 @@ FieldPathUpdateTestCase::testWhereClause()
}
void
+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);
+}
+
+void
FieldPathUpdateTestCase::testNoIterateMapValues()
{
DocumentTypeRepo repo(getRepoConfig());
@@ -1183,4 +1198,23 @@ FieldPathUpdateTestCase::testGenerateSerializedFile()
close(fd);
}
+void 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");
+
+ ArrayFieldValue str_array(field.getDataType());
+ str_array.add(StringFieldValue("jerry"));
+ doc->setValue("strarray", str_array);
+
+ DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("id::foobar::1"));
+ docUp.addFieldPathUpdate(FieldPathUpdate::CP(
+ new AssignFieldPathUpdate(*doc->getDataType(), "strarray[1]", "", StringFieldValue("george"))));
+ docUp.applyTo(*doc);
+
+ // Doc is unmodified.
+ auto new_arr = doc->getAs<ArrayFieldValue>(field);
+ CPPUNIT_ASSERT_EQUAL(str_array, *new_arr);
+}
+
}