test/ClientTest.h

00001 /*
00002  * Copyright (C) 2005-2006 Funambol
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  */
00018 
00019 #ifndef INCL_TESTSYNCCLIENT
00020 #define INCL_TESTSYNCCLIENT
00021 
00025 #include <string>
00026 #include "spds/SyncSource.h"
00027 #include "spds/SyncReport.h"
00028 
00029 #ifdef ENABLE_INTEGRATION_TESTS
00030 
00040 class CheckSyncReport {
00041   public:
00042     CheckSyncReport(int clAdded = -1, int clUpdated = -1, int clDeleted = -1,
00043                     int srAdded = -1, int srUpdated = -1, int srDeleted = -1) :
00044         clientAdded(clAdded),
00045         clientUpdated(clUpdated),
00046         clientDeleted(clDeleted),
00047         serverAdded(srAdded),
00048         serverUpdated(srUpdated),
00049         serverDeleted(srDeleted)
00050         {}
00051 
00052     const int clientAdded, clientUpdated, clientDeleted,
00053         serverAdded, serverUpdated, serverDeleted;
00054 
00062     virtual void check(int res, SyncReport &report) const;
00063 };
00064 
00108 class ClientTest {
00109   public:
00110     ClientTest(int serverSleepSec = 0, const std::string &serverLog= "");
00111     virtual ~ClientTest();
00112     
00122     virtual void registerTests();
00123 
00127     static int dump(ClientTest &client, SyncSource &source, const char *file);
00128 
00132     static int import(ClientTest &client, SyncSource &source, const char *file);
00133 
00138     static bool compare(ClientTest &client, const char *fileA, const char *fileB);
00139     
00140     struct Config;
00141     
00156     static void getTestData(const char *type, Config &config);
00157 
00165     struct Config {
00169         const char *sourceName;
00170 
00174         const char *uri;
00175 
00199         typedef SyncSource *(*createsource_t)(ClientTest &client, int source, bool isSourceA);
00200 
00206         createsource_t createSourceA;
00207         
00224         createsource_t createSourceB;
00225 
00233         const char *templateItem;
00234 
00239         const char *uniqueProperties;
00240 
00244         int numItems;
00245 
00250         const char *sizeProperty;
00251 
00256         const char *insertItem;
00257 
00263         const char *updateItem;
00264 
00270         const char *complexUpdateItem;
00271 
00276         const char *mergeItem1;
00277 
00284         const char *mergeItem2;
00285 
00297         int (*dump)(ClientTest &client, SyncSource &source, const char *file);
00298 
00311         int (*import)(ClientTest &client, SyncSource &source, const char *file);
00312         
00320         bool (*compare)(ClientTest &client, const char *fileA, const char *fileB);
00321 
00325         const char *testcases;
00326 
00331         const char *type;
00332     };
00333     
00338     virtual int getNumSources() = 0;
00339 
00346     virtual void getSourceConfig(int source, Config &config) = 0;
00347 
00357     virtual ClientTest *getClientB() = 0;
00358 
00364     virtual bool isB64Enabled() = 0;
00365     
00385     virtual int sync(
00386         const int *activeSources,
00387         SyncMode syncMode,
00388         const CheckSyncReport &checkReport,
00389         long maxMsgSize = 0,
00390         long maxObjSize = 0,
00391         bool loSupport = false,
00392         const char *encoding = "") = 0;
00393 
00403     virtual void postSync(int res, const std::string &logname);
00404 
00405   protected:
00409     int serverSleepSeconds;
00410 
00416     std::string serverLogFileName;
00417 
00418   private:
00424     void *factory;
00425 };
00426 
00428 #define CLIENT_TEST_EQUAL( _prefix, \
00429                            _expected, \
00430                            _actual ) \
00431     CPPUNIT_ASSERT_EQUAL_MESSAGE( std::string(_prefix) + ": " + #_expected + " == " + #_actual, \
00432                                   _expected, \
00433                                   _actual )
00434 
00435 #endif // ENABLE_INTEGRATION_TESTS
00436 
00439 #endif // INCL_TESTSYNCCLIENT

Generated on Fri Apr 27 12:29:19 2007 for Funambol C++ Client Library by  doxygen 1.5.2