ClientTest: infrastructure for removing and updating specific items

This commit is contained in:
Patrick Ohly 2008-12-28 19:11:38 +01:00
parent 69d5dc588b
commit c74a620257
2 changed files with 135 additions and 91 deletions

View file

@ -297,6 +297,27 @@ static std::string updateItem(CreateSource createSource, const std::string &uid,
return newuid;
}
/** updates specific item locally via sync source */
static void removeItem(CreateSource createSource, const std::string &luid)
{
CPPUNIT_ASSERT(createSource.createSource);
// create source
std::auto_ptr<SyncSource> source(createSource());
CPPUNIT_ASSERT(source.get() != 0);
SOURCE_ASSERT(source.get(), source->beginSync() == 0);
// remove item
SyncItem item;
WCHAR* wuid = toWideChar(luid.c_str());
item.setKey(wuid);
delete wuid;
SOURCE_ASSERT_EQUAL(source.get(), (int)STC_OK, source->deleteItem(item));
SOURCE_ASSERT(source.get(), source->endSync() == 0);
CPPUNIT_ASSERT_NO_THROW(source.reset());
}
void LocalTests::update(CreateSource createSource, const char *data, bool check) {
CPPUNIT_ASSERT(createSource.createSource);
CPPUNIT_ASSERT(data);
@ -436,39 +457,13 @@ void LocalTests::compareDatabases(const char *refFile, SyncSource &copy, bool ra
CPPUNIT_ASSERT(config.compare(client, sourceFile.c_str(), copyFile.c_str()));
}
/**
* insert artificial items, number of them determined by config.numItems
* unless passed explicitly
*
* @param createSource a factory for the sync source that is to be used
* @param startIndex IDs are generated starting with this value
* @param numItems number of items to be inserted if non-null, otherwise config.numItems is used
* @param size minimum size for new items
* @return LUIDs of all inserted items
*/
std::list<std::string> LocalTests::insertManyItems(CreateSource createSource, int startIndex, int numItems, int size) {
std::list<std::string> luids;
CPPUNIT_ASSERT(config.templateItem);
CPPUNIT_ASSERT(config.uniqueProperties);
std::auto_ptr<SyncSource> source;
SOURCE_ASSERT_NO_FAILURE(source.get(), source.reset(createSourceA()));
SOURCE_ASSERT_EQUAL(source.get(), 0, source->beginSync());
CPPUNIT_ASSERT(startIndex > 1 || !countItems(source.get()));
int firstIndex = startIndex;
if (firstIndex < 0) {
firstIndex = 1;
}
int lastIndex = firstIndex + (numItems >= 1 ? numItems : config.numItems) - 1;
for (int item = firstIndex; item <= lastIndex; item++) {
std::string LocalTests::createItem(int item, const std::string &revision, int size)
{
std::string data = config.templateItem;
std::stringstream prefix;
prefix << std::setfill('0') << std::setw(3) << item << " ";
const char *prop = config.uniqueProperties;
const char *nextProp;
while (*prop) {
@ -496,6 +491,7 @@ std::list<std::string> LocalTests::insertManyItems(CreateSource createSource, in
}
prop = nextProp + 1;
}
data.replace(data.find("<<REVISION>>"), strlen("<<REVISION>>"), revision);
if (size > 0 && (int)data.size() < size) {
int additionalBytes = size - (int)data.size();
int added = 0;
@ -548,8 +544,39 @@ std::list<std::string> LocalTests::insertManyItems(CreateSource createSource, in
data.replace(off, toreplace, stuffing.str());
}
return data;
}
/**
* insert artificial items, number of them determined by config.numItems
* unless passed explicitly
*
* @param createSource a factory for the sync source that is to be used
* @param startIndex IDs are generated starting with this value
* @param numItems number of items to be inserted if non-null, otherwise config.numItems is used
* @param size minimum size for new items
* @return LUIDs of all inserted items
*/
std::list<std::string> LocalTests::insertManyItems(CreateSource createSource, int startIndex, int numItems, int size) {
std::list<std::string> luids;
CPPUNIT_ASSERT(config.templateItem);
CPPUNIT_ASSERT(config.uniqueProperties);
std::auto_ptr<SyncSource> source;
SOURCE_ASSERT_NO_FAILURE(source.get(), source.reset(createSourceA()));
SOURCE_ASSERT_EQUAL(source.get(), 0, source->beginSync());
CPPUNIT_ASSERT(startIndex > 1 || !countItems(source.get()));
int firstIndex = startIndex;
if (firstIndex < 0) {
firstIndex = 1;
}
int lastIndex = firstIndex + (numItems >= 1 ? numItems : config.numItems) - 1;
for (int item = firstIndex; item <= lastIndex; item++) {
std::string data = createItem(item, "", size);
luids.push_back(importItem(source.get(), data));
data = "";
}
SOURCE_ASSERT_EQUAL(source.get(), 0, source->endSync());
@ -2953,7 +2980,7 @@ void ClientTest::getTestData(const char *type, Config &config)
"TEL;TYPE=WORK;TYPE=VOICE:business 1\n"
"X-EVOLUTION-FILE-AS:Doe\\, John\n"
"X-MOZILLA-HTML:FALSE\n"
"NOTE:\n"
"NOTE:<<REVISION>>\n"
"END:VCARD\n";
config.updateItem =
"BEGIN:VCARD\n"
@ -3021,7 +3048,7 @@ void ClientTest::getTestData(const char *type, Config &config)
"N:Doe;John;;;\n"
"TEL;TYPE=WORK;TYPE=VOICE:business 1\n"
"X-MOZILLA-HTML:FALSE\n"
"NOTE:\n"
"NOTE:<<REVISION>>\n"
"END:VCARD\n";
config.updateItem =
"BEGIN:VCARD\n"
@ -3091,7 +3118,7 @@ void ClientTest::getTestData(const char *type, Config &config)
"LAST-MODIFIED:20060409T213201\n"
"CREATED:20060409T213201\n"
"LOCATION:my office\n"
"DESCRIPTION:let's talk\n"
"DESCRIPTION:let's talk<<REVISION>>\n"
"CLASS:PUBLIC\n"
"TRANSP:OPAQUE\n"
"SEQUENCE:1\n"
@ -3218,7 +3245,7 @@ void ClientTest::getTestData(const char *type, Config &config)
"DTSTART:20060406T160000Z\n"
"DTSTAMP:20060406T211449Z\n"
"LOCATION:my office\n"
"DESCRIPTION:let's talk\n"
"DESCRIPTION:let's talk<<REVISION>>\n"
"END:VEVENT\n"
"END:VCALENDAR\n";
config.updateItem =
@ -3278,7 +3305,7 @@ void ClientTest::getTestData(const char *type, Config &config)
"UID:20060417T173712Z-4360-727-1-2730@gollum\n"
"DTSTAMP:20060417T173712Z\n"
"SUMMARY:do me\n"
"DESCRIPTION:to be done\n"
"DESCRIPTION:to be done<<REVISION>>\n"
"PRIORITY:0\n"
"STATUS:IN-PROCESS\n"
"CREATED:20060417T173712\n"

View file

@ -280,6 +280,8 @@ class ClientTest {
* properties.
*
* This is the template for these automatically generated items.
* It must contain the string <<REVISION>> which will be replaced
* with the revision parameter of the createItem() method.
*/
const char *templateItem;
@ -620,6 +622,21 @@ public:
*/
virtual std::list<std::string> insertManyItems(CreateSource createSource, int startIndex = 1, int numItems = 0, int size = -1);
/**
* create an artificial item for the current database
*
* @param item item number: items with different number should be
* recognized as different by SyncML servers
* @param revision differentiates items with the same item number (= updates of an older item)
* @param size if > 0, then create items at least that large (in bytes)
* @return created item
*/
std::string createItem(int item, const std::string &revision, int size);
std::string createItem(int item, int revision, int size) {
char buffer[32];
sprintf(buffer, "%d", revision);
return createItem(item, std::string(buffer), size);
}
/* for more information on the different tests see their implementation */