(file) Return to test_datetime.cpp CVS log (file) (dir) Up to [OMI] / omi / tests / micxx

  1 krisbash 1.1 /*
  2              **==============================================================================
  3              **
  4              ** Open Management Infrastructure (OMI)
  5              **
  6              ** Copyright (c) Microsoft Corporation
  7              ** 
  8              ** Licensed under the Apache License, Version 2.0 (the "License"); you may not 
  9              ** use this file except in compliance with the License. You may obtain a copy 
 10              ** of the License at 
 11              **
 12              **     http://www.apache.org/licenses/LICENSE-2.0 
 13              **
 14              ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15              ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
 16              ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
 17              ** MERCHANTABLITY OR NON-INFRINGEMENT. 
 18              **
 19              ** See the Apache 2 License for the specific language governing permissions 
 20              ** and limitations under the License.
 21              **
 22 krisbash 1.1 **==============================================================================
 23              */
 24              
 25              #include <ut/ut.h>
 26              #include <micxx/datetime.h>
 27              #include <pal/strings.h>
 28              #include <common.h>
 29              
 30              using namespace mi;
 31              
 32              NitsSetup(TestDatetimeSetup)
 33              NitsEndSetup
 34              
 35              NitsCleanup(TestDatetimeSetup)
 36              NitsEndCleanup
 37              
 38              
 39              NitsTestWithSetup(TestTimestamp, TestDatetimeSetup)
 40              {
 41                  /* YYYYMMDDHHMMSS.MMMMMMSUTC */
 42                  const TChar STR[] = ZT("20101225123011.123456-360");
 43 krisbash 1.1     TChar buffer[26];
 44                  buffer[0] = '\0';
 45              
 46                  Datetime dt;
 47                  UT_ASSERT(dt.Set(STR) == true);
 48                  UT_ASSERT(dt.IsTimestamp() == true);
 49              
 50              
 51                  MI_Uint32 year;
 52                  MI_Uint32 month;
 53                  MI_Uint32 day;
 54                  MI_Uint32 hour;
 55                  MI_Uint32 minute;
 56                  MI_Uint32 second;
 57                  MI_Uint32 microseconds;
 58                  MI_Sint32 utc;
 59                  bool f = dt.Get(year, month, day, hour, minute, second, microseconds, utc);
 60              
 61                  UT_ASSERT(f == true);
 62                  UT_ASSERT(year == 2010);
 63                  UT_ASSERT(month == 12);
 64 krisbash 1.1     UT_ASSERT(day == 25);
 65                  UT_ASSERT(hour == 12);
 66                  UT_ASSERT(minute == 30);
 67                  UT_ASSERT(second == 11);
 68                  UT_ASSERT(microseconds == 123456);
 69                  UT_ASSERT(utc == -360);
 70              
 71                  dt.ToString(buffer);
 72                  UT_ASSERT(Tcscmp(STR, buffer) == 0);
 73              
 74                  Datetime dt2;
 75                  dt2.Set(year, month, day, hour, minute, second, microseconds, utc);
 76                  dt2.ToString(buffer);
 77                  UT_ASSERT(Tcscmp(STR, buffer) == 0);
 78                  UT_ASSERT(dt == dt2);
 79              
 80                  Datetime dt3(year, month, day, hour, minute, second, microseconds, utc);
 81                  UT_ASSERT(dt == dt3);
 82              }
 83              NitsEndTest
 84              
 85 krisbash 1.1 NitsTestWithSetup(TestInterval, TestDatetimeSetup)
 86              {
 87                  /* DDDDDDDDHHMMSS.MMMMMM:000 */
 88                  const TChar STR[] = ZT("12345678151617.123456:000");
 89                  TChar buffer[26];
 90                  buffer[0] = '\0';
 91              
 92                  Datetime dt;
 93                  UT_ASSERT(dt.Set(STR) == true);
 94                  UT_ASSERT(dt.IsTimestamp() == false);
 95              
 96                  MI_Uint32 days;
 97                  MI_Uint32 hours;
 98                  MI_Uint32 minutes;
 99                  MI_Uint32 seconds;
100                  MI_Uint32 microseconds;
101                  bool f = dt.Get(days, hours, minutes, seconds, microseconds);
102                  UT_ASSERT(f == true);
103              
104                  UT_ASSERT(days == 12345678);
105                  UT_ASSERT(hours == 15);
106 krisbash 1.1     UT_ASSERT(minutes == 16);
107                  UT_ASSERT(seconds == 17);
108                  UT_ASSERT(microseconds == 123456);
109              
110                  dt.ToString(buffer);
111                  UT_ASSERT(Tcscmp(STR, buffer) == 0);
112              
113                  Datetime dt2;
114                  dt2.Set(days, hours, minutes, seconds, microseconds);
115                  dt2.ToString(buffer);
116                  UT_ASSERT(Tcscmp(STR, buffer) == 0);
117                  UT_ASSERT(dt == dt2);
118              
119                  Datetime dt3(days, hours, minutes, seconds, microseconds);
120                  UT_ASSERT(dt == dt3);
121              
122                  Datetime dt4;
123                  dt4 = dt3;
124                  UT_ASSERT(dt3 == dt4);
125              }
126              NitsEndTest
127 krisbash 1.1 
128              NitsTestWithSetup(TestCurrent, TestDatetimeSetup)
129              {
130                  Datetime x;
131                  UT_ASSERT(x.SetCurrent() == true);
132              }
133              NitsEndTest
134              
135              
136              
137              

ViewCVS 0.9.2