00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "EvolutionContactSource.h"
00020 #include "SyncEvolutionUtil.h"
00021
00022 static EvolutionSyncSource *createSource(const EvolutionSyncSourceParams ¶ms)
00023 {
00024 pair <string, string> sourceType = EvolutionSyncSource::getSourceType(params.m_nodes);
00025 bool isMe = sourceType.first == "Evolution Address Book";
00026 bool maybeMe = sourceType.first == "addressbook";
00027 bool enabled;
00028
00029 #ifdef ENABLE_EBOOK
00030 enabled = e_book_new && e_source_group_peek_sources;
00031 #else
00032 enabled = false;
00033 #endif
00034
00035 if (isMe || maybeMe) {
00036 if (sourceType.second == "" || sourceType.second == "text/x-vcard") {
00037 return
00038 #ifdef ENABLE_EBOOK
00039 enabled ? new EvolutionContactSource(params, EVC_FORMAT_VCARD_21) :
00040 #endif
00041 isMe ? RegisterSyncSource::InactiveSource : NULL;
00042 } else if (sourceType.second == "text/vcard") {
00043 return
00044 #ifdef ENABLE_EBOOK
00045 enabled ? new EvolutionContactSource(params, EVC_FORMAT_VCARD_30) :
00046 #endif
00047 isMe ? RegisterSyncSource::InactiveSource : NULL;
00048 }
00049 }
00050 return NULL;
00051 }
00052
00053 static RegisterSyncSource registerMe("Evolution Address Book",
00054 #ifdef ENABLE_EBOOK
00055 true,
00056 #else
00057 false,
00058 #endif
00059 createSource,
00060 "Evolution Address Book = Evolution Contacts = addressbook = contacts = evolution-contacts\n"
00061 " vCard 2.1 (default) = text/x-vcard\n"
00062 " vCard 3.0 = text/vcard\n"
00063 " The later is the internal format of Evolution and preferred with\n"
00064 " servers that support it. One such server is ScheduleWorld\n"
00065 " together with the \"card3\" uri.\n",
00066 Values() +
00067 (Aliases("Evolution Address Book") + "Evolution Contacts" + "evolution-contacts"));
00068
00069 #ifdef ENABLE_EBOOK
00070 #ifdef ENABLE_UNIT_TESTS
00071
00072 class EvolutionContactTest : public CppUnit::TestFixture {
00073 CPPUNIT_TEST_SUITE(EvolutionContactTest);
00074 CPPUNIT_TEST(testInstantiate);
00075 CPPUNIT_TEST(testImport);
00076 CPPUNIT_TEST_SUITE_END();
00077
00078 protected:
00079 void testInstantiate() {
00080 boost::shared_ptr<EvolutionSyncSource> source;
00081 source.reset(EvolutionSyncSource::createTestingSource("addressbook", "addressbook", true));
00082 source.reset(EvolutionSyncSource::createTestingSource("addressbook", "contacts", true));
00083 source.reset(EvolutionSyncSource::createTestingSource("addressbook", "evolution-contacts", true));
00084 source.reset(EvolutionSyncSource::createTestingSource("addressbook", "Evolution Contacts", true));
00085 source.reset(EvolutionSyncSource::createTestingSource("addressbook", "Evolution Address Book:text/x-vcard", true));
00086 source.reset(EvolutionSyncSource::createTestingSource("addressbook", "Evolution Address Book:text/vcard", true));
00087 }
00088
00089
00090
00091
00092
00093
00094 void testImport() {
00095
00096
00097 boost::shared_ptr<EvolutionContactSource> source21(dynamic_cast<EvolutionContactSource *>(EvolutionSyncSource::createTestingSource("evolutioncontactsource21", "evolution-contacts:text/x-vcard", true)));
00098 boost::shared_ptr<EvolutionContactSource> source30(dynamic_cast<EvolutionContactSource *>(EvolutionSyncSource::createTestingSource("evolutioncontactsource30", "Evolution Address Book:text/vcard", true)));
00099 string parsed;
00100
00101
00102 parsed = "BEGIN:VCARD\r\nVERSION:3.0\r\nTEL;CELL:cell\r\nEND:VCARD\r\n";
00103 CPPUNIT_ASSERT_EQUAL(parsed,
00104 preparse(*source21,
00105 "BEGIN:VCARD\nVERSION:2.1\nTEL;CELL:cell\nEND:VCARD\n",
00106 "text/x-vcard"));
00107
00108 parsed = "BEGIN:VCARD\r\nVERSION:3.0\r\nTEL;TYPE=CAR:car\r\nEND:VCARD\r\n";
00109 CPPUNIT_ASSERT_EQUAL(parsed,
00110 preparse(*source21,
00111 "BEGIN:VCARD\nVERSION:2.1\nTEL;TYPE=CAR:car\nEND:VCARD\n",
00112 "text/x-vcard"));
00113
00114 parsed = "BEGIN:VCARD\r\nVERSION:3.0\r\nTEL;TYPE=HOME:home\r\nEND:VCARD\r\n";
00115 CPPUNIT_ASSERT_EQUAL(parsed,
00116 preparse(*source21,
00117 "BEGIN:VCARD\nVERSION:2.1\nTEL:home\nEND:VCARD\n",
00118 "text/x-vcard"));
00119
00120
00121 parsed = "BEGIN:VCARD\r\nVERSION:3.0\r\nTEL;TYPE=OTHER:other\r\nEND:VCARD\r\n";
00122 CPPUNIT_ASSERT_EQUAL(parsed,
00123 preparse(*source21,
00124 "BEGIN:VCARD\nVERSION:2.1\nTEL;TYPE=PARCEL:other\nEND:VCARD\n",
00125 "text/x-vcard"));
00126
00127 parsed = "BEGIN:VCARD\r\nVERSION:3.0\r\nTEL;TYPE=HOME;TYPE=VOICE:cell\r\nEND:VCARD\r\n";
00128 CPPUNIT_ASSERT_EQUAL(parsed,
00129 preparse(*source21,
00130 "BEGIN:VCARD\nVERSION:2.1\nTEL;TYPE=HOME,VOICE:cell\nEND:VCARD\n",
00131 "text/x-vcard"));
00132 }
00133
00134 private:
00135 string preparse(EvolutionContactSource &source,
00136 const char *data,
00137 const char *type) {
00138 SyncItem item;
00139 item.setData(data, strlen(data));
00140 item.setDataType(type);
00141 return source.preparseVCard(item);
00142 }
00143 };
00144
00145 SYNCEVOLUTION_TEST_SUITE_REGISTRATION(EvolutionContactTest);
00146 #endif // ENABLE_UNIT_TESTS
00147
00148 #ifdef ENABLE_INTEGRATION_TESTS
00149
00150 namespace {
00151 #if 0
00152 }
00153 #endif
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 static class VCard21Test : public RegisterSyncSourceTest {
00166 public:
00167 VCard21Test() : RegisterSyncSourceTest("vcard21", "vcard30") {}
00168
00169 virtual void updateConfig(ClientTestConfig &config) const
00170 {
00171 config.uri = "card";
00172 config.type = "evolution-contacts:text/x-vcard";
00173 config.dump = dump;
00174 }
00175 } vCard21Test;
00176
00177 static class VCard30Test : public RegisterSyncSourceTest {
00178 public:
00179 VCard30Test() : RegisterSyncSourceTest("vcard30", "vcard30") {}
00180
00181 virtual void updateConfig(ClientTestConfig &config) const
00182 {
00183 config.type = "evolution-contacts:text/vcard";
00184 }
00185 } vCard30Test;
00186
00187 }
00188 #endif // ENABLE_INTEGRATION_TESTS
00189
00190 #endif // ENABLE_EBOOK
00191