File: Bug_3432_Regression_Test.cpp

package info (click to toggle)
ace 6.0.3%2Bdfsg-0.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 49,368 kB
  • sloc: cpp: 341,826; perl: 30,850; ansic: 20,952; makefile: 10,144; sh: 4,744; python: 828; exp: 787; yacc: 511; xml: 330; lex: 158; lisp: 116; csh: 48; tcl: 5
file content (72 lines) | stat: -rw-r--r-- 1,833 bytes parent folder | download | duplicates (2)
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
// $Id: Bug_3432_Regression_Test.cpp 91671 2010-09-08 18:39:23Z johnnyw $

// ============================================================================
//
// = 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 (void)
{
  // 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;
  ACE_OS::gmtime_r (&time, &tm_time);
  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;
}