diff options
author | Patrick Ohly <patrick.ohly@intel.com> | 2012-07-02 14:58:10 +0200 |
---|---|---|
committer | Patrick Ohly <patrick.ohly@intel.com> | 2012-07-02 14:58:10 +0200 |
commit | dfbd3dc45cf5c021041b31d53ea5bb2d3d007e45 (patch) | |
tree | 6cf630f8b2f63917a2ea5f8b099dc04538834b19 /test/ClientTest.cpp | |
parent | 2add74a5ea79d69e0b8909c4a7636efb5e07aa9b (diff) |
testing: check result of "item already exists" during insert
The new testInsertTwice checks what the backend does when the same
item already exists in the database. This is only done for test data
which has a UID (i.e. for calendar data, but not for contacts). This
test exercises the code which previously failed with 412 "Precondition
Failed" in the CalDAVMemo backend.
Diffstat (limited to 'test/ClientTest.cpp')
-rw-r--r-- | test/ClientTest.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/ClientTest.cpp b/test/ClientTest.cpp index b3f37282..1c28ce58 100644 --- a/test/ClientTest.cpp +++ b/test/ClientTest.cpp @@ -1095,6 +1095,42 @@ void LocalTests::testComplexInsert() { CT_ASSERT_NO_THROW(testIterateTwice()); } +// insert the same item (identified by UID) twice => either +// ITEM_NEEDS_MERGE, ITEM_REPLACED or ITEM_MERGED are acceptable +void LocalTests::testInsertTwice() { + CT_ASSERT(config.m_createSourceA); + CT_ASSERT(!config.m_insertItem.empty()); + CT_ASSERT(config.m_insertItem.find("\nUID:") != std::string::npos); + CT_ASSERT_NO_THROW(deleteAll(createSourceA)); + + // create source + TestingSyncSourcePtr source; + SOURCE_ASSERT_NO_FAILURE(source.get(), source.reset(createSourceA())); + + // mangle data once + std::string data = config.m_mangleItem(config.m_insertItem, false); + + // insert new item + SyncSourceRaw::InsertItemResult first; + SOURCE_ASSERT_NO_FAILURE(source.get(), first = source->insertItemRaw("", data)); + CT_ASSERT_EQUAL(ITEM_OKAY, first.m_state); + + // and again + SyncSourceRaw::InsertItemResult second; + SOURCE_ASSERT_NO_FAILURE(source.get(), second = source->insertItemRaw("", data)); + CLIENT_TEST_LOG("item %s", + second.m_state == ITEM_NEEDS_MERGE ? "needs to be merged" : + second.m_state == ITEM_REPLACED ? "was replaced" : + second.m_state == ITEM_MERGED ? "was merged" : + second.m_state == ITEM_OKAY ? "was added, which is broken!" : + "unknown result ?!"); + CT_ASSERT(second.m_state == ITEM_NEEDS_MERGE || second.m_state == ITEM_REPLACED || second.m_state == ITEM_MERGED); + CT_ASSERT_EQUAL(first.m_luid, second.m_luid); + if (second.m_state == ITEM_REPLACED || second.m_state == ITEM_MERGED) { + CT_ASSERT(first.m_revision != second.m_revision); + } +} + // clean database, insert item, update it void LocalTests::testLocalUpdate() { // check additional requirements |