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 #include "HttpConnectionTest.h"
00059
00060 USE_NAMESPACE
00061
00071 class CheckSyncReport {
00072 public:
00073 CheckSyncReport(int clAdded = -1, int clUpdated = -1, int clDeleted = -1,
00074 int srAdded = -1, int srUpdated = -1, int srDeleted = -1) :
00075 clientAdded(clAdded),
00076 clientUpdated(clUpdated),
00077 clientDeleted(clDeleted),
00078 serverAdded(srAdded),
00079 serverUpdated(srUpdated),
00080 serverDeleted(srDeleted)
00081 {}
00082
00083 virtual ~CheckSyncReport() {}
00084
00085 const int clientAdded, clientUpdated, clientDeleted,
00086 serverAdded, serverUpdated, serverDeleted;
00087
00095 virtual void check(int res, SyncReport &report) const;
00096 };
00097
00098 class LocalTests;
00099 class SyncTests;
00100
00144 class ClientTest {
00145 public:
00146 ClientTest(int serverSleepSec = 0, const std::string &serverLog= "");
00147 virtual ~ClientTest();
00148
00157 virtual void registerTests();
00158
00159 struct Config;
00160
00171 virtual LocalTests *createLocalTests(const std::string &name, int sourceParam, ClientTest::Config &co);
00172
00181 virtual SyncTests *createSyncTests(const std::string &name, std::vector<int> sourceIndices, bool isClientA = true);
00182
00186 static int dump(ClientTest &client, SyncSource &source, const char *file);
00187
00191 static int import(ClientTest &client, SyncSource &source, const char *file);
00192
00197 static bool compare(ClientTest &client, const char *fileA, const char *fileB);
00198
00213 static void getTestData(const char *type, Config &config);
00214
00222 struct Config {
00226 const char *sourceName;
00227
00231 const char *uri;
00232
00256 typedef SyncSource *(*createsource_t)(ClientTest &client, int source, bool isSourceA);
00257
00263 createsource_t createSourceA;
00264
00281 createsource_t createSourceB;
00282
00290 const char *templateItem;
00291
00296 const char *uniqueProperties;
00297
00301 int numItems;
00302
00307 const char *sizeProperty;
00308
00313 const char *insertItem;
00314
00320 const char *updateItem;
00321
00327 const char *complexUpdateItem;
00328
00333 const char *mergeItem1;
00334
00341 const char *mergeItem2;
00342
00359 const char *parentItem, *childItem;
00360
00366 #ifndef LINKED_ITEMS_RELAXED_SEMANTIC
00367 # define LINKED_ITEMS_RELAXED_SEMANTIC 1
00368 #endif
00369
00381 int (*dump)(ClientTest &client, SyncSource &source, const char *file);
00382
00395 int (*import)(ClientTest &client, SyncSource &source, const char *file);
00396
00404 bool (*compare)(ClientTest &client, const char *fileA, const char *fileB);
00405
00409 const char *testcases;
00410
00415 const char *type;
00416 };
00417
00422 virtual int getNumSources() = 0;
00423
00430 virtual void getSourceConfig(int source, Config &config) = 0;
00431
00441 virtual ClientTest *getClientB() = 0;
00442
00448 virtual bool isB64Enabled() = 0;
00449
00469 virtual int sync(
00470 const int *activeSources,
00471 SyncMode syncMode,
00472 const CheckSyncReport &checkReport,
00473 long maxMsgSize = 0,
00474 long maxObjSize = 0,
00475 bool loSupport = false,
00476 const char *encoding = "") = 0;
00477
00487 virtual void postSync(int res, const std::string &logname);
00488
00489 protected:
00493 int serverSleepSeconds;
00494
00500 std::string serverLogFileName;
00501
00502 private:
00508 void *factory;
00509 };
00510
00515 class CreateSource {
00516 public:
00517 CreateSource(ClientTest::Config::createsource_t createSourceParam, ClientTest &clientParam, int sourceParam, bool isSourceAParam) :
00518 createSource(createSourceParam),
00519 client(clientParam),
00520 source(sourceParam),
00521 isSourceA(isSourceAParam) {}
00522
00523 SyncSource *operator() () {
00524 CPPUNIT_ASSERT(createSource);
00525 return createSource(client, source, isSourceA);
00526 }
00527
00528 const ClientTest::Config::createsource_t createSource;
00529 ClientTest &client;
00530 const int source;
00531 const bool isSourceA;
00532 };
00533
00534
00539 class LocalTests : public CppUnit::TestSuite, public CppUnit::TestFixture {
00540 public:
00542 ClientTest &client;
00543
00545 const int source;
00546
00548 const ClientTest::Config config;
00549
00551 CreateSource createSourceA, createSourceB;
00552
00553 LocalTests(const std::string &name, ClientTest &cl, int sourceParam, ClientTest::Config &co) :
00554 CppUnit::TestSuite(name),
00555 client(cl),
00556 source(sourceParam),
00557 config(co),
00558 createSourceA(co.createSourceA, cl, sourceParam, true),
00559 createSourceB(co.createSourceB, cl, sourceParam, false)
00560 {}
00561
00567 virtual void addTests();
00568
00579 virtual std::string insert(CreateSource createSource, const char *data, bool relaxed = false);
00580
00588 virtual void update(CreateSource createSource, const char *data, bool check = true);
00589
00591 virtual void deleteAll(CreateSource createSource);
00592
00601 virtual void compareDatabases(const char *refFile, SyncSource ©, bool raiseAssert = true);
00602
00613 virtual int insertManyItems(CreateSource createSource, int startIndex = 1, int numItems = 0, int size = -1);
00614
00615
00616
00617
00618 virtual void testOpen();
00619 virtual void testIterateTwice();
00620 virtual void testSimpleInsert();
00621 virtual void testLocalDeleteAll();
00622 virtual void testComplexInsert();
00623 virtual void testLocalUpdate();
00624 virtual void testChanges();
00625 virtual void testImport();
00626 virtual void testImportDelete();
00627 virtual void testManyChanges();
00628 virtual void testLinkedItemsParent();
00629 virtual void testLinkedItemsChild();
00630 virtual void testLinkedItemsParentChild();
00631 virtual void testLinkedItemsChildParent();
00632 virtual void testLinkedItemsChildChangesParent();
00633 virtual void testLinkedItemsRemoveParentFirst();
00634 virtual void testLinkedItemsRemoveNormal();
00635 virtual void testLinkedItemsInsertParentTwice();
00636 virtual void testLinkedItemsInsertChildTwice();
00637 virtual void testLinkedItemsParentUpdate();
00638 virtual void testLinkedItemsUpdateChild();
00639 virtual void testLinkedItemsInsertBothUpdateChild();
00640 virtual void testLinkedItemsInsertBothUpdateParent();
00641
00642 };
00643
00644 enum itemType {
00645 NEW_ITEMS,
00646 UPDATED_ITEMS,
00647 DELETED_ITEMS,
00648 TOTAL_ITEMS
00649 };
00650
00657 int countItemsOfType(SyncSource *source, itemType type);
00658
00659 typedef std::list<std::string> UIDList;
00663 UIDList listItemsOfType(SyncSource *source, itemType type);
00664
00670 class SyncTests : public CppUnit::TestSuite, public CppUnit::TestFixture {
00671 public:
00673 ClientTest &client;
00674
00675 SyncTests(const std::string &name, ClientTest &cl, std::vector<int> sourceIndices, bool isClientA = true);
00676 ~SyncTests();
00677
00679 virtual void addTests();
00680
00681 protected:
00683 std::vector< std::pair<int, LocalTests *> > sources;
00684 typedef std::vector< std::pair<int, LocalTests *> >::iterator source_it;
00685
00687 int *sourceArray;
00688
00690 SyncTests *accessClientB;
00691
00693 SyncItemListener* itemListener;
00694
00695
00696 enum DeleteAllMode {
00697 DELETE_ALL_SYNC,
00700 DELETE_ALL_REFRESH
00701 };
00702
00704 virtual void compareDatabases();
00705
00707 virtual void deleteAll(DeleteAllMode mode = DELETE_ALL_SYNC);
00708
00710 virtual void doCopy();
00711
00717 virtual void refreshClient();
00718
00719
00720
00721
00722 virtual void testTwoWaySync() {
00723 sync(SYNC_TWO_WAY);
00724 }
00725
00726
00727 virtual void testSlowSync() {
00728 sync(SYNC_SLOW);
00729 }
00730
00731 virtual void testRefreshFromServerSync() {
00732 sync(SYNC_REFRESH_FROM_SERVER);
00733 }
00734
00735
00736 virtual void testRefreshFromClientSync() {
00737 sync(SYNC_REFRESH_FROM_CLIENT);
00738 }
00739
00740
00741 virtual void testDeleteAllSync() {
00742 deleteAll(DELETE_ALL_SYNC);
00743 }
00744
00745 virtual void testDeleteAllRefresh();
00746 virtual void testRefreshSemantic();
00747 virtual void testRefreshStatus();
00748
00749
00750 void testCopy() {
00751 doCopy();
00752 compareDatabases();
00753 }
00754
00755 virtual void testUpdate();
00756 virtual void testComplexUpdate();
00757 virtual void testDelete();
00758 virtual void testMerge();
00759 virtual void testTwinning();
00760 virtual void testOneWayFromServer();
00761 virtual void testOneWayFromClient();
00762 virtual void testItems();
00763 virtual void testAddUpdate();
00764
00765
00766
00767 void testMaxMsg() {
00768 doVarSizes(true, false, NULL);
00769 }
00770
00771 void testLargeObject() {
00772 doVarSizes(true, true, NULL);
00773 }
00774
00775 void testLargeObjectBin() {
00776 doVarSizes(true, true, "bin");
00777 }
00778
00779 void testLargeObjectEncoded() {
00780 doVarSizes(true, true, "b64");
00781 }
00782
00783 virtual void testManyItems();
00784
00785
00786 virtual void testMappings() {
00787 MappingsTest mapping;
00788 mapping.runTests();
00789 }
00790
00791 virtual void testConfigSyncSource() {
00792 ConfigSyncSourceTest css;
00793 css.runTests();
00794 }
00795
00796 virtual void testServerError506() {
00797 SyncManagerTest test;
00798 test.testServerError506();
00799 }
00800
00801 virtual void testLargeObject2() {
00802 SyncManagerTest test;
00803 test.testLargeObject2();
00804 }
00805
00806 virtual void testLOItem() {
00807 LOItemTest test;
00808 test.testLOItem();
00809 }
00810 virtual void testLOItemb64() {
00811 LOItemTest test;
00812 test.testLOItemb64();
00813 }
00814 virtual void testLOItemSlowSync() {
00815 LOItemTest test;
00816 test.testLOItemSlowSync();
00817 }
00818 virtual void testLOItemSlowSyncb64() {
00819 LOItemTest test;
00820 test.testLOItemSlowSyncb64();
00821 }
00822 virtual void testLOItemReplaceb64() {
00823 LOItemTest test;
00824 test.testLOItemReplaceb64();
00825 }
00826
00827 virtual void testLOItemWithItemEncoding() {
00828 LOItemTest test;
00829 test.testLOItemWithItemEncoding();
00830 }
00831 virtual void testLOItemDES() {
00832 LOItemTest test;
00833 test.testLOItemDES();
00834 }
00835 virtual void testFileSyncSource() {
00836 LOItemTest test;
00837 test.testFileSyncSource();
00838 }
00839
00840 virtual void testHttpConnection() {
00841 HttpConnectionTest test;
00842 test.testCompressedHttpConnection();
00843 }
00844
00849 virtual void doVarSizes(bool withMaxMsgSize,
00850 bool withLargeObject,
00851 const char *encoding);
00852
00857 virtual void sync(SyncMode syncMode,
00858 const std::string &logprefix = "",
00859 CheckSyncReport checkReport = CheckSyncReport(),
00860 long maxMsgSize = 0,
00861 long maxObjSize = 0,
00862 bool loSupport = false,
00863 const char *encoding = "");
00864 };
00865
00866
00868 #define CLIENT_TEST_EQUAL( _prefix, \
00869 _expected, \
00870 _actual ) \
00871 CPPUNIT_ASSERT_EQUAL_MESSAGE( std::string(_prefix) + ": " + #_expected + " == " + #_actual, \
00872 _expected, \
00873 _actual )
00874
00876 #define SOURCE_ASSERT_NO_FAILURE(_source, _x) \
00877 { \
00878 CPPUNIT_ASSERT_NO_THROW(_x); \
00879 CPPUNIT_ASSERT((_source) && (!(_source)->getReport() || (_source)->getReport()->getState() != SOURCE_ERROR)); \
00880 }
00881
00883 #define SOURCE_ASSERT(_source, _x) \
00884 { \
00885 CPPUNIT_ASSERT(_x); \
00886 CPPUNIT_ASSERT((_source) && (!(_source)->getReport() || (_source)->getReport()->getState() != SOURCE_ERROR)); \
00887 }
00888
00890 #define SOURCE_ASSERT_EQUAL(_source, _value, _x) \
00891 { \
00892 CPPUNIT_ASSERT_EQUAL(_value, _x); \
00893 CPPUNIT_ASSERT((_source) && (!(_source)->getReport() || (_source)->getReport()->getState() != SOURCE_ERROR)); \
00894 }
00895
00897 #define SOURCE_ASSERT_MESSAGE(_message, _source, _x) \
00898 { \
00899 CPPUNIT_ASSERT_MESSAGE((_message), (_x)); \
00900 CPPUNIT_ASSERT((_source) && (!(_source)->getReport() || (_source)->getReport()->getState() != SOURCE_ERROR)); \
00901 }
00902
00903
00911 #define ADD_TEST(_class, _function) \
00912 addTest(new CppUnit::TestCaller<_class>(getName() + "::" #_function, &_class::_function, *this))
00913
00914
00915 #endif // ENABLE_INTEGRATION_TESTS
00916
00917
00920 #endif // INCL_TESTSYNCCLIENT