]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/api/test/trace/scope_test.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / api / test / trace / scope_test.cc
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 #include "opentelemetry/trace/scope.h"
5 #include "opentelemetry/context/context.h"
6 #include "opentelemetry/nostd/shared_ptr.h"
7 #include "opentelemetry/trace/noop.h"
8
9 #include <gtest/gtest.h>
10
11 using opentelemetry::trace::kSpanKey;
12 using opentelemetry::trace::NoopSpan;
13 using opentelemetry::trace::Scope;
14 using opentelemetry::trace::Span;
15 namespace nostd = opentelemetry::nostd;
16 namespace context = opentelemetry::context;
17
18 TEST(ScopeTest, Construct)
19 {
20 nostd::shared_ptr<Span> span(new NoopSpan(nullptr));
21 Scope scope(span);
22
23 context::ContextValue active_span_value = context::RuntimeContext::GetValue(kSpanKey);
24 ASSERT_TRUE(nostd::holds_alternative<nostd::shared_ptr<Span>>(active_span_value));
25
26 auto active_span = nostd::get<nostd::shared_ptr<Span>>(active_span_value);
27 ASSERT_EQ(active_span, span);
28 }
29
30 TEST(ScopeTest, Destruct)
31 {
32 nostd::shared_ptr<Span> span(new NoopSpan(nullptr));
33 Scope scope(span);
34
35 {
36 nostd::shared_ptr<Span> span_nested(new NoopSpan(nullptr));
37 Scope scope_nested(span_nested);
38
39 context::ContextValue active_span_value = context::RuntimeContext::GetValue(kSpanKey);
40 ASSERT_TRUE(nostd::holds_alternative<nostd::shared_ptr<Span>>(active_span_value));
41
42 auto active_span = nostd::get<nostd::shared_ptr<Span>>(active_span_value);
43 ASSERT_EQ(active_span, span_nested);
44 }
45
46 context::ContextValue active_span_value = context::RuntimeContext::GetValue(kSpanKey);
47 ASSERT_TRUE(nostd::holds_alternative<nostd::shared_ptr<Span>>(active_span_value));
48
49 auto active_span = nostd::get<nostd::shared_ptr<Span>>(active_span_value);
50 ASSERT_EQ(active_span, span);
51 }