sync tests now work on Linux: - implemented sync() method using FILESyncSource - clarified naming of clients and different change tracking
git-svn-id: https://core.forge.funambol.org/svn/core/top-level/trunk/3x/client-api/native@12301 e8e8ed6c-164c-0410-afcf-9e9a7c7d8c10
This commit is contained in:
parent
af7e085f25
commit
f89bdcb76f
|
@ -1595,7 +1595,7 @@ private:
|
|||
long maxMsgSize = 0,
|
||||
long maxObjSize = 0,
|
||||
bool loSupport = false,
|
||||
const char *encoding = 0) {
|
||||
const char *encoding = "") {
|
||||
int res = 0;
|
||||
static int syncCounter = 0;
|
||||
static std::string lastTest;
|
||||
|
|
|
@ -36,9 +36,11 @@
|
|||
* servers. Although the framework always always tests against the
|
||||
* same server, for most tests it is necessary to access the database
|
||||
* without affecting the next synchronization with the server. This is
|
||||
* done by asking the client for another sync source which it must
|
||||
* create in a suitable way - pretty much as if the client was
|
||||
* synchronized against different server.
|
||||
* done by asking the client for two different sync sources via
|
||||
* Config::createSourceA and Config::createSourceB which have to
|
||||
* create them in a suitable way - pretty much as if the client was
|
||||
* synchronized against different server. A third, different change
|
||||
* tracking is needed for real synchronizations of the data.
|
||||
*
|
||||
* Furthermore the client is expected to support multiple data sources
|
||||
* of the same kind, f.i. two different address books. This is used to
|
||||
|
@ -324,8 +326,8 @@ class ClientTest {
|
|||
* @param syncMode the synchronization mode to be used
|
||||
* @param maxMsgSize >0: enable the maximum message size, else disable it
|
||||
* @param maxObjSize same as maxMsgSize for maximum object size
|
||||
* @param encoding if non-NULL, then let client library transform all items
|
||||
* into this format
|
||||
* @param encoding if non-empty, then let client library transform all items
|
||||
* into this format (guaranteed to be not NULL)
|
||||
*
|
||||
* @return - 0 on success, an error otherwise (may also throw an exception)
|
||||
*/
|
||||
|
@ -335,7 +337,7 @@ class ClientTest {
|
|||
long maxMsgSize = 0,
|
||||
long maxObjSize = 0,
|
||||
bool loSupport = false,
|
||||
const char *encoding = 0) = 0;
|
||||
const char *encoding = "") = 0;
|
||||
|
||||
/**
|
||||
* This is called after successful sync() calls (res == 0) as well
|
||||
|
|
|
@ -84,7 +84,9 @@
|
|||
|
||||
#include "spdm/DeviceManagementNode.h"
|
||||
#include "spds/RawFILESyncSource.h"
|
||||
#include "spds/spdsutils.h"
|
||||
#include "client/DMTClientConfig.h"
|
||||
#include "client/SyncClient.h"
|
||||
#include "test/ClientTest.h"
|
||||
|
||||
#include <string>
|
||||
|
@ -126,17 +128,20 @@ public:
|
|||
}
|
||||
|
||||
// get configuration and set obligatory fields
|
||||
LOG.setLevel(LOG_LEVEL_DEBUG);
|
||||
std::string root = std::string("client-test/") + server + "_" + id;
|
||||
config.reset(new DMTClientConfig(root.c_str()));
|
||||
config->read();
|
||||
DeviceConfig &dc(config->getDeviceConfig());
|
||||
if (!strlen(dc.getDevID())) {
|
||||
// no configuration yet
|
||||
config->setClientDefaults();
|
||||
dc.setDevID(id == "1" ? "sc-api-nat" : "sc-pim-ppc");
|
||||
dc.setDevID(id == "A" ? "sc-api-nat" : "sc-pim-ppc");
|
||||
}
|
||||
for (int source = 0; source < sources.size(); source++) {
|
||||
SyncSourceConfig* sc = config->getSyncSourceConfig(sources[source].c_str());
|
||||
if (!sc) {
|
||||
// no configuration yet
|
||||
config->setSourceDefaults(sources[source].c_str());
|
||||
sc = config->getSyncSourceConfig(sources[source].c_str());
|
||||
CPPUNIT_ASSERT(sc);
|
||||
|
@ -150,9 +155,9 @@ public:
|
|||
config->save();
|
||||
config->open();
|
||||
|
||||
if (id == "1") {
|
||||
if (id == "A") {
|
||||
/* we are the primary client, create a second one */
|
||||
clientB.reset(new TestFileSource("2"));
|
||||
clientB.reset(new TestFileSource("B"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -176,15 +181,46 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
virtual int sync(const int*, SyncMode, long int, long int, bool, const char*) {
|
||||
return 1;
|
||||
virtual int sync(
|
||||
const int *activeSources,
|
||||
SyncMode syncMode,
|
||||
long maxMsgSize,
|
||||
long maxObjSize,
|
||||
bool loSupport,
|
||||
const char *encoding = 0) {
|
||||
SyncSource **syncSources = new SyncSource *[sources.size() + 1];
|
||||
int source;
|
||||
memset(syncSources, 0, sizeof(syncSources[0]) * (sources.size() + 1));
|
||||
|
||||
for (source = 0; activeSources[source] >= 0 && source < sources.size(); source++) {
|
||||
// rewrite configuration as needed for test
|
||||
SyncSourceConfig *sourceConfig = config->getSyncSourceConfig(sources[source].c_str());
|
||||
CPPUNIT_ASSERT(sourceConfig);
|
||||
sourceConfig->setSync(syncModeKeyword(syncMode));
|
||||
sourceConfig->setEncoding(encoding);
|
||||
config->getAccessConfig().setMaxMsgSize(maxMsgSize);
|
||||
config->getDeviceConfig().setMaxObjSize(maxObjSize);
|
||||
config->getDeviceConfig().setLoSupport(loSupport);
|
||||
|
||||
// create sync source using the third change tracking for syncs
|
||||
syncSources[source] = createSource(source, "S");
|
||||
}
|
||||
|
||||
SyncClient client;
|
||||
int res = client.sync(*config, syncSources);
|
||||
|
||||
for (source = 0; syncSources[source]; source++) {
|
||||
delete syncSources[source];
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
private:
|
||||
/** either "1" or "2" for first respectively second client */
|
||||
/** either "A" or "B" for first respectively second client */
|
||||
std::string clientID;
|
||||
|
||||
/** only in "1": pointer to second client */
|
||||
/** only in "A": pointer to second client */
|
||||
std::auto_ptr<TestFileSource> clientB;
|
||||
|
||||
/** vector of enabled sync sources, identified by a name which SyncClient::getConfig() supports */
|
||||
|
@ -194,6 +230,11 @@ private:
|
|||
std::auto_ptr<DMTClientConfig> config;
|
||||
|
||||
static SyncSource *createSource(ClientTest &client, int source, bool isSourceA) {
|
||||
// hand work over to real member function
|
||||
((TestFileSource &)client).createSource(source, isSourceA ? "A" : "B");
|
||||
}
|
||||
|
||||
SyncSource *createSource(int source, const char *trackingSuffix) {
|
||||
class RawFILESyncSourceWithReport : public RawFILESyncSource {
|
||||
public:
|
||||
RawFILESyncSourceWithReport(const char* nodeName, const char* name, SyncSourceConfig* sc) :
|
||||
|
@ -207,25 +248,24 @@ private:
|
|||
*/
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
private:
|
||||
SyncSourceReport report;
|
||||
DeviceManagementNode fileNode;
|
||||
};
|
||||
|
||||
TestFileSource &testFileSource((TestFileSource &)client);
|
||||
CPPUNIT_ASSERT(source < testFileSource.sources.size());
|
||||
ManagementNode *sourceNode = testFileSource.config->getSyncSourceNode(testFileSource.sources[source].c_str());
|
||||
CPPUNIT_ASSERT(source < sources.size());
|
||||
ManagementNode *sourceNode = config->getSyncSourceNode(sources[source].c_str());
|
||||
CPPUNIT_ASSERT(sourceNode);
|
||||
char *fullName = sourceNode->createFullName();
|
||||
std::string nodeName = std::string(fullName) + "/changes_" + (isSourceA ? "A" : "B");
|
||||
std::string nodeName = std::string(fullName) + "/changes_" + trackingSuffix;
|
||||
std::string dirName = sources[source] + "_" + clientID;
|
||||
delete [] fullName;
|
||||
FILESyncSource *ss = new RawFILESyncSourceWithReport(
|
||||
nodeName.c_str(),
|
||||
testFileSource.sources[source].c_str(),
|
||||
testFileSource.config->getSyncSourceConfig(testFileSource.sources[source].c_str()));
|
||||
mkdir(testFileSource.sources[source].c_str(), S_IRWXU);
|
||||
ss->setDir(testFileSource.sources[source].c_str());
|
||||
sources[source].c_str(),
|
||||
config->getSyncSourceConfig(sources[source].c_str()));
|
||||
mkdir(dirName.c_str(), S_IRWXU);
|
||||
ss->setDir(dirName.c_str());
|
||||
|
||||
return ss;
|
||||
}
|
||||
|
@ -239,7 +279,7 @@ private:
|
|||
static class RegisterTest {
|
||||
public:
|
||||
RegisterTest() :
|
||||
testFileSource("1") {
|
||||
testFileSource("A") {
|
||||
testFileSource.registerTests();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue