• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

test/TestEnv.cpp

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 #include <spl/Debug.h>
00018 #include <spl/Environment.h>
00019 #include <spl/Log.h>
00020 
00021 #ifdef DEBUG
00022 
00023 static void _TestEnvVariable()
00024 {
00025         Environment::SetVariable("_SPLTEST", "YES");
00026         UNIT_ASSERT("Should be YES", Environment::GetVariable("_SPLTEST") == "YES");
00027 
00028         Log::SWriteOkFail( "Environment GetVariable test" );
00029 }
00030 
00031 static void _TestEnvGetDrives()
00032 {
00033         Vector<StringPtr> driveList = Environment::GetLogicalDrives(true);
00034         UNIT_ASSERT("Should be one or more drives", driveList.Count() > 0);
00035 
00036         if (driveList.Count() == 1)
00037         {
00038                 UNIT_ASSERT("Should be /", *driveList.ElementAt(0) == "/" || driveList.ElementAt(0)->EndsWith(":\\"));
00039         }
00040         else if (driveList.Count() > 1)
00041         {
00042                 UNIT_ASSERT("Should be c:", driveList.ElementAt(0)->EndsWith(":\\"));
00043         }
00044 
00045         Log::SWriteOkFail( "Environment GetLogicalDrives test" );
00046 }
00047 
00048 static void _TestEnvHostName()
00049 {
00050         UNIT_ASSERT("Should be not null", Environment::HostName().Length() > 0);
00051 
00052         Log::SWriteOkFail( "Environment HostName test" );
00053 }
00054 
00055 static void _TestEnvHostArchitecture()
00056 {
00057         UNIT_ASSERT("Should be not null", Environment::HostArchitecture().Length() > 0);
00058 
00059         Log::SWriteOkFail( "Environment HostArchitecture test" );
00060 }
00061 
00062 static void _TestEnvOSName()
00063 {
00064         UNIT_ASSERT("Should be not null", Environment::OSName().Length() > 0);
00065 
00066         Log::SWriteOkFail( "Environment OSName test" );
00067 }
00068 
00069 static void _TestEnvOSVersion()
00070 {
00071         UNIT_ASSERT("Should be not null", Environment::OSVersion().Length() > 0);
00072 
00073         Log::SWriteOkFail( "Environment OSVersion test" );
00074 }
00075 
00076 static void _TestEnvUserName()
00077 {
00078         UNIT_ASSERT("Should be not null", Environment::UserName().Length() > 0);
00079 
00080         Log::SWriteOkFail( "Environment UserName test" );
00081 }
00082 
00083 static void _TestEnvHomeDirectory()
00084 {
00085         UNIT_ASSERT("Should be not null", Environment::HomeDirectory().Length() > 0);
00086 
00087         Log::SWriteOkFail( "Environment HomeDirectory test" );
00088 }
00089 
00090 static void _TestEnvTempDirectory()
00091 {
00092         UNIT_ASSERT("Temp direcotry should be greater than zero", Environment::TempDirectory().Length() > 0);
00093 
00094         Log::SWriteOkFail( "Environment TempDirectory test" );
00095 }
00096 
00097 static void _TestEnvDiskFreeSpace()
00098 {
00099         UNIT_ASSERT("Should be not 0", Environment::DiskFreeSpace() > 0);
00100 
00101         Log::SWriteOkFail( "Environment DiskFreeSpace test" );
00102 }
00103 
00104 static void _TestEnvProcessorCount()
00105 {
00106         UNIT_ASSERT("Should be not 0", Environment::ProcessorCount() > 0);
00107 
00108         Log::SWriteOkFail( "Environment ProcessorCount test" );
00109 }
00110 
00111 static void _TestEnvProcName()
00112 {
00113         String procName = Environment::ProcessName();
00114         UNIT_ASSERT("Should be not null", procName.Length() > 0);
00115 #ifdef _WINDOWS
00116         UNIT_ASSERT("Should end with .exe", procName.EndsWith(".exe"));
00117 #endif
00118         UNIT_ASSERT("Should find something", !procName.Equals("unknown"));
00119         UNIT_ASSERT("Shouldn't have path", procName.IndexOf('/') < 0);
00120         UNIT_ASSERT("Shouldn't have path", procName.IndexOf('\\') < 0);
00121 
00122         Log::SWriteOkFail( "Environment ProcessName test" );
00123 }
00124 
00125 void _TestEnv()
00126 {
00127         _TestEnvVariable();
00128         DEBUG_CLEAR_MEM_CHECK_POINTS();
00129         DEBUG_DUMP_MEM_LEAKS();
00130 
00131         _TestEnvGetDrives();
00132         DEBUG_CLEAR_MEM_CHECK_POINTS();
00133         DEBUG_DUMP_MEM_LEAKS();
00134 
00135         _TestEnvHostName();
00136         DEBUG_CLEAR_MEM_CHECK_POINTS();
00137         DEBUG_DUMP_MEM_LEAKS();
00138 
00139         _TestEnvHostArchitecture();
00140         DEBUG_CLEAR_MEM_CHECK_POINTS();
00141         DEBUG_DUMP_MEM_LEAKS();
00142 
00143         _TestEnvOSName();
00144         DEBUG_CLEAR_MEM_CHECK_POINTS();
00145         DEBUG_DUMP_MEM_LEAKS();
00146 
00147         _TestEnvOSVersion();
00148         DEBUG_CLEAR_MEM_CHECK_POINTS();
00149         DEBUG_DUMP_MEM_LEAKS();
00150 
00151         _TestEnvUserName();
00152         DEBUG_CLEAR_MEM_CHECK_POINTS();
00153         DEBUG_DUMP_MEM_LEAKS();
00154 
00155         _TestEnvHomeDirectory();
00156         DEBUG_CLEAR_MEM_CHECK_POINTS();
00157         DEBUG_DUMP_MEM_LEAKS();
00158 
00159         _TestEnvTempDirectory();
00160         DEBUG_CLEAR_MEM_CHECK_POINTS();
00161         DEBUG_DUMP_MEM_LEAKS();
00162 
00163         _TestEnvDiskFreeSpace();
00164         DEBUG_CLEAR_MEM_CHECK_POINTS();
00165         DEBUG_DUMP_MEM_LEAKS();
00166 
00167         _TestEnvProcessorCount();
00168         DEBUG_CLEAR_MEM_CHECK_POINTS();
00169         DEBUG_DUMP_MEM_LEAKS();
00170         
00171         _TestEnvProcName();
00172         DEBUG_CLEAR_MEM_CHECK_POINTS();
00173         DEBUG_DUMP_MEM_LEAKS();
00174 }
00175 
00176 #endif