Skip to content

Commit 0b0ef58

Browse files
committed
Fix valgrind issues with gtest
1 parent 75aa431 commit 0b0ef58

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

api/test/trace/propagation/detail/string_test.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ struct SplitStringTestData
1414
size_t max_count;
1515
std::vector<opentelemetry::nostd::string_view> splits;
1616
size_t expected_number_strings;
17+
18+
// When googletest registers parameterized tests, it uses this method to format the parameters.
19+
// The default implementation prints hex dump of all bytes in the object. If there is any padding
20+
// in these bytes, valgrind reports this as a warning - "Use of uninitialized bytes".
21+
// See https://github.com/google/googletest/issues/3805.
22+
friend void PrintTo(const SplitStringTestData& data, std::ostream* os) {
23+
std::stringstream ss;
24+
for (auto it = data.splits.begin(); it != data.splits.end(); it++) {
25+
if (it != data.splits.begin()) {
26+
ss << ",";
27+
}
28+
ss << *it;
29+
}
30+
*os << "(" << data.input << "," << data.separator << "," << data.max_count << "," << ss.str() << "," << data.expected_number_strings << ")";
31+
}
1732
};
1833

1934
const SplitStringTestData split_string_test_cases[] = {

0 commit comments

Comments
 (0)