From 9874c4cab7648c8d1268262fff52812ac2d5cc8d Mon Sep 17 00:00:00 2001 From: Sam Atac Date: Wed, 10 Jun 2020 17:27:36 +0000 Subject: [PATCH] renamed some variables, added tests --- api/test/CMakeLists.txt | 1 + api/test/context/context_test.cc | 4 --- api/test/context/runtimeContext_test.cc | 37 +++++++++++++++++++++---- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/api/test/CMakeLists.txt b/api/test/CMakeLists.txt index 21b3e9a350..5c5a8590e4 100644 --- a/api/test/CMakeLists.txt +++ b/api/test/CMakeLists.txt @@ -1,4 +1,5 @@ add_subdirectory(core) +add_subdirectory(context) add_subdirectory(plugin) add_subdirectory(nostd) add_subdirectory(trace) diff --git a/api/test/context/context_test.cc b/api/test/context/context_test.cc index 253543dab5..a8903be443 100644 --- a/api/test/context/context_test.cc +++ b/api/test/context/context_test.cc @@ -43,7 +43,3 @@ TEST(Context_test, context_write_new_object) EXPECT_EQ(new_test_context.GetValue(foo_key), 1); } - - - - diff --git a/api/test/context/runtimeContext_test.cc b/api/test/context/runtimeContext_test.cc index 2021125299..682443cf48 100644 --- a/api/test/context/runtimeContext_test.cc +++ b/api/test/context/runtimeContext_test.cc @@ -4,6 +4,25 @@ using namespace opentelemetry::context; + +/* Tests whether the runtimeContext object properly returns the current context + */ +TEST(runtimeContext_test, get_current_context) +{ + + Context::ContextKey test_key = Context::ContextKey("test_key"); + Context test_context = Context(test_key, 7); + + RuntimeContext test_runtime = RuntimeContext(test_context); + + EXPECT_EQ(test_runtime.GetCurrent().GetValue(test_key), + test_context.GetValue(test_key)); + +} + + + + /* Tests whether the runtimeContext object properly attaches and detaches * the context object. */ @@ -18,17 +37,23 @@ TEST(runtimeContext_test, attach_detach_context) Context::ContextKey foo_key = Context::ContextKey("foo_key"); Context foo_context = Context(foo_key, 5); - EXPECT_EQ(test_runtime.GetCurrent().GetValue(test_key), test_context.GetValue(test_key)); - EXPECT_NE(test_runtime.GetCurrent().GetValue(foo_key), foo_context.GetValue(foo_key)); + EXPECT_EQ(test_runtime.GetCurrent().GetValue(test_key), + test_context.GetValue(test_key)); + EXPECT_NE(test_runtime.GetCurrent().GetValue(foo_key), + foo_context.GetValue(foo_key)); Token test_token = test_runtime.Attach(foo_context); - EXPECT_NE(test_runtime.GetCurrent().GetValue(test_key), test_context.GetValue(test_key)); - EXPECT_EQ(test_runtime.GetCurrent().GetValue(foo_key), foo_context.GetValue(foo_key)); + EXPECT_NE(test_runtime.GetCurrent().GetValue(test_key), + test_context.GetValue(test_key)); + EXPECT_EQ(test_runtime.GetCurrent().GetValue(foo_key), + foo_context.GetValue(foo_key)); test_runtime.Detach(test_token); - EXPECT_EQ(test_runtime.GetCurrent().GetValue(test_key), test_context.GetValue(test_key)); - EXPECT_NE(test_runtime.GetCurrent().GetValue(foo_key), foo_context.GetValue(foo_key)); + EXPECT_EQ(test_runtime.GetCurrent().GetValue(test_key), + test_context.GetValue(test_key)); + EXPECT_NE(test_runtime.GetCurrent().GetValue(foo_key), + foo_context.GetValue(foo_key)); }