Imported Upstream version 1.4.1
[platform/upstream/syncevolution.git] / test / IcalTest.cpp
1 /*
2  * Copyright (C) 2005-2009 Patrick Ohly <patrick.ohly@gmx.de>
3  * Copyright (C) 2009 Intel Corporation
4  *
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.
9  *
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.
14  *
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
18  * 02110-1301  USA
19  */
20
21 #include "config.h"
22
23 #ifdef ENABLE_ICAL
24 #include "test.h"
25 #include <syncevo/eds_abi_wrapper.h>
26 #include <syncevo/icalstrdup.h>
27 #include <syncevo/SmartPtr.h>
28
29 SE_BEGIN_CXX
30
31 class IcalTest : public CppUnit::TestFixture {
32     CPPUNIT_TEST_SUITE(IcalTest);
33     CPPUNIT_TEST(testTimezone);
34     CPPUNIT_TEST_SUITE_END();
35
36 protected:
37     /**
38      * Ensures that we get VTIMEZONE with RRULE from libical.
39      *
40      * This only works with libical 1.0 if we successfully
41      * pick up our icaltimezone_get_component() or
42      * libical uses our icaltzutil_fetch_timezone().
43      *
44      * This test uses the function lookup via eds_abi_wrapper.h if that
45      * was enabled, otherwise goes via the static or dynamic linker.
46      *
47      * It only passes if the given timezone has not been loaded by
48      * libical internally yet, because we cannot influence that. Only
49      * direct calls to icaltimezone_get_component() as done by
50      * libsynthesis are caught. This means that "Europe/Paris" must
51      * not be used by, for example, test data used in
52      * Client::Source::eds_event.
53      */
54     void testTimezone()
55     {
56         icaltimezone *zone = icaltimezone_get_builtin_timezone("Europe/Paris");
57         CPPUNIT_ASSERT(zone);
58         icalcomponent *comp = icaltimezone_get_component(zone);
59         CPPUNIT_ASSERT(comp);
60         SyncEvo::eptr<char> str(ical_strdup(icalcomponent_as_ical_string(comp)));
61         CPPUNIT_ASSERT(str);
62         // We are very specific here. This'll work until we change our
63         // code or the zone data from Europe/Paris changes (not likely).
64         CPPUNIT_ASSERT_EQUAL(std::string(str), std::string(
65             "BEGIN:VTIMEZONE\r\n"
66             "TZID:/freeassociation.sourceforge.net/Tzfile/Europe/Paris\r\n"
67             "X-LIC-LOCATION:Europe/Paris\r\n"
68             "BEGIN:STANDARD\r\n"
69             "TZNAME:CET\r\n"
70             "DTSTART:19701026T030000\r\n"
71             "RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10\r\n"
72             "TZOFFSETFROM:+0200\r\n"
73             "TZOFFSETTO:+0100\r\n"
74             "END:STANDARD\r\n"
75             "BEGIN:DAYLIGHT\r\n"
76             "TZNAME:CEST\r\n"
77             "DTSTART:19700330T020000\r\n"
78             "RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3\r\n"
79             "TZOFFSETFROM:+0100\r\n"
80             "TZOFFSETTO:+0200\r\n"
81             "END:DAYLIGHT\r\n"
82             "END:VTIMEZONE\r\n"
83             ));
84     }
85 };
86
87 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(IcalTest, "SyncEvolution" );
88
89 SE_END_CXX
90
91 #endif // ENABLE_ICAL