From 575cc6cfeeade3591f28df6c4799cfa23d53713c Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Fri, 1 Nov 2024 03:30:46 +0000 Subject: [PATCH] Move the test cases within test scope --- .../trace/propagation/detail/string_test.cc | 65 +++++++++++++------ 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/api/test/trace/propagation/detail/string_test.cc b/api/test/trace/propagation/detail/string_test.cc index f8c355e1cd..3662556e36 100644 --- a/api/test/trace/propagation/detail/string_test.cc +++ b/api/test/trace/propagation/detail/string_test.cc @@ -8,7 +8,7 @@ #include "opentelemetry/nostd/string_view.h" using namespace opentelemetry; - +// // struct SplitStringTestData //{ // opentelemetry::nostd::string_view input; @@ -37,25 +37,50 @@ using namespace opentelemetry; // "00f067aa0ba902b7", "01"}, // 4}, // }; -// -// -// TEST(StringTest, SplitStringTest) -//{ -// for (auto &test_param : split_string_test_cases) { -// std::vector fields{}; -// fields.reserve(test_param.expected_number_strings); -// size_t got_splits_num = opentelemetry::trace::propagation::detail::SplitString( -// test_param.input, test_param.separator, fields.data(), test_param.max_count); -// -// // Assert on the output -// EXPECT_EQ(got_splits_num, test_param.expected_number_strings); -// for (size_t i = 0; i < got_splits_num; i++) -// { -// // Checks for resulting strings in-order -// EXPECT_EQ(fields[i], test_param.splits[i]); -// } -// } -// } + +TEST(StringTest, SplitStringTest) +{ + struct + { + opentelemetry::nostd::string_view input; + char separator; + size_t max_count; + std::vector splits; + size_t expected_number_strings; + } test_cases[] = { + {"foo,bar,baz", ',', 4, std::vector{"foo", "bar", "baz"}, + 3}, + {"foo,bar,baz,foobar", ',', 4, + std::vector{"foo", "bar", "baz", "foobar"}, 4}, + {"foo,bar,baz,foobar", '.', 4, + std::vector{"foo,bar,baz,foobar"}, 1}, + {"foo,bar,baz,", ',', 4, + std::vector{"foo", "bar", "baz", ""}, 4}, + {"foo,bar,baz,", ',', 2, std::vector{"foo", "bar"}, 2}, + {"foo ,bar, baz ", ',', 4, + std::vector{"foo ", "bar", " baz "}, 3}, + {"foo ,bar, baz ", ',', 4, + std::vector{"foo ", "bar", " baz "}, 3}, + {"00-0af7651916cd43dd8448eb211c80319c-00f067aa0ba902b7-01", '-', 4, + std::vector{"00", "0af7651916cd43dd8448eb211c80319c", + "00f067aa0ba902b7", "01"}, + 4}}; + for (auto &test_param : test_cases) + { + std::vector fields{}; + fields.reserve(test_param.expected_number_strings); + size_t got_splits_num = opentelemetry::trace::propagation::detail::SplitString( + test_param.input, test_param.separator, fields.data(), test_param.max_count); + + // Assert on the output + EXPECT_EQ(got_splits_num, test_param.expected_number_strings); + for (size_t i = 0; i < got_splits_num; i++) + { + // Checks for resulting strings in-order + EXPECT_EQ(fields[i], test_param.splits[i]); + } + } +} TEST(StringTest, SimpleTest) {