Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmPreferences: Removed std::cout printing contact background colour
[xestiaab/.git] / source / tests / xestiaab_common.h
1  // xestiaab_common.h - Xestia Address Book Common Functions Unit Tests.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
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 Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include <gtest/gtest.h>
20 #include "../common/dirs.h"
21 #include "../common/filename.h"
22 #include "../common/mime.h"
23 #include "../common/svrblist.h"
24 #include "../common/textprocessing.h"
26 TEST(CommonFunctions, GetUserDir){
27         
28         // Run the unit tests depending on the operating system being used.
29         
30 #if defined(__WIN32__)
31         
32 #elif defined(__APPLE__)
33         
34 #else
35         
36         // Setup for comparison purposes. Should be /home/<user>/.xestiaab
37         
38         wxString UserDirCheck = "";
39         UserDirCheck.Append(wxString::FromUTF8(getenv("HOME")));
40         UserDirCheck.Append(wxT("/.xestiaab/"));
41         
42         wxString UserDir = GetUserDir();
43         
44         ASSERT_EQ(UserDir, UserDirCheck);
45         
46 #endif
47         
48 }
50 TEST(CommonFunctions, GetUserPrefDir){
51         
52         // Run the unit tests depending on the operating system being used.
53         
54 #if defined(__WIN32__)
55         
56 #elif defined(__APPLE__)
57         
58 #else
59         
60         // Setup for comparison purposes. Should be /home/<user>/.xestiaab/preferences
61         
62         wxString UserDirCheck = "";
63         UserDirCheck.Append(wxString::FromUTF8(getenv("HOME")));
64         UserDirCheck.Append(wxT("/.xestiaab/preferences/"));
65         
66         wxString UserDir = GetUserPrefDir();
67                 ASSERT_EQ(UserDir, UserDirCheck);
68         
69 #endif
70         
71 }
73 TEST(CommonFunctions, GetAccountDir){
74         
75         // Run the unit tests depending on the operating system being used.
76         
77 #if defined(__WIN32__)
78         
79 #elif defined(__APPLE__)
80         
81 #else
82         
83         // Setup for comparison purposes. Should be /home/<user>/.xestiaab/preferences
84         
85         wxString AccountDirCheck1 = "";
86         wxString AccountDirCheck2 = "";
87         wxString AccountDirCheck3 = "";
88         
89         wxString AccountDirInput1 = "Example1";
90         wxString AccountDirInput2 = "Example2";
91         wxString AccountDirInput3 = "Example3";
92         
93         AccountDirCheck1.Append(wxString::FromUTF8(getenv("HOME")));
94         AccountDirCheck1.Append(wxT("/.xestiaab/accounts/"));
95         AccountDirCheck1.Append("Example1");
96         AccountDirCheck1.Append(wxT("/"));
98         AccountDirCheck2.Append(wxString::FromUTF8(getenv("HOME")));
99         AccountDirCheck2.Append(wxT("/.xestiaab/accounts/"));
100         AccountDirCheck2.Append("Example2");
101         AccountDirCheck2.Append(wxT("/"));      
102         
103         AccountDirCheck3.Append(wxString::FromUTF8(getenv("HOME")));
104         AccountDirCheck3.Append(wxT("/.xestiaab/accounts/"));
105         AccountDirCheck3.Append("Example3");
106         AccountDirCheck3.Append(wxT("/"));
107         
108         wxString AccountDir1 = GetAccountDir(AccountDirInput1, false);
109         wxString AccountDir2 = GetAccountDir(AccountDirInput2, false);
110         wxString AccountDir3 = GetAccountDir(AccountDirInput3, false);
112         ASSERT_EQ(AccountDir1, AccountDirCheck1);
113         ASSERT_EQ(AccountDir2, AccountDirCheck2);
114         ASSERT_EQ(AccountDir3, AccountDirCheck3);
115         
116 #endif
117         
120 TEST(CommonFunctions, GetAccountDirCertificate){
121         
122         // Run the unit tests depending on the operating system being used.
123         
124 #if defined(__WIN32__)
125         
126 #elif defined(__APPLE__)
127         
128 #else
129         
130         // Setup for comparison purposes. Should be /home/<user>/.xestiaab/preferences
131         
132         wxString AccountDirCheck1 = "";
133         wxString AccountDirCheck2 = "";
134         wxString AccountDirCheck3 = "";
135         
136         wxString AccountDirInput1 = "Example1";
137         wxString AccountDirInput2 = "Example2";
138         wxString AccountDirInput3 = "Example3";
139         
140         AccountDirCheck1.Append(wxString::FromUTF8(getenv("HOME")));
141         AccountDirCheck1.Append(wxT("/.xestiaab/accounts/"));
142         AccountDirCheck1.Append("Example1");
143         AccountDirCheck1.Append(wxT("/server.crt"));
145         AccountDirCheck2.Append(wxString::FromUTF8(getenv("HOME")));
146         AccountDirCheck2.Append(wxT("/.xestiaab/accounts/"));
147         AccountDirCheck2.Append("Example2");
148         AccountDirCheck2.Append(wxT("/server.crt"));
149         
150         AccountDirCheck3.Append(wxString::FromUTF8(getenv("HOME")));
151         AccountDirCheck3.Append(wxT("/.xestiaab/accounts/"));
152         AccountDirCheck3.Append("Example3");
153         AccountDirCheck3.Append(wxT("/server.crt"));
154         
155         wxString AccountDir1 = GetAccountDir(AccountDirInput1, true);
156         wxString AccountDir2 = GetAccountDir(AccountDirInput2, true);
157         wxString AccountDir3 = GetAccountDir(AccountDirInput3, true);
159         ASSERT_EQ(AccountDir1, AccountDirCheck1);
160         ASSERT_EQ(AccountDir2, AccountDirCheck2);
161         ASSERT_EQ(AccountDir3, AccountDirCheck3);
162         
163 #endif
164         
167 TEST(CommonFunctions, GetAccountsFile){
168         
169         // Run the unit tests depending on the operating system being used.
170         
171 #if defined(__WIN32__)
172         
173 #elif defined(__APPLE__)
174         
175 #else
176         
177         // Setup for comparison purposes. Should be 
178         // /home/<user>/.xestiaab/preferences/accounts
179         
180         wxString AccountsFileCheck = "";
181         AccountsFileCheck.Clear();
182         AccountsFileCheck.Append(wxString::FromUTF8(getenv("HOME")));
183         AccountsFileCheck.Append(wxT("/.xestiaab/preferences/accounts"));
184         
185         wxString AccountsFile = GetAccountsFile();
186         
187         ASSERT_EQ(AccountsFile, AccountsFileCheck);
188         
189 #endif
190         
193 TEST(CommonFunctions, GetSettingsFile){
194         
195         // Run the unit tests depending on the operating system being used.
196         
197 #if defined(__WIN32__)
198         
199 #elif defined(__APPLE__)
200         
201 #else
202         
203         // Setup for comparison purposes. Should be 
204         // /home/<user>/.xestiaab/preferences/accounts
205         
206         wxString SettingsFileCheck = "";
207         SettingsFileCheck.Clear();
208         SettingsFileCheck.Append(wxString::FromUTF8(getenv("HOME")));
209         SettingsFileCheck.Append(wxT("/.xestiaab/preferences/settings"));
210         
211         wxString SettingsFile = GetSettingsFile();
212         
213         ASSERT_EQ(SettingsFile, SettingsFileCheck);
214         
215 #endif
216         
219 TEST(CommonFunctions, CreateFilenamePath){
220         
221         // Run the unit tests depending on the operating system being used.
222         
223 #if defined(__WIN32__)
224         
225 #elif defined(__APPLE__)
226         
227 #else
228                 
229         ASSERT_EQ("/test", CreateFilenamePath("", "test"));
230         ASSERT_EQ("/example/test", CreateFilenamePath("/example", "test"));
231         ASSERT_EQ("/home/meep/test", CreateFilenamePath("/home/meep", "test"));
232         ASSERT_EQ("/home/meep/moo/test", CreateFilenamePath("/home/meep/moo", "test"));
233         ASSERT_EQ("/home/meep/moo/yargh/test", CreateFilenamePath("/home/meep/moo/yargh", "test"));
234         
235 #endif
236         
239 TEST(CommonFunctions, GetMIME){
240         
241         // Get the MIME type based on the files given.
242         
243         ASSERT_EQ("text/plain", GetMIME("TextMIMEExample.txt"));
244         ASSERT_EQ("image/png", GetMIME("PictureMIMEExample.png"));
245         
248 TEST(CommonFunctions, CheckBlacklist){
249         
250         // Test that the blacklist is actually working.
251         
252         ASSERT_EQ(false, CheckBlacklist("example.com"));
253         ASSERT_EQ(true, CheckBlacklist("google.com"));
254         
257 TEST(CommonFunctions, EscapeString){
259         // Test the escape string function.
261         wxString EscapeStringData = "Example";
262         EscapeString(&EscapeStringData, false);
263         ASSERT_EQ("Example", EscapeStringData.ToStdString());
265         EscapeStringData = "Here we go, an \"example\" of escaping string.";
266         EscapeString(&EscapeStringData, false);
267         ASSERT_EQ("Here we go\\, an \"example\" of escaping string.", EscapeStringData.ToStdString());
269         EscapeStringData = "Lets put some \nnew \nlines \nin \nhere.";
270         EscapeString(&EscapeStringData, false);
271         ASSERT_EQ("Lets put some \\nnew \\nlines \\nin \\nhere.", EscapeStringData.ToStdString());
273         EscapeStringData = "Lets put some \r\nnew \r\nlines \r\nin \r\nhere.";
274         EscapeString(&EscapeStringData, false);
275         ASSERT_EQ("Lets put some \\nnew \\nlines \\nin \\nhere.", EscapeStringData.ToStdString());
277         EscapeStringData = "A:\\path\\example\\lets\\have\\some\\fun";
278         EscapeString(&EscapeStringData, false);
279         ASSERT_EQ("A:\\\\path\\\\example\\\\lets\\\\have\\\\some\\\\fun", EscapeStringData.ToStdString());
283 TEST(CommonFunctions, CaptureString){
285         // Test the capture string function.
286         
287         wxString CaptureStringData = "Example";
288         CaptureString(&CaptureStringData, false);
289         ASSERT_EQ("Example", CaptureStringData.ToStdString());
291         CaptureStringData = "Here we go\\, an \"example\" of escaping string.";
292         CaptureString(&CaptureStringData, false);
293         ASSERT_EQ("Here we go, an \"example\" of escaping string.", CaptureStringData.ToStdString());
295         CaptureStringData = "Lets put some \\nnew \\nlines \\nin \\nhere.";
296         CaptureString(&CaptureStringData, false);
297         ASSERT_EQ("Lets put some \nnew \nlines \nin \nhere.", CaptureStringData.ToStdString());
299         CaptureStringData = "A:\\\\path\\\\example\\\\lets\\\\have\\\\some\\\\fun";
300         CaptureString(&CaptureStringData, false);
301         ASSERT_EQ("A:\\path\\example\\lets\\have\\some\\fun", CaptureStringData.ToStdString());
305 TEST(CommonFunctions, ResetUnusedString){
307         // Tests for resetting an unused string.
309         wxString ResetUnusedStringData = "Random string with a \\\\\\\\serverpath\\\\location";
310         ResetUnusedString(&ResetUnusedStringData);
311         ASSERT_EQ("Random string with a \\\\serverpath\\location", ResetUnusedStringData.ToStdString());        
313         ResetUnusedStringData = "Some text \\nwith new \\nlines!";
314         ResetUnusedString(&ResetUnusedStringData);
315         ASSERT_EQ("Some text \nwith new \nlines!", ResetUnusedStringData.ToStdString());
317         ResetUnusedStringData = "Some text \\nwith new \\nlines!";
318         ResetUnusedString(&ResetUnusedStringData);
319         ASSERT_EQ("Some text \nwith new \nlines!", ResetUnusedStringData.ToStdString());
320         
321         ResetUnusedStringData = "And now the list of characters: \\\\ \\n \\; \\,";
322         ResetUnusedString(&ResetUnusedStringData);
323         ASSERT_EQ("And now the list of characters: \\ \n ; ,", ResetUnusedStringData.ToStdString());
327 TEST(CommonFunctions, ConvertToHTML){
329         // Tests for converting data for inserting into a HTML
330         // formatted document.
332         wxString ConvertToHTMLData = "The test line where < is probably better than >!";
333         ConvertToHTML(&ConvertToHTMLData);
334         ASSERT_EQ("The test line where &lt; is probably better than &gt;!", ConvertToHTMLData.ToStdString());
336         ConvertToHTMLData = "More testing &<>\n";
337         ConvertToHTML(&ConvertToHTMLData);
338         ASSERT_EQ("More testing &amp;&lt;&gt;<br>", ConvertToHTMLData.ToStdString());
340         ConvertToHTMLData = "This is the first line.\nThis is the second line.\nThis is the third line.";
341         ConvertToHTML(&ConvertToHTMLData);
342         ASSERT_EQ("This is the first line.<br>This is the second line.<br>This is the third line.", ConvertToHTMLData.ToStdString());
346 TEST(CommonFunctions, MapDataExists){
348         // Tests for checking that map data exists.
350         std::map<int,int> MapExample;
351         int ItemIndex = 0;
353         MapExample.insert(std::make_pair(0,1));
354         MapExample.insert(std::make_pair(1,1));
355         MapExample.insert(std::make_pair(2,1));
356         MapExample.insert(std::make_pair(5,1));
357         MapExample.insert(std::make_pair(500,1));
358         MapExample.insert(std::make_pair(2415,1));
360         ASSERT_EQ(true, MapDataExists(&ItemIndex, &MapExample));
362         ItemIndex = 1;
363         ASSERT_EQ(true, MapDataExists(&ItemIndex, &MapExample));
365         ItemIndex = 2;
366         ASSERT_EQ(true, MapDataExists(&ItemIndex, &MapExample));
368         ItemIndex = 3;
369         ASSERT_EQ(false, MapDataExists(&ItemIndex, &MapExample));
371         ItemIndex = 5;
372         ASSERT_EQ(true, MapDataExists(&ItemIndex, &MapExample));
374         ItemIndex = 6;
375         ASSERT_EQ(false, MapDataExists(&ItemIndex, &MapExample));
377         ItemIndex = 499;
378         ASSERT_EQ(false, MapDataExists(&ItemIndex, &MapExample));
380         ItemIndex = 500;
381         ASSERT_EQ(true, MapDataExists(&ItemIndex, &MapExample));
383         ItemIndex = 501;
384         ASSERT_EQ(false, MapDataExists(&ItemIndex, &MapExample));
386         ItemIndex = 2414;
387         ASSERT_EQ(false, MapDataExists(&ItemIndex, &MapExample));
389         ItemIndex = 2415;
390         ASSERT_EQ(true, MapDataExists(&ItemIndex, &MapExample));
392         ItemIndex = 2416;
393         ASSERT_EQ(false, MapDataExists(&ItemIndex, &MapExample));
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