1 // xestiaab_common.h - Xestia Address Book Common Functions Unit Tests.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
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 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"
25 TEST(CommonFunctions, GetUserDir){
27 // Run the unit tests depending on the operating system being used.
29 #if defined(__WIN32__)
31 #elif defined(__APPLE__)
35 // Setup for comparison purposes. Should be /home/<user>/.xestiaab
37 wxString UserDirCheck = "";
38 UserDirCheck.Append(wxString::FromUTF8(getenv("HOME")));
39 UserDirCheck.Append(wxT("/.xestiaab/"));
41 wxString UserDir = GetUserDir();
43 ASSERT_EQ(UserDir, UserDirCheck);
49 TEST(CommonFunctions, GetUserPrefDir){
51 // Run the unit tests depending on the operating system being used.
53 #if defined(__WIN32__)
55 #elif defined(__APPLE__)
59 // Setup for comparison purposes. Should be /home/<user>/.xestiaab/preferences
61 wxString UserDirCheck = "";
62 UserDirCheck.Append(wxString::FromUTF8(getenv("HOME")));
63 UserDirCheck.Append(wxT("/.xestiaab/preferences/"));
65 wxString UserDir = GetUserPrefDir();
66 ASSERT_EQ(UserDir, UserDirCheck);
72 TEST(CommonFunctions, GetAccountDir){
74 // Run the unit tests depending on the operating system being used.
76 #if defined(__WIN32__)
78 #elif defined(__APPLE__)
82 // Setup for comparison purposes. Should be /home/<user>/.xestiaab/preferences
84 wxString AccountDirCheck1 = "";
85 wxString AccountDirCheck2 = "";
86 wxString AccountDirCheck3 = "";
88 AccountDirCheck1.Append(wxString::FromUTF8(getenv("HOME")));
89 AccountDirCheck1.Append(wxT("/.xestiaab/accounts/"));
90 AccountDirCheck1.Append("Example1");
91 AccountDirCheck1.Append(wxT("/"));
93 AccountDirCheck2.Append(wxString::FromUTF8(getenv("HOME")));
94 AccountDirCheck2.Append(wxT("/.xestiaab/accounts/"));
95 AccountDirCheck2.Append("Example2");
96 AccountDirCheck2.Append(wxT("/"));
98 AccountDirCheck3.Append(wxString::FromUTF8(getenv("HOME")));
99 AccountDirCheck3.Append(wxT("/.xestiaab/accounts/"));
100 AccountDirCheck3.Append("Example3");
101 AccountDirCheck3.Append(wxT("/"));
103 wxString AccountDir1 = GetAccountDir("Example1", false);
104 wxString AccountDir2 = GetAccountDir("Example2", false);
105 wxString AccountDir3 = GetAccountDir("Example3", false);
107 ASSERT_EQ(AccountDir1, AccountDirCheck1);
108 ASSERT_EQ(AccountDir2, AccountDirCheck2);
109 ASSERT_EQ(AccountDir3, AccountDirCheck3);
115 TEST(CommonFunctions, GetAccountDirCertificate){
117 // Run the unit tests depending on the operating system being used.
119 #if defined(__WIN32__)
121 #elif defined(__APPLE__)
125 // Setup for comparison purposes. Should be /home/<user>/.xestiaab/preferences
127 wxString AccountDirCheck1 = "";
128 wxString AccountDirCheck2 = "";
129 wxString AccountDirCheck3 = "";
131 AccountDirCheck1.Append(wxString::FromUTF8(getenv("HOME")));
132 AccountDirCheck1.Append(wxT("/.xestiaab/accounts/"));
133 AccountDirCheck1.Append("Example1");
134 AccountDirCheck1.Append(wxT("/server.crt"));
136 AccountDirCheck2.Append(wxString::FromUTF8(getenv("HOME")));
137 AccountDirCheck2.Append(wxT("/.xestiaab/accounts/"));
138 AccountDirCheck2.Append("Example2");
139 AccountDirCheck2.Append(wxT("/server.crt"));
141 AccountDirCheck3.Append(wxString::FromUTF8(getenv("HOME")));
142 AccountDirCheck3.Append(wxT("/.xestiaab/accounts/"));
143 AccountDirCheck3.Append("Example3");
144 AccountDirCheck3.Append(wxT("/server.crt"));
146 wxString AccountDir1 = GetAccountDir("Example1", true);
147 wxString AccountDir2 = GetAccountDir("Example2", true);
148 wxString AccountDir3 = GetAccountDir("Example3", true);
150 ASSERT_EQ(AccountDir1, AccountDirCheck1);
151 ASSERT_EQ(AccountDir2, AccountDirCheck2);
152 ASSERT_EQ(AccountDir3, AccountDirCheck3);
158 TEST(CommonFunctions, GetAccountsFile){
160 // Run the unit tests depending on the operating system being used.
162 #if defined(__WIN32__)
164 #elif defined(__APPLE__)
168 // Setup for comparison purposes. Should be
169 // /home/<user>/.xestiaab/preferences/accounts
171 wxString AccountsFileCheck = "";
172 AccountsFileCheck.Clear();
173 AccountsFileCheck.Append(wxString::FromUTF8(getenv("HOME")));
174 AccountsFileCheck.Append(wxT("/.xestiaab/preferences/accounts"));
176 wxString AccountsFile = GetAccountsFile();
178 ASSERT_EQ(AccountsFile, AccountsFileCheck);
184 TEST(CommonFunctions, GetSettingsFile){
186 // Run the unit tests depending on the operating system being used.
188 #if defined(__WIN32__)
190 #elif defined(__APPLE__)
194 // Setup for comparison purposes. Should be
195 // /home/<user>/.xestiaab/preferences/accounts
197 wxString SettingsFileCheck = "";
198 SettingsFileCheck.Clear();
199 SettingsFileCheck.Append(wxString::FromUTF8(getenv("HOME")));
200 SettingsFileCheck.Append(wxT("/.xestiaab/preferences/settings"));
202 wxString SettingsFile = GetSettingsFile();
204 ASSERT_EQ(SettingsFile, SettingsFileCheck);
210 TEST(CommonFunctions, CreateFilenamePath){
212 // Run the unit tests depending on the operating system being used.
214 #if defined(__WIN32__)
216 #elif defined(__APPLE__)
220 ASSERT_EQ("/test", CreateFilenamePath("", "test"));
221 ASSERT_EQ("/example/test", CreateFilenamePath("/example", "test"));
222 ASSERT_EQ("/home/meep/test", CreateFilenamePath("/home/meep", "test"));
223 ASSERT_EQ("/home/meep/moo/test", CreateFilenamePath("/home/meep/moo", "test"));
224 ASSERT_EQ("/home/meep/moo/yargh/test", CreateFilenamePath("/home/meep/moo/yargh", "test"));
230 TEST(CommonFunctions, GetMIME){
232 // Get the MIME type based on the files given.
234 ASSERT_EQ("text/plain", GetMIME("TextMIMEExample.txt"));
235 ASSERT_EQ("image/png", GetMIME("PictureMIMEExample.png"));
239 TEST(CommonFunctions, CheckBlacklist){
241 // Test that the blacklist is actually working.
243 ASSERT_EQ(false, CheckBlacklist("example.com"));
244 ASSERT_EQ(true, CheckBlacklist("google.com"));
248 TEST(CommonFunctions, EscapeString){
250 // Test the escape string function.
252 EscapeStringData = "\"Example\"";
254 ASSERT_EQ("\\\"Example\\\"", EscapeStringData(&EscapeStringData, false));
256 EscapeStringData = "Here we go, an \"example\" of escaping string.";
258 ASSERT_EQ("Here we go\\, an \\\"example\\\" of escaping string.", EscapeStringData(&EscapeStringData, false));
260 EscapeStringData = "Lets put some \nnew \nlines \nin \nhere.";
262 ASSERT_EQ("Lets put some \\nnew \\nlines \\nin \\nhere.", EscapeStringData(&EscapeStringData, false));
264 EscapeStringData = "Lets put some \r\nnew \r\nlines \r\nin \r\nhere.";
266 ASSERT_EQ("Lets put some \\nnew \\nlines \\nin \\nhere.", EscapeStringData(&EscapeStringData, false));
268 EscapeStringData = "A:\path\example\lets\have\some\fun";
270 ASSERT_EQ("A:\\path\\example\\lets\\have\\some\\fun", EscapeStringData(&EscapeStringData, false));
275 TEST(CommonFunctions, GetEscapeString){
279 TEST(CommonFunctions, CaptureString){
283 TEST(CommonFunctions, ResetUnusedString){
287 TEST(CommonFunctions, ConvertToHTML){
291 TEST(CommonFunctions, DeleteMapDataProcess){
295 TEST(CommonFunctions, MapDataExists){