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"
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();
67 ASSERT_EQ(UserDir, UserDirCheck);
73 TEST(CommonFunctions, GetAccountDir){
75 // Run the unit tests depending on the operating system being used.
77 #if defined(__WIN32__)
79 #elif defined(__APPLE__)
83 // Setup for comparison purposes. Should be /home/<user>/.xestiaab/preferences
85 wxString AccountDirCheck1 = "";
86 wxString AccountDirCheck2 = "";
87 wxString AccountDirCheck3 = "";
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("/"));
99 AccountDirCheck3.Append(wxString::FromUTF8(getenv("HOME")));
100 AccountDirCheck3.Append(wxT("/.xestiaab/accounts/"));
101 AccountDirCheck3.Append("Example3");
102 AccountDirCheck3.Append(wxT("/"));
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);
116 TEST(CommonFunctions, GetAccountDirCertificate){
118 // Run the unit tests depending on the operating system being used.
120 #if defined(__WIN32__)
122 #elif defined(__APPLE__)
126 // Setup for comparison purposes. Should be /home/<user>/.xestiaab/preferences
128 wxString AccountDirCheck1 = "";
129 wxString AccountDirCheck2 = "";
130 wxString AccountDirCheck3 = "";
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"));
142 AccountDirCheck3.Append(wxString::FromUTF8(getenv("HOME")));
143 AccountDirCheck3.Append(wxT("/.xestiaab/accounts/"));
144 AccountDirCheck3.Append("Example3");
145 AccountDirCheck3.Append(wxT("/server.crt"));
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);
159 TEST(CommonFunctions, GetAccountsFile){
161 // Run the unit tests depending on the operating system being used.
163 #if defined(__WIN32__)
165 #elif defined(__APPLE__)
169 // Setup for comparison purposes. Should be
170 // /home/<user>/.xestiaab/preferences/accounts
172 wxString AccountsFileCheck = "";
173 AccountsFileCheck.Clear();
174 AccountsFileCheck.Append(wxString::FromUTF8(getenv("HOME")));
175 AccountsFileCheck.Append(wxT("/.xestiaab/preferences/accounts"));
177 wxString AccountsFile = GetAccountsFile();
179 ASSERT_EQ(AccountsFile, AccountsFileCheck);
185 TEST(CommonFunctions, GetSettingsFile){
187 // Run the unit tests depending on the operating system being used.
189 #if defined(__WIN32__)
191 #elif defined(__APPLE__)
195 // Setup for comparison purposes. Should be
196 // /home/<user>/.xestiaab/preferences/accounts
198 wxString SettingsFileCheck = "";
199 SettingsFileCheck.Clear();
200 SettingsFileCheck.Append(wxString::FromUTF8(getenv("HOME")));
201 SettingsFileCheck.Append(wxT("/.xestiaab/preferences/settings"));
203 wxString SettingsFile = GetSettingsFile();
205 ASSERT_EQ(SettingsFile, SettingsFileCheck);
211 TEST(CommonFunctions, CreateFilenamePath){
213 // Run the unit tests depending on the operating system being used.
215 #if defined(__WIN32__)
217 #elif defined(__APPLE__)
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"));
231 TEST(CommonFunctions, GetMIME){
233 // Get the MIME type based on the files given.
235 ASSERT_EQ("text/plain", GetMIME("TextMIMEExample.txt"));
236 ASSERT_EQ("image/png", GetMIME("PictureMIMEExample.png"));
240 TEST(CommonFunctions, CheckBlacklist){
242 // Test that the blacklist is actually working.
244 ASSERT_EQ(false, CheckBlacklist("example.com"));
245 ASSERT_EQ(true, CheckBlacklist("google.com"));