< prev index next >

test/native/logging/test_logDecorations.cpp

Print this page
rev 11906 : 8164939: GTest LogDecorations.iso8601_time_test fails on macOS


 127   ASSERT_TRUE(decorator_selection.parse("time"));
 128   LogDecorations decorations(LogLevel::Info, tagset, decorator_selection);
 129 
 130   const char *timestr = decorations.decoration(LogDecorators::time_decorator);
 131   time_t expected_ts = time(NULL);
 132 
 133   // Verify format
 134   int y, M, d, h, m;
 135   double s;
 136   int read = sscanf(timestr, "%d-%d-%dT%d:%d:%lfZ", &y, &M, &d, &h, &m, &s);
 137   ASSERT_EQ(6, read);
 138 
 139   // Verify reported time & date
 140   struct tm reported_time = {0};
 141   reported_time.tm_year = y - 1900;
 142   reported_time.tm_mon = M - 1;
 143   reported_time.tm_mday = d;
 144   reported_time.tm_hour = h;
 145   reported_time.tm_min = m;
 146   reported_time.tm_sec = s;
 147   reported_time.tm_isdst = daylight;
 148   time_t reported_ts = mktime(&reported_time);
 149   expected_ts = mktime(localtime(&expected_ts));
 150   time_t diff = reported_ts - expected_ts;
 151   if (diff < 0) {
 152     diff = -diff;
 153   }
 154   // Allow up to 10 seconds in difference
 155   ASSERT_LE(diff, 10) << "Reported time: " << reported_ts << " (" << timestr << ")"
 156       << ", expected time: " << expected_ts;
 157 }
 158 
 159 // Test the pid and tid decorations
 160 TEST(LogDecorations, identifiers) {
 161   LogDecorators decorator_selection;
 162   ASSERT_TRUE(decorator_selection.parse("pid,tid"));
 163   LogDecorations decorations(LogLevel::Info, tagset, decorator_selection);
 164 
 165   struct {
 166       intx expected;
 167       LogDecorators::Decorator decorator;


 127   ASSERT_TRUE(decorator_selection.parse("time"));
 128   LogDecorations decorations(LogLevel::Info, tagset, decorator_selection);
 129 
 130   const char *timestr = decorations.decoration(LogDecorators::time_decorator);
 131   time_t expected_ts = time(NULL);
 132 
 133   // Verify format
 134   int y, M, d, h, m;
 135   double s;
 136   int read = sscanf(timestr, "%d-%d-%dT%d:%d:%lfZ", &y, &M, &d, &h, &m, &s);
 137   ASSERT_EQ(6, read);
 138 
 139   // Verify reported time & date
 140   struct tm reported_time = {0};
 141   reported_time.tm_year = y - 1900;
 142   reported_time.tm_mon = M - 1;
 143   reported_time.tm_mday = d;
 144   reported_time.tm_hour = h;
 145   reported_time.tm_min = m;
 146   reported_time.tm_sec = s;
 147   reported_time.tm_isdst = -1; // let mktime deduce DST settings
 148   time_t reported_ts = mktime(&reported_time);
 149   expected_ts = mktime(localtime(&expected_ts));
 150   time_t diff = reported_ts - expected_ts;
 151   if (diff < 0) {
 152     diff = -diff;
 153   }
 154   // Allow up to 10 seconds in difference
 155   ASSERT_LE(diff, 10) << "Reported time: " << reported_ts << " (" << timestr << ")"
 156       << ", expected time: " << expected_ts;
 157 }
 158 
 159 // Test the pid and tid decorations
 160 TEST(LogDecorations, identifiers) {
 161   LogDecorators decorator_selection;
 162   ASSERT_TRUE(decorator_selection.parse("pid,tid"));
 163   LogDecorations decorations(LogLevel::Info, tagset, decorator_selection);
 164 
 165   struct {
 166       intx expected;
 167       LogDecorators::Decorator decorator;
< prev index next >