< prev index next >

test/native/logging/test_logTagSet.cpp

Print this page
rev 11942 : 8165600: Convert internal logging tests to GTest


 111 
 112 TEST(LogTagSet, label) {
 113   char buf[256];
 114   const LogTagSet& ts = LogTagSetMapping<LOG_TAGS(logging, safepoint)>::tagset();
 115   ASSERT_NE(-1, ts.label(buf, sizeof(buf)));
 116   EXPECT_STREQ("logging,safepoint", buf);
 117   // Verify using a custom separator
 118   ASSERT_NE(-1, ts.label(buf, sizeof(buf), "++"));
 119   EXPECT_STREQ("logging++safepoint", buf);
 120 
 121   // Verify with three tags
 122   const LogTagSet& ts1 = LogTagSetMapping<LOG_TAGS(logging, safepoint, jni)>::tagset();
 123   ASSERT_NE(-1, ts1.label(buf, sizeof(buf)));
 124   EXPECT_STREQ("logging,safepoint,jni", buf);
 125 
 126   // Verify with a single tag
 127   const LogTagSet& ts2 = LogTagSetMapping<LOG_TAGS(logging)>::tagset();
 128   ASSERT_NE(-1, ts2.label(buf, sizeof(buf)));
 129   EXPECT_STREQ("logging", buf);
 130 }













































 111 
 112 TEST(LogTagSet, label) {
 113   char buf[256];
 114   const LogTagSet& ts = LogTagSetMapping<LOG_TAGS(logging, safepoint)>::tagset();
 115   ASSERT_NE(-1, ts.label(buf, sizeof(buf)));
 116   EXPECT_STREQ("logging,safepoint", buf);
 117   // Verify using a custom separator
 118   ASSERT_NE(-1, ts.label(buf, sizeof(buf), "++"));
 119   EXPECT_STREQ("logging++safepoint", buf);
 120 
 121   // Verify with three tags
 122   const LogTagSet& ts1 = LogTagSetMapping<LOG_TAGS(logging, safepoint, jni)>::tagset();
 123   ASSERT_NE(-1, ts1.label(buf, sizeof(buf)));
 124   EXPECT_STREQ("logging,safepoint,jni", buf);
 125 
 126   // Verify with a single tag
 127   const LogTagSet& ts2 = LogTagSetMapping<LOG_TAGS(logging)>::tagset();
 128   ASSERT_NE(-1, ts2.label(buf, sizeof(buf)));
 129   EXPECT_STREQ("logging", buf);
 130 }
 131 
 132 TEST(logging, LogTagSet_duplicates) {
 133   for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
 134     char ts_name[512];
 135     ts->label(ts_name, sizeof(ts_name), ",");
 136 
 137     // verify that NO_TAG is never followed by a real tag
 138     for (size_t i = 0; i < LogTag::MaxTags; i++) {
 139       if (ts->tag(i) == LogTag::__NO_TAG) {
 140         for (i++; i < LogTag::MaxTags; i++) {
 141           EXPECT_EQ(LogTag::__NO_TAG, ts->tag(i))
 142             << "NO_TAG was followed by a real tag (" << LogTag::name(ts->tag(i)) << ") in tagset " <<  ts_name;
 143         }
 144       }
 145     }
 146 
 147     // verify that there are no duplicate tagsets (same tags in different order)
 148     for (LogTagSet* other = ts->next(); other != NULL; other = other->next()) {
 149       if (ts->ntags() != other->ntags()) {
 150         continue;
 151       }
 152       bool equal = true;
 153       for (size_t i = 0; i < ts->ntags(); i++) {
 154         LogTagType tag = ts->tag(i);
 155         if (!other->contains(tag)) {
 156           equal = false;
 157           break;
 158         }
 159       }
 160       // Since tagsets are implemented using template arguments, using both of
 161       // the (logically equivalent) tagsets (t1, t2) and (t2, t1) somewhere will
 162       // instantiate two different LogTagSetMappings. This causes multiple
 163       // tagset instances to be created for the same logical set. We want to
 164       // avoid this to save time, memory and prevent any confusion around it.
 165       if (equal) {
 166         char other_name[512];
 167         other->label(other_name, sizeof(other_name), ",");
 168         FAIL() << "duplicate LogTagSets found: '" << ts_name << "' vs '" << other_name << "' "
 169           << "(tags must always be specified in the same order for each tagset)";
 170       }
 171     }
 172   }
 173 }
< prev index next >