Compile fixes
[ACE_TAO.git] / ACE / tests / Bug_3432_Regression_Test.cpp
blobe0ff5a8c9cb822346775e54822998550e17d7b7d
1 // ============================================================================
2 //
3 // = LIBRARY
4 // tests
5 //
6 // = DESCRIPTION
7 // Test ACE_OS::strptime
8 //
9 // = AUTHOR
10 // Johnny Willemsen
12 // ============================================================================
14 #include "test_config.h"
15 #include "ace/OS_NS_string.h"
16 #include "ace/OS_NS_strings.h"
17 #include "ace/OS_NS_stdlib.h"
18 #include "ace/OS_NS_sys_time.h"
19 #include "ace/OS_NS_time.h"
22 int
23 strptime_test ()
25 // convert UTC time string to UTC ACE_Time_Value
26 int error_count = 0;
27 const char* original_time = "2008-06-21 23:45";
28 tm lTime;
29 ACE_OS::strptime(original_time, "%Y-%m-%d %H:%M", &lTime);
30 lTime.tm_isdst = 0; // do not change due to daylight saving time
31 time_t lNewTime = ACE_OS::mktime(&lTime);
32 ACE_Time_Value lValue(lNewTime - ACE_OS::timezone(), 0); // do not change because of timezone
34 // convert UTC ACE_Time_Value to UTC time string
35 char lBuffer[128];
36 time_t time = lValue.sec();
37 struct tm tm_time;
38 if (ACE_OS::gmtime_r (&time, &tm_time) == 0 && errno == ENOTSUP)
40 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("gmtime_r is not supported on this platform\n")));
42 if (ACE_OS::strftime(lBuffer, 128, "%Y-%m-%d %H:%M", &tm_time) == 0 && errno == ENOTSUP)
44 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("strftime is not supported on this platform\n")));
46 else if (ACE_OS::strcmp (lBuffer, original_time) != 0)
48 ACE_ERROR ((LM_ERROR, ACE_TEXT ("%C != %C\n"), lBuffer, original_time));
49 ++error_count;
51 else
53 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("strptime_test succeeded\n")));
56 return error_count;
59 int
60 run_main (int, ACE_TCHAR *[])
62 ACE_START_TEST (ACE_TEXT ("Bug_3432_Regression_Test"));
64 int status = 0;
65 int result = 0;
67 if ((result = strptime_test ()) != 0)
68 status = result;
70 ACE_END_TEST;
71 return status;