lldate_tut.cpp

Go to the documentation of this file.
00001 
00034 #include <tut/tut.h>
00035 #include "linden_common.h"
00036 #include "lldate.h"
00037 
00038 #define VALID_DATE                                                                      "2003-04-30T04:00:00Z"
00039 #define VALID_DATE_LEAP                                                         "2004-02-29T04:00:00Z"
00040 #define VALID_DATE_HOUR_BOUNDARY                                        "2003-04-30T23:59:59Z"
00041 #define VALID_DATE_FRACTIONAL_SECS                                      "2007-09-26T20:31:33.70Z"
00042 
00043 // invalid format
00044 #define INVALID_DATE_MISSING_YEAR                                       "-04-30T22:59:59Z"
00045 #define INVALID_DATE_MISSING_MONTH                                      "1900-0430T22:59:59Z"
00046 #define INVALID_DATE_MISSING_DATE                                       "1900-0430-T22:59:59Z"
00047 #define INVALID_DATE_MISSING_T                                          "1900-04-30-22:59:59Z"
00048 #define INVALID_DATE_MISSING_HOUR                                       "1900-04-30T:59:59Z"
00049 #define INVALID_DATE_MISSING_MIN                                        "1900-04-30T01::59Z"
00050 #define INVALID_DATE_MISSING_SEC                                        "1900-04-30T01:59Z"
00051 #define INVALID_DATE_MISSING_Z                                          "1900-04-30T01:59:23"
00052 #define INVALID_DATE_EMPTY                                                      ""
00053 
00054 // invalid values
00055 // apr 1.1.1 seems to not care about constraining the date to valid
00056 // dates. Put these back when the parser checks.
00057 #define LL_DATE_PARSER_CHECKS_BOUNDARY 0
00058 //#define INVALID_DATE_24HOUR_BOUNDARY                          "2003-04-30T24:00:00Z"
00059 //#define INVALID_DATE_LEAP                                                     "2003-04-29T04:00:00Z"
00060 //#define INVALID_DATE_HOUR                                                     "2003-04-30T24:59:59Z"
00061 //#define INVALID_DATE_MIN                                                      "2003-04-30T22:69:59Z"
00062 //#define INVALID_DATE_SEC                                                      "2003-04-30T22:59:69Z"
00063 //#define INVALID_DATE_YEAR                                                     "0-04-30T22:59:59Z"
00064 //#define INVALID_DATE_MONTH                                                    "2003-13-30T22:59:59Z"
00065 //#define INVALID_DATE_DAY                                                      "2003-04-35T22:59:59Z"
00066 
00067 namespace tut
00068 {
00069         struct date_test
00070         {
00071 
00072         };
00073         typedef test_group<date_test> date_test_t;
00074         typedef date_test_t::object date_test_object_t;
00075         tut::date_test_t tut_date_test("date_test");
00076 
00077         /* format validation */
00078         template<> template<>
00079         void date_test_object_t::test<1>()
00080         {
00081                 LLDate date(VALID_DATE);
00082                 std::string  expected_string;
00083                 bool result;
00084                 expected_string = VALID_DATE;
00085                 ensure_equals("Valid Date failed" , expected_string, date.asString());
00086 
00087                 result = date.fromString(VALID_DATE_LEAP);
00088                 expected_string = VALID_DATE_LEAP;      
00089                 ensure_equals("VALID_DATE_LEAP failed" , expected_string, date.asString());
00090 
00091                 result = date.fromString(VALID_DATE_HOUR_BOUNDARY);
00092                 expected_string = VALID_DATE_HOUR_BOUNDARY;     
00093                 ensure_equals("VALID_DATE_HOUR_BOUNDARY failed" , expected_string, date.asString());
00094 
00095                 result = date.fromString(VALID_DATE_FRACTIONAL_SECS);
00096                 expected_string = VALID_DATE_FRACTIONAL_SECS;
00097                 ensure_equals("VALID_DATE_FRACTIONAL_SECS failed" , expected_string, date.asString());
00098 
00099                 result = date.fromString(INVALID_DATE_MISSING_YEAR);
00100                 ensure_equals("INVALID_DATE_MISSING_YEAR should have failed" , result, false);
00101 
00102                 result = date.fromString(INVALID_DATE_MISSING_MONTH);
00103                 ensure_equals("INVALID_DATE_MISSING_MONTH should have failed" , result, false);
00104 
00105                 result = date.fromString(INVALID_DATE_MISSING_DATE);
00106                 ensure_equals("INVALID_DATE_MISSING_DATE should have failed" , result, false);
00107 
00108                 result = date.fromString(INVALID_DATE_MISSING_T);
00109                 ensure_equals("INVALID_DATE_MISSING_T should have failed" , result, false);
00110 
00111                 result = date.fromString(INVALID_DATE_MISSING_HOUR);
00112                 ensure_equals("INVALID_DATE_MISSING_HOUR should have failed" , result, false);
00113 
00114                 result = date.fromString(INVALID_DATE_MISSING_MIN);
00115                 ensure_equals("INVALID_DATE_MISSING_MIN should have failed" , result, false);
00116 
00117                 result = date.fromString(INVALID_DATE_MISSING_SEC);
00118                 ensure_equals("INVALID_DATE_MISSING_SEC should have failed" , result, false);
00119 
00120                 result = date.fromString(INVALID_DATE_MISSING_Z);
00121                 ensure_equals("INVALID_DATE_MISSING_Z should have failed" , result, false);
00122 
00123                 result = date.fromString(INVALID_DATE_EMPTY);
00124                 ensure_equals("INVALID_DATE_EMPTY should have failed" , result, false);
00125         }
00126 
00127         /* Invalid Value Handling */
00128         template<> template<>
00129         void date_test_object_t::test<2>()
00130         {
00131 #if LL_DATE_PARSER_CHECKS_BOUNDARY
00132                 LLDate date;
00133                 std::string  expected_string;
00134                 bool result;
00135 
00136                 result = date.fromString(INVALID_DATE_24HOUR_BOUNDARY);
00137                 ensure_equals("INVALID_DATE_24HOUR_BOUNDARY should have failed" , result, false);
00138                 ensure_equals("INVALID_DATE_24HOUR_BOUNDARY date still set to old value on failure!" , date.secondsSinceEpoch(), 0);
00139 
00140                 result = date.fromString(INVALID_DATE_LEAP);
00141                 ensure_equals("INVALID_DATE_LEAP should have failed" , result, false);
00142 
00143                 result = date.fromString(INVALID_DATE_HOUR);
00144                 ensure_equals("INVALID_DATE_HOUR should have failed" , result, false);
00145 
00146                 result = date.fromString(INVALID_DATE_MIN);
00147                 ensure_equals("INVALID_DATE_MIN should have failed" , result, false);
00148 
00149                 result = date.fromString(INVALID_DATE_SEC);
00150                 ensure_equals("INVALID_DATE_SEC should have failed" , result, false);
00151 
00152                 result = date.fromString(INVALID_DATE_YEAR);
00153                 ensure_equals("INVALID_DATE_YEAR should have failed" , result, false);
00154 
00155                 result = date.fromString(INVALID_DATE_MONTH);
00156                 ensure_equals("INVALID_DATE_MONTH should have failed" , result, false);
00157 
00158                 result = date.fromString(INVALID_DATE_DAY);
00159                 ensure_equals("INVALID_DATE_DAY should have failed" , result, false);
00160 #endif
00161         }
00162 
00163         /* API checks */
00164         template<> template<>
00165         void date_test_object_t::test<3>()
00166         {
00167                 LLDate date;
00168                 std::istringstream stream(VALID_DATE);
00169                 std::string  expected_string = VALID_DATE;
00170                 date.fromStream(stream);
00171                 ensure_equals("fromStream failed", date.asString(), expected_string);
00172         }
00173 
00174         template<> template<>
00175         void date_test_object_t::test<4>()
00176         {
00177                 LLDate date1(VALID_DATE);
00178                 LLDate date2(date1);
00179                 ensure_equals("LLDate(const LLDate& date) constructor failed", date1.asString(), date2.asString());
00180         }
00181 
00182         template<> template<>
00183         void date_test_object_t::test<5>()
00184         {
00185                 LLDate date1(VALID_DATE);
00186                 LLDate date2(date1.secondsSinceEpoch());
00187                 ensure_equals("secondsSinceEpoch not equal",date1.secondsSinceEpoch(), date2.secondsSinceEpoch());
00188                 ensure_equals("LLDate created using secondsSinceEpoch not equal", date1.asString(), date2.asString());
00189         }
00190 
00191         template<> template<>
00192         void date_test_object_t::test<6>()
00193         {
00194                 LLDate date(VALID_DATE);
00195                 std::ostringstream stream;
00196                 stream << date;
00197                 std::string expected_str = VALID_DATE;
00198                 ensure_equals("ostringstream failed", expected_str, stream.str());
00199         }
00200 
00201         template<> template<>
00202         void date_test_object_t::test<7>()
00203         {
00204                 LLDate date;
00205                 std::istringstream stream(VALID_DATE);
00206                 stream >> date;
00207                 std::string expected_str = VALID_DATE;
00208                 std::ostringstream out_stream;
00209         out_stream << date;
00210 
00211                 ensure_equals("<< failed", date.asString(),expected_str);
00212                 ensure_equals("<< to >> failed", stream.str(),out_stream.str());                
00213         }
00214 }

Generated on Thu Jul 1 06:08:24 2010 for Second Life Viewer by  doxygen 1.4.7