2 * Copyright (C) 2008-2009 Patrick Ohly <patrick.ohly@gmx.de>
3 * Copyright (C) 2009 Intel Corporation
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) version 3.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include "FileSyncSource.h"
24 #include <syncevo/declarations.h>
27 static SyncSource *createSource(const SyncSourceParams ¶ms)
29 SourceType sourceType = SyncSource::getSourceType(params.m_nodes);
30 // The string returned by getSourceType() is always the one
31 // registered as main Aliases() below.
32 bool isMe = sourceType.m_backend == "Files in one directory";
35 // tell SyncEvolution if the user wanted to use a disabled sync source,
36 // otherwise let it continue searching
37 return isMe ? RegisterSyncSource::InactiveSource : NULL;
39 // Also recognize one of the standard types?
40 // Not in the FileSyncSource!
41 bool maybeMe = false /* sourceType.m_backend == "addressbook" */;
43 if (isMe || maybeMe) {
44 // The FileSyncSource always needs the data format
45 // parameter in sourceType.m_format.
46 if (/* sourceType.m_format == "" || sourceType.m_format == "text/x-vcard" */
47 sourceType.m_format.size()) {
48 return new FileSyncSource(params, sourceType.m_format);
57 static RegisterSyncSource registerMe("Files in one directory",
64 "Files in one directory = file\n"
65 " Stores items in one directory as one file per item.\n"
66 " The directory is selected via evolutionsource=[file://]<path>.\n"
67 " It will only be created if the prefix is given, otherwise\n"
68 " it must exist already. Only items of the same type can\n"
69 " be synchronized and this type must be specified explicitly\n"
70 " with both mime type and version.\n"
71 " Examples for type:\n"
72 " file:text/plain:1.0\n"
73 " file:text/x-vcard:2.1\n"
74 " file:text/vcard:3.0\n"
75 " file:text/x-vcalendar:1.0\n"
76 " file:text/calendar:2.0\n"
77 " Examples for evolutionsource:\n"
78 " /home/joe/datadir - directory must exist\n"
79 " file:///tmp/scratch - directory is created\n",
81 (Aliases("Files in one directory") + "file"));
84 #ifdef ENABLE_UNIT_TESTS
86 class FileSyncSourceUnitTest : public CppUnit::TestFixture {
87 CPPUNIT_TEST_SUITE(FileSyncSourceUnitTest);
88 CPPUNIT_TEST(testInstantiate);
89 CPPUNIT_TEST_SUITE_END();
92 void testInstantiate() {
93 boost::shared_ptr<SyncSource> source;
94 source.reset(SyncSource::createTestingSource("file", "file:text/vcard:3.0", true));
95 source.reset(SyncSource::createTestingSource("file", "file:text/plain:1.0", true));
96 source.reset(SyncSource::createTestingSource("file", "Files in one directory:text/x-vcard:2.1", true));
100 SYNCEVOLUTION_TEST_SUITE_REGISTRATION(FileSyncSourceUnitTest);
102 #endif // ENABLE_UNIT_TESTS
104 // The anonymous namespace ensures that we don't get
105 // name clashes: although the classes and objects are
106 // only defined in this file, the methods generated
107 // for local classes will clash with other methods
108 // of other classes with the same name if no namespace
111 // The code above is not yet inside the anonymous
112 // name space because it would show up inside
113 // the CPPUnit unit test names. Use a unique class
120 static class VCard21Test : public RegisterSyncSourceTest {
122 VCard21Test() : RegisterSyncSourceTest("file_vcard21", "vcard21") {}
124 virtual void updateConfig(ClientTestConfig &config) const
126 // set type as required by FileSyncSource
127 // and leave everything else at its default
128 config.type = "file:text/x-vcard:2.1";
132 static class VCard30Test : public RegisterSyncSourceTest {
134 VCard30Test() : RegisterSyncSourceTest("file_vcard30", "vcard30") {}
136 virtual void updateConfig(ClientTestConfig &config) const
138 config.type = "file:text/vcard:3.0";
142 static class ICal20Test : public RegisterSyncSourceTest {
144 ICal20Test() : RegisterSyncSourceTest("file_ical20", "ical20") {}
146 virtual void updateConfig(ClientTestConfig &config) const
148 config.type = "file:text/calendar:2.0";
150 // A sync source which supports linked items (= recurring
151 // event with detached exception) is expected to handle
152 // inserting the parent or child twice by turning the
153 // second operation into an update. The file backend is
154 // to dumb for that and therefore fails these tests:
156 // Client::Source::file_ical20::testLinkedItemsInsertParentTwice
157 // Client::Source::file_ical20::testLinkedItemsInsertChildTwice
159 // Disable linked item testing to avoid this.
160 config.sourceKnowsItemSemantic = false;
164 static class ITodo20Test : public RegisterSyncSourceTest {
166 ITodo20Test() : RegisterSyncSourceTest("file_itodo20", "itodo20") {}
168 virtual void updateConfig(ClientTestConfig &config) const
170 config.type = "file:text/calendar:2.0";
176 #endif // ENABLE_FILE