summaryrefslogtreecommitdiff
path: root/ACE/tests/Date_Time_Test.cpp
blob: ac50bea608f1b56642444c5eff1a3a896f12a17d (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// $Id$

// ============================================================================
//
// = LIBRARY
//    tests
//
// = DESCRIPTION
//    This program verifies the ACE_Date_Time class.
//
// = AUTHOR
//    Steve Huston  <shuston@riverace.com>
//
// ============================================================================

#include "ace/Date_Time.h"
#include "test_config.h"

ACE_RCSID(tests, Date_Time_Test, "$Id$")

static ACE_Date_Time static_dt;   // Making sure it doesn't crash.

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

  int error = 0;

  ACE_Date_Time dt;

  long month   = dt.month ();
  long day     = dt.day ();
  long year    = dt.year ();
  long hour    = dt.hour ();
  long minute  = dt.minute ();
  long seconds = dt.second ();
  long usec    = dt.microsec ();
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("ACE_Date_Time (m/d/y, h:m:s.u): %d/%d/%d, %d:%d:%d.%d\n"),
              month, day, year, hour, minute, seconds, usec));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("ACE_Log thinks it is: %D\n")));

  if (month < 1 || month > 12)
    {
      ACE_ERROR ((LM_ERROR, ACE_TEXT ("Month (%d) out of range (1-12)\n"),
                  month));
      error = 1;
    }
  if (day < 1 || day > 31)
    {
      ACE_ERROR ((LM_ERROR, ACE_TEXT ("Day (%d) out of range (1-31)\n"),
                  day));
      error = 1;
    }
  if (year < 1900 || year > 2100)
    {
      ACE_ERROR ((LM_ERROR, ACE_TEXT ("Year (%d) out of range (1900-2100)\n"),
                  year));
      error = 1;
    }
  if (hour < 0 || hour > 23)
    {
      ACE_ERROR ((LM_ERROR, ACE_TEXT ("Hour (%d) out of range (0-23)\n"),
                  hour));
      error = 1;
    }
  if (minute < 0 || minute > 59)
    {
      ACE_ERROR ((LM_ERROR, ACE_TEXT ("Minute (%d) out of range (0-59)\n"),
                  minute));
      error = 1;
    }
  if (seconds < 0 || seconds > 59)
    {
      ACE_ERROR ((LM_ERROR, ACE_TEXT ("Seconds (%d) out of range (0-59)\n"),
                  seconds));
      error = 1;
    }
  if (usec < 0 || usec > 999999)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Microseconds (%d) out of range (0-999999)\n"),
                  usec));
      error = 1;
    }

  // The static ACE_Date_Time object is primarily to be sure it doesn't
  // crash; However, let's do some sanity checks on it to be sure it's
  // legit as well.
  if (static_dt.month () != month)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Static month (%d) doesn't match %d\n"),
                  static_dt.month (), month));
      error = 1;
    }
  if (static_dt.day () != day)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Static day (%d) doesn't match %d\n"),
                  static_dt.day (), day));
      error = 1;
    }
  if (static_dt.year () != year)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Static year (%d) doesn't match %d\n"),
                  static_dt.year (), year));
      error = 1;
    }
  if (static_dt.hour () != hour)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Static hour (%d) doesn't match %d\n"),
                  static_dt.hour (), hour));
      error = 1;
    }
  if (static_dt.minute () != minute)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Static minute (%d) doesn't match %d\n"),
                  static_dt.minute (), minute));
      error = 1;
    }
  ACE_END_TEST;
  return error;
}