22// SPDX-License-Identifier: Apache-2.0
33
44#include < gtest/gtest.h>
5- #include < array>
5+ #include < array>
66#include < map>
77#include < string>
88#include < unordered_map>
99
1010#include " opentelemetry/common/key_value_iterable_view.h"
11- #include " opentelemetry/nostd/variant.h"
1211#include " opentelemetry/nostd/span.h"
1312#include " opentelemetry/nostd/string_view.h"
13+ #include " opentelemetry/nostd/variant.h"
1414#include " opentelemetry/sdk/common/attribute_utils.h"
1515
1616TEST (AttributeMapTest, DefaultConstruction)
@@ -61,96 +61,122 @@ TEST(OrderedAttributeMapTest, AttributesConstruction)
6161
6262TEST (AttributeEqualToVisitorTest, AttributeValueEqualTo)
6363{
64- namespace sdk = opentelemetry::sdk::common;
65- namespace api = opentelemetry::common;
64+ namespace sdk = opentelemetry::sdk::common;
65+ namespace api = opentelemetry::common;
6666 namespace nostd = opentelemetry::nostd;
67-
67+
6868 using AV = api::AttributeValue;
69- using OV = sdk::OwnedAttributeValue;
69+ using OV = sdk::OwnedAttributeValue;
7070
7171 sdk::AttributeEqualToVisitor equal_to_visitor;
72-
72+
7373 // arithmetic types
7474 EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor, OV{bool (true )}, AV{bool (true )}));
7575 EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor, OV{int32_t (22 )}, AV{int32_t (22 )}));
7676 EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor, OV{int64_t (22 )}, AV{int64_t (22 )}));
7777 EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor, OV{uint32_t (22 )}, AV{uint32_t (22 )}));
7878 EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor, OV{uint64_t (22 )}, AV{uint64_t (22 )}));
79- EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor, OV{double (22.0 )}, AV{double (22.0 )}));
80-
81- // string types
82- EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::string (" string to const char*" )}, AV{" string to const char*" }));
83- EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::string (" string to string_view" )}, AV{nostd::string_view (" string to string_view" )}));
84-
85- // container types
86- EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::vector<bool >{true , false }}, AV{std::array<const bool , 2 >{true , false }}));
87- EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::vector<uint8_t >{33 , 44 }}, AV{std::array<const uint8_t , 2 >{33 , 44 }}));
88- EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::vector<int32_t >{33 , 44 }}, AV{std::array<const int32_t , 2 >{33 , 44 }}));
89- EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::vector<int64_t >{33 , 44 }}, AV{std::array<const int64_t , 2 >{33 , 44 }}));
90- EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::vector<uint32_t >{33 , 44 }}, AV{std::array<const uint32_t , 2 >{33 , 44 }}));
91- EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::vector<uint64_t >{33 , 44 }}, AV{std::array<const uint64_t , 2 >{33 , 44 }}));
92- EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::vector<double >{33.0 , 44.0 }}, AV{std::array<const double , 2 >{33.0 , 44.0 }}));
93- EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::vector<std::string>{" a string" , " another string" }}, AV{std::array<const nostd::string_view, 2 >{" a string" , " another string" }}));
79+ EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor, OV{double (22.0 )}, AV{double (22.0 )}));
80+
81+ // string types
82+ EXPECT_TRUE (opentelemetry::nostd::visit (
83+ equal_to_visitor, OV{std::string (" string to const char*" )}, AV{" string to const char*" }));
84+ EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor,
85+ OV{std::string (" string to string_view" )},
86+ AV{nostd::string_view (" string to string_view" )}));
87+
88+ // container types
89+ EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::vector<bool >{true , false }},
90+ AV{std::array<const bool , 2 >{true , false }}));
91+ EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::vector<uint8_t >{33 , 44 }},
92+ AV{std::array<const uint8_t , 2 >{33 , 44 }}));
93+ EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::vector<int32_t >{33 , 44 }},
94+ AV{std::array<const int32_t , 2 >{33 , 44 }}));
95+ EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::vector<int64_t >{33 , 44 }},
96+ AV{std::array<const int64_t , 2 >{33 , 44 }}));
97+ EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::vector<uint32_t >{33 , 44 }},
98+ AV{std::array<const uint32_t , 2 >{33 , 44 }}));
99+ EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::vector<uint64_t >{33 , 44 }},
100+ AV{std::array<const uint64_t , 2 >{33 , 44 }}));
101+ EXPECT_TRUE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::vector<double >{33.0 , 44.0 }},
102+ AV{std::array<const double , 2 >{33.0 , 44.0 }}));
103+ EXPECT_TRUE (opentelemetry::nostd::visit (
104+ equal_to_visitor, OV{std::vector<std::string>{" a string" , " another string" }},
105+ AV{std::array<const nostd::string_view, 2 >{" a string" , " another string" }}));
94106}
95107
96108TEST (AttributeEqualToVisitorTest, AttributeValueNotEqualTo)
97109{
98- namespace sdk = opentelemetry::sdk::common;
99- namespace api = opentelemetry::common;
110+ namespace sdk = opentelemetry::sdk::common;
111+ namespace api = opentelemetry::common;
100112 namespace nostd = opentelemetry::nostd;
101-
113+
102114 using AV = api::AttributeValue;
103- using OV = sdk::OwnedAttributeValue;
115+ using OV = sdk::OwnedAttributeValue;
104116
105117 sdk::AttributeEqualToVisitor equal_to_visitor;
106-
107- // check different values of the same type
118+
119+ // check different values of the same type
108120 EXPECT_FALSE (opentelemetry::nostd::visit (equal_to_visitor, OV{bool (true )}, AV{bool (false )}));
109121 EXPECT_FALSE (opentelemetry::nostd::visit (equal_to_visitor, OV{int32_t (22 )}, AV{int32_t (33 )}));
110122 EXPECT_FALSE (opentelemetry::nostd::visit (equal_to_visitor, OV{int64_t (22 )}, AV{int64_t (33 )}));
111123 EXPECT_FALSE (opentelemetry::nostd::visit (equal_to_visitor, OV{uint32_t (22 )}, AV{uint32_t (33 )}));
112124 EXPECT_FALSE (opentelemetry::nostd::visit (equal_to_visitor, OV{double (22.2 )}, AV{double (33.3 )}));
113- EXPECT_FALSE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::string (" string one" )}, AV{" another string" }));
114- EXPECT_FALSE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::string (" string one" )}, AV{nostd::string_view (" another string" )}));
125+ EXPECT_FALSE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::string (" string one" )},
126+ AV{" another string" }));
127+ EXPECT_FALSE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::string (" string one" )},
128+ AV{nostd::string_view (" another string" )}));
115129
116- // check different value types
130+ // check different value types
117131 EXPECT_FALSE (opentelemetry::nostd::visit (equal_to_visitor, OV{bool (true )}, AV{uint32_t (0 )}));
118132 EXPECT_FALSE (opentelemetry::nostd::visit (equal_to_visitor, OV{int32_t (22 )}, AV{uint32_t (22 )}));
119133
120134 // check containers of different element values
121- EXPECT_FALSE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::vector<bool >{true , false }}, AV{std::array<const bool , 2 >{false , true }}));
122- EXPECT_FALSE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::vector<int32_t >{22 , 33 }}, AV{std::array<const int32_t , 2 >{33 , 44 }}));
123- EXPECT_FALSE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::vector<std::string>{" a string" , " another string" }}, AV{std::array<const nostd::string_view, 2 >{" a string" , " a really different string" }}));
135+ EXPECT_FALSE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::vector<bool >{true , false }},
136+ AV{std::array<const bool , 2 >{false , true }}));
137+ EXPECT_FALSE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::vector<int32_t >{22 , 33 }},
138+ AV{std::array<const int32_t , 2 >{33 , 44 }}));
139+ EXPECT_FALSE (opentelemetry::nostd::visit (
140+ equal_to_visitor, OV{std::vector<std::string>{" a string" , " another string" }},
141+ AV{std::array<const nostd::string_view, 2 >{" a string" , " a really different string" }}));
124142
125143 // check containers of different element types
126- EXPECT_FALSE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::vector<int32_t >{22 , 33 }}, AV{std::array<const uint32_t , 2 >{22 , 33 }}));
144+ EXPECT_FALSE (opentelemetry::nostd::visit (equal_to_visitor, OV{std::vector<int32_t >{22 , 33 }},
145+ AV{std::array<const uint32_t , 2 >{22 , 33 }}));
127146}
128147
129148TEST (AttributeMapTest, EqualTo)
130149{
131- using Attributes = std::initializer_list<std::pair<opentelemetry::nostd::string_view, opentelemetry::common::AttributeValue>>;
132-
150+ using Attributes = std::initializer_list<
151+ std::pair<opentelemetry::nostd::string_view, opentelemetry::common::AttributeValue>>;
152+
133153 // check for case where both are empty
134- Attributes attributes_empty = {};
135- auto kv_iterable_empty = opentelemetry::common::MakeKeyValueIterableView<Attributes>(attributes_empty);
154+ Attributes attributes_empty = {};
155+ auto kv_iterable_empty =
156+ opentelemetry::common::MakeKeyValueIterableView<Attributes>(attributes_empty);
136157 opentelemetry::sdk::common::AttributeMap attribute_map_empty (kv_iterable_empty);
137158 EXPECT_TRUE (attribute_map_empty.EqualTo (kv_iterable_empty));
138159
139- // check for equality with a range of attributes and types
140- Attributes attributes = {{" key0" , " some value" }, {" key1" , 1 }, {" key2" , 2.0 }, {" key3" , true }};
160+ // check for equality with a range of attributes and types
161+ Attributes attributes = {{" key0" , " some value" }, {" key1" , 1 }, {" key2" , 2.0 }, {" key3" , true }};
141162 auto kv_iterable_match = opentelemetry::common::MakeKeyValueIterableView<Attributes>(attributes);
142163 opentelemetry::sdk::common::AttributeMap attribute_map (attributes);
143164 EXPECT_TRUE (attribute_map.EqualTo (kv_iterable_match));
144165
145- // check for several cases where the attributes are different
146- Attributes attributes_different_value = {{" key0" , " some value" }, {" key1" , 1 }, {" key2" , 2.0 }, {" key3" , false }};
147- Attributes attributes_different_type = {{" key0" , " some value" }, {" key1" , 1.0 } ,{" key2" , 2.0 }, {" key3" , true }};
148- Attributes attributes_different_size = {{" key0" , " some value" }};
149- auto kv_iterable_different_value = opentelemetry::common::MakeKeyValueIterableView<Attributes>(attributes_different_value);
150- auto kv_iterable_different_type = opentelemetry::common::MakeKeyValueIterableView<Attributes>(attributes_different_type);
151- auto kv_iterable_different_size = opentelemetry::common::MakeKeyValueIterableView<Attributes>(attributes_different_size);
152-
166+ // check for several cases where the attributes are different
167+ Attributes attributes_different_value = {
168+ {" key0" , " some value" }, {" key1" , 1 }, {" key2" , 2.0 }, {" key3" , false }};
169+ Attributes attributes_different_type = {
170+ {" key0" , " some value" }, {" key1" , 1.0 }, {" key2" , 2.0 }, {" key3" , true }};
171+ Attributes attributes_different_size = {{" key0" , " some value" }};
172+ auto kv_iterable_different_value =
173+ opentelemetry::common::MakeKeyValueIterableView<Attributes>(attributes_different_value);
174+ auto kv_iterable_different_type =
175+ opentelemetry::common::MakeKeyValueIterableView<Attributes>(attributes_different_type);
176+ auto kv_iterable_different_size =
177+ opentelemetry::common::MakeKeyValueIterableView<Attributes>(attributes_different_size);
178+
153179 EXPECT_FALSE (attribute_map.EqualTo (kv_iterable_different_value));
154- EXPECT_FALSE (attribute_map.EqualTo (kv_iterable_different_type));
155- EXPECT_FALSE (attribute_map.EqualTo (kv_iterable_different_size));
180+ EXPECT_FALSE (attribute_map.EqualTo (kv_iterable_different_type));
181+ EXPECT_FALSE (attribute_map.EqualTo (kv_iterable_different_size));
156182}
0 commit comments