-// ----------------------------------------------------------------------------
-// wxGet/SetEnv
-// ----------------------------------------------------------------------------
-
-#ifdef TEST_ENVIRON
-
-#include "wx/utils.h"
-
-static wxString MyGetEnv(const wxString& var)
-{
- wxString val;
- if ( !wxGetEnv(var, &val) )
- val = wxT("<empty>");
- else
- val = wxString(wxT('\'')) + val + wxT('\'');
-
- return val;
-}
-
-static void TestEnvironment()
-{
- const wxChar *var = wxT("wxTestVar");
-
- wxPuts(wxT("*** testing environment access functions ***"));
-
- wxPrintf(wxT("Initially getenv(%s) = %s\n"), var, MyGetEnv(var).c_str());
- wxSetEnv(var, wxT("value for wxTestVar"));
- wxPrintf(wxT("After wxSetEnv: getenv(%s) = %s\n"), var, MyGetEnv(var).c_str());
- wxSetEnv(var, wxT("another value"));
- wxPrintf(wxT("After 2nd wxSetEnv: getenv(%s) = %s\n"), var, MyGetEnv(var).c_str());
- wxUnsetEnv(var);
- wxPrintf(wxT("After wxUnsetEnv: getenv(%s) = %s\n"), var, MyGetEnv(var).c_str());
- wxPrintf(wxT("PATH = %s\n"), MyGetEnv(wxT("PATH")).c_str());
-}
-
-#endif // TEST_ENVIRON
-
-// ----------------------------------------------------------------------------
-// file
-// ----------------------------------------------------------------------------
-
-#ifdef TEST_FILE
-
-#include "wx/file.h"
-#include "wx/ffile.h"
-#include "wx/textfile.h"
-
-static void TestFileRead()
-{
- wxPuts(wxT("*** wxFile read test ***"));
-
- wxFile file(wxT("makefile.vc"));
- if ( file.IsOpened() )
- {
- wxPrintf(wxT("File length: %lu\n"), file.Length());
-
- wxPuts(wxT("File dump:\n----------"));
-
- static const size_t len = 1024;
- wxChar buf[len];
- for ( ;; )
- {
- size_t nRead = file.Read(buf, len);
- if ( nRead == (size_t)wxInvalidOffset )
- {
- wxPrintf(wxT("Failed to read the file."));
- break;
- }
-
- fwrite(buf, nRead, 1, stdout);
-
- if ( nRead < len )
- break;
- }
-
- wxPuts(wxT("----------"));
- }
- else
- {
- wxPrintf(wxT("ERROR: can't open test file.\n"));
- }
-
- wxPuts(wxEmptyString);
-}
-
-static void TestTextFileRead()
-{
- wxPuts(wxT("*** wxTextFile read test ***"));
-
- wxTextFile file(wxT("makefile.vc"));
- if ( file.Open() )
- {
- wxPrintf(wxT("Number of lines: %u\n"), file.GetLineCount());
- wxPrintf(wxT("Last line: '%s'\n"), file.GetLastLine().c_str());
-
- wxString s;
-
- wxPuts(wxT("\nDumping the entire file:"));
- for ( s = file.GetFirstLine(); !file.Eof(); s = file.GetNextLine() )
- {
- wxPrintf(wxT("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str());
- }
- wxPrintf(wxT("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str());
-
- wxPuts(wxT("\nAnd now backwards:"));
- for ( s = file.GetLastLine();
- file.GetCurrentLine() != 0;
- s = file.GetPrevLine() )
- {
- wxPrintf(wxT("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str());
- }
- wxPrintf(wxT("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str());
- }
- else
- {
- wxPrintf(wxT("ERROR: can't open '%s'\n"), file.GetName());
- }
-
- wxPuts(wxEmptyString);
-}
-
-static void TestFileCopy()
-{
- wxPuts(wxT("*** Testing wxCopyFile ***"));
-
- static const wxChar *filename1 = wxT("makefile.vc");
- static const wxChar *filename2 = wxT("test2");
- if ( !wxCopyFile(filename1, filename2) )
- {
- wxPuts(wxT("ERROR: failed to copy file"));
- }
- else
- {
- wxFFile f1(filename1, wxT("rb")),
- f2(filename2, wxT("rb"));
-
- if ( !f1.IsOpened() || !f2.IsOpened() )
- {
- wxPuts(wxT("ERROR: failed to open file(s)"));
- }
- else
- {
- wxString s1, s2;
- if ( !f1.ReadAll(&s1) || !f2.ReadAll(&s2) )
- {
- wxPuts(wxT("ERROR: failed to read file(s)"));
- }
- else
- {
- if ( (s1.length() != s2.length()) ||
- (memcmp(s1.c_str(), s2.c_str(), s1.length()) != 0) )
- {
- wxPuts(wxT("ERROR: copy error!"));
- }
- else
- {
- wxPuts(wxT("File was copied ok."));
- }
- }
- }
- }
-
- if ( !wxRemoveFile(filename2) )
- {
- wxPuts(wxT("ERROR: failed to remove the file"));
- }
-
- wxPuts(wxEmptyString);
-}
-
-static void TestTempFile()
-{
- wxPuts(wxT("*** wxTempFile test ***"));
-
- wxTempFile tmpFile;
- if ( tmpFile.Open(wxT("test2")) && tmpFile.Write(wxT("the answer is 42")) )
- {
- if ( tmpFile.Commit() )
- wxPuts(wxT("File committed."));
- else
- wxPuts(wxT("ERROR: could't commit temp file."));
-
- wxRemoveFile(wxT("test2"));
- }
-
- wxPuts(wxEmptyString);
-}
-
-#endif // TEST_FILE
-