GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: test/lpp/custom/test_lpp_custom_log_string.cc Lines: 48 48 100.0 %
Date: 2025-03-04 18:34:12 Branches: 74 214 34.6 %

Line Branch Exec Source
1
//
2
// Created by 4c3y (acey) on 24.11.22.
3
//
4
5
#include <gtest/gtest.h>
6
#include <log++.h>
7
#include <test_utils.h>
8
#include "callback.h"
9
10
using namespace lpp::custom;
11
12
4
TEST(lpp_log_string, severity_info) {
13

2
  LOG_INIT(*test_argv, logCallback);
14
15
2
  std::vector<std::string> errors;
16
17
//Can't capture variables in lambda with LPP_CAPTURE_STDERR()
18
2
  testing::internal::CaptureStdout();
19

2
  LOG_STRING(INFO, &errors) << "test" << 123;
20
2
  std::string output = testing::internal::GetCapturedStdout();
21
22


2
  ASSERT_EQ(output, "");
23



2
  ASSERT_EQ("test123", errors.at(0));
24
}
25
26
4
TEST(lpp_log_string, severity_info_null) {
27

2
  LOG_INIT(*test_argv, logCallback);
28
29

3
  std::string output = LPP_CAPTURE_STDOUT(LOG_STRING(INFO, nullptr) << "test" << 123);
30



4
  ASSERT_EQ(output, info + test123);
31
}
32
33
4
TEST(lpp_log_string, severity_warning) {
34

2
  LOG_INIT(*test_argv, logCallback);
35
36
2
  std::vector<std::string> errors;
37
38
//Can't capture variables in lambda with LPP_CAPTURE_STDERR()
39
2
  testing::internal::CaptureStdout();
40

2
  LOG_STRING(WARNING, &errors) << "test" << 123;
41
2
  std::string output = testing::internal::GetCapturedStdout();
42
43


2
  ASSERT_EQ(output, "");
44



2
  ASSERT_EQ("test123", errors.at(0));
45
}
46
47
4
TEST(lpp_log_string, severity_warning_null) {
48

2
  LOG_INIT(*test_argv, logCallback);
49
50

3
  std::string output = LPP_CAPTURE_STDOUT(LOG_STRING(WARNING, nullptr) << "test" << 123);
51



4
  ASSERT_EQ(output, warning + test123);
52
}
53
54
4
TEST(lpp_log_string, severity_error) {
55

2
  LOG_INIT(*test_argv, logCallback);
56
57
2
  std::vector<std::string> errors;
58
59
//Can't capture variables in lambda with LPP_CAPTURE_STDERR()
60
2
  testing::internal::CaptureStdout();
61

2
  LOG_STRING(ERROR, &errors) << "test" << 123;
62
2
  std::string output = testing::internal::GetCapturedStdout();
63
64


2
  ASSERT_EQ(output, "");
65



2
  ASSERT_EQ("test123", errors.at(0));
66
}
67
68
4
TEST(lpp_log_string, severity_error_null) {
69

2
  LOG_INIT(*test_argv, logCallback);
70
71

3
  std::string output = LPP_CAPTURE_STDOUT(LOG_STRING(ERROR, nullptr) << "test" << 123);
72



4
  ASSERT_EQ(output, error + test123);
73
}
74
75
4
TEST(lpp_log_string, severity_fatal) {
76

2
  LOG_INIT(*test_argv, logCallback);
77
78
2
  std::vector<std::string> errors;
79
80
//Can't capture variables in lambda with LPP_CAPTURE_STDERR()
81
2
  testing::internal::CaptureStdout();
82

2
  LOG_STRING(FATAL, &errors) << "test" << 123;
83
2
  std::string output = testing::internal::GetCapturedStdout();
84


2
  ASSERT_EQ(output, "");
85
86



2
  ASSERT_EQ("test123", errors.at(0));
87
}
88
89
2
TEST(lpp_log_string, severity_fatal_null) {
90
1
  LOG_INIT(*test_argv, logCallback);
91
92

2
  std::string output = LPP_CAPTURE_STDOUT(LOG_STRING(FATAL, nullptr) << "test" << 123);
93
2
  ASSERT_EQ(output, fatal + test123);
94
}