summaryrefslogtreecommitdiff
path: root/ACE/tests/Bug_3432_Regression_Test.cpp
blob: c56d92c5ae7aff426540b6c21118eba87b4418ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// ============================================================================
//
// = LIBRARY
//    tests
//
// = DESCRIPTION
//    Test ACE_OS::strptime
//
// = AUTHOR
//    Johnny Willemsen
//
// ============================================================================

#include "test_config.h"
#include "ace/OS_NS_string.h"
#include "ace/OS_NS_strings.h"
#include "ace/OS_NS_stdlib.h"
#include "ace/OS_NS_sys_time.h"
#include "ace/OS_NS_time.h"



int
strptime_test ()
{
  // convert UTC time string to UTC ACE_Time_Value
  int error_count = 0;
  const char* original_time = "2008-06-21 23:45";
  tm lTime;
  ACE_OS::strptime(original_time, "%Y-%m-%d %H:%M", &lTime);
  lTime.tm_isdst = 0; // do not change due to daylight saving time
  time_t lNewTime = ACE_OS::mktime(&lTime);
  ACE_Time_Value lValue(lNewTime - ACE_OS::timezone(), 0); // do  not change because of timezone

  // convert UTC ACE_Time_Value to UTC time string
  char lBuffer[128];
  time_t time = lValue.sec();
  struct tm tm_time;
  if (ACE_OS::gmtime_r (&time, &tm_time) == 0 && errno == ENOTSUP)
    {
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("gmtime_r is not supported on this platform\n")));
    }
  if (ACE_OS::strftime(lBuffer, 128, "%Y-%m-%d %H:%M", &tm_time) == 0 && errno == ENOTSUP)
    {
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("strftime is not supported on this platform\n")));
    }
  else if (ACE_OS::strcmp (lBuffer, original_time) != 0)
    {
      ACE_ERROR ((LM_ERROR, ACE_TEXT ("%C != %C\n"), lBuffer, original_time));
      ++error_count;
    }
  else
    {
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("strptime_test succeeded\n")));
    }

  return error_count;
}

int
run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("Bug_3432_Regression_Test"));

  int status = 0;
  int result = 0;

  if ((result = strptime_test ()) != 0)
      status = result;

  ACE_END_TEST;
  return status;
}