1 // xestiacalendar_commonfunctions.h - Xestia Calendar Common Functions Unit Tests
3 // (c) 2016 Xestia Software Development.
5 // This file is part of Xestia Calendar.
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.
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.
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){
24 ASSERT_EQ(false, FileExists("iCalendarEvent-Missing.vcf"));
25 ASSERT_EQ(true, FileExists("iCalendarEvent-InvalidPermissions.vcf"));
29 TEST(CommonFunctions, ProcessTextVectorsTests){
31 // Setup the objects to be used for processing.
33 vector<string> TextPropertiesExample1;
34 vector<string> TextValueExample1;
35 multimap<string, string> TextExample1TestResult;
37 TextPropertiesExample1.push_back("ATTENDEE");
38 TextValueExample1.push_back("Example Attendee 1");
40 TextPropertiesExample1.push_back("ATTENDEE");
41 TextValueExample1.push_back("Example Attendee 2");
43 TextPropertiesExample1.push_back("ATTENDEE");
44 TextValueExample1.push_back("Example Attendee 3");
46 TextPropertiesExample1.push_back("CATEGORIES");
47 TextValueExample1.push_back("CATEGORY 1");
49 TextPropertiesExample1.push_back("CATEGORIES");
50 TextValueExample1.push_back("CATEGORY 2");
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.");
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");
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"));
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."));
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"));
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){
178 map<string, string> TextExample1TestResult;
180 TextExample1TestResult.insert(make_pair("RELATION", "NO"));
181 TextExample1TestResult.insert(make_pair("TEST", "YES"));
182 TextExample1TestResult.insert(make_pair("DATA", "SOMEDATA"));
184 ASSERT_EQ(TextExample1TestResult, SplitValues("TEST;RELATION=NO;TEST=YES;DATA=SOMEDATA"));
188 TEST(CommonFunctions, SplitNameValueTests){
190 PropertyNameValue NameValueResult;
192 NameValueResult = SplitNameValue("TEST=OK");
194 string PropertyName = NameValueResult.Name;
195 string PropertyValue = NameValueResult.Value;
197 ASSERT_EQ(PropertyName, "TEST");
198 ASSERT_EQ(PropertyValue, "OK");
202 TEST(CommonFunctions, HexToInt){
204 string Value1 = "10"; // 16
205 string Value2 = "50"; // 80
206 string Value3 = "4F"; // 79
207 string Value4 = "FF"; // 255
208 string Value5 = "FFF"; // 4095
209 string Value6 = "FFFF"; // 65535
210 string Value7 = "75AB"; // 30123
211 string Value8 = "2AC"; // 684
212 string Value9 = "!"; // Fail
213 string Value10 = "4BZ"; // Fail
214 string Value11 = "Z?!$"; // Fail
219 Result = HexToInt(&Value1, &OutputValue);
221 ASSERT_EQ(Result, true);
222 ASSERT_EQ(OutputValue, 16);
224 Result = HexToInt(&Value2, &OutputValue);
225 ASSERT_EQ(Result, true);
226 ASSERT_EQ(OutputValue, 80);
228 Result = HexToInt(&Value3, &OutputValue);
229 ASSERT_EQ(Result, true);
230 ASSERT_EQ(OutputValue, 79);
232 Result = HexToInt(&Value4, &OutputValue);
233 ASSERT_EQ(Result, true);
234 ASSERT_EQ(OutputValue, 255);
236 Result = HexToInt(&Value5, &OutputValue);
237 ASSERT_EQ(Result, true);
238 ASSERT_EQ(OutputValue, 4095);
240 Result = HexToInt(&Value6, &OutputValue);
241 ASSERT_EQ(Result, true);
242 ASSERT_EQ(OutputValue, 65535);
244 Result = HexToInt(&Value7, &OutputValue);
245 ASSERT_EQ(Result, true);
246 ASSERT_EQ(OutputValue, 30123);
248 Result = HexToInt(&Value8, &OutputValue);
249 ASSERT_EQ(Result, true);
250 ASSERT_EQ(OutputValue, 684);
252 Result = HexToInt(&Value9, &OutputValue);
253 ASSERT_EQ(Result, false);
255 Result = HexToInt(&Value10, &OutputValue);
256 ASSERT_EQ(Result, false);
258 Result = HexToInt(&Value11, &OutputValue);
259 ASSERT_EQ(Result, false);