GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: test/glog/test_glog_every_n.cc Lines: 76 84 90.5 %
Date: 2025-03-04 18:34:12 Branches: 184 594 31.0 %

Line Branch Exec Source
1
//
2
// Created by 4c3y (acey) on 08.09.22.
3
//
4
5
#include <gtest/gtest.h>
6
#include <test_utils.h>
7
#include <log++.h>
8
9
4
TEST(glog_LogEveryN, lpp_syntax_severity_debug) {
10
2
  LOG_INIT(*test_argv);
11
12
12
  for (int i = 0; i < 5; i++) {
13


15
    std::string output = LPP_CAPTURE_STDERR(LOG_EVERY(D, 3, "Test" << 123));
14
15
10
    if (i % 3 == 0) {
16



4
      ASSERT_TRUE(isSubstring(output, "Test123"));
17



4
      ASSERT_TRUE(isSubstring(output, "test_glog_every_n.cc"));
18



4
      ASSERT_EQ(output[0], 'I');
19
    } else {
20


6
      ASSERT_EQ(output, "");
21
    }
22
  }
23
}
24
25
4
TEST(glog_LogEveryN, lpp_syntax_severity_info) {
26
2
  LOG_INIT(*test_argv);
27
28
12
  for (int i = 0; i < 5; i++) {
29


15
    std::string output = LPP_CAPTURE_STDERR(LOG_EVERY(I, 3, "Test" << 123));
30
31
10
    if (i % 3 == 0) {
32



4
      ASSERT_TRUE(isSubstring(output, "Test123"));
33



4
      ASSERT_TRUE(isSubstring(output, "test_glog_every_n.cc"));
34



4
      ASSERT_EQ(output[0], 'I');
35
    } else {
36


6
      ASSERT_EQ(output, "");
37
    }
38
  }
39
}
40
41
4
TEST(glog_LogEveryN, lpp_syntax_severity_warning) {
42
2
  LOG_INIT(*test_argv);
43
44
12
  for (int i = 0; i < 5; i++) {
45


15
    std::string output = LPP_CAPTURE_STDERR(LOG_EVERY(W, 3, "Test" << 123));
46
47
10
    if (i % 3 == 0) {
48



4
      ASSERT_TRUE(isSubstring(output, "Test123"));
49



4
      ASSERT_TRUE(isSubstring(output, "test_glog_every_n.cc"));
50



4
      ASSERT_EQ(output[0], 'W');
51
    } else {
52


6
      ASSERT_EQ(output, "");
53
    }
54
  }
55
}
56
57
4
TEST(glog_LogEveryN, lpp_syntax_severity_error) {
58
2
  LOG_INIT(*test_argv);
59
60
12
  for (int i = 0; i < 5; i++) {
61


15
    std::string output = LPP_CAPTURE_STDERR(LOG_EVERY(E, 3, "Test" << 123));
62
63
10
    if (i % 3 == 0) {
64



4
      ASSERT_TRUE(isSubstring(output, "Test123"));
65



4
      ASSERT_TRUE(isSubstring(output, "test_glog_every_n.cc"));
66



4
      ASSERT_EQ(output[0], 'E');
67
    } else {
68


6
      ASSERT_EQ(output, "");
69
    }
70
  }
71
}
72
73
4
TEST(glog_LogEveryN, glog_syntax_severity_debug) {
74
2
  LOG_INIT(*test_argv);
75
76
12
  for (int i = 0; i < 5; i++) {
77


15
    std::string output = LPP_CAPTURE_STDERR(DLOG_EVERY_N(INFO, 3) << "Test" << 123);
78
79
10
    if (i % 3 == 0) {
80



4
      ASSERT_TRUE(isSubstring(output, "Test123"));
81



4
      ASSERT_TRUE(isSubstring(output, "test_glog_every_n.cc"));
82



4
      ASSERT_EQ(output[0], 'I');
83
    } else {
84


6
      ASSERT_EQ(output, "");
85
    }
86
  }
87
}
88
89
4
TEST(glog_LogEveryN, glog_syntax_severity_info) {
90
2
  LOG_INIT(*test_argv);
91
92
12
  for (int i = 0; i < 5; i++) {
93


15
    std::string output = LPP_CAPTURE_STDERR(LOG_EVERY_N(INFO, 3) << "Test" << 123);
94
95
10
    if (i % 3 == 0) {
96



4
      ASSERT_TRUE(isSubstring(output, "Test123"));
97



4
      ASSERT_TRUE(isSubstring(output, "test_glog_every_n.cc"));
98



4
      ASSERT_EQ(output[0], 'I');
99
    } else {
100


6
      ASSERT_EQ(output, "");
101
    }
102
  }
103
}
104
105
4
TEST(glog_LogEveryN, glog_syntax_severity_warning) {
106
2
  LOG_INIT(*test_argv);
107
108
12
  for (int i = 0; i < 5; i++) {
109


15
    std::string output = LPP_CAPTURE_STDERR(LOG_EVERY_N(WARNING, 3) << "Test" << 123);
110
111
10
    if (i % 3 == 0) {
112



4
      ASSERT_TRUE(isSubstring(output, "Test123"));
113



4
      ASSERT_TRUE(isSubstring(output, "test_glog_every_n.cc"));
114



4
      ASSERT_EQ(output[0], 'W');
115
    } else {
116


6
      ASSERT_EQ(output, "");
117
    }
118
  }
119
}
120
121
4
TEST(glog_LogEveryN, glog_syntax_severity_error) {
122
2
  LOG_INIT(*test_argv);
123
124
12
  for (int i = 0; i < 5; i++) {
125


15
    std::string output = LPP_CAPTURE_STDERR(LOG_EVERY_N(ERROR, 3) << "Test" << 123);
126
127
10
    if (i % 3 == 0) {
128



4
      ASSERT_TRUE(isSubstring(output, "Test123"));
129



4
      ASSERT_TRUE(isSubstring(output, "test_glog_every_n.cc"));
130



4
      ASSERT_EQ(output[0], 'E');
131
    } else {
132


6
      ASSERT_EQ(output, "");
133
    }
134
  }
135
}
136
137
2
TEST(glog_LogEveryN, glog_syntax_severity_fatal) {
138
1
  LOG_INIT(*test_argv);
139
140
  std::function<void()> fn = []() {
141
    for (int i = 0; i < 5; i++) {
142
      std::string output = LPP_CAPTURE_STDERR(LOG_EVERY_N(FATAL, 3) << "Test" << 123);
143
144
      if (i % 3 == 0) {
145
        ASSERT_TRUE(isSubstring(output, "Test123"));
146
        ASSERT_TRUE(isSubstring(output, "test_glog_every_n.cc"));
147
        ASSERT_EQ(output[0], 'E');
148
      } else {
149
        ASSERT_EQ(output, "");
150
      }
151
    }
152
1
  };
153
1
  ASSERT_TRUE(checkAbort(fn));
154
}