2 * Copyright (c) 2017 Uber Technologies, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "jaegertracing/SpanContext.h"
18 #include "jaegertracing/TraceID.h"
20 #include <gtest/gtest.h>
24 namespace jaegertracing
{
27 struct FromStreamTestCase
{
32 } // anonymous namespace
34 TEST(SpanContext
, testFromStream
)
36 const FromStreamTestCase testCases
[] = {
44 { "01234567890123456789012345678901234:1:1:1", false },
45 { "01234567890123456789012345678901:1:1:1", true },
46 { "01234_67890123456789012345678901:1:1:1", false },
47 { "0123456789012345678901_345678901:1:1:1", false },
48 { "1:0123456789012345:1:1", true },
49 { "1:01234567890123456:1:1", false },
50 { "10000000000000001:1:1:1", true },
51 { "10000000000000001:1:1", false },
55 for (auto&& testCase
: testCases
) {
56 SpanContext spanContext
;
59 ss
<< testCase
._input
;
60 spanContext
= SpanContext::fromStream(ss
);
61 ASSERT_EQ(testCase
._success
, spanContext
.isValid())
62 << "input=" << testCase
._input
;
65 SpanContext spanContextFromStreamOp
;
68 ss
<< testCase
._input
;
69 ss
>> spanContextFromStreamOp
;
72 ASSERT_EQ(spanContext
, spanContextFromStreamOp
);
76 TEST(SpanContext
, testFormatting
)
78 SpanContext
spanContext(TraceID(255, 255), 0, 0, 0, SpanContext::StrMap());
79 std::ostringstream oss
;
81 ASSERT_EQ("ff00000000000000ff:0:0:0", oss
.str());
84 TEST(SpanContext
, testBaggage
)
86 const SpanContext
spanContext(
91 SpanContext::StrMap({ { "key1", "value1" }, { "key2", "value2" } }));
93 std::string valueCopy
;
94 spanContext
.ForeachBaggageItem(
95 [&keyCopy
, &valueCopy
](const std::string
& key
,
96 const std::string
& value
) {
101 ASSERT_TRUE(keyCopy
== "key1" || keyCopy
== "key2");
102 if (keyCopy
== "key1") {
103 ASSERT_EQ("value1", valueCopy
);
106 ASSERT_EQ("value2", valueCopy
);
110 TEST(SpanContext
, testDebug
)
112 const SpanContext spanContext
;
113 ASSERT_FALSE(spanContext
.isDebug());
114 ASSERT_FALSE(spanContext
.isDebugIDContainerOnly());
117 } // namespace jaegertracing