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"
23 TEST(CommonFunctions, GetUserDir){
25 // Run the unit tests depending on the operating system being used.
27 #if defined(__WIN32__)
29 #elif defined(__APPLE__)
33 // Setup for comparison purposes. Should be /home/<user>/.xestiaab
35 wxString UserDirCheck = "";
36 UserDirCheck.Append(wxString::FromUTF8(getenv("HOME")));
37 UserDirCheck.Append(wxT("/.xestiaab/"));
39 wxString UserDir = GetUserDir();
41 ASSERT_EQ(UserDir, UserDirCheck);
47 TEST(CommonFunctions, GetUserPrefDir){
49 // Run the unit tests depending on the operating system being used.
51 #if defined(__WIN32__)
53 #elif defined(__APPLE__)
57 // Setup for comparison purposes. Should be /home/<user>/.xestiaab/preferences
59 wxString UserDirCheck = "";
60 UserDirCheck.Append(wxString::FromUTF8(getenv("HOME")));
61 UserDirCheck.Append(wxT("/.xestiaab/preferences/"));
63 wxString UserDir = GetUserPrefDir();
65 ASSERT_EQ(UserDir, UserDirCheck);
71 TEST(CommonFunctions, GetAccountDir){
73 // Run the unit tests depending on the operating system being used.
75 #if defined(__WIN32__)
77 #elif defined(__APPLE__)
81 // Setup for comparison purposes. Should be /home/<user>/.xestiaab/preferences
83 wxString AccountDirCheck1 = "";
84 wxString AccountDirCheck2 = "";
85 wxString AccountDirCheck3 = "";
87 AccountDirCheck1.Append(wxString::FromUTF8(getenv("HOME")));
88 AccountDirCheck1.Append(wxT("/.xestiaab/accounts/"));
89 AccountDirCheck1.Append("Example1");
90 AccountDirCheck1.Append(wxT("/"));
92 AccountDirCheck2.Append(wxString::FromUTF8(getenv("HOME")));
93 AccountDirCheck2.Append(wxT("/.xestiaab/accounts/"));
94 AccountDirCheck2.Append("Example2");
95 AccountDirCheck2.Append(wxT("/"));
97 AccountDirCheck3.Append(wxString::FromUTF8(getenv("HOME")));
98 AccountDirCheck3.Append(wxT("/.xestiaab/accounts/"));
99 AccountDirCheck3.Append("Example3");
100 AccountDirCheck3.Append(wxT("/"));
102 wxString AccountDir1 = GetAccountDir("Example1", false);
103 wxString AccountDir2 = GetAccountDir("Example2", false);
104 wxString AccountDir3 = GetAccountDir("Example3", false);
106 ASSERT_EQ(AccountDir1, AccountDirCheck1);
107 ASSERT_EQ(AccountDir2, AccountDirCheck2);
108 ASSERT_EQ(AccountDir3, AccountDirCheck3);
114 TEST(CommonFunctions, GetAccountDirCertificate){
116 // Run the unit tests depending on the operating system being used.
118 #if defined(__WIN32__)
120 #elif defined(__APPLE__)
124 // Setup for comparison purposes. Should be /home/<user>/.xestiaab/preferences
126 wxString AccountDirCheck1 = "";
127 wxString AccountDirCheck2 = "";
128 wxString AccountDirCheck3 = "";
130 AccountDirCheck1.Append(wxString::FromUTF8(getenv("HOME")));
131 AccountDirCheck1.Append(wxT("/.xestiaab/accounts/"));
132 AccountDirCheck1.Append("Example1");
133 AccountDirCheck1.Append(wxT("/server.crt"));
135 AccountDirCheck2.Append(wxString::FromUTF8(getenv("HOME")));
136 AccountDirCheck2.Append(wxT("/.xestiaab/accounts/"));
137 AccountDirCheck2.Append("Example2");
138 AccountDirCheck2.Append(wxT("/server.crt"));
140 AccountDirCheck3.Append(wxString::FromUTF8(getenv("HOME")));
141 AccountDirCheck3.Append(wxT("/.xestiaab/accounts/"));
142 AccountDirCheck3.Append("Example3");
143 AccountDirCheck3.Append(wxT("/server.crt"));
145 wxString AccountDir1 = GetAccountDir("Example1", true);
146 wxString AccountDir2 = GetAccountDir("Example2", true);
147 wxString AccountDir3 = GetAccountDir("Example3", true);
149 ASSERT_EQ(AccountDir1, AccountDirCheck1);
150 ASSERT_EQ(AccountDir2, AccountDirCheck2);
151 ASSERT_EQ(AccountDir3, AccountDirCheck3);
157 TEST(CommonFunctions, GetAccountsFile){
159 // Run the unit tests depending on the operating system being used.
161 #if defined(__WIN32__)
163 #elif defined(__APPLE__)
167 // Setup for comparison purposes. Should be
168 // /home/<user>/.xestiaab/preferences/accounts
170 wxString AccountsFileCheck = "";
171 AccountsFileCheck.Clear();
172 AccountsFileCheck.Append(wxString::FromUTF8(getenv("HOME")));
173 AccountsFileCheck.Append(wxT("/.xestiaab/preferences/accounts"));
175 wxString AccountsFile = GetAccountsFile();
177 ASSERT_EQ(AccountsFile, AccountsFileCheck);
183 TEST(CommonFunctions, GetSettingsFile){
185 // Run the unit tests depending on the operating system being used.
187 #if defined(__WIN32__)
189 #elif defined(__APPLE__)
193 // Setup for comparison purposes. Should be
194 // /home/<user>/.xestiaab/preferences/accounts
196 wxString SettingsFileCheck = "";
197 SettingsFileCheck.Clear();
198 SettingsFileCheck.Append(wxString::FromUTF8(getenv("HOME")));
199 SettingsFileCheck.Append(wxT("/.xestiaab/preferences/settings"));
201 wxString SettingsFile = GetSettingsFile();
203 ASSERT_EQ(SettingsFile, SettingsFileCheck);
209 TEST(CommonFunctions, CreateFilenamePath){
211 // Run the unit tests depending on the operating system being used.
213 #if defined(__WIN32__)
215 #elif defined(__APPLE__)
219 ASSERT_EQ("/test", CreateFilenamePath("", "test"));
220 ASSERT_EQ("/example/test", CreateFilenamePath("/example", "test"));
221 ASSERT_EQ("/home/meep/test", CreateFilenamePath("/home/meep", "test"));
222 ASSERT_EQ("/home/meep/moo/test", CreateFilenamePath("/home/meep/moo", "test"));
223 ASSERT_EQ("/home/meep/moo/yargh/test", CreateFilenamePath("/home/meep/moo/yargh", "test"));