Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added unit tests for checking if data within a map exists.
[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         AccountDirCheck1.Append(wxString::FromUTF8(getenv("HOME")));
90         AccountDirCheck1.Append(wxT("/.xestiaab/accounts/"));
91         AccountDirCheck1.Append("Example1");
92         AccountDirCheck1.Append(wxT("/"));
94         AccountDirCheck2.Append(wxString::FromUTF8(getenv("HOME")));
95         AccountDirCheck2.Append(wxT("/.xestiaab/accounts/"));
96         AccountDirCheck2.Append("Example2");
97         AccountDirCheck2.Append(wxT("/"));      
98         
99         AccountDirCheck3.Append(wxString::FromUTF8(getenv("HOME")));
100         AccountDirCheck3.Append(wxT("/.xestiaab/accounts/"));
101         AccountDirCheck3.Append("Example3");
102         AccountDirCheck3.Append(wxT("/"));
103         
104         wxString AccountDir1 = GetAccountDir("Example1", false);
105         wxString AccountDir2 = GetAccountDir("Example2", false);
106         wxString AccountDir3 = GetAccountDir("Example3", false);
108         ASSERT_EQ(AccountDir1, AccountDirCheck1);
109         ASSERT_EQ(AccountDir2, AccountDirCheck2);
110         ASSERT_EQ(AccountDir3, AccountDirCheck3);
111         
112 #endif
113         
116 TEST(CommonFunctions, GetAccountDirCertificate){
117         
118         // Run the unit tests depending on the operating system being used.
119         
120 #if defined(__WIN32__)
121         
122 #elif defined(__APPLE__)
123         
124 #else
125         
126         // Setup for comparison purposes. Should be /home/<user>/.xestiaab/preferences
127         
128         wxString AccountDirCheck1 = "";
129         wxString AccountDirCheck2 = "";
130         wxString AccountDirCheck3 = "";
131         
132         AccountDirCheck1.Append(wxString::FromUTF8(getenv("HOME")));
133         AccountDirCheck1.Append(wxT("/.xestiaab/accounts/"));
134         AccountDirCheck1.Append("Example1");
135         AccountDirCheck1.Append(wxT("/server.crt"));
137         AccountDirCheck2.Append(wxString::FromUTF8(getenv("HOME")));
138         AccountDirCheck2.Append(wxT("/.xestiaab/accounts/"));
139         AccountDirCheck2.Append("Example2");
140         AccountDirCheck2.Append(wxT("/server.crt"));
141         
142         AccountDirCheck3.Append(wxString::FromUTF8(getenv("HOME")));
143         AccountDirCheck3.Append(wxT("/.xestiaab/accounts/"));
144         AccountDirCheck3.Append("Example3");
145         AccountDirCheck3.Append(wxT("/server.crt"));
146         
147         wxString AccountDir1 = GetAccountDir("Example1", true);
148         wxString AccountDir2 = GetAccountDir("Example2", true);
149         wxString AccountDir3 = GetAccountDir("Example3", true);
151         ASSERT_EQ(AccountDir1, AccountDirCheck1);
152         ASSERT_EQ(AccountDir2, AccountDirCheck2);
153         ASSERT_EQ(AccountDir3, AccountDirCheck3);
154         
155 #endif
156         
159 TEST(CommonFunctions, GetAccountsFile){
160         
161         // Run the unit tests depending on the operating system being used.
162         
163 #if defined(__WIN32__)
164         
165 #elif defined(__APPLE__)
166         
167 #else
168         
169         // Setup for comparison purposes. Should be 
170         // /home/<user>/.xestiaab/preferences/accounts
171         
172         wxString AccountsFileCheck = "";
173         AccountsFileCheck.Clear();
174         AccountsFileCheck.Append(wxString::FromUTF8(getenv("HOME")));
175         AccountsFileCheck.Append(wxT("/.xestiaab/preferences/accounts"));
176         
177         wxString AccountsFile = GetAccountsFile();
178         
179         ASSERT_EQ(AccountsFile, AccountsFileCheck);
180         
181 #endif
182         
185 TEST(CommonFunctions, GetSettingsFile){
186         
187         // Run the unit tests depending on the operating system being used.
188         
189 #if defined(__WIN32__)
190         
191 #elif defined(__APPLE__)
192         
193 #else
194         
195         // Setup for comparison purposes. Should be 
196         // /home/<user>/.xestiaab/preferences/accounts
197         
198         wxString SettingsFileCheck = "";
199         SettingsFileCheck.Clear();
200         SettingsFileCheck.Append(wxString::FromUTF8(getenv("HOME")));
201         SettingsFileCheck.Append(wxT("/.xestiaab/preferences/settings"));
202         
203         wxString SettingsFile = GetSettingsFile();
204         
205         ASSERT_EQ(SettingsFile, SettingsFileCheck);
206         
207 #endif
208         
211 TEST(CommonFunctions, CreateFilenamePath){
212         
213         // Run the unit tests depending on the operating system being used.
214         
215 #if defined(__WIN32__)
216         
217 #elif defined(__APPLE__)
218         
219 #else
220                 
221         ASSERT_EQ("/test", CreateFilenamePath("", "test"));
222         ASSERT_EQ("/example/test", CreateFilenamePath("/example", "test"));
223         ASSERT_EQ("/home/meep/test", CreateFilenamePath("/home/meep", "test"));
224         ASSERT_EQ("/home/meep/moo/test", CreateFilenamePath("/home/meep/moo", "test"));
225         ASSERT_EQ("/home/meep/moo/yargh/test", CreateFilenamePath("/home/meep/moo/yargh", "test"));
226         
227 #endif
228         
231 TEST(CommonFunctions, GetMIME){
232         
233         // Get the MIME type based on the files given.
234         
235         ASSERT_EQ("text/plain", GetMIME("TextMIMEExample.txt"));
236         ASSERT_EQ("image/png", GetMIME("PictureMIMEExample.png"));
237         
240 TEST(CommonFunctions, CheckBlacklist){
241         
242         // Test that the blacklist is actually working.
243         
244         ASSERT_EQ(false, CheckBlacklist("example.com"));
245         ASSERT_EQ(true, CheckBlacklist("google.com"));
246         
249 TEST(CommonFunctions, EscapeString){
251         // Test the escape string function.
253         wxString EscapeStringData = "Example";
254         EscapeString(&EscapeStringData, false);
255         ASSERT_EQ("Example", EscapeStringData.ToStdString());
257         EscapeStringData = "Here we go, an \"example\" of escaping string.";
258         EscapeString(&EscapeStringData, false);
259         ASSERT_EQ("Here we go\\, an \"example\" of escaping string.", EscapeStringData.ToStdString());
261         EscapeStringData = "Lets put some \nnew \nlines \nin \nhere.";
262         EscapeString(&EscapeStringData, false);
263         ASSERT_EQ("Lets put some \\nnew \\nlines \\nin \\nhere.", EscapeStringData.ToStdString());
265         EscapeStringData = "Lets put some \r\nnew \r\nlines \r\nin \r\nhere.";
266         EscapeString(&EscapeStringData, false);
267         ASSERT_EQ("Lets put some \\nnew \\nlines \\nin \\nhere.", EscapeStringData.ToStdString());
269         EscapeStringData = "A:\\path\\example\\lets\\have\\some\\fun";
270         EscapeString(&EscapeStringData, false);
271         ASSERT_EQ("A:\\\\path\\\\example\\\\lets\\\\have\\\\some\\\\fun", EscapeStringData.ToStdString());
275 TEST(CommonFunctions, CaptureString){
277         // Test the capture string function.
278         
279         wxString CaptureStringData = "Example";
280         CaptureString(&CaptureStringData, false);
281         ASSERT_EQ("Example", CaptureStringData.ToStdString());
283         CaptureStringData = "Here we go\\, an \"example\" of escaping string.";
284         CaptureString(&CaptureStringData, false);
285         ASSERT_EQ("Here we go, an \"example\" of escaping string.", CaptureStringData.ToStdString());
287         CaptureStringData = "Lets put some \\nnew \\nlines \\nin \\nhere.";
288         CaptureString(&CaptureStringData, false);
289         ASSERT_EQ("Lets put some \nnew \nlines \nin \nhere.", CaptureStringData.ToStdString());
291         CaptureStringData = "A:\\\\path\\\\example\\\\lets\\\\have\\\\some\\\\fun";
292         CaptureString(&CaptureStringData, false);
293         ASSERT_EQ("A:\\path\\example\\lets\\have\\some\\fun", CaptureStringData.ToStdString());
297 TEST(CommonFunctions, ResetUnusedString){
299         // Tests for resetting an unused string.
301         wxString ResetUnusedStringData = "Random string with a \\\\\\\\serverpath\\\\location";
302         ResetUnusedString(&ResetUnusedStringData);
303         ASSERT_EQ("Random string with a \\\\serverpath\\location", ResetUnusedStringData.ToStdString());        
305         ResetUnusedStringData = "Some text \\nwith new \\nlines!";
306         ResetUnusedString(&ResetUnusedStringData);
307         ASSERT_EQ("Some text \nwith new \nlines!", ResetUnusedStringData.ToStdString());
309         ResetUnusedStringData = "Some text \\nwith new \\nlines!";
310         ResetUnusedString(&ResetUnusedStringData);
311         ASSERT_EQ("Some text \nwith new \nlines!", ResetUnusedStringData.ToStdString());
312         
313         ResetUnusedStringData = "And now the list of characters: \\\\ \\n \\; \\,";
314         ResetUnusedString(&ResetUnusedStringData);
315         ASSERT_EQ("And now the list of characters: \\ \n ; ,", ResetUnusedStringData.ToStdString());
319 TEST(CommonFunctions, ConvertToHTML){
321         // Tests for converting data for inserting into a HTML
322         // formatted document.
324         wxString ConvertToHTMLData = "The test line where < is probably better than >!";
325         ConvertToHTML(&ConvertToHTMLData);
326         ASSERT_EQ("The test line where &lt; is probably better than &gt;!", ConvertToHTMLData.ToStdString());
328         ConvertToHTMLData = "More testing &<>\n";
329         ConvertToHTML(&ConvertToHTMLData);
330         ASSERT_EQ("More testing &amp;&lt;&gt;<br>", ConvertToHTMLData.ToStdString());
332         ConvertToHTMLData = "This is the first line.\nThis is the second line.\nThis is the third line.";
333         ConvertToHTML(&ConvertToHTMLData);
334         ASSERT_EQ("This is the first line.<br>This is the second line.<br>This is the third line.", ConvertToHTMLData.ToStdString());
338 TEST(CommonFunctions, MapDataExists){
340         // Tests for checking that map data exists.
342         std::map<int,int> MapExample;
343         int ItemIndex = 0;
345         MapExample.insert(std::make_pair(0,1));
346         MapExample.insert(std::make_pair(1,1));
347         MapExample.insert(std::make_pair(2,1));
348         MapExample.insert(std::make_pair(5,1));
349         MapExample.insert(std::make_pair(500,1));
350         MapExample.insert(std::make_pair(2415,1));
352         ASSERT_EQ(true, MapDataExists(&ItemIndex, &MapExample));
354         ItemIndex = 1;
355         ASSERT_EQ(true, MapDataExists(&ItemIndex, &MapExample));
357         ItemIndex = 2;
358         ASSERT_EQ(true, MapDataExists(&ItemIndex, &MapExample));
360         ItemIndex = 3;
361         ASSERT_EQ(false, MapDataExists(&ItemIndex, &MapExample));
363         ItemIndex = 5;
364         ASSERT_EQ(true, MapDataExists(&ItemIndex, &MapExample));
366         ItemIndex = 6;
367         ASSERT_EQ(false, MapDataExists(&ItemIndex, &MapExample));
369         ItemIndex = 499;
370         ASSERT_EQ(false, MapDataExists(&ItemIndex, &MapExample));
372         ItemIndex = 500;
373         ASSERT_EQ(true, MapDataExists(&ItemIndex, &MapExample));
375         ItemIndex = 501;
376         ASSERT_EQ(false, MapDataExists(&ItemIndex, &MapExample));
378         ItemIndex = 2414;
379         ASSERT_EQ(false, MapDataExists(&ItemIndex, &MapExample));
381         ItemIndex = 2415;
382         ASSERT_EQ(true, MapDataExists(&ItemIndex, &MapExample));
384         ItemIndex = 2416;
385         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