Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / ACE / tests / Bug_3432_Regression_Test.cpp
blob4da4eb21c1e1877d708194ea3ca71fa4e53e7572
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"
23 int
24 strptime_test (void)
26 // convert UTC time string to UTC ACE_Time_Value
27 int error_count = 0;
28 const char* original_time = "2008-06-21 23:45";
29 tm lTime;
30 ACE_OS::strptime(original_time, "%Y-%m-%d %H:%M", &lTime);
31 lTime.tm_isdst = 0; // do not change due to daylight saving time
32 time_t lNewTime = ACE_OS::mktime(&lTime);
33 ACE_Time_Value lValue(lNewTime - ACE_OS::timezone(), 0); // do not change because of timezone
35 // convert UTC ACE_Time_Value to UTC time string
36 char lBuffer[128];
37 time_t time = lValue.sec();
38 struct tm tm_time;
39 if (ACE_OS::gmtime_r (&time, &tm_time) == 0 && errno == ENOTSUP)
41 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("gmtime_r is not supported on this platform\n")));
43 if (ACE_OS::strftime(lBuffer, 128, "%Y-%m-%d %H:%M", &tm_time) == 0 && errno == ENOTSUP)
45 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("strftime is not supported on this platform\n")));
47 else if (ACE_OS::strcmp (lBuffer, original_time) != 0)
49 ACE_ERROR ((LM_ERROR, ACE_TEXT ("%C != %C\n"), lBuffer, original_time));
50 ++error_count;
52 else
54 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("strptime_test succeeded\n")));
57 return error_count;
60 int
61 run_main (int, ACE_TCHAR *[])
63 ACE_START_TEST (ACE_TEXT ("Bug_3432_Regression_Test"));
65 int status = 0;
66 int result = 0;
68 if ((result = strptime_test ()) != 0)
69 status = result;
71 ACE_END_TEST;
72 return status;