testing: enhanced infrastructure (LUIDs)

Changed the utility functions so that they pass around and use
LUIDs. This allows building more complex tests which need to
modify specific items.
This commit is contained in:
Patrick Ohly 2008-12-21 21:53:18 +01:00
parent 807c835ccf
commit 6869110b3d
2 changed files with 42 additions and 15 deletions

View File

@ -147,7 +147,8 @@ static int countItems( SyncSource *source ) { return listItems(source).size(); }
int countItemsOfType(SyncSource *source, itemType type) { return listItemsOfType(source, type).size(); }
static void importItem(SyncSource *source, std::string &data)
/** insert new item, return LUID */
static std::string importItem(SyncSource *source, std::string &data)
{
CPPUNIT_ASSERT(source);
if (data.size()) {
@ -159,6 +160,9 @@ static void importItem(SyncSource *source, std::string &data)
CPPUNIT_ASSERT(status == STC_OK || status == STC_ITEM_ADDED);
CPPUNIT_ASSERT(item.getKey() != 0);
CPPUNIT_ASSERT(wcslen(item.getKey()) > 0);
return item.getKey();
} else {
return "";
}
}
@ -293,12 +297,6 @@ static std::string updateItem(CreateSource createSource, const std::string &uid,
return newuid;
}
/**
* assumes that exactly one element is currently inserted and updates it with the given item
*
* The type of the item is cleared, as in insert() above.
*/
void LocalTests::update(CreateSource createSource, const char *data, bool check) {
CPPUNIT_ASSERT(createSource.createSource);
CPPUNIT_ASSERT(data);
@ -337,6 +335,26 @@ void LocalTests::update(CreateSource createSource, const char *data, bool check)
CPPUNIT_ASSERT( !wcscmp( item->getKey(), modifiedItem->getKey() ) );
}
void LocalTests::update(CreateSource createSource, const char *data, const std::string &luid) {
CPPUNIT_ASSERT(createSource.createSource);
CPPUNIT_ASSERT(data);
// create source
std::auto_ptr<SyncSource> source(createSource());
CPPUNIT_ASSERT(source.get() != 0);
SOURCE_ASSERT(source.get(), source->beginSync() == 0);
// get existing item, then update it
SOURCE_ASSERT(source.get(), source->beginSync() == 0 );
SyncItem item;
item.setData(data, (long)strlen(data) + 1);
item.setDataType(TEXT(""));
item.setKey(luid.c_str());
SOURCE_ASSERT_EQUAL(source.get(), (int)STC_OK, source->updateItem(item));
SOURCE_ASSERT(source.get(), source->endSync() == 0);
CPPUNIT_ASSERT_NO_THROW(source.reset());
}
/** deletes all items locally via sync source */
void LocalTests::deleteAll(CreateSource createSource) {
CPPUNIT_ASSERT(createSource.createSource);
@ -426,9 +444,11 @@ void LocalTests::compareDatabases(const char *refFile, SyncSource &copy, bool ra
* @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 number of items inserted
* @return LUIDs of all inserted items
*/
int LocalTests::insertManyItems(CreateSource createSource, int startIndex, int numItems, int size) {
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);
@ -528,13 +548,13 @@ int LocalTests::insertManyItems(CreateSource createSource, int startIndex, int n
data.replace(off, toreplace, stuffing.str());
}
importItem(source.get(), data);
luids.push_back(importItem(source.get(), data));
data = "";
}
SOURCE_ASSERT_EQUAL(source.get(), 0, source->endSync());
CPPUNIT_ASSERT_NO_THROW(source.reset());
return lastIndex - firstIndex + 1;
return luids;
}
// creating sync source
@ -769,7 +789,7 @@ void LocalTests::testManyChanges() {
CPPUNIT_ASSERT_NO_THROW(copy.reset());
// now insert plenty of items
int numItems = insertManyItems(createSourceA);
int numItems = insertManyItems(createSourceA).size();
// check that exactly this number of items is listed as new
SOURCE_ASSERT_NO_FAILURE(copy.get(), copy.reset(createSourceB()));

View File

@ -565,19 +565,26 @@ public:
* can handle that.
*
* @param relaxed if true, then disable some of the additional checks after adding the item
* @return the UID of the inserted item
* @return the LUID of the inserted item
*/
virtual std::string insert(CreateSource createSource, const char *data, bool relaxed = false);
/**
* assumes that exactly one element is currently inserted and updates it with the given item
*
* The type of the item is cleared, as in insert() above.
* The type of the item is unset, as in insert() above.
*
* @param check if true, then reopen the source and verify that the reported items are as expected
*/
virtual void update(CreateSource createSource, const char *data, bool check = true);
/**
* updates one item identified by its LUID with the given item
*
* The type of the item is cleared, as in insert() above.
*/
virtual void update(CreateSource createSource, const char *data, const std::string &luid);
/** deletes all items locally via sync source */
virtual void deleteAll(CreateSource createSource);
@ -601,7 +608,7 @@ public:
* @param size minimum size for new items
* @return number of items inserted
*/
virtual int insertManyItems(CreateSource createSource, int startIndex = 1, int numItems = 0, int size = -1);
virtual std::list<std::string> insertManyItems(CreateSource createSource, int startIndex = 1, int numItems = 0, int size = -1);
/* for more information on the different tests see their implementation */