Skip to content

Commit

Permalink
Fix dangling pointer warnings in test
Browse files Browse the repository at this point in the history
  • Loading branch information
psx95 committed Jan 23, 2025
1 parent 6bc257e commit 5b72b3e
Showing 1 changed file with 23 additions and 28 deletions.
51 changes: 23 additions & 28 deletions sdk/test/trace/tracer_config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,50 +45,45 @@ static std::pair<opentelemetry::nostd::string_view, opentelemetry::common::Attri
static std::pair<opentelemetry::nostd::string_view, opentelemetry::common::AttributeValue> attr3 = {
"accept_third_attr", 3};

static instrumentation_scope::InstrumentationScope *test_scope_1 =
std::move(instrumentation_scope::InstrumentationScope::Create("test_scope_1")).get();
static instrumentation_scope::InstrumentationScope *test_scope_2 =
std::move(instrumentation_scope::InstrumentationScope::Create("test_scope_2", "1.0")).get();
static instrumentation_scope::InstrumentationScope *test_scope_3 =
std::move(instrumentation_scope::InstrumentationScope::Create(
"test_scope_3",
"0",
"https://opentelemetry.io/schemas/v1.18.0"))
.get();
static instrumentation_scope::InstrumentationScope *test_scope_4 =
std::move(instrumentation_scope::InstrumentationScope::Create(
"test_scope_4",
"0",
"https://opentelemetry.io/schemas/v1.18.0",
{attr1}))
.get();
static instrumentation_scope::InstrumentationScope *test_scope_5 =
std::move(instrumentation_scope::InstrumentationScope::Create(
"test_scope_5",
"0",
"https://opentelemetry.io/schemas/v1.18.0",
{attr1, attr2, attr3}))
.get();
static instrumentation_scope::InstrumentationScope test_scope_1 =
*std::move(instrumentation_scope::InstrumentationScope::Create("test_scope_1"));
static instrumentation_scope::InstrumentationScope test_scope_2 =
*std::move(instrumentation_scope::InstrumentationScope::Create("test_scope_2", "1.0"));
static instrumentation_scope::InstrumentationScope test_scope_3 =
*std::move(instrumentation_scope::InstrumentationScope::Create(
"test_scope_3",
"0",
"https://opentelemetry.io/schemas/v1.18.0"));
static instrumentation_scope::InstrumentationScope test_scope_4 = *std::move(
instrumentation_scope::InstrumentationScope::Create("test_scope_4",
"0",
"https://opentelemetry.io/schemas/v1.18.0",
{attr1}));
static instrumentation_scope::InstrumentationScope test_scope_5 = *std::move(
instrumentation_scope::InstrumentationScope::Create("test_scope_5",
"0",
"https://opentelemetry.io/schemas/v1.18.0",
{attr1, attr2, attr3}));

const std::array<instrumentation_scope::InstrumentationScope *, 5> instrumentation_scopes = {
const std::array<instrumentation_scope::InstrumentationScope, 5> instrumentation_scopes = {
test_scope_1, test_scope_2, test_scope_3, test_scope_4, test_scope_5,
};

// Test fixture for VerifyDefaultConfiguratorBehavior
class DefaultTracerConfiguratorTestFixture
: public ::testing::TestWithParam<instrumentation_scope::InstrumentationScope *>
: public ::testing::TestWithParam<instrumentation_scope::InstrumentationScope>
{};

// verifies that the default configurator always returns the default tracer config
TEST_P(DefaultTracerConfiguratorTestFixture, VerifyDefaultConfiguratorBehavior)
{
instrumentation_scope::InstrumentationScope *scope = GetParam();
instrumentation_scope::InstrumentationScope scope = GetParam();
instrumentation_scope::ScopeConfigurator<trace_sdk::TracerConfig> default_configurator =
instrumentation_scope::ScopeConfigurator<trace_sdk::TracerConfig>::Builder(
trace_sdk::TracerConfig::Default())
.Build();

ASSERT_EQ(default_configurator.ComputeConfig(*scope), trace_sdk::TracerConfig::Default());
ASSERT_EQ(default_configurator.ComputeConfig(scope), trace_sdk::TracerConfig::Default());
}

INSTANTIATE_TEST_SUITE_P(InstrumentationScopes,
Expand Down

0 comments on commit 5b72b3e

Please sign in to comment.