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

  1 mike  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 mike  1.1 **==============================================================================
 23           */
 24           
 25           #include <ut/ut.h>
 26           #include <micxx/datetime.h>
 27           #include <base/strings.h>
 28           #include <common.h>
 29           
 30           using namespace mi;
 31           
 32           static void setUp()
 33           {
 34           }
 35           
 36           static void cleanup()
 37           {
 38           }
 39           
 40           
 41           static void TestTimestamp()
 42           {
 43 mike  1.1     /* YYYYMMDDHHMMSS.MMMMMMSUTC */
 44               const MI_Char STR[] = T("20101225123011.123456-360");
 45               MI_Char buffer[26];
 46           
 47               Datetime dt;
 48               UT_ASSERT(dt.Set(STR) == true);
 49               UT_ASSERT(dt.IsTimestamp() == true);
 50           
 51           
 52               MI_Uint32 year;
 53               MI_Uint32 month;
 54               MI_Uint32 day;
 55               MI_Uint32 hour;
 56               MI_Uint32 minute;
 57               MI_Uint32 second;
 58               MI_Uint32 microseconds;
 59               MI_Sint32 utc;
 60               bool f = dt.Get(year, month, day, hour, minute, second, microseconds, utc);
 61           
 62               UT_ASSERT(f == true);
 63               UT_ASSERT(year == 2010);
 64 mike  1.1     UT_ASSERT(month == 12);
 65               UT_ASSERT(day == 25);
 66               UT_ASSERT(hour == 12);
 67               UT_ASSERT(minute == 30);
 68               UT_ASSERT(second == 11);
 69               UT_ASSERT(microseconds == 123456);
 70               UT_ASSERT(utc == -360);
 71           
 72               dt.ToString(buffer);
 73               UT_ASSERT(Zcmp(STR, buffer) == 0);
 74           
 75               Datetime dt2;
 76               dt2.Set(year, month, day, hour, minute, second, microseconds, utc);
 77               dt2.ToString(buffer);
 78               UT_ASSERT(Zcmp(STR, buffer) == 0);
 79               UT_ASSERT(dt == dt2);
 80           
 81               Datetime dt3(year, month, day, hour, minute, second, microseconds, utc);
 82               UT_ASSERT(dt == dt3);
 83           }
 84           
 85 mike  1.1 static void TestInterval()
 86           {
 87               /* DDDDDDDDHHMMSS.MMMMMM:000 */
 88               const MI_Char STR[] = T("12345678151617.123456:000");
 89               MI_Char buffer[26];
 90           
 91               Datetime dt;
 92               UT_ASSERT(dt.Set(STR) == true);
 93               UT_ASSERT(dt.IsTimestamp() == false);
 94           
 95               MI_Uint32 days;
 96               MI_Uint32 hours;
 97               MI_Uint32 minutes;
 98               MI_Uint32 seconds;
 99               MI_Uint32 microseconds;
100               bool f = dt.Get(days, hours, minutes, seconds, microseconds);
101               UT_ASSERT(f == true);
102           
103               UT_ASSERT(days == 12345678);
104               UT_ASSERT(hours == 15);
105               UT_ASSERT(minutes == 16);
106 mike  1.1     UT_ASSERT(seconds == 17);
107               UT_ASSERT(microseconds == 123456);
108           
109               dt.ToString(buffer);
110               UT_ASSERT(Zcmp(STR, buffer) == 0);
111           
112               Datetime dt2;
113               dt2.Set(days, hours, minutes, seconds, microseconds);
114               dt2.ToString(buffer);
115               UT_ASSERT(Zcmp(STR, buffer) == 0);
116               UT_ASSERT(dt == dt2);
117           
118               Datetime dt3(days, hours, minutes, seconds, microseconds);
119               UT_ASSERT(dt == dt3);
120           
121               Datetime dt4;
122               dt4 = dt3;
123               UT_ASSERT(dt3 == dt4);
124           }
125           
126           static void TestCurrent()
127 mike  1.1 {
128               Datetime x;
129               UT_ASSERT(x.SetCurrent() == true);
130           }
131           
132           static void RunTests()
133           {
134               UT_TEST(TestTimestamp);
135               UT_TEST(TestInterval);
136               UT_TEST(TestCurrent);
137           }
138           
139           UT_ENTRY_POINT(RunTests);

ViewCVS 0.9.2