From a14099c1e1090200b64c1d604ec15c09753d7b3f Mon Sep 17 00:00:00 2001 From: NeaguGeorgiana23 Date: Wed, 3 Dec 2025 17:07:17 +0000 Subject: [PATCH 1/7] Add unit-tests for "noop_provider". Signed-off-by: NeaguGeorgiana23 --- test/BUILD | 12 ++++++++ test/noop_provider_test.cpp | 56 +++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 test/noop_provider_test.cpp diff --git a/test/BUILD b/test/BUILD index c7a0f66..4ca702e 100644 --- a/test/BUILD +++ b/test/BUILD @@ -8,4 +8,16 @@ cc_test( # Google Test dependency remains the same "@googletest//:gtest_main", ], +) + +cc_test( + name = "noop_provider_test", + # Path is relative to cpp-sdk/src/test/ + srcs = ["noop_provider_test.cpp"], + deps = [ + # We reference the library defined in the parent 'src' package + "//src:noop_provider", + # Google Test dependency remains the same + "@googletest//:gtest_main", + ], ) \ No newline at end of file diff --git a/test/noop_provider_test.cpp b/test/noop_provider_test.cpp new file mode 100644 index 0000000..0c29e54 --- /dev/null +++ b/test/noop_provider_test.cpp @@ -0,0 +1,56 @@ +#include "openfeature/noop_provider.h" + +#include + +using namespace openfeature; + +class NoopProviderTest : public ::testing::Test { + protected: + NoopProvider provider; +}; + +// Test to verify the metadata returned by the provider +TEST_F(NoopProviderTest, ShouldReturnProviderNameForMetadata) { + const Metadata metadata = provider.GetMetadata(); + EXPECT_EQ(metadata.name, "Noop Provider"); +} + +// Test to verify the boolean evaluation returns the default value +TEST_F(NoopProviderTest, BooleanEvaluationShouldReturnDefaultValue) { + const std::string flagKey = "my-bool-flag"; + const EvaluationContext ctx; + + // Test case with default value set to true + { + const bool defaultValue = true; + const std::unique_ptr details = + provider.GetBooleanEvaluation(flagKey, defaultValue, ctx); + + EXPECT_EQ(details->GetValue(), defaultValue); + EXPECT_EQ(details->GetReason(), Reason::kDefault); + EXPECT_EQ(details->GetVariant(), "default-variant"); + EXPECT_FALSE(details->GetErrorCode().has_value()); + ASSERT_TRUE(details->GetErrorMessage().has_value()); + EXPECT_TRUE(details->GetErrorMessage()->empty()); + } + + // Test case with default value set to false + { + const bool defaultValue = false; + const std::unique_ptr details = + provider.GetBooleanEvaluation(flagKey, defaultValue, ctx); + + EXPECT_EQ(details->GetValue(), defaultValue); + EXPECT_EQ(details->GetReason(), Reason::kDefault); + EXPECT_EQ(details->GetVariant(), "default-variant"); + EXPECT_FALSE(details->GetErrorCode().has_value()); + ASSERT_TRUE(details->GetErrorMessage().has_value()); + EXPECT_TRUE(details->GetErrorMessage()->empty()); + } +} + +// Main function to initialize and run all tests +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file From 5d886922c9690fcff81a64b9eaf12d50d385d826 Mon Sep 17 00:00:00 2001 From: NeaguGeorgiana23 Date: Thu, 4 Dec 2025 09:44:00 +0000 Subject: [PATCH 2/7] Fix comments. Signed-off-by: NeaguGeorgiana23 --- test/BUILD | 2 +- test/noop_provider_test.cpp | 54 ++++++++++++++----------------------- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/test/BUILD b/test/BUILD index 4ca702e..84f7760 100644 --- a/test/BUILD +++ b/test/BUILD @@ -20,4 +20,4 @@ cc_test( # Google Test dependency remains the same "@googletest//:gtest_main", ], -) \ No newline at end of file +) diff --git a/test/noop_provider_test.cpp b/test/noop_provider_test.cpp index 0c29e54..88ed3ab 100644 --- a/test/noop_provider_test.cpp +++ b/test/noop_provider_test.cpp @@ -4,53 +4,39 @@ using namespace openfeature; -class NoopProviderTest : public ::testing::Test { - protected: - NoopProvider provider; -}; +class NoopProviderBooleanTest : public ::testing::Test, + public ::testing::WithParamInterface {}; // Test to verify the metadata returned by the provider -TEST_F(NoopProviderTest, ShouldReturnProviderNameForMetadata) { +TEST(NoopProviderTest, ShouldReturnProviderNameForMetadata) { + NoopProvider provider; const Metadata metadata = provider.GetMetadata(); EXPECT_EQ(metadata.name, "Noop Provider"); } // Test to verify the boolean evaluation returns the default value -TEST_F(NoopProviderTest, BooleanEvaluationShouldReturnDefaultValue) { +TEST_P(NoopProviderBooleanTest, BooleanEvaluationShouldReturnDefaultValue) { + NoopProvider provider; const std::string flagKey = "my-bool-flag"; const EvaluationContext ctx; + const bool defaultValue = GetParam(); - // Test case with default value set to true - { - const bool defaultValue = true; - const std::unique_ptr details = - provider.GetBooleanEvaluation(flagKey, defaultValue, ctx); - - EXPECT_EQ(details->GetValue(), defaultValue); - EXPECT_EQ(details->GetReason(), Reason::kDefault); - EXPECT_EQ(details->GetVariant(), "default-variant"); - EXPECT_FALSE(details->GetErrorCode().has_value()); - ASSERT_TRUE(details->GetErrorMessage().has_value()); - EXPECT_TRUE(details->GetErrorMessage()->empty()); - } - - // Test case with default value set to false - { - const bool defaultValue = false; - const std::unique_ptr details = - provider.GetBooleanEvaluation(flagKey, defaultValue, ctx); - - EXPECT_EQ(details->GetValue(), defaultValue); - EXPECT_EQ(details->GetReason(), Reason::kDefault); - EXPECT_EQ(details->GetVariant(), "default-variant"); - EXPECT_FALSE(details->GetErrorCode().has_value()); - ASSERT_TRUE(details->GetErrorMessage().has_value()); - EXPECT_TRUE(details->GetErrorMessage()->empty()); - } + const std::unique_ptr details = + provider.GetBooleanEvaluation(flagKey, defaultValue, ctx); + + EXPECT_EQ(details->GetValue(), defaultValue); + EXPECT_EQ(details->GetReason(), Reason::kDefault); + EXPECT_EQ(details->GetVariant(), "default-variant"); + EXPECT_FALSE(details->GetErrorCode().has_value()); + ASSERT_TRUE(details->GetErrorMessage().has_value()); + EXPECT_TRUE(details->GetErrorMessage()->empty()); } +INSTANTIATE_TEST_SUITE_P(BooleanDefaultValues, NoopProviderBooleanTest, + ::testing::Values(true, false)); + // Main function to initialize and run all tests int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); -} \ No newline at end of file +} From 1f40da940a68df0004d5594a47043dc2f952b209 Mon Sep 17 00:00:00 2001 From: NeaguGeorgiana23 Date: Thu, 4 Dec 2025 14:17:43 +0000 Subject: [PATCH 3/7] Fix comments. Signed-off-by: NeaguGeorgiana23 --- test/noop_provider_test.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/test/noop_provider_test.cpp b/test/noop_provider_test.cpp index 88ed3ab..d8fa029 100644 --- a/test/noop_provider_test.cpp +++ b/test/noop_provider_test.cpp @@ -4,25 +4,24 @@ using namespace openfeature; -class NoopProviderBooleanTest : public ::testing::Test, - public ::testing::WithParamInterface {}; - -// Test to verify the metadata returned by the provider +// Test to verify the metadata returned by the provider. TEST(NoopProviderTest, ShouldReturnProviderNameForMetadata) { NoopProvider provider; const Metadata metadata = provider.GetMetadata(); EXPECT_EQ(metadata.name, "Noop Provider"); } -// Test to verify the boolean evaluation returns the default value +class NoopProviderBooleanTest : public ::testing::Test, + public ::testing::WithParamInterface {}; + +// Test to verify the boolean evaluation returns the default value. TEST_P(NoopProviderBooleanTest, BooleanEvaluationShouldReturnDefaultValue) { NoopProvider provider; - const std::string flagKey = "my-bool-flag"; - const EvaluationContext ctx; const bool defaultValue = GetParam(); const std::unique_ptr details = - provider.GetBooleanEvaluation(flagKey, defaultValue, ctx); + provider.GetBooleanEvaluation("my-bool-flag", defaultValue, + EvaluationContext{}); EXPECT_EQ(details->GetValue(), defaultValue); EXPECT_EQ(details->GetReason(), Reason::kDefault); @@ -33,10 +32,10 @@ TEST_P(NoopProviderBooleanTest, BooleanEvaluationShouldReturnDefaultValue) { } INSTANTIATE_TEST_SUITE_P(BooleanDefaultValues, NoopProviderBooleanTest, - ::testing::Values(true, false)); + testing::Values(true, false)); -// Main function to initialize and run all tests +// Main function to initialize and run all tests. int main(int argc, char** argv) { - ::testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } From 0bcc8d46436fbb2a609b2a75f75ceecc8315eb01 Mon Sep 17 00:00:00 2001 From: NeaguGeorgiana23 Date: Wed, 3 Dec 2025 17:07:17 +0000 Subject: [PATCH 4/7] Add unit-tests for "noop_provider". Signed-off-by: NeaguGeorgiana23 --- test/BUILD | 12 ++++++++ test/noop_provider_test.cpp | 56 +++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 test/noop_provider_test.cpp diff --git a/test/BUILD b/test/BUILD index c7a0f66..4ca702e 100644 --- a/test/BUILD +++ b/test/BUILD @@ -8,4 +8,16 @@ cc_test( # Google Test dependency remains the same "@googletest//:gtest_main", ], +) + +cc_test( + name = "noop_provider_test", + # Path is relative to cpp-sdk/src/test/ + srcs = ["noop_provider_test.cpp"], + deps = [ + # We reference the library defined in the parent 'src' package + "//src:noop_provider", + # Google Test dependency remains the same + "@googletest//:gtest_main", + ], ) \ No newline at end of file diff --git a/test/noop_provider_test.cpp b/test/noop_provider_test.cpp new file mode 100644 index 0000000..0c29e54 --- /dev/null +++ b/test/noop_provider_test.cpp @@ -0,0 +1,56 @@ +#include "openfeature/noop_provider.h" + +#include + +using namespace openfeature; + +class NoopProviderTest : public ::testing::Test { + protected: + NoopProvider provider; +}; + +// Test to verify the metadata returned by the provider +TEST_F(NoopProviderTest, ShouldReturnProviderNameForMetadata) { + const Metadata metadata = provider.GetMetadata(); + EXPECT_EQ(metadata.name, "Noop Provider"); +} + +// Test to verify the boolean evaluation returns the default value +TEST_F(NoopProviderTest, BooleanEvaluationShouldReturnDefaultValue) { + const std::string flagKey = "my-bool-flag"; + const EvaluationContext ctx; + + // Test case with default value set to true + { + const bool defaultValue = true; + const std::unique_ptr details = + provider.GetBooleanEvaluation(flagKey, defaultValue, ctx); + + EXPECT_EQ(details->GetValue(), defaultValue); + EXPECT_EQ(details->GetReason(), Reason::kDefault); + EXPECT_EQ(details->GetVariant(), "default-variant"); + EXPECT_FALSE(details->GetErrorCode().has_value()); + ASSERT_TRUE(details->GetErrorMessage().has_value()); + EXPECT_TRUE(details->GetErrorMessage()->empty()); + } + + // Test case with default value set to false + { + const bool defaultValue = false; + const std::unique_ptr details = + provider.GetBooleanEvaluation(flagKey, defaultValue, ctx); + + EXPECT_EQ(details->GetValue(), defaultValue); + EXPECT_EQ(details->GetReason(), Reason::kDefault); + EXPECT_EQ(details->GetVariant(), "default-variant"); + EXPECT_FALSE(details->GetErrorCode().has_value()); + ASSERT_TRUE(details->GetErrorMessage().has_value()); + EXPECT_TRUE(details->GetErrorMessage()->empty()); + } +} + +// Main function to initialize and run all tests +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file From de996064e40a9c0d418afb0aa2cf56274c48d54f Mon Sep 17 00:00:00 2001 From: NeaguGeorgiana23 Date: Thu, 4 Dec 2025 09:44:00 +0000 Subject: [PATCH 5/7] Fix comments. Signed-off-by: NeaguGeorgiana23 --- test/BUILD | 2 +- test/noop_provider_test.cpp | 54 ++++++++++++++----------------------- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/test/BUILD b/test/BUILD index 4ca702e..84f7760 100644 --- a/test/BUILD +++ b/test/BUILD @@ -20,4 +20,4 @@ cc_test( # Google Test dependency remains the same "@googletest//:gtest_main", ], -) \ No newline at end of file +) diff --git a/test/noop_provider_test.cpp b/test/noop_provider_test.cpp index 0c29e54..88ed3ab 100644 --- a/test/noop_provider_test.cpp +++ b/test/noop_provider_test.cpp @@ -4,53 +4,39 @@ using namespace openfeature; -class NoopProviderTest : public ::testing::Test { - protected: - NoopProvider provider; -}; +class NoopProviderBooleanTest : public ::testing::Test, + public ::testing::WithParamInterface {}; // Test to verify the metadata returned by the provider -TEST_F(NoopProviderTest, ShouldReturnProviderNameForMetadata) { +TEST(NoopProviderTest, ShouldReturnProviderNameForMetadata) { + NoopProvider provider; const Metadata metadata = provider.GetMetadata(); EXPECT_EQ(metadata.name, "Noop Provider"); } // Test to verify the boolean evaluation returns the default value -TEST_F(NoopProviderTest, BooleanEvaluationShouldReturnDefaultValue) { +TEST_P(NoopProviderBooleanTest, BooleanEvaluationShouldReturnDefaultValue) { + NoopProvider provider; const std::string flagKey = "my-bool-flag"; const EvaluationContext ctx; + const bool defaultValue = GetParam(); - // Test case with default value set to true - { - const bool defaultValue = true; - const std::unique_ptr details = - provider.GetBooleanEvaluation(flagKey, defaultValue, ctx); - - EXPECT_EQ(details->GetValue(), defaultValue); - EXPECT_EQ(details->GetReason(), Reason::kDefault); - EXPECT_EQ(details->GetVariant(), "default-variant"); - EXPECT_FALSE(details->GetErrorCode().has_value()); - ASSERT_TRUE(details->GetErrorMessage().has_value()); - EXPECT_TRUE(details->GetErrorMessage()->empty()); - } - - // Test case with default value set to false - { - const bool defaultValue = false; - const std::unique_ptr details = - provider.GetBooleanEvaluation(flagKey, defaultValue, ctx); - - EXPECT_EQ(details->GetValue(), defaultValue); - EXPECT_EQ(details->GetReason(), Reason::kDefault); - EXPECT_EQ(details->GetVariant(), "default-variant"); - EXPECT_FALSE(details->GetErrorCode().has_value()); - ASSERT_TRUE(details->GetErrorMessage().has_value()); - EXPECT_TRUE(details->GetErrorMessage()->empty()); - } + const std::unique_ptr details = + provider.GetBooleanEvaluation(flagKey, defaultValue, ctx); + + EXPECT_EQ(details->GetValue(), defaultValue); + EXPECT_EQ(details->GetReason(), Reason::kDefault); + EXPECT_EQ(details->GetVariant(), "default-variant"); + EXPECT_FALSE(details->GetErrorCode().has_value()); + ASSERT_TRUE(details->GetErrorMessage().has_value()); + EXPECT_TRUE(details->GetErrorMessage()->empty()); } +INSTANTIATE_TEST_SUITE_P(BooleanDefaultValues, NoopProviderBooleanTest, + ::testing::Values(true, false)); + // Main function to initialize and run all tests int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); -} \ No newline at end of file +} From a27b4ee8cc438df723b9f59d7bf0d87d5e6febaf Mon Sep 17 00:00:00 2001 From: NeaguGeorgiana23 Date: Thu, 4 Dec 2025 14:17:43 +0000 Subject: [PATCH 6/7] Fix comments. Signed-off-by: NeaguGeorgiana23 --- test/noop_provider_test.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/test/noop_provider_test.cpp b/test/noop_provider_test.cpp index 88ed3ab..d8fa029 100644 --- a/test/noop_provider_test.cpp +++ b/test/noop_provider_test.cpp @@ -4,25 +4,24 @@ using namespace openfeature; -class NoopProviderBooleanTest : public ::testing::Test, - public ::testing::WithParamInterface {}; - -// Test to verify the metadata returned by the provider +// Test to verify the metadata returned by the provider. TEST(NoopProviderTest, ShouldReturnProviderNameForMetadata) { NoopProvider provider; const Metadata metadata = provider.GetMetadata(); EXPECT_EQ(metadata.name, "Noop Provider"); } -// Test to verify the boolean evaluation returns the default value +class NoopProviderBooleanTest : public ::testing::Test, + public ::testing::WithParamInterface {}; + +// Test to verify the boolean evaluation returns the default value. TEST_P(NoopProviderBooleanTest, BooleanEvaluationShouldReturnDefaultValue) { NoopProvider provider; - const std::string flagKey = "my-bool-flag"; - const EvaluationContext ctx; const bool defaultValue = GetParam(); const std::unique_ptr details = - provider.GetBooleanEvaluation(flagKey, defaultValue, ctx); + provider.GetBooleanEvaluation("my-bool-flag", defaultValue, + EvaluationContext{}); EXPECT_EQ(details->GetValue(), defaultValue); EXPECT_EQ(details->GetReason(), Reason::kDefault); @@ -33,10 +32,10 @@ TEST_P(NoopProviderBooleanTest, BooleanEvaluationShouldReturnDefaultValue) { } INSTANTIATE_TEST_SUITE_P(BooleanDefaultValues, NoopProviderBooleanTest, - ::testing::Values(true, false)); + testing::Values(true, false)); -// Main function to initialize and run all tests +// Main function to initialize and run all tests. int main(int argc, char** argv) { - ::testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } From 83e8fbdf48e5c7a104e18fc58e24c47d05211682 Mon Sep 17 00:00:00 2001 From: NeaguGeorgiana23 Date: Thu, 4 Dec 2025 15:11:35 +0000 Subject: [PATCH 7/7] Update tests to include "Init()" and "Shutdown()". Signed-off-by: NeaguGeorgiana23 --- test/noop_provider_test.cpp | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/test/noop_provider_test.cpp b/test/noop_provider_test.cpp index d8fa029..67f0d72 100644 --- a/test/noop_provider_test.cpp +++ b/test/noop_provider_test.cpp @@ -2,26 +2,43 @@ #include +#include "absl/status/status.h" + using namespace openfeature; -// Test to verify the metadata returned by the provider. -TEST(NoopProviderTest, ShouldReturnProviderNameForMetadata) { +class NoopProviderTest : public ::testing::Test { + protected: NoopProvider provider; + EvaluationContext ctx; +}; + +// Test to verify the metadata returned by the provider. +TEST_F(NoopProviderTest, ShouldReturnProviderNameForMetadata) { const Metadata metadata = provider.GetMetadata(); EXPECT_EQ(metadata.name, "Noop Provider"); } -class NoopProviderBooleanTest : public ::testing::Test, +// Test to verify the Init method returns an OK status. +TEST_F(NoopProviderTest, InitShouldReturnOkStatus) { + const absl::Status status = provider.Init(ctx); + EXPECT_EQ(status, absl::OkStatus()); +} + +// Test to verify the Shutdown method returns an OK status. +TEST_F(NoopProviderTest, ShutdownShouldReturnOkStatus) { + const absl::Status status = provider.Shutdown(); + EXPECT_EQ(status, absl::OkStatus()); +} + +class NoopProviderBooleanTest : public NoopProviderTest, public ::testing::WithParamInterface {}; // Test to verify the boolean evaluation returns the default value. TEST_P(NoopProviderBooleanTest, BooleanEvaluationShouldReturnDefaultValue) { - NoopProvider provider; const bool defaultValue = GetParam(); const std::unique_ptr details = - provider.GetBooleanEvaluation("my-bool-flag", defaultValue, - EvaluationContext{}); + provider.GetBooleanEvaluation("my-bool-flag", defaultValue, ctx); EXPECT_EQ(details->GetValue(), defaultValue); EXPECT_EQ(details->GetReason(), Reason::kDefault);