2 * Copyright (C) 2008 Patrick Ohly
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program 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
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "FileSyncSource.h"
21 static EvolutionSyncSource *createSource(const EvolutionSyncSourceParams ¶ms)
23 pair <string, string> sourceType = EvolutionSyncSource::getSourceType(params.m_nodes);
24 // The string returned by getSourceType() is always the one
25 // registered as main Aliases() below.
26 bool isMe = sourceType.first == "Files in one directory";
29 // tell SyncEvolution if the user wanted to use a disabled sync source,
30 // otherwise let it continue searching
31 return isMe ? RegisterSyncSource::InactiveSource : NULL;
33 // Also recognize one of the standard types?
34 // Not in the FileSyncSource!
35 bool maybeMe = false /* sourceType.first == "addressbook" */;
37 if (isMe || maybeMe) {
38 // The FileSyncSource always needs the data format
39 // parameter in sourceType.second.
40 if (/* sourceType.second == "" || sourceType.second == "text/x-vcard" */
41 sourceType.second.size()) {
42 return new FileSyncSource(params, sourceType.second);
51 static RegisterSyncSource registerMe("Files in one directory",
58 "Files in one directory = file\n"
59 " Stores items in one directory as one file per item.\n"
60 " The directory is selected via [file://]<path>; it\n"
61 " will only be created if the prefix is given, otherwise\n"
62 " it must exist already. Only items of the same type can\n"
63 " be synchronized and this type must be specified explicitly\n"
64 " with both mime type and version.\n"
66 " file:text/plain:1.0\n"
67 " file:text/x-vcard:2.1\n"
68 " file:text/vcard:3.0\n"
69 " file:text/x-calendar:1.0\n"
70 " file:text/calendar:2.0\n",
72 (Aliases("Files in one directory") + "file"));
75 #ifdef ENABLE_UNIT_TESTS
77 class FileSyncSourceUnitTest : public CppUnit::TestFixture {
78 CPPUNIT_TEST_SUITE(FileSyncSourceUnitTest);
79 CPPUNIT_TEST(testInstantiate);
80 CPPUNIT_TEST_SUITE_END();
83 void testInstantiate() {
84 boost::shared_ptr<EvolutionSyncSource> source;
85 source.reset(EvolutionSyncSource::createTestingSource("file", "file:text/vcard:3.0", true));
86 source.reset(EvolutionSyncSource::createTestingSource("file", "file:text/plain:1.0", true));
87 source.reset(EvolutionSyncSource::createTestingSource("file", "Files in one directory:text/x-vcard:2.1", true));
91 SYNCEVOLUTION_TEST_SUITE_REGISTRATION(FileSyncSourceUnitTest);
93 #endif // ENABLE_UNIT_TESTS
95 #ifdef ENABLE_INTEGRATION_TESTS
97 // The anonymous namespace ensures that we don't get
98 // name clashes: although the classes and objects are
99 // only defined in this file, the methods generated
100 // for local classes will clash with other methods
101 // of other classes with the same name if no namespace
104 // The code above is not yet inside the anonymous
105 // name space because it would show up inside
106 // the CPPUnit unit test names. Use a unique class
113 static class VCard21Test : public RegisterSyncSourceTest {
115 VCard21Test() : RegisterSyncSourceTest("file_vcard21", "vcard21") {}
117 virtual void updateConfig(ClientTestConfig &config) const
119 // set type as required by FileSyncSource
120 // and leave everything else at its default
121 config.type = "file:text/x-vcard:2.1";
125 static class VCard30Test : public RegisterSyncSourceTest {
127 VCard30Test() : RegisterSyncSourceTest("file_vcard30", "vcard30") {}
129 virtual void updateConfig(ClientTestConfig &config) const
131 config.type = "file:text/vcard:3.0";
135 static class ICal20Test : public RegisterSyncSourceTest {
137 ICal20Test() : RegisterSyncSourceTest("file_ical20", "ical20") {}
139 virtual void updateConfig(ClientTestConfig &config) const
141 config.type = "file:text/calendar:2.0";
143 // A sync source which supports linked items (= recurring
144 // event with detached exception) is expected to handle
145 // inserting the parent or child twice by turning the
146 // second operation into an update. The file backend is
147 // to dumb for that and therefore fails these tests:
149 // Client::Source::file_ical20::testLinkedItemsInsertParentTwice
150 // Client::Source::file_ical20::testLinkedItemsInsertChildTwice
152 // Disable linked item testing to avoid this.
154 config.childItem = NULL;
158 static class ITodo20Test : public RegisterSyncSourceTest {
160 ITodo20Test() : RegisterSyncSourceTest("file_itodo20", "itodo20") {}
162 virtual void updateConfig(ClientTestConfig &config) const
164 config.type = "file:text/calendar:2.0";
169 #endif // ENABLE_INTEGRATION_TESTS
171 #endif // ENABLE_FILE