From c04fe1b1c6a5e46cf85691d96d6d79056b48c8c5 Mon Sep 17 00:00:00 2001 From: Steve Huston Date: Wed, 21 Jun 2000 18:48:58 +0000 Subject: ChangeLogTag:Wed Jun 21 13:41:27 2000 Steve Huston --- tests/OS_Test.cpp | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/OS_Test.dsp | 137 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/run_tests.lst | 1 + 3 files changed, 281 insertions(+) create mode 100644 tests/OS_Test.cpp create mode 100644 tests/OS_Test.dsp diff --git a/tests/OS_Test.cpp b/tests/OS_Test.cpp new file mode 100644 index 00000000000..a89093ebc02 --- /dev/null +++ b/tests/OS_Test.cpp @@ -0,0 +1,143 @@ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// tests +// +// = DESCRIPTION +// This simple test exercises and illustrates use of OS wrapper functions. +// +// = AUTHOR +// Steve Huston +// +// ============================================================================ + +#include "ace/OS.h" +#include "test_config.h" + +ACE_RCSID(tests, OS_Test, "$Id$") + +// Test ACE_OS::rename to be sure the files come and go as expected. +int +rename_test (void) +{ +#if defined (ACE_LACKS_RENAME) + ACE_ERROR_RETURN ((LM_INFO, + ACE_TEXT ("rename not supported on this platform\n")), + 0); +#else + ACE_TCHAR old_file[MAXPATHLEN]; + ACE_TCHAR new_file[MAXPATHLEN]; + ACE_OS::strcpy (old_file, ACE_TEXT ("rename_test_old")); + ACE_OS::strcpy (new_file, ACE_TEXT ("rename_test_new")); + + // Test 1. Rename old to new when new already exists. + // To set up, create two files, old and new. Both get opened and truncated + // in case they're left over from a previous run. The first one (old) gets + // something written in it so it's non-zero length - this is how the rename + // is verified. + FILE *f = ACE_OS::fopen (old_file, ACE_TEXT ("w+")); + if (f == 0) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%s: %p\n"), + old_file, + ACE_TEXT ("fopen")), + -1); + // Write something in the old_file so it has non-zero length + ACE_OS::fputs (ACE_TEXT ("this is a test\n"), f); + ACE_OS::fclose (f); + f = ACE_OS::fopen (new_file, ACE_TEXT ("w+")); + if (f == 0) + { + ACE_OS::unlink (old_file); + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%s: %p\n"), + new_file, + ACE_TEXT ("fopen")), + -1); + } + ACE_OS::fclose (f); + + if (ACE_OS::rename (old_file, new_file) != 0) + { + ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("rename test 1"))); + ACE_OS::unlink (old_file); + ACE_OS::unlink (new_file); + return -1; + } + // Verify that the old file was really renamed. + struct stat checking; + int result = 0; + if (ACE_OS::stat (new_file, &checking) == -1 || checking.st_size == 0) + { + result = -1; + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Rename test 1: new_file not correct\n"))); + } + if (ACE_OS::stat (old_file, &checking) == 0) + { + result = -1; + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Rename test 1: old_file still there\n"))); + } + if (result == 0) + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Rename when dest. exists: success\n"))); + + // Now test 2 - rename when the new file does not exist. If test 1 worked, + // the old_file is now new_file and there is no old_file. + if (ACE_OS::rename (new_file, old_file) != 0) + { + ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("rename test 2"))); + ACE_OS::unlink (old_file); + ACE_OS::unlink (new_file); + return -1; + } + if (ACE_OS::stat (old_file, &checking) == -1 || checking.st_size == 0) + { + result = -1; + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Rename test 2: new_file not correct\n"))); + } + else if (ACE_OS::stat (new_file, &checking) == 0) + { + result = -1; + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Rename test 2: old_file still there\n"))); + } + else + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Rename when dest. gone: success\n"))); + + ACE_OS::unlink (new_file); + ACE_OS::unlink (old_file); + + // Test 3: It should fail... there are no files. + if (ACE_OS::rename (old_file, new_file) == -1) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("%p\n"), ACE_TEXT ("Rename expected fail"))); + else + { + result = -1; + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Rename expected fail, but succeeded\n"))); + } + + return result; +#endif /* ACE_LACKS_RENAME */ +} + + +int +main (int, char *argv[]) +{ + ACE_START_TEST (ACE_TEXT ("OS_Test")); + + int status = 0; + int result; + + if ((result = rename_test ()) != 0) + status = result; + + ACE_END_TEST; + return status; +} diff --git a/tests/OS_Test.dsp b/tests/OS_Test.dsp new file mode 100644 index 00000000000..fa45f66fb5b --- /dev/null +++ b/tests/OS_Test.dsp @@ -0,0 +1,137 @@ +# Microsoft Developer Studio Project File - Name="OS_Test" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 +# TARGTYPE "Win32 (ALPHA) Console Application" 0x0603 + +CFG=OS_Test - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "OS_Test.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "OS_Test.mak" CFG="OS_Test - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "OS_Test - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "OS_Test - Win32 Alpha Debug" (based on "Win32 (ALPHA) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" + +!IF "$(CFG)" == "OS_Test - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir ".\OS_Test\Debug" +# PROP BASE Intermediate_Dir ".\OS_Test\Debug" +# PROP BASE Target_Dir ".\OS_Test" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "." +# PROP Intermediate_Dir ".\DLL\Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir ".\OS_Test" +CPP=cl.exe +# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /YX /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\\" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /FD /c +# SUBTRACT CPP /YX +RSC=rc.exe +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 +# ADD LINK32 aced.lib /nologo /subsystem:console /debug /machine:I386 /libpath:"..\ace" + +!ELSEIF "$(CFG)" == "OS_Test - Win32 Alpha Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "OS_Test\Alpha Debug" +# PROP BASE Intermediate_Dir "OS_Test\Alpha Debug" +# PROP BASE Ignore_Export_Lib 0 +# PROP BASE Target_Dir "OS_Test" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "OS_Test" +CPP=cl.exe +# ADD BASE CPP /nologo /Gt0 /W3 /GX /Zi /Od /I"..\\" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /MTd /c +# ADD CPP /nologo /Gt0 /W3 /GX /Zi /Od /I"..\\" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FD /MDd /c +# SUBTRACT CPP /YX +RSC=rc.exe +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 wsock32.lib aced.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:console /debug /machine:ALPHA /libpath:"..\ace" +# ADD LINK32 aced.lib /nologo /subsystem:console /debug /machine:ALPHA /libpath:"..\ace" + +!ENDIF + +# Begin Target + +# Name "OS_Test - Win32 Debug" +# Name "OS_Test - Win32 Alpha Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;hpj;bat;for;f90" +# Begin Source File + +SOURCE=.\OS_Test.cpp + +!IF "$(CFG)" == "OS_Test - Win32 Debug" + +!ELSEIF "$(CFG)" == "OS_Test - Win32 Alpha Debug" + +DEP_CPP_OS=\ + "..\ace\config-win32-common.h"\ + "..\ace\config-win32.h"\ + "..\ace\config.h"\ + "..\ace\Log_Msg.h"\ + "..\ace\Log_Priority.h"\ + "..\ace\Log_Record.h"\ + "..\ace\Log_Record.i"\ + "..\ace\OS.h"\ + "..\ace\OS.i"\ + "..\ace\Version.h"\ + "..\ace\ws2tcpip.h"\ + ".\test_config.h"\ + +NODEP_CPP_OS=\ + "..\ace\stdcpp.h"\ + + +!ENDIF + +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl;fi;fd" +# Begin Source File + +SOURCE=.\test_config.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/tests/run_tests.lst b/tests/run_tests.lst index 646d29ec18b..e0eabab80f0 100644 --- a/tests/run_tests.lst +++ b/tests/run_tests.lst @@ -81,3 +81,4 @@ Enum_Interfaces_Test chorus/Upgradable_RW_Test chorus/Conn_Test DISABLED/New_Fail_Test +OS_Test -- cgit v1.2.1