ClientTest: better infrastructure for data file comparisons

File names now only contain a single underscore instead of
multiple ones. The compare functions can be called so that they
return the result instead of throwing an assertion (useful for
doing multiple comparisons and then checking the result).
The synccompare Perl script is told to print the file names
that it is comparing.
This commit is contained in:
Patrick Ohly 2008-12-28 21:26:58 +01:00
parent c5900a63a1
commit 1170ba8b38
3 changed files with 46 additions and 10 deletions

View File

@ -430,7 +430,7 @@ static void deleteItem(CreateSource createSource, const std::string &uid) {
* @param copy a sync source which contains the copied items, begin/endSync will be called
* @param raiseAssert raise assertion if comparison yields differences (defaults to true)
*/
void LocalTests::compareDatabases(const char *refFile, SyncSource &copy, bool raiseAssert) {
bool LocalTests::compareDatabases(const char *refFile, SyncSource &copy, bool raiseAssert) {
CPPUNIT_ASSERT(config.dump);
std::string sourceFile, copyFile;
@ -438,7 +438,7 @@ void LocalTests::compareDatabases(const char *refFile, SyncSource &copy, bool ra
if (refFile) {
sourceFile = refFile;
} else {
sourceFile = getCurrentTest() + ".source.test.dat";
sourceFile = getCurrentTest() + ".A.test.dat";
simplifyFilename(sourceFile);
std::auto_ptr<SyncSource> source;
SOURCE_ASSERT_NO_FAILURE(source.get(), source.reset(createSourceA()));
@ -448,13 +448,16 @@ void LocalTests::compareDatabases(const char *refFile, SyncSource &copy, bool ra
CPPUNIT_ASSERT_NO_THROW(source.reset());
}
copyFile = getCurrentTest() + ".copy.test.dat";
copyFile = getCurrentTest() + ".B.test.dat";
simplifyFilename(copyFile);
SOURCE_ASSERT_EQUAL(&copy, 0, copy.beginSync());
SOURCE_ASSERT_EQUAL(&copy, 0, config.dump(client, copy, copyFile.c_str()));
SOURCE_ASSERT_EQUAL(&copy, 0, copy.endSync());
CPPUNIT_ASSERT(config.compare(client, sourceFile.c_str(), copyFile.c_str()));
bool equal = config.compare(client, sourceFile.c_str(), copyFile.c_str());
CPPUNIT_ASSERT(!raiseAssert || equal);
return equal;
}
std::string LocalTests::createItem(int item, const std::string &revision, int size)
@ -1668,10 +1671,10 @@ void SyncTests::addTests() {
}
}
/** compare databases of first and second client */
void SyncTests::compareDatabases() {
bool SyncTests::compareDatabases(const char *refFileBase, bool raiseAssert) {
source_it it1;
source_it it2;
bool equal = true;
CPPUNIT_ASSERT(accessClientB);
for (it1 = sources.begin(), it2 = accessClientB->sources.begin();
@ -1679,11 +1682,26 @@ void SyncTests::compareDatabases() {
++it1, ++it2) {
std::auto_ptr<SyncSource> copy;
SOURCE_ASSERT_NO_FAILURE(copy.get(), copy.reset(it2->second->createSourceB()));
it1->second->compareDatabases(NULL, *copy.get());
if (refFileBase) {
std::string refFile = refFileBase;
refFile += it1->second->config.sourceName;
refFile += ".dat";
simplifyFilename(refFile);
if (!it1->second->compareDatabases(refFile.c_str(), *copy.get(), raiseAssert)) {
equal = false;
}
} else {
if (!it1->second->compareDatabases(NULL, *copy.get(), raiseAssert)) {
equal = false;
}
}
CPPUNIT_ASSERT_NO_THROW(copy.reset());
}
CPPUNIT_ASSERT(it1 == sources.end());
CPPUNIT_ASSERT(it2 == accessClientB->sources.end());
CPPUNIT_ASSERT(!raiseAssert || equal);
return equal;
}
/** deletes all items locally and on server */
@ -2941,6 +2959,10 @@ int ClientTest::import(ClientTest &client, SyncSource &source, const char *file)
bool ClientTest::compare(ClientTest &client, const char *fileA, const char *fileB)
{
std::string cmdstr = std::string("perl synccompare.pl ") + fileA + " " + fileB;
setenv("CLIENT_TEST_LEFT_NAME", fileA, 1);
setenv("CLIENT_TEST_RIGHT_NAME", fileB, 1);
setenv("CLIENT_TEST_REMOVED", "only in left file", 1);
setenv("CLIENT_TEST_ADDED", "only in right file", 1);
return system(cmdstr.c_str()) == 0;
}

View File

@ -607,8 +607,9 @@ public:
* @param refFile existing file with source reference items, NULL uses a dump of sync source A instead
* @param copy a sync source which contains the copied items, begin/endSync will be called
* @param raiseAssert raise assertion if comparison yields differences (defaults to true)
* @return true if the two databases are equal
*/
virtual void compareDatabases(const char *refFile, SyncSource &copy, bool raiseAssert = true);
virtual bool compareDatabases(const char *refFile, SyncSource &copy, bool raiseAssert = true);
/**
* insert artificial items, number of them determined by TEST_EVOLUTION_NUM_ITEMS
@ -742,8 +743,13 @@ protected:
DELETE_ALL_REFRESH /**< delete locally, refresh server */
};
/** compare databases of first and second client */
virtual void compareDatabases();
/**
* Compare databases second client with either reference file(s)
* or first client. The reference file(s) must follow the naming
* scheme <reFileBase><source name>.dat
*/
virtual bool compareDatabases(const char *refFileBase = NULL,
bool raiseAssert = true);
/** deletes all items locally and on server */
virtual void deleteAll(DeleteAllMode mode = DELETE_ALL_SYNC);

View File

@ -73,6 +73,14 @@ void simplifyFilename(string &filename)
}
filename.replace(pos, 1, "_");
}
pos = 0;
while (true) {
pos = filename.find("__", pos);
if (pos == filename.npos) {
break;
}
filename.erase(pos, 1);
}
}
class ClientOutputter : public CppUnit::CompilerOutputter {