77
88#include " opentelemetry/nostd/string_view.h"
99
10- struct SplitStringTestData
11- {
12- opentelemetry::nostd::string_view input;
13- char separator;
14- size_t max_count;
15- std::vector<opentelemetry::nostd::string_view> splits;
16- size_t expected_number_strings;
10+ using namespace opentelemetry ;
1711
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- }
32- };
12+ // struct SplitStringTestData
13+ // {
14+ // opentelemetry::nostd::string_view input;
15+ // char separator;
16+ // size_t max_count;
17+ // std::vector<opentelemetry::nostd::string_view> splits;
18+ // size_t expected_number_strings;
19+ // };
20+ //
21+ // const SplitStringTestData split_string_test_cases[] = {
22+ // {"foo,bar,baz", ',', 4, std::vector<opentelemetry::nostd::string_view>{"foo", "bar", "baz"}, 3},
23+ // {"foo,bar,baz,foobar", ',', 4,
24+ // std::vector<opentelemetry::nostd::string_view>{"foo", "bar", "baz", "foobar"}, 4},
25+ // {"foo,bar,baz,foobar", '.', 4,
26+ // std::vector<opentelemetry::nostd::string_view>{"foo,bar,baz,foobar"}, 1},
27+ // {"foo,bar,baz,", ',', 4,
28+ // std::vector<opentelemetry::nostd::string_view>{"foo", "bar", "baz", ""}, 4},
29+ // {"foo,bar,baz,", ',', 2, std::vector<opentelemetry::nostd::string_view>{"foo", "bar"}, 2},
30+ // {"foo ,bar, baz ", ',', 4,
31+ // std::vector<opentelemetry::nostd::string_view>{"foo ", "bar", " baz "}, 3},
32+ // {"foo ,bar, baz ", ',', 4,
33+ // std::vector<opentelemetry::nostd::string_view>{"foo ", "bar", " baz "}, 3},
34+ // {"00-0af7651916cd43dd8448eb211c80319c-00f067aa0ba902b7-01", '-', 4,
35+ // std::vector<opentelemetry::nostd::string_view>{"00", "0af7651916cd43dd8448eb211c80319c",
36+ // "00f067aa0ba902b7", "01"},
37+ // 4},
38+ // };
39+ //
40+ //
41+ // TEST(StringTest, SplitStringTest)
42+ // {
43+ // for (auto &test_param : split_string_test_cases) {
44+ // std::vector<opentelemetry::nostd::string_view> fields{};
45+ // fields.reserve(test_param.expected_number_strings);
46+ // size_t got_splits_num = opentelemetry::trace::propagation::detail::SplitString(
47+ // test_param.input, test_param.separator, fields.data(), test_param.max_count);
48+ //
49+ // // Assert on the output
50+ // EXPECT_EQ(got_splits_num, test_param.expected_number_strings);
51+ // for (size_t i = 0; i < got_splits_num; i++)
52+ // {
53+ // // Checks for resulting strings in-order
54+ // EXPECT_EQ(fields[i], test_param.splits[i]);
55+ // }
56+ // }
57+ // }
3358
34- const SplitStringTestData split_string_test_cases[] = {
35- {" foo,bar,baz" , ' ,' , 4 , std::vector<opentelemetry::nostd::string_view>{" foo" , " bar" , " baz" }, 3 },
36- {" foo,bar,baz,foobar" , ' ,' , 4 ,
37- std::vector<opentelemetry::nostd::string_view>{" foo" , " bar" , " baz" , " foobar" }, 4 },
38- {" foo,bar,baz,foobar" , ' .' , 4 ,
39- std::vector<opentelemetry::nostd::string_view>{" foo,bar,baz,foobar" }, 1 },
40- {" foo,bar,baz," , ' ,' , 4 ,
41- std::vector<opentelemetry::nostd::string_view>{" foo" , " bar" , " baz" , " " }, 4 },
42- {" foo,bar,baz," , ' ,' , 2 , std::vector<opentelemetry::nostd::string_view>{" foo" , " bar" }, 2 },
43- {" foo ,bar, baz " , ' ,' , 4 ,
44- std::vector<opentelemetry::nostd::string_view>{" foo " , " bar" , " baz " }, 3 },
45- {" foo ,bar, baz " , ' ,' , 4 ,
46- std::vector<opentelemetry::nostd::string_view>{" foo " , " bar" , " baz " }, 3 },
47- {" 00-0af7651916cd43dd8448eb211c80319c-00f067aa0ba902b7-01" , ' -' , 4 ,
48- std::vector<opentelemetry::nostd::string_view>{" 00" , " 0af7651916cd43dd8448eb211c80319c" ,
49- " 00f067aa0ba902b7" , " 01" },
50- 4 },
51- };
52-
53- // Test fixture
54- class SplitStringTestFixture : public ::testing::TestWithParam<SplitStringTestData>
55- {};
56-
57- TEST_P (SplitStringTestFixture, SplitsAsExpected)
58- {
59- SplitStringTestData test_param = GetParam ();
60- std::vector<opentelemetry::nostd::string_view> fields{};
61- fields.reserve (test_param.expected_number_strings );
62- size_t got_splits_num = opentelemetry::trace::propagation::detail::SplitString (
63- test_param.input , test_param.separator , fields.data (), test_param.max_count );
64-
65- // Assert on the output
66- EXPECT_EQ (got_splits_num, test_param.expected_number_strings );
67- for (size_t i = 0 ; i < got_splits_num; i++)
68- {
69- // Checks for resulting strings in-order
70- EXPECT_EQ (fields[i], test_param.splits [i]);
71- }
72- }
73-
74- INSTANTIATE_TEST_SUITE_P (SplitStringTestCases,
75- SplitStringTestFixture,
76- ::testing::ValuesIn (split_string_test_cases));
59+ TEST (StringTest, SimpleTest) {
60+ nostd::string_view input = " foo,bar,baz" ;
61+ std::array<nostd::string_view, 4 > fields{};
62+ size_t got_splits = ::trace::propagation::detail::SplitString (input, ' ,' , fields.data (), 4 );
63+ EXPECT_EQ (3 , got_splits);
64+ }
0 commit comments