GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: test/lpp/custom/test_lpp_custom_first_n.cc Lines: 105 105 100.0 %
Date: 2025-03-04 18:34:12 Branches: 239 590 40.5 %

Line Branch Exec Source
1
//
2
// Created by 4c3y (acey) on 24.11.22.
3
//
4
5
#include <gtest/gtest.h>
6
#include <test_utils.h>
7
#include <log++.h>
8
#include "callback.h"
9
10
using namespace lpp::custom;
11
12
4
TEST(lpp_custom_LogFirstN, lpp_syntax_severity_debug) {
13
2
  LOG_INIT(*test_argv, logCallback);
14
12
  for (int i = 0; i < 5; i++) {
15



15
    std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST(D, 3, "test" << 123));
16
17
10
    if (i < 3) {
18



12
      ASSERT_EQ(output, debug + test123);
19
    } else {
20


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



15
    std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST(I, 3, "test" << 123));
29
30
10
    if (i < 3) {
31



12
      ASSERT_EQ(output, info + test123);
32
    } else {
33


4
      ASSERT_EQ(output, "");
34
    }
35
  }
36
}
37
38
4
TEST(lpp_custom_LogFirstN, lpp_syntax_severity_warning) {
39
2
  LOG_INIT(*test_argv, logCallback);
40
12
  for (int i = 0; i < 5; i++) {
41



15
    std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST(W, 3, "test" << 123));
42
43
10
    if (i < 3) {
44



12
      ASSERT_EQ(output, warning + test123);
45
    } else {
46


4
      ASSERT_EQ(output, "");
47
    }
48
  }
49
}
50
51
4
TEST(lpp_custom_LogFirstN, lpp_syntax_severity_error) {
52
2
  LOG_INIT(*test_argv, logCallback);
53
12
  for (int i = 0; i < 5; i++) {
54



15
    std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST(E, 3, "test" << 123));
55
56
10
    if (i < 3) {
57



12
      ASSERT_EQ(output, error + test123);
58
    } else {
59


4
      ASSERT_EQ(output, "");
60
    }
61
  }
62
}
63
64
4
TEST(lpp_custom_LogFirstN, lpp_syntax_severity_fatal) {
65
2
  LOG_INIT(*test_argv, logCallback);
66
12
  for (int i = 0; i < 5; i++) {
67



15
    std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST(F, 3, "test" << 123));
68
69
10
    if (i < 3) {
70



12
      ASSERT_EQ(output, fatal + test123);
71
    } else {
72


4
      ASSERT_EQ(output, "");
73
    }
74
  }
75
}
76
77
4
TEST(lpp_custom_LogFirstN, glog_syntax_severity_debug) {
78
2
  LOG_INIT(*test_argv, logCallback);
79
12
  for (int i = 0; i < 5; i++) {
80



15
    std::string output = LPP_CAPTURE_STDOUT(DLOG_FIRST_N(INFO, 3) << "test" << 123);
81
82
10
    if (i < 3) {
83



12
      ASSERT_EQ(output, debug + test123);
84
    } else {
85


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



15
    std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST_N(INFO, 3) << "test" << 123);
94
95
10
    if (i < 3) {
96



12
      ASSERT_EQ(output, info + test123);
97
    } else {
98


4
      ASSERT_EQ(output, "");
99
    }
100
  }
101
}
102
103
4
TEST(lpp_custom_LogFirstN, glog_syntax_severity_warning) {
104
2
  LOG_INIT(*test_argv, logCallback);
105
12
  for (int i = 0; i < 5; i++) {
106



15
    std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST_N(WARNING, 3) << "test" << 123);
107
108
10
    if (i < 3) {
109



12
      ASSERT_EQ(output, warning + test123);
110
    } else {
111


4
      ASSERT_EQ(output, "");
112
    }
113
  }
114
}
115
116
4
TEST(lpp_custom_LogFirstN, glog_syntax_severity_error) {
117
2
  LOG_INIT(*test_argv, logCallback);
118
12
  for (int i = 0; i < 5; i++) {
119



15
    std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST_N(ERROR, 3) << "test" << 123);
120
121
10
    if (i < 3) {
122



12
      ASSERT_EQ(output, error + test123);
123
    } else {
124


4
      ASSERT_EQ(output, "");
125
    }
126
  }
127
}
128
129
4
TEST(lpp_custom_LogFirstN, glog_syntax_severity_fatal) {
130
2
  LOG_INIT(*test_argv, logCallback);
131
12
  for (int i = 0; i < 5; i++) {
132



15
    std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST_N(FATAL, 3) << "test" << 123);
133
134
10
    if (i < 3) {
135



12
      ASSERT_EQ(output, fatal + test123);
136
    } else {
137


4
      ASSERT_EQ(output, "");
138
    }
139
  }
140
}
141
142
4
TEST(lpp_custom_LogFirstN, ros_debug_once) {
143
2
  LOG_INIT(*test_argv, logCallback);
144
145
12
  for (int i = 0; i < 5; i++) {
146



15
    std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG_ONCE("test123"));
147
148
10
    if (i == 0) {
149



4
      ASSERT_EQ(output, debug + test123);
150
    } else {
151


8
      ASSERT_EQ("", output);
152
    }
153
  }
154
}
155
156
4
TEST(lpp_custom_LogFirstN, ros_info_once) {
157
2
  LOG_INIT(*test_argv, logCallback);
158
159
12
  for (int i = 0; i < 5; i++) {
160



15
    std::string output = LPP_CAPTURE_STDOUT(ROS_INFO_ONCE("test123"));
161
162
10
    if (i == 0) {
163



4
      ASSERT_EQ(output, info + test123);
164
    } else {
165


8
      ASSERT_EQ("", output);
166
    }
167
  }
168
}
169
170
4
TEST(lpp_custom_LogFirstN, ros_warn_once) {
171
2
  LOG_INIT(*test_argv, logCallback);
172
173
12
  for (int i = 0; i < 5; i++) {
174



15
    std::string output = LPP_CAPTURE_STDOUT(ROS_WARN_ONCE("test123"));
175
176
10
    if (i == 0) {
177



4
      ASSERT_EQ(output, warning + test123);
178
    } else {
179


8
      ASSERT_EQ("", output);
180
    }
181
  }
182
}
183
184
4
TEST(lpp_custom_LogFirstN, ros_error_once) {
185
2
  LOG_INIT(*test_argv, logCallback);
186
187
12
  for (int i = 0; i < 5; i++) {
188



15
    std::string output = LPP_CAPTURE_STDOUT(ROS_ERROR_ONCE("test123"));
189
190
10
    if (i == 0) {
191



4
      ASSERT_EQ(output, error + test123);
192
    } else {
193


8
      ASSERT_EQ("", output);
194
    }
195
  }
196
}
197
198
2
TEST(lpp_custom_LogFirstN, ros_fatal_once) {
199
1
  LOG_INIT(*test_argv, logCallback);
200
201
6
  for (int i = 0; i < 5; i++) {
202



10
    std::string output = LPP_CAPTURE_STDOUT(ROS_FATAL_ONCE("test123"));
203
204
5
    if (i == 0) {
205
2
      ASSERT_EQ(output, fatal + test123);
206
    } else {
207
4
      ASSERT_EQ("", output);
208
    }
209
  }
210
}