00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef INCL_TESTSYNCCLIENT
00037 #define INCL_TESTSYNCCLIENT
00038
00042 #include <string>
00043 #include <vector>
00044 #include <list>
00045 #include "spds/SyncSource.h"
00046 #include "spds/SyncReport.h"
00047
00048 #ifdef ENABLE_INTEGRATION_TESTS
00049
00050 #include <cppunit/TestSuite.h>
00051 #include <cppunit/TestAssert.h>
00052 #include <cppunit/TestFixture.h>
00053 #include "base/globalsdef.h"
00054 #include "MappingsTest.h"
00055 #include "ConfigSyncSourceTest.h"
00056 #include "SyncManagerTest.h"
00057 #include "LOItemTest.h"
00058
00059 USE_NAMESPACE
00060
00070 class CheckSyncReport {
00071 public:
00072 CheckSyncReport(int clAdded = -1, int clUpdated = -1, int clDeleted = -1,
00073 int srAdded = -1, int srUpdated = -1, int srDeleted = -1) :
00074 clientAdded(clAdded),
00075 clientUpdated(clUpdated),
00076 clientDeleted(clDeleted),
00077 serverAdded(srAdded),
00078 serverUpdated(srUpdated),
00079 serverDeleted(srDeleted)
00080 {}
00081
00082 virtual ~CheckSyncReport() {}
00083
00084 const int clientAdded, clientUpdated, clientDeleted,
00085 serverAdded, serverUpdated, serverDeleted;
00086
00094 virtual void check(int res, SyncReport &report) const;
00095 };
00096
00097 class LocalTests;
00098 class SyncTests;
00099
00143 class ClientTest {
00144 public:
00145 ClientTest(int serverSleepSec = 0, const std::string &serverLog= "");
00146 virtual ~ClientTest();
00147
00156 virtual void registerTests();
00157
00158 struct Config;
00159
00170 virtual LocalTests *createLocalTests(const std::string &name, int sourceParam, ClientTest::Config &co);
00171
00180 virtual SyncTests *createSyncTests(const std::string &name, std::vector<int> sourceIndices, bool isClientA = true);
00181
00185 static int dump(ClientTest &client, SyncSource &source, const char *file);
00186
00190 static int import(ClientTest &client, SyncSource &source, const char *file);
00191
00196 static bool compare(ClientTest &client, const char *fileA, const char *fileB);
00197
00212 static void getTestData(const char *type, Config &config);
00213
00221 struct Config {
00225 const char *sourceName;
00226
00230 const char *uri;
00231
00255 typedef SyncSource *(*createsource_t)(ClientTest &client, int source, bool isSourceA);
00256
00262 createsource_t createSourceA;
00263
00280 createsource_t createSourceB;
00281
00289 const char *templateItem;
00290
00295 const char *uniqueProperties;
00296
00300 int numItems;
00301
00306 const char *sizeProperty;
00307
00312 const char *insertItem;
00313
00319 const char *updateItem;
00320
00326 const char *complexUpdateItem;
00327
00332 const char *mergeItem1;
00333
00340 const char *mergeItem2;
00341
00358 const char *parentItem, *childItem;
00359
00365 #ifndef LINKED_ITEMS_RELAXED_SEMANTIC
00366 # define LINKED_ITEMS_RELAXED_SEMANTIC 1
00367 #endif
00368
00380 int (*dump)(ClientTest &client, SyncSource &source, const char *file);
00381
00394 int (*import)(ClientTest &client, SyncSource &source, const char *file);
00395
00403 bool (*compare)(ClientTest &client, const char *fileA, const char *fileB);
00404
00408 const char *testcases;
00409
00414 const char *type;
00415 };
00416
00421 virtual int getNumSources() = 0;
00422
00429 virtual void getSourceConfig(int source, Config &config) = 0;
00430
00440 virtual ClientTest *getClientB() = 0;
00441
00447 virtual bool isB64Enabled() = 0;
00448
00468 virtual int sync(
00469 const int *activeSources,
00470 SyncMode syncMode,
00471 const CheckSyncReport &checkReport,
00472 long maxMsgSize = 0,
00473 long maxObjSize = 0,
00474 bool loSupport = false,
00475 const char *encoding = "") = 0;
00476
00486 virtual void postSync(int res, const std::string &logname);
00487
00488 protected:
00492 int serverSleepSeconds;
00493
00499 std::string serverLogFileName;
00500
00501 private:
00507 void *factory;
00508 };
00509
00514 class CreateSource {
00515 public:
00516 CreateSource(ClientTest::Config::createsource_t createSourceParam, ClientTest &clientParam, int sourceParam, bool isSourceAParam) :
00517 createSource(createSourceParam),
00518 client(clientParam),
00519 source(sourceParam),
00520 isSourceA(isSourceAParam) {}
00521
00522 SyncSource *operator() () {
00523 CPPUNIT_ASSERT(createSource);
00524 return createSource(client, source, isSourceA);
00525 }
00526
00527 const ClientTest::Config::createsource_t createSource;
00528 ClientTest &client;
00529 const int source;
00530 const bool isSourceA;
00531 };
00532
00533
00538 class LocalTests : public CppUnit::TestSuite, public CppUnit::TestFixture {
00539 public:
00541 ClientTest &client;
00542
00544 const int source;
00545
00547 const ClientTest::Config config;
00548
00550 CreateSource createSourceA, createSourceB;
00551
00552 LocalTests(const std::string &name, ClientTest &cl, int sourceParam, ClientTest::Config &co) :
00553 CppUnit::TestSuite(name),
00554 client(cl),
00555 source(sourceParam),
00556 config(co),
00557 createSourceA(co.createSourceA, cl, sourceParam, true),
00558 createSourceB(co.createSourceB, cl, sourceParam, false)
00559 {}
00560
00566 virtual void addTests();
00567
00578 virtual std::string insert(CreateSource createSource, const char *data, bool relaxed = false);
00579
00587 virtual void update(CreateSource createSource, const char *data, bool check = true);
00588
00590 virtual void deleteAll(CreateSource createSource);
00591
00600 virtual void compareDatabases(const char *refFile, SyncSource ©, bool raiseAssert = true);
00601
00612 virtual int insertManyItems(CreateSource createSource, int startIndex = 1, int numItems = 0, int size = -1);
00613
00614
00615
00616
00617 virtual void testOpen();
00618 virtual void testIterateTwice();
00619 virtual void testSimpleInsert();
00620 virtual void testLocalDeleteAll();
00621 virtual void testComplexInsert();
00622 virtual void testLocalUpdate();
00623 virtual void testChanges();
00624 virtual void testImport();
00625 virtual void testImportDelete();
00626 virtual void testManyChanges();
00627 virtual void testLinkedItemsParent();
00628 virtual void testLinkedItemsChild();
00629 virtual void testLinkedItemsParentChild();
00630 virtual void testLinkedItemsChildParent();
00631 virtual void testLinkedItemsChildChangesParent();
00632 virtual void testLinkedItemsRemoveParentFirst();
00633 virtual void testLinkedItemsRemoveNormal();
00634 virtual void testLinkedItemsInsertParentTwice();
00635 virtual void testLinkedItemsInsertChildTwice();
00636 virtual void testLinkedItemsParentUpdate();
00637 virtual void testLinkedItemsUpdateChild();
00638 virtual void testLinkedItemsInsertBothUpdateChild();
00639 virtual void testLinkedItemsInsertBothUpdateParent();
00640
00641 };
00642
00643 enum itemType {
00644 NEW_ITEMS,
00645 UPDATED_ITEMS,
00646 DELETED_ITEMS,
00647 TOTAL_ITEMS
00648 };
00649
00656 int countItemsOfType(SyncSource *source, itemType type);
00657
00658 typedef std::list<std::string> UIDList;
00662 UIDList listItemsOfType(SyncSource *source, itemType type);
00663
00669 class SyncTests : public CppUnit::TestSuite, public CppUnit::TestFixture {
00670 public:
00672 ClientTest &client;
00673
00674 SyncTests(const std::string &name, ClientTest &cl, std::vector<int> sourceIndices, bool isClientA = true);
00675 ~SyncTests();
00676
00678 virtual void addTests();
00679
00680 protected:
00682 std::vector< std::pair<int, LocalTests *> > sources;
00683 typedef std::vector< std::pair<int, LocalTests *> >::iterator source_it;
00684
00686 int *sourceArray;
00687
00689 SyncTests *accessClientB;
00690
00692 SyncItemListener* itemListener;
00693
00694
00695 enum DeleteAllMode {
00696 DELETE_ALL_SYNC,
00699 DELETE_ALL_REFRESH
00700 };
00701
00703 virtual void compareDatabases();
00704
00706 virtual void deleteAll(DeleteAllMode mode = DELETE_ALL_SYNC);
00707
00709 virtual void doCopy();
00710
00716 virtual void refreshClient();
00717
00718
00719
00720
00721 virtual void testTwoWaySync() {
00722 sync(SYNC_TWO_WAY);
00723 }
00724
00725
00726 virtual void testSlowSync() {
00727 sync(SYNC_SLOW);
00728 }
00729
00730 virtual void testRefreshFromServerSync() {
00731 sync(SYNC_REFRESH_FROM_SERVER);
00732 }
00733
00734
00735 virtual void testRefreshFromClientSync() {
00736 sync(SYNC_REFRESH_FROM_CLIENT);
00737 }
00738
00739
00740 virtual void testDeleteAllSync() {
00741 deleteAll(DELETE_ALL_SYNC);
00742 }
00743
00744 virtual void testDeleteAllRefresh();
00745 virtual void testRefreshSemantic();
00746 virtual void testRefreshStatus();
00747
00748
00749 void testCopy() {
00750 doCopy();
00751 compareDatabases();
00752 }
00753
00754 virtual void testUpdate();
00755 virtual void testComplexUpdate();
00756 virtual void testDelete();
00757 virtual void testMerge();
00758 virtual void testTwinning();
00759 virtual void testOneWayFromServer();
00760 virtual void testOneWayFromClient();
00761 virtual void testItems();
00762 virtual void testAddUpdate();
00763
00764
00765
00766 void testMaxMsg() {
00767 doVarSizes(true, false, NULL);
00768 }
00769
00770 void testLargeObject() {
00771 doVarSizes(true, true, NULL);
00772 }
00773
00774 void testLargeObjectBin() {
00775 doVarSizes(true, true, "bin");
00776 }
00777
00778 void testLargeObjectEncoded() {
00779 doVarSizes(true, true, "b64");
00780 }
00781
00782 virtual void testManyItems();
00783
00784
00785 virtual void testMappings() {
00786 MappingsTest mapping;
00787 mapping.runTests();
00788 }
00789
00790 virtual void testConfigSyncSource() {
00791 ConfigSyncSourceTest css;
00792 css.runTests();
00793 }
00794
00795 virtual void testServerError506() {
00796 SyncManagerTest test;
00797 test.testServerError506();
00798 }
00799
00800 virtual void testLargeObject2() {
00801 SyncManagerTest test;
00802 test.testLargeObject2();
00803 }
00804
00805 virtual void testLOItem() {
00806 LOItemTest test;
00807 test.testLOItem();
00808 }
00809 virtual void testLOItemb64() {
00810 LOItemTest test;
00811 test.testLOItemb64();
00812 }
00813 virtual void testLOItemSlowSync() {
00814 LOItemTest test;
00815 test.testLOItemSlowSync();
00816 }
00817 virtual void testLOItemSlowSyncb64() {
00818 LOItemTest test;
00819 test.testLOItemSlowSyncb64();
00820 }
00821 virtual void testLOItemReplaceb64() {
00822 LOItemTest test;
00823 test.testLOItemReplaceb64();
00824 }
00825
00826 virtual void testLOItemWithItemEncoding() {
00827 LOItemTest test;
00828 test.testLOItemWithItemEncoding();
00829 }
00830 virtual void testLOItemDES() {
00831 LOItemTest test;
00832 test.testLOItemDES();
00833 }
00834 virtual void testFileSyncSource() {
00835 LOItemTest test;
00836 test.testFileSyncSource();
00837 }
00838
00843 virtual void doVarSizes(bool withMaxMsgSize,
00844 bool withLargeObject,
00845 const char *encoding);
00846
00851 virtual void sync(SyncMode syncMode,
00852 const std::string &logprefix = "",
00853 CheckSyncReport checkReport = CheckSyncReport(),
00854 long maxMsgSize = 0,
00855 long maxObjSize = 0,
00856 bool loSupport = false,
00857 const char *encoding = "");
00858 };
00859
00860
00862 #define CLIENT_TEST_EQUAL( _prefix, \
00863 _expected, \
00864 _actual ) \
00865 CPPUNIT_ASSERT_EQUAL_MESSAGE( std::string(_prefix) + ": " + #_expected + " == " + #_actual, \
00866 _expected, \
00867 _actual )
00868
00870 #define SOURCE_ASSERT_NO_FAILURE(_source, _x) \
00871 { \
00872 CPPUNIT_ASSERT_NO_THROW(_x); \
00873 CPPUNIT_ASSERT((_source) && (!(_source)->getReport() || (_source)->getReport()->getState() != SOURCE_ERROR)); \
00874 }
00875
00877 #define SOURCE_ASSERT(_source, _x) \
00878 { \
00879 CPPUNIT_ASSERT(_x); \
00880 CPPUNIT_ASSERT((_source) && (!(_source)->getReport() || (_source)->getReport()->getState() != SOURCE_ERROR)); \
00881 }
00882
00884 #define SOURCE_ASSERT_EQUAL(_source, _value, _x) \
00885 { \
00886 CPPUNIT_ASSERT_EQUAL(_value, _x); \
00887 CPPUNIT_ASSERT((_source) && (!(_source)->getReport() || (_source)->getReport()->getState() != SOURCE_ERROR)); \
00888 }
00889
00891 #define SOURCE_ASSERT_MESSAGE(_message, _source, _x) \
00892 { \
00893 CPPUNIT_ASSERT_MESSAGE((_message), (_x)); \
00894 CPPUNIT_ASSERT((_source) && (!(_source)->getReport() || (_source)->getReport()->getState() != SOURCE_ERROR)); \
00895 }
00896
00897
00905 #define ADD_TEST(_class, _function) \
00906 addTest(new CppUnit::TestCaller<_class>(getName() + "::" #_function, &_class::_function, *this))
00907
00908
00909 #endif // ENABLE_INTEGRATION_TESTS
00910
00911
00914 #endif // INCL_TESTSYNCCLIENT