GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: test/roslog/test_roslog_log_string.cc Lines: 48 48 100.0 %
Date: 2025-03-04 18:34:12 Branches: 70 206 34.0 %

Line Branch Exec Source
1
//
2
// Created by 4c3y (acey) on 28.09.22.
3
//
4
5
#include <gtest/gtest.h>
6
#include <log++.h>
7
#include <test_utils.h>
8
9
using namespace lpp::logstr;
10
11
4
TEST(roslog_log_string, severity_info) {
12
2
  LOG_INIT(*test_argv);
13
14
2
  std::vector<std::string> errors;
15
16
  //Can't capture variables in lambda with LPP_CAPTURE_STDERR()
17
2
  testing::internal::CaptureStdout();
18

2
  LOG_STRING(INFO, &errors) << "LOG_STRING: " << "collected info";
19
2
  std::string output = testing::internal::GetCapturedStdout();
20
21


2
  ASSERT_EQ(output, "");
22



2
  ASSERT_EQ("LOG_STRING: collected info", errors.at(0));
23
}
24
25
4
TEST(roslog_log_string, severity_info_null) {
26
2
  LOG_INIT(*test_argv);
27
28

3
  std::string output = LPP_CAPTURE_STDOUT(LOG_STRING(INFO, nullptr) << "LOG_STRING: " << "collected info");
29



4
  ASSERT_EQ(removeNumbersFromString(output), info);
30
}
31
32
4
TEST(roslog_log_string, severity_warning) {
33
2
  LOG_INIT(*test_argv);
34
35
2
  std::vector<std::string> errors;
36
37
  //Can't capture variables in lambda with LPP_CAPTURE_STDERR()
38
2
  testing::internal::CaptureStderr();
39

2
  LOG_STRING(WARNING, &errors) << "LOG_STRING: " << "collected warn";
40
2
  std::string output = testing::internal::GetCapturedStderr();
41
42


2
  ASSERT_EQ(output, "");
43



2
  ASSERT_EQ("LOG_STRING: collected warn", errors.at(0));
44
}
45
46
4
TEST(roslog_log_string, severity_warning_null) {
47
2
  LOG_INIT(*test_argv);
48
49

3
  std::string output = LPP_CAPTURE_STDERR(LOG_STRING(WARNING, nullptr) << "LOG_STRING: " << "collected warn");
50



4
  ASSERT_EQ(removeNumbersFromString(output), warning);
51
}
52
53
4
TEST(roslog_log_string, severity_error) {
54
2
  LOG_INIT(*test_argv);
55
56
2
  std::vector<std::string> errors;
57
58
  //Can't capture variables in lambda with LPP_CAPTURE_STDERR()
59
2
  testing::internal::CaptureStderr();
60

2
  LOG_STRING(ERROR, &errors) << "LOG_STRING: " << "collected error";
61
2
  std::string output = testing::internal::GetCapturedStderr();
62
63


2
  ASSERT_EQ(output, "");
64



2
  ASSERT_EQ("LOG_STRING: collected error", errors.at(0));
65
}
66
67
4
TEST(roslog_log_string, severity_error_null) {
68
2
  LOG_INIT(*test_argv);
69
70

3
  std::string output = LPP_CAPTURE_STDERR(LOG_STRING(ERROR, nullptr) << "LOG_STRING: " << "collected error");
71



4
  ASSERT_EQ(removeNumbersFromString(output), error);
72
}
73
74
4
TEST(roslog_log_string, severity_fatal) {
75
2
  LOG_INIT(*test_argv);
76
77
2
  std::vector<std::string> errors;
78
79
  //Can't capture variables in lambda with LPP_CAPTURE_STDERR()
80
2
  testing::internal::CaptureStderr();
81

2
  LOG_STRING(FATAL, &errors) << "LOG_STRING: " << "collected fatal";
82
2
  std::string output = testing::internal::GetCapturedStderr();
83


2
  ASSERT_EQ(output, "");
84
85



2
  ASSERT_EQ("LOG_STRING: collected fatal", errors.at(0));
86
}
87
88
2
TEST(roslog_log_string, severity_fatal_null) {
89
1
  LOG_INIT(*test_argv);
90
91

2
  std::string output = LPP_CAPTURE_STDERR(LOG_STRING(FATAL, nullptr) << "LOG_STRING: " << "collected fatal");
92
2
  ASSERT_EQ(removeNumbersFromString(output), fatal);
93
}