Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Inserted copyright and license header for xestiacalendar_commonfunctions.h
[xestiacalendar/.git] / source / tests / xestiacalendar_commonfunctions.h
1 // xestiacalendar_commonfunctions.h - Xestia Calendar Common Functions Unit Tests
2 //
3 // (c) 2016 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar.
6 //
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
10 //
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Calendar. If not, see <http://www.gnu.org/licenses/>
19 #include "../common/file.h"
20 #include "../common/text.h"
22 TEST(CommonFunctions, FileTests){
23         
24         ASSERT_EQ(false, FileExists("iCalendarEvent-Missing.vcf"));
25         ASSERT_EQ(true, FileExists("iCalendarEvent-InvalidPermissions.vcf"));
26         
27 }
29 TEST(CommonFunctions, ProcessTextVectorsTests){
30         
31         // Setup the objects to be used for processing.
32         
33         vector<string> TextPropertiesExample1;
34         vector<string> TextValueExample1;
35         multimap<string, string> TextExample1TestResult;
36         
37         TextPropertiesExample1.push_back("ATTENDEE");
38         TextValueExample1.push_back("Example Attendee 1");
40         TextPropertiesExample1.push_back("ATTENDEE");
41         TextValueExample1.push_back("Example Attendee 2");
42         
43         TextPropertiesExample1.push_back("ATTENDEE");
44         TextValueExample1.push_back("Example Attendee 3");
45         
46         TextPropertiesExample1.push_back("CATEGORIES");
47         TextValueExample1.push_back("CATEGORY 1");
49         TextPropertiesExample1.push_back("CATEGORIES");
50         TextValueExample1.push_back("CATEGORY 2");
51         
52         TextPropertiesExample1.push_back("CATEGORIES");
53         TextValueExample1.push_back("CATEGORY 3");
55         TextPropertiesExample1.push_back("COMMENT");
56         TextValueExample1.push_back("This is the first comment.");
58         TextPropertiesExample1.push_back("COMMENT");
59         TextValueExample1.push_back("This is the second comment.");
60         
61         TextPropertiesExample1.push_back("COMMENT");
62         TextValueExample1.push_back("This is the third comment.");
64         TextPropertiesExample1.push_back("CONTACT;TEST=VALUE");
65         TextValueExample1.push_back("First Contact");
67         TextPropertiesExample1.push_back("CONTACT;LAZY=NOPE");
68         TextValueExample1.push_back("Second Contact");
70         TextPropertiesExample1.push_back("CONTACT;SETUP=NO");
71         TextValueExample1.push_back("Third Contact");
72         
73         TextPropertiesExample1.push_back("RESOURCES;ROOM=YES");
74         TextValueExample1.push_back("First Resource Widget");
76         TextPropertiesExample1.push_back("RESOURCES;ROOM=NO");
77         TextValueExample1.push_back("Second Resource Widget");
79         TextPropertiesExample1.push_back("RESOURCES;ROOM=UNKNOWN");
80         TextValueExample1.push_back("Third Resource Widget");
82         TextPropertiesExample1.push_back("RELATED;RELATION=NO");
83         TextValueExample1.push_back("First Relation");
85         TextPropertiesExample1.push_back("RELATED;RELATION=YES");
86         TextValueExample1.push_back("Second Relation");
88         TextPropertiesExample1.push_back("RELATED;RELATION=MAYBE");
89         TextValueExample1.push_back("Third Relation");
91         // Examples 1 & 2: ATTENDEE
93         TextExample1TestResult.insert(make_pair("ATTENDEE", "Example Attendee 1"));
94         TextExample1TestResult.insert(make_pair("ATTENDEE", "Example Attendee 2"));
95         TextExample1TestResult.insert(make_pair("ATTENDEE", "Example Attendee 3"));
96         
97         ASSERT_EQ(TextExample1TestResult, ProcessTextVectors(&TextPropertiesExample1, &TextValueExample1, true, "ATTENDEE"));
99         TextExample1TestResult.clear();
100         TextExample1TestResult.insert(make_pair("ATTENDEE", "Example Attendee 1"));
102         ASSERT_EQ(TextExample1TestResult, ProcessTextVectors(&TextPropertiesExample1, &TextValueExample1, false, "ATTENDEE"));
104         // Examples 3 & 4: CATEGORIES
106         TextExample1TestResult.clear();
107         TextExample1TestResult.insert(make_pair("CATEGORIES", "CATEGORY 1"));
108         TextExample1TestResult.insert(make_pair("CATEGORIES", "CATEGORY 2"));
109         TextExample1TestResult.insert(make_pair("CATEGORIES", "CATEGORY 3"));
111         ASSERT_EQ(TextExample1TestResult, ProcessTextVectors(&TextPropertiesExample1, &TextValueExample1, true, "CATEGORIES"));
113         TextExample1TestResult.clear();
114         TextExample1TestResult.insert(make_pair("CATEGORIES", "CATEGORY 1"));
116         // Examples 5 & 6: COMMENT
118         ASSERT_EQ(TextExample1TestResult, ProcessTextVectors(&TextPropertiesExample1, &TextValueExample1, false, "CATEGORIES"));
120         TextExample1TestResult.clear();
121         TextExample1TestResult.insert(make_pair("COMMENT", "This is the first comment."));
122         TextExample1TestResult.insert(make_pair("COMMENT", "This is the second comment."));
123         TextExample1TestResult.insert(make_pair("COMMENT", "This is the third comment."));
124         
125         ASSERT_EQ(TextExample1TestResult, ProcessTextVectors(&TextPropertiesExample1, &TextValueExample1, true, "COMMENT"));
127         TextExample1TestResult.clear();
128         TextExample1TestResult.insert(make_pair("COMMENT", "This is the first comment."));
130         // Examples 7 & 8: CONTACT;(properties)
132         ASSERT_EQ(TextExample1TestResult, ProcessTextVectors(&TextPropertiesExample1, &TextValueExample1, false, "COMMENT"));
134         TextExample1TestResult.clear();
135         TextExample1TestResult.insert(make_pair("CONTACT;TEST=VALUE", "First Contact"));
136         TextExample1TestResult.insert(make_pair("CONTACT;LAZY=NOPE", "Second Contact"));
137         TextExample1TestResult.insert(make_pair("CONTACT;SETUP=NO", "Third Contact"));
138         
139         ASSERT_EQ(TextExample1TestResult, ProcessTextVectors(&TextPropertiesExample1, &TextValueExample1, true, "CONTACT"));
141         TextExample1TestResult.clear();
142         TextExample1TestResult.insert(make_pair("CONTACT;TEST=VALUE", "First Contact"));
144         // Examples 9 & 10: RESOURCES;(properties)
146         ASSERT_EQ(TextExample1TestResult, ProcessTextVectors(&TextPropertiesExample1, &TextValueExample1, false, "CONTACT"));
148         TextExample1TestResult.clear();
149         TextExample1TestResult.insert(make_pair("RESOURCES;ROOM=YES", "First Resource Widget"));
150         TextExample1TestResult.insert(make_pair("RESOURCES;ROOM=NO", "Second Resource Widget"));
151         TextExample1TestResult.insert(make_pair("RESOURCES;ROOM=UNKNOWN", "Third Resource Widget"));
153         ASSERT_EQ(TextExample1TestResult, ProcessTextVectors(&TextPropertiesExample1, &TextValueExample1, true, "RESOURCES"));
155         TextExample1TestResult.clear();
156         TextExample1TestResult.insert(make_pair("RESOURCES;ROOM=YES", "First Resource Widget"));
158         ASSERT_EQ(TextExample1TestResult, ProcessTextVectors(&TextPropertiesExample1, &TextValueExample1, false, "RESOURCES"));
160         // Examples 11 & 12: RELATED;(properties)
162         TextExample1TestResult.clear();
163         TextExample1TestResult.insert(make_pair("RELATED;RELATION=NO", "First Relation"));
164         TextExample1TestResult.insert(make_pair("RELATED;RELATION=YES", "Second Relation"));
165         TextExample1TestResult.insert(make_pair("RELATED;RELATION=MAYBE", "Third Relation"));
167         ASSERT_EQ(TextExample1TestResult, ProcessTextVectors(&TextPropertiesExample1, &TextValueExample1, true, "RELATED"));
169         TextExample1TestResult.clear();
170         TextExample1TestResult.insert(make_pair("RELATED;RELATION=NO", "First Relation"));
172         ASSERT_EQ(TextExample1TestResult, ProcessTextVectors(&TextPropertiesExample1, &TextValueExample1, false, "RELATED"));
176 TEST(CommonFunctions, SplitValuesTests){
177         
178         map<string, string> TextExample1TestResult;
179         
180         TextExample1TestResult.insert(make_pair("RELATION", "NO"));
181         TextExample1TestResult.insert(make_pair("TEST", "YES"));
182         TextExample1TestResult.insert(make_pair("DATA", "SOMEDATA"));
183         
184         ASSERT_EQ(TextExample1TestResult, SplitValues("TEST;RELATION=NO;TEST=YES;DATA=SOMEDATA"));
185         
188 TEST(CommonFunctions, SplitNameValueTests){
189         
190         PropertyNameValue NameValueResult;
191                 
192         NameValueResult = SplitNameValue("TEST=OK");
193         
194         string PropertyName = NameValueResult.Name;
195         string PropertyValue = NameValueResult.Value;
196         
197         ASSERT_EQ(PropertyName, "TEST");
198         ASSERT_EQ(PropertyValue, "OK");
199         
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy