llhttpdate_tut.cpp

Go to the documentation of this file.
00001 
00033 #include "linden_common.h"
00034 #include "lltut.h"
00035 
00036 #include "lldate.h"
00037 #include "llframetimer.h"
00038 
00039 namespace tut
00040 {
00041     struct httpdate_data
00042     {
00043         LLDate some_date;
00044     };
00045     typedef test_group<httpdate_data> httpdate_test;
00046     typedef httpdate_test::object httpdate_object;
00047     tut::httpdate_test httpdate("httpdate");
00048 
00049     template<> template<>
00050     void httpdate_object::test<1>()
00051     {
00052         static std::string epoch_expected = "Thursday, 01 Jan 1970 00:00:00 GMT" ;
00053         ensure("Check Epoch in RFC 1123", ( epoch_expected == some_date.asRFC1123()));
00054     }
00055 
00056     template<> template<>
00057     void httpdate_object::test<2>()
00058     {
00059         static std::string expected = "Wednesday, 18 Jul 2007 22:17:24 GMT" ;
00060         some_date = LLDate(1184797044.037586);
00061         ensure("Check some timestamp in RFC 1123", ( expected == some_date.asRFC1123()));
00062     }
00063 
00064     // This test of course most generic.. runs off current time
00065     template<> template<>
00066     void httpdate_object::test<3>()
00067     {
00068         //F64 sometime = LLFrameTimer::getTotalSeconds();
00069         time_t sometime;
00070         time(&sometime);
00071         some_date = LLDate((F64) sometime);
00072         struct tm result;
00073         char expected[255], *actual;
00074         
00075         gmtime_r((time_t *)&sometime, &result);
00076         /*
00077         std::cout << " seconds: "<< result.tm_sec 
00078                   << ", minutes: " << result.tm_min
00079                   << ", hours: " << result.tm_hour
00080                   << ", day of the month: " << result.tm_mday
00081                   << ", month: " << result.tm_mon
00082                   << ", year: " << result.tm_year
00083                   << ", day of the week: " << result.tm_wday
00084                   << ", day in the year: " << result.tm_yday
00085                   << ", DST: " << result.tm_isdst << std::endl;
00086         */
00087         strftime(expected, 255, "%A, %d %h %Y %H:%M:%S GMT", &result);
00088         actual = (char *) some_date.asRFC1123().c_str();
00089         // probably not a good idea to use strcmp but this is just a unit test
00090         ensure("Current time in RFC 1123", (strcmp(expected, actual) == 0));
00091     }
00092 }

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