diff --git a/libs/server-sdk/include/launchdarkly/server_side/bindings/c/sdk.h b/libs/server-sdk/include/launchdarkly/server_side/bindings/c/sdk.h index acccc586d..e493e907e 100644 --- a/libs/server-sdk/include/launchdarkly/server_side/bindings/c/sdk.h +++ b/libs/server-sdk/include/launchdarkly/server_side/bindings/c/sdk.h @@ -303,7 +303,7 @@ LDServerSDK_IntVariationDetail(LDServerSDK sdk, * @return The variation for the given context, or default_value if the * flag is disabled in the LaunchDarkly control panel. */ -LD_EXPORT(int) +LD_EXPORT(double) LDServerSDK_DoubleVariation(LDServerSDK sdk, LDContext context, char const* flag_key, @@ -322,7 +322,7 @@ LDServerSDK_DoubleVariation(LDServerSDK sdk, * @return The variation for the given context, or default_value if the * flag is disabled in the LaunchDarkly control panel. */ -LD_EXPORT(int) +LD_EXPORT(double) LDServerSDK_DoubleVariationDetail(LDServerSDK sdk, LDContext context, char const* flag_key, diff --git a/libs/server-sdk/src/bindings/c/sdk.cpp b/libs/server-sdk/src/bindings/c/sdk.cpp index fe4959e23..087a17eb7 100644 --- a/libs/server-sdk/src/bindings/c/sdk.cpp +++ b/libs/server-sdk/src/bindings/c/sdk.cpp @@ -26,8 +26,7 @@ struct Detail; #define FROM_DETAIL(ptr) (reinterpret_cast(ptr)) -#define TO_DATASOURCESTATUS(ptr) \ - (reinterpret_cast(ptr)) +#define TO_DATASOURCESTATUS(ptr) (reinterpret_cast(ptr)) #define FROM_DATASOURCESTATUS(ptr) \ (reinterpret_cast(ptr)) @@ -260,7 +259,7 @@ LDServerSDK_IntVariationDetail(LDServerSDK sdk, }); } -LD_EXPORT(int) +LD_EXPORT(double) LDServerSDK_DoubleVariation(LDServerSDK sdk, LDContext context, char const* flag_key, @@ -273,7 +272,7 @@ LDServerSDK_DoubleVariation(LDServerSDK sdk, default_value); } -LD_EXPORT(int) +LD_EXPORT(double) LDServerSDK_DoubleVariationDetail(LDServerSDK sdk, LDContext context, char const* flag_key, diff --git a/libs/server-sdk/tests/client_test.cpp b/libs/server-sdk/tests/client_test.cpp index b2c4f5cfe..a19adc49b 100644 --- a/libs/server-sdk/tests/client_test.cpp +++ b/libs/server-sdk/tests/client_test.cpp @@ -52,7 +52,8 @@ TEST_F(ClientTest, IntVariationDefaultPassesThrough) { TEST_F(ClientTest, DoubleVariationDefaultPassesThrough) { std::string const flag = "weight"; - std::vector values = {0.0, 12.0, 13.0, 24.0, 1000.0}; + std::vector values = {0.0, 0.0001, 0.5, 1.234, + 12.0, 13.0, 24.0, 1000.0}; for (auto const& v : values) { ASSERT_EQ(client_.DoubleVariation(context_, flag, v), v); ASSERT_EQ(*client_.DoubleVariationDetail(context_, flag, v), v); diff --git a/libs/server-sdk/tests/server_c_bindings_test.cpp b/libs/server-sdk/tests/server_c_bindings_test.cpp index 7a53b5129..53c71c9f5 100644 --- a/libs/server-sdk/tests/server_c_bindings_test.cpp +++ b/libs/server-sdk/tests/server_c_bindings_test.cpp @@ -159,3 +159,30 @@ TEST(ClientBindings, AllFlagsState) { LDContext_Free(context); LDServerSDK_Free(sdk); } + +TEST(ClientBindings, DoubleVariationPassesThroughDefault) { + LDServerConfigBuilder cfg_builder = LDServerConfigBuilder_New("sdk-123"); + + LDServerConfig config; + LDStatus status = LDServerConfigBuilder_Build(cfg_builder, &config); + ASSERT_TRUE(LDStatus_Ok(status)); + + LDServerSDK sdk = LDServerSDK_New(config); + + LDContextBuilder ctx_builder = LDContextBuilder_New(); + LDContextBuilder_AddKind(ctx_builder, "user", "shadow"); + LDContext context = LDContextBuilder_Build(ctx_builder); + + std::string const flag = "weight"; + std::vector values = {0.0, 0.0001, 0.5, 1.234, + 12.9, 13.211, 24.0, 1000.0}; + for (auto const& v : values) { + ASSERT_EQ(LDServerSDK_DoubleVariation(sdk, context, "weight", v), v); + ASSERT_EQ(LDServerSDK_DoubleVariationDetail(sdk, context, "weight", v, + LD_DISCARD_DETAIL), + v); + } + + LDServerSDK_Free(sdk); + LDContext_Free(context); +}