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

« back to all changes in this revision

Viewing changes to src/client-test-buteo.h

  • 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:
 
1
/*
 
2
 * Copyright (C) 2010 Intel Corporation
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Lesser General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2.1 of the License, or (at your option) version 3.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Lesser General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Lesser General Public
 
15
 * License along with this library; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
17
 * 02110-1301  USA
 
18
 */
 
19
#ifndef INCL_SYNC_BUTEOTEST
 
20
#define INCL_SYNC_BUTEOTEST
 
21
 
 
22
#include <syncevo/util.h>
 
23
#include <syncevo/declarations.h>
 
24
#include <QString>
 
25
#include <QObject>
 
26
#include <QtDBus>
 
27
#include <QDomDocument>
 
28
#include "ClientTest.h"
 
29
 
 
30
using namespace SyncEvo;
 
31
 
 
32
/**
 
33
 * ButeoTest is used to invoke buteo to do client test with the help
 
34
 * of client test framework. The basic idea is to implement doSync and
 
35
 * replace with invocation of buteo's dbus server - 'msyncd'.
 
36
 * The main steps are:
 
37
 * 1) pre-run: This may include set up sync options for local client
 
38
 * and target server, prepare local databases
 
39
 * 2) run: run sync by sending dbus calls to 'msyncd' and wait until
 
40
 * it finishes
 
41
 * 3) post-run: collect sync result and statistics
 
42
 */
 
43
class ButeoTest : public QObject {
 
44
    Q_OBJECT
 
45
public:
 
46
    ButeoTest(ClientTest &client,
 
47
              const string &server,
 
48
              const string &logbase,
 
49
              const SyncEvo::SyncOptions &options); 
 
50
 
 
51
    // prepare sync sources
 
52
    void prepareSources(const int *sources, const vector<string> &source2Config);
 
53
 
 
54
    // do actually sync
 
55
    SyncEvo::SyncMLStatus doSync(SyncEvo::SyncReport *report); 
 
56
 
 
57
private slots:
 
58
    void syncStatus(QString, int, QString, int);
 
59
    void resultsAvailable(QString, QString);
 
60
    void serviceUnregistered(QString);
 
61
 
 
62
private:
 
63
 
 
64
    /** initialize
 
65
     */
 
66
    static void init();
 
67
 
 
68
    /**
 
69
     * 1. set deviceid, max-message-size options to /etc/sync/meego-sync-conf.xml
 
70
     * 2. set wbxml option, sync mode, enabled selected sources and disable other sources 
 
71
     */
 
72
    void setupOptions();
 
73
 
 
74
    // kill all msyncd  
 
75
    void killAllMsyncd();
 
76
 
 
77
    // start msyncd  
 
78
    int startMsyncd();
 
79
 
 
80
    // do actually running 
 
81
    bool run();
 
82
 
 
83
    // get sync results from buteo and set them to sync report
 
84
    void genSyncResults(const QString &text, SyncEvo::SyncReport *report);
 
85
 
 
86
    // whether configured sources include contacts
 
87
    bool inclContacts();
 
88
 
 
89
    // truncate file and write content to file
 
90
    static void writeToFile(const QString &filePath, const QString &content );
 
91
 
 
92
    //replace the element value with a new value
 
93
    static void replaceElement(QString &xml, const QString &elem, const QString &value);
 
94
 
 
95
    // build a dom tree from file
 
96
    static void buildDomFromFile(QDomDocument &doc, const QString &filePath);
 
97
 
 
98
    ClientTest &m_client;
 
99
    string m_server;
 
100
    string m_logbase;
 
101
    SyncEvo::SyncOptions m_options;
 
102
    std::set<string> m_configedSources;
 
103
    QString m_syncResults;
 
104
 
 
105
    //device ids
 
106
    static QString m_deviceIds[2];
 
107
    //mappings for syncevolution source and buteo storage
 
108
    static map<string, string> m_source2storage;
 
109
    //flag for initialization
 
110
    static bool m_inited;
 
111
};
 
112
 
 
113
 
 
114
/**
 
115
 * Qtcontacts use tracker to store data. However, it can't specify
 
116
 * the place where to store them. Since we have to separate client A
 
117
 * and B's data, restore and backup their databases
 
118
 */
 
119
class QtContactsSwitcher {
 
120
public:
 
121
    /** do preparation */
 
122
    static void prepare(ClientTest &client);
 
123
 
 
124
    static string getId(ClientTest &client);
 
125
 
 
126
    /**
 
127
     * prepare storage:
 
128
     * 1. terminate tracker
 
129
     * 2. copy tracker databases from backup to its default place
 
130
     * according to id
 
131
     * 3. restart tracker 
 
132
     */
 
133
    static void restoreStorage(ClientTest &client);
 
134
 
 
135
    /**
 
136
     * backup storage:
 
137
     * 1. terminate tracker
 
138
     * 2. copy tracker databases from default place to backup
 
139
     * 3. restart tracker
 
140
     */
 
141
    static void backupStorage(ClientTest &client);
 
142
    
 
143
    static void setDatabases(const string databases[]);
 
144
private:
 
145
    // get the file path of databases
 
146
    static std::string getDatabasePath(int index = 0);
 
147
 
 
148
    //terminate tracker daemons
 
149
    static void terminate();
 
150
 
 
151
    //start tracker daemons
 
152
    static void start();
 
153
 
 
154
    //copy databases between default place and backup place
 
155
    static void copyDatabases(ClientTest &client, bool fromDefault = true);
 
156
 
 
157
    //databases used by tracker
 
158
    static std::string m_databases[5];
 
159
    static std::string m_dirs[2];
 
160
};
 
161
#endif