GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: test/glog/test_glog_vlog.cc Lines: 107 107 100.0 %
Date: 2025-03-04 18:34:12 Branches: 246 708 34.7 %

Line Branch Exec Source
1
//
2
// Created by 4c3y (acey) on 27.09.22.
3
//
4
5
#include <gtest/gtest.h>
6
#include <log++.h>
7
#include <test_utils.h>
8
9
4
TEST(glog_vlog, glog_syntax_severity_v1) {
10
2
  LOG_INIT(*test_argv);
11
2
  FLAGS_v = 3;
12
13





3
  std::string output = LPP_CAPTURE_STDERR(VLOG(1) << "Test" << 123);
14



2
  ASSERT_TRUE(isSubstring(output, "Test123"));
15




2
  ASSERT_TRUE(isSubstring(output, LPP_FILENAME));
16



2
  ASSERT_EQ(output[0], 'I');
17
}
18
19
4
TEST(glog_vlog, glog_syntax_severity_v3) {
20
2
  LOG_INIT(*test_argv);
21
2
  FLAGS_v = 3;
22
23




3
  std::string output = LPP_CAPTURE_STDERR(VLOG(3) << "Test123");
24



2
  ASSERT_TRUE(isSubstring(output, "Test123"));
25




2
  ASSERT_TRUE(isSubstring(output, LPP_FILENAME));
26



2
  ASSERT_EQ(output[0], 'I');
27
}
28
29
4
TEST(glog_vlog, glog_syntax_severity_v5) {
30
2
  LOG_INIT(*test_argv);
31
2
  FLAGS_v = 3;
32
33




3
  std::string output = LPP_CAPTURE_STDERR(VLOG(5) << "Test123");
34


2
  ASSERT_EQ(output, "");
35
}
36
37
4
TEST(glog_vlog, glog_syntax_if_severity_v1) {
38
2
  LOG_INIT(*test_argv);
39
2
  FLAGS_v = 3;
40
41




3
  std::string output = LPP_CAPTURE_STDERR(VLOG_IF(1, true) << "Test123");
42
43



2
  ASSERT_TRUE(isSubstring(output, "Test123"));
44




2
  ASSERT_TRUE(isSubstring(output, LPP_FILENAME));
45



2
  ASSERT_EQ(output[0], 'I');
46
}
47
48
4
TEST(glog_vlog, glog_syntax_if_severity_v3) {
49
2
  LOG_INIT(*test_argv);
50
2
  FLAGS_v = 3;
51
52




3
  std::string output = LPP_CAPTURE_STDERR(VLOG_IF(1, true) << "Test123");
53
54



2
  ASSERT_TRUE(isSubstring(output, "Test123"));
55




2
  ASSERT_TRUE(isSubstring(output, LPP_FILENAME));
56



2
  ASSERT_EQ(output[0], 'I');
57
}
58
59
4
TEST(glog_vlog, glog_syntax_if_severity_v5) {
60
2
  LOG_INIT(*test_argv);
61
2
  FLAGS_v = 3;
62
63




3
  std::string output = LPP_CAPTURE_STDERR(VLOG_IF(5, true) << "Test123");
64


2
  ASSERT_EQ(output, "");
65
}
66
67
4
TEST(glog_vlog, glog_syntax_ifnot_severity_v1) {
68
2
  LOG_INIT(*test_argv);
69
2
  FLAGS_v = 3;
70
71
3
  std::string output = LPP_CAPTURE_STDERR(VLOG_IF(1, false) << "Test123");
72


2
  ASSERT_EQ(output, "");
73
}
74
75
4
TEST(glog_vlog, glog_syntax_ifnot_severity_v3) {
76
2
  LOG_INIT(*test_argv);
77
2
  FLAGS_v = 3;
78
79
3
  std::string output = LPP_CAPTURE_STDERR(VLOG_IF(3, false) << "Test123");
80


2
  ASSERT_EQ(output, "");
81
}
82
83
4
TEST(glog_vlog, glog_syntax_ifnot_severity_v5) {
84
2
  LOG_INIT(*test_argv);
85
2
  FLAGS_v = 3;
86
87
3
  std::string output = LPP_CAPTURE_STDERR(VLOG_IF(5, false) << "Test123");
88


2
  ASSERT_EQ(output, "");
89
}
90
91
4
TEST(default_vlog, glog_syntax_every_n_severity_v1) {
92
2
  LOG_INIT(*test_argv);
93
2
  FLAGS_v = 3;
94
95
12
  for (int i = 0; i < 5; i++) {
96




15
    std::string output = LPP_CAPTURE_STDERR(VLOG_EVERY_N(1, 3) << "Test" << 123);
97
98
10
    if (i % 3 == 0) {
99



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




4
      ASSERT_TRUE(isSubstring(output, LPP_FILENAME));
101



4
      ASSERT_EQ(output[0], 'I');
102
    } else {
103


6
      ASSERT_EQ(output, "");
104
    }
105
  }
106
}
107
108
4
TEST(default_vlog, glog_syntax_every_n_severity_v3) {
109
2
  LOG_INIT(*test_argv);
110
2
  FLAGS_v = 3;
111
112
12
  for (int i = 0; i < 5; i++) {
113




15
    std::string output = LPP_CAPTURE_STDERR(VLOG_EVERY_N(3, 3) << "Test" << 123);
114
115
10
    if (i % 3 == 0) {
116



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




4
      ASSERT_TRUE(isSubstring(output, LPP_FILENAME));
118



4
      ASSERT_EQ(output[0], 'I');
119
    } else {
120


6
      ASSERT_EQ(output, "");
121
    }
122
  }
123
}
124
125
4
TEST(default_vlog, glog_syntax_every_n_severity_v5) {
126
2
  LOG_INIT(*test_argv);
127
2
  FLAGS_v = 3;
128
129
12
  for (int i = 0; i < 5; i++) {
130




15
    std::string output = LPP_CAPTURE_STDERR(VLOG_EVERY_N(5, 3) << "Test" << 123);
131


10
    ASSERT_EQ(output, "");
132
  }
133
}
134
135
4
TEST(default_vlog, glog_syntax_if_every_n_severity_v1) {
136
12
  for (int i = 0; i < 5; i++) {
137
10
    testing::internal::CaptureStderr();
138






10
    VLOG_IF_EVERY_N(1, i <= 3, 3) << "Test" << 123;
139
10
    std::string output = testing::internal::GetCapturedStderr();
140
141
142

10
    if (i <= 3 && i % 3 == 0) {
143



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




4
      ASSERT_TRUE(isSubstring(output, LPP_FILENAME));
145



8
      ASSERT_EQ(output[0], 'I');
146
    } else {
147


6
      ASSERT_EQ(output, "");
148
    }
149
  }
150
}
151
152
4
TEST(default_vlog, glog_syntax_if_every_n_severity_v3) {
153
12
  for (int i = 0; i < 5; i++) {
154
10
    testing::internal::CaptureStderr();
155






10
    VLOG_IF_EVERY_N(3, i <= 3, 3) << "Test" << 123;
156
10
    std::string output = testing::internal::GetCapturedStderr();
157
158
159

10
    if (i <= 3 && i % 3 == 0) {
160



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




4
      ASSERT_TRUE(isSubstring(output, LPP_FILENAME));
162



8
      ASSERT_EQ(output[0], 'I');
163
    } else {
164


6
      ASSERT_EQ(output, "");
165
    }
166
  }
167
}
168
169
2
TEST(default_vlog, glog_syntax_if_every_n_severity_v5) {
170
1
  LOG_INIT(*test_argv);
171
1
  FLAGS_v = 3;
172
173
6
  for (int i = 0; i < 5; i++) {
174
5
    testing::internal::CaptureStderr();
175
5
    VLOG_IF_EVERY_N(5, i <= 3, 3) << "Test" << 123;
176
5
    std::string output = testing::internal::GetCapturedStderr();
177
178
5
    ASSERT_EQ(output, "");
179
  }
180
}