GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: test/lpp/custom/test_lpp_custom_every_n.cc Lines: 70 70 100.0 %
Date: 2025-03-04 18:34:12 Branches: 154 380 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_LogEveryN, 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_EVERY(D, 3, "test" << 123));
16
17
10
    if (i % 3 == 0) {
18



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


6
      ASSERT_EQ(output, "");
21
    }
22
  }
23
}
24
25
4
TEST(lpp_custom_LogEveryN, 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_EVERY(I, 3, "test" << 123));
29
30
10
    if (i % 3 == 0) {
31



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


6
      ASSERT_EQ(output, "");
34
    }
35
  }
36
}
37
38
4
TEST(lpp_custom_LogEveryN, 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_EVERY(W, 3, "test" << 123));
42
43
10
    if (i % 3 == 0) {
44



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


6
      ASSERT_EQ(output, "");
47
    }
48
  }
49
}
50
51
4
TEST(lpp_custom_LogEveryN, 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_EVERY(E, 3, "test" << 123));
55
56
10
    if (i % 3 == 0) {
57



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


6
      ASSERT_EQ(output, "");
60
    }
61
  }
62
}
63
64
4
TEST(lpp_custom_LogEveryN, 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_EVERY(F, 3, "test" << 123));
68
69
10
    if (i % 3 == 0) {
70



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


6
      ASSERT_EQ(output, "");
73
    }
74
  }
75
}
76
77
4
TEST(lpp_custom_LogEveryN, 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_EVERY_N(INFO, 3) << "test" << 123);
81
82
10
    if (i % 3 == 0) {
83



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


6
      ASSERT_EQ(output, "");
86
    }
87
  }
88
}
89
90
4
TEST(lpp_custom_LogEveryN, 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_EVERY_N(INFO, 3) << "test" << 123);
94
95
10
    if (i % 3 == 0) {
96



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


6
      ASSERT_EQ(output, "");
99
    }
100
  }
101
}
102
103
4
TEST(lpp_custom_LogEveryN, 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_EVERY_N(WARNING, 3) << "test" << 123);
107
108
10
    if (i % 3 == 0) {
109



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


6
      ASSERT_EQ(output, "");
112
    }
113
  }
114
}
115
116
4
TEST(lpp_custom_LogEveryN, 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_EVERY_N(ERROR, 3) << "test" << 123);
120
121
10
    if (i % 3 == 0) {
122



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


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


10
    std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY_N(FATAL, 3) << "test" << 123);
133
134
5
    if (i % 3 == 0) {
135
4
      ASSERT_EQ(output, fatal + test123);
136
    } else {
137
3
      ASSERT_EQ(output, "");
138
    }
139
  }
140
}