~ubuntu-branches/ubuntu/trusty/syncevolution/trusty-proposed

« back to all changes in this revision

Viewing changes to src/client-test-app.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Tino Keitel
  • Date: 2011-07-20 16:02:02 UTC
  • mfrom: (3.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110720160202-e8uf7ogw4vh0q0f3
Tags: 1.1.99.5a-1
* New upstream version 1.1.99.5a, first release candiate for 1.2
* Added python-openssl dependency, the HTTP server needs it for HTTPS support
* Added versioned dependency on libsynthesis0 to get required features
* Fixed .orig.tar.gz generation in get-orig-source target
* Added myself to Uploaders:, thanks to David for sponsoring
* Use updated upstream tag for source package generation
* Removed 0001-Replace-with-in-call-to-PKG_CHECK_MODULES.patch, fixed upstream
* Renamed NEWS.Debian to NEWS so that it is actually used
* Updated NEWS for 1.1.99.5a

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#endif
37
37
 
38
38
#include "CmdlineSyncClient.h"
39
 
#include "EvolutionSyncSource.h"
 
39
#include <syncevo/SyncSource.h>
40
40
#include <syncevo/util.h>
41
41
#include <syncevo/VolatileConfigNode.h>
42
42
 
 
43
#include <boost/bind.hpp>
 
44
 
43
45
#include <syncevo/declarations.h>
 
46
 
 
47
#ifdef ENABLE_BUTEO_TESTS
 
48
#include "client-test-buteo.h"
 
49
#endif
 
50
 
44
51
SE_BEGIN_CXX
45
52
 
46
53
/*
109
116
 * not delivered, see e-cal.c), which then leads to D-Bus errors.
110
117
 *
111
118
 * The workaround consists of keeping one open SyncEvolution backend
112
 
 * around for each of ical20 and vcard21/30, if they ever were used
 
119
 * around for each of eds_event and eds_contact/30, if they ever were used
113
120
 * during testing.
114
121
 */
115
122
static map<string, boost::shared_ptr<TestingSyncSource> > lockEvolution;
163
170
        ClientTest(getenv("CLIENT_TEST_DELAY") ? atoi(getenv("CLIENT_TEST_DELAY")) : 0,
164
171
                   getenv("CLIENT_TEST_LOG") ? getenv("CLIENT_TEST_LOG") : ""),
165
172
        m_clientID(id),
166
 
        m_configs(EvolutionSyncSource::getTestRegistry())
 
173
        m_configs(SyncSource::getTestRegistry())
167
174
    {
168
175
        const char *server = getenv("CLIENT_TEST_SERVER");
169
176
 
255
262
                    boost::shared_ptr<SyncSourceConfig> scServerTemplate = from->getSyncSourceConfig(testconfig.sourceNameServerTemplate);
256
263
                    sc->setURI(scServerTemplate->getURI());
257
264
                }
258
 
                sc->setSourceType(testconfig.type);
259
265
            }
260
266
 
261
267
            // always set these properties: they might have changed since the last run
263
269
            sc->setDatabaseID(database);
264
270
            sc->setUser(m_evoUser);
265
271
            sc->setPassword(m_evoPassword);
 
272
            sc->setBackend(SourceType(testconfig.type).m_backend);
266
273
        }
267
274
        config->flush();
268
275
    }
319
326
        return false;
320
327
    }
321
328
 
 
329
#ifdef ENABLE_BUTEO_TESTS
 
330
    virtual void setup() {
 
331
        QtContactsSwitcher::prepare(*this);
 
332
    }
 
333
#endif
 
334
 
322
335
    virtual SyncMLStatus doSync(const int *sources,
323
336
                                const std::string &logbase,
324
337
                                const SyncOptions &options)
325
338
    {
 
339
        // check whether using buteo to do sync
 
340
        const char *buteo = getenv("CLIENT_TEST_BUTEO");
 
341
        bool useButeo = false;
 
342
        if (buteo && 
 
343
                (boost::equals(buteo, "1") || boost::iequals(buteo, "t"))) {
 
344
            useButeo = true;
 
345
        }
 
346
 
326
347
        string server = getenv("CLIENT_TEST_SERVER") ? getenv("CLIENT_TEST_SERVER") : "funambol";
327
348
        server += "_";
328
349
        server += m_clientID;
329
350
        
 
351
 
 
352
        if (useButeo) {
 
353
#ifdef ENABLE_BUTEO_TESTS
 
354
            ButeoTest buteo(*this, server, logbase, options);
 
355
            buteo.prepareSources(sources, m_syncSource2Config);
 
356
            SyncReport report;
 
357
            SyncMLStatus status = buteo.doSync(&report);
 
358
            options.m_checkReport.check(status, report);
 
359
            return status;
 
360
#else
 
361
            throw runtime_error("This client-test was built without enabling buteo testing.");
 
362
#endif
 
363
        }
330
364
        class ClientTest : public CmdlineSyncClient {
331
365
        public:
332
366
            ClientTest(const string &server,
347
381
                setWBXML(m_options.m_isWBXML, true);
348
382
                setRetryDuration(m_options.m_retryDuration, true);
349
383
                setRetryInterval(m_options.m_retryInterval, true);
 
384
                if (m_options.m_syncMode == SYNC_TWO_WAY &&
 
385
                    m_options.m_checkReport.syncMode == SYNC_NONE) {
 
386
                    // For this test, any kind of final sync mode is
 
387
                    // acceptable. Disable slow sync prevention
 
388
                    // temporarily. The check for the requested sync
 
389
                    // mode is perhaps too conservative, but in
 
390
                    // practice the only test where slow sync
 
391
                    // prevention caused a test failure was
 
392
                    // Client::Sync::eds_contact::testTwoWaySync after
 
393
                    // some other failed test, so let's be conservative...
 
394
                    setPreventSlowSync(false);
 
395
                }
350
396
                SyncContext::prepare();
 
397
                if (m_options.m_prepareCallback &&
 
398
                    m_options.m_prepareCallback(*this, m_options)) {
 
399
                    m_options.m_isAborted = true;
 
400
                }
351
401
            }
352
402
 
353
403
            virtual void displaySyncProgress(sysync::TProgressEventEnum type,
384
434
        // configure active sources with the desired sync mode,
385
435
        // disable the rest
386
436
        FilterConfigNode::ConfigFilter filter;
387
 
        filter[SyncSourceConfig::m_sourcePropSync.getName()] = "none";
 
437
        filter["sync"] = "none";
388
438
        client.setConfigFilter(false, "", filter);
389
 
        filter[SyncSourceConfig::m_sourcePropSync.getName()] =
 
439
        filter["sync"] =
390
440
            PrettyPrintSyncMode(options.m_syncMode);
391
441
        for(int i = 0; sources[i] >= 0; i++) {
392
442
            std::string &name = m_syncSource2Config[sources[i]];
419
469
    /** returns the name of the Evolution database */
420
470
    string getDatabaseName(const string &configName) {
421
471
        if (configName == "calendar+todo") {
422
 
            return "ical20,itodo20";
 
472
            return "eds_event,eds_task";
423
473
        } else if (configName == "file_calendar+todo") {
424
 
            return "file_ical20,file_itodo20";
 
474
            return "file_event,file_task";
425
475
        }
426
476
        return m_evoPrefix + configName + "_" + m_clientID;
427
477
    }
434
484
        // implement Evolution shutdown workaround (see lockEvolution above)
435
485
        evClient.checkEvolutionSource(name);
436
486
 
437
 
        return evClient.createSource(name, isSourceA);
 
487
        return evClient.createNamedSource(name, isSourceA);
438
488
    }
439
489
 
440
490
    /** called internally in this class */
441
 
    TestingSyncSource *createSource(const string &name, bool isSourceA) {
 
491
    TestingSyncSource *createNamedSource(const string &name, bool isSourceA) {
442
492
        string database = getDatabaseName(name);
443
 
        SyncConfig config("client-test-changes");
444
 
        SyncSourceNodes nodes = config.getSyncSourceNodes(name,
445
 
                                                          string("_") + m_clientID +
446
 
                                                          "_" + (isSourceA ? "A" : "B"));
 
493
        boost::shared_ptr<SyncConfig> context(new SyncConfig("target-config@client-test"));
 
494
        SyncSourceNodes nodes = context->getSyncSourceNodes(name,
 
495
                                                            string("_") + m_clientID +
 
496
                                                            "_" + (isSourceA ? "A" : "B"));
447
497
 
448
498
        // always set this property: the name might have changes since last test run
449
499
        nodes.getProperties()->setProperty("evolutionsource", database.c_str());
451
501
        nodes.getProperties()->setProperty("evolutionpassword", m_evoPassword.c_str());
452
502
 
453
503
        SyncSourceParams params(name,
454
 
                                nodes);
455
 
 
 
504
                                nodes,
 
505
                                context);
456
506
        const RegisterSyncSourceTest *test = m_configs[name];
457
507
        ClientTestConfig testConfig;
458
508
        getSourceConfig(test, testConfig);
459
509
 
460
510
        PersistentSyncSourceConfig sourceConfig(params.m_name, params.m_nodes);
461
 
        sourceConfig.setSourceType(testConfig.type);
 
511
        sourceConfig.setSourceType(SourceType(testConfig.type));
462
512
 
463
513
        // downcasting here: anyone who registers his sources for testing
464
514
        // must ensure that they are indeed TestingSyncSource instances
487
537
        // hard-coded names as used by src/backends/evolution;
488
538
        // if some other backend reuses them, it gets the
489
539
        // same treatment, which shouldn't cause any harm
490
 
        if (name == "vcard21" ||
491
 
            name == "vcard30") {
 
540
        if (name == "eds_contact") {
492
541
            basename = "ebook";
493
 
        } else if (name == "ical20" ||
 
542
        } else if (name == "eds_event" ||
494
543
                   name == "text") {
495
544
            basename = "ecal";
496
545
        }
497
546
 
498
547
        if (!basename.empty() &&
499
548
            lockEvolution.find(basename) == lockEvolution.end()) {
500
 
            lockEvolution[basename].reset(createSource(name, true));
 
549
            lockEvolution[basename].reset(createNamedSource(name, true));
501
550
            lockEvolution[basename]->open();
502
551
            ClientTest::registerCleanup(CleanupSources);
503
552
        }