Fix RedisModule_ReplyWithLongDouble ptr definition, add tests
This commit is contained in:
parent
a24f1971f4
commit
52a00f773b
@ -476,7 +476,7 @@ int REDISMODULE_API_FUNC(RedisModule_ReplyWithEmptyString)(RedisModuleCtx *ctx);
|
|||||||
int REDISMODULE_API_FUNC(RedisModule_ReplyWithVerbatimString)(RedisModuleCtx *ctx, const char *buf, size_t len);
|
int REDISMODULE_API_FUNC(RedisModule_ReplyWithVerbatimString)(RedisModuleCtx *ctx, const char *buf, size_t len);
|
||||||
int REDISMODULE_API_FUNC(RedisModule_ReplyWithNull)(RedisModuleCtx *ctx);
|
int REDISMODULE_API_FUNC(RedisModule_ReplyWithNull)(RedisModuleCtx *ctx);
|
||||||
int REDISMODULE_API_FUNC(RedisModule_ReplyWithDouble)(RedisModuleCtx *ctx, double d);
|
int REDISMODULE_API_FUNC(RedisModule_ReplyWithDouble)(RedisModuleCtx *ctx, double d);
|
||||||
int REDISMODULE_API_FUNC(RedisModule_ReplyWithLongDouble)(RedisModuleCtx *ctx, double d);
|
int REDISMODULE_API_FUNC(RedisModule_ReplyWithLongDouble)(RedisModuleCtx *ctx, long double d);
|
||||||
int REDISMODULE_API_FUNC(RedisModule_ReplyWithCallReply)(RedisModuleCtx *ctx, RedisModuleCallReply *reply);
|
int REDISMODULE_API_FUNC(RedisModule_ReplyWithCallReply)(RedisModuleCtx *ctx, RedisModuleCallReply *reply);
|
||||||
int REDISMODULE_API_FUNC(RedisModule_StringToLongLong)(const RedisModuleString *str, long long *ll);
|
int REDISMODULE_API_FUNC(RedisModule_StringToLongLong)(const RedisModuleString *str, long long *ll);
|
||||||
int REDISMODULE_API_FUNC(RedisModule_StringToDouble)(const RedisModuleString *str, double *d);
|
int REDISMODULE_API_FUNC(RedisModule_StringToDouble)(const RedisModuleString *str, double *d);
|
||||||
|
@ -40,6 +40,43 @@ int test_call_info(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
|
|||||||
return REDISMODULE_OK;
|
return REDISMODULE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int test_ld_conv(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||||
|
long double ld = 0.00000000000000001L;
|
||||||
|
const char *ldstr = "0.00000000000000001";
|
||||||
|
RedisModuleString *s1 = RedisModule_CreateStringFromLongDouble(ctx, ld, 1);
|
||||||
|
RedisModuleString *s2 =
|
||||||
|
RedisModule_CreateString(ctx, ldstr, strlen(ldstr));
|
||||||
|
if (RedisModule_StringCompare(s1, s2) != 0) {
|
||||||
|
char err[4096];
|
||||||
|
snprintf(err, 4096,
|
||||||
|
"Failed to convert long double to string ('%s' != '%s')",
|
||||||
|
RedisModule_StringPtrLen(s1, NULL),
|
||||||
|
RedisModule_StringPtrLen(s2, NULL));
|
||||||
|
RedisModule_ReplyWithError(ctx, err);
|
||||||
|
goto final;
|
||||||
|
}
|
||||||
|
long double ld2 = 0;
|
||||||
|
if (RedisModule_StringToLongDouble(s2, &ld2) == REDISMODULE_ERR) {
|
||||||
|
RedisModule_ReplyWithError(ctx,
|
||||||
|
"Failed to convert string to long double");
|
||||||
|
goto final;
|
||||||
|
}
|
||||||
|
if (ld2 != ld) {
|
||||||
|
char err[4096];
|
||||||
|
snprintf(err, 4096,
|
||||||
|
"Failed to convert string to long double (%.40Lf != %.40Lf)",
|
||||||
|
ld2,
|
||||||
|
ld);
|
||||||
|
RedisModule_ReplyWithError(ctx, err);
|
||||||
|
goto final;
|
||||||
|
}
|
||||||
|
RedisModule_ReplyWithLongDouble(ctx, ld2);
|
||||||
|
final:
|
||||||
|
RedisModule_FreeString(ctx, s1);
|
||||||
|
RedisModule_FreeString(ctx, s2);
|
||||||
|
return REDISMODULE_OK;
|
||||||
|
}
|
||||||
|
|
||||||
int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||||
REDISMODULE_NOT_USED(argv);
|
REDISMODULE_NOT_USED(argv);
|
||||||
REDISMODULE_NOT_USED(argc);
|
REDISMODULE_NOT_USED(argc);
|
||||||
@ -50,6 +87,7 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
|
|||||||
return REDISMODULE_ERR;
|
return REDISMODULE_ERR;
|
||||||
if (RedisModule_CreateCommand(ctx,"test.call_info", test_call_info,"",0,0,0) == REDISMODULE_ERR)
|
if (RedisModule_CreateCommand(ctx,"test.call_info", test_call_info,"",0,0,0) == REDISMODULE_ERR)
|
||||||
return REDISMODULE_ERR;
|
return REDISMODULE_ERR;
|
||||||
|
if (RedisModule_CreateCommand(ctx,"test.ld_conversion", test_ld_conv, "",0,0,0) == REDISMODULE_ERR)
|
||||||
|
return REDISMODULE_ERR;
|
||||||
return REDISMODULE_OK;
|
return REDISMODULE_OK;
|
||||||
}
|
}
|
||||||
|
@ -16,4 +16,9 @@ start_server {tags {"modules"}} {
|
|||||||
assert { [string match "*cmdstat_module*" $info] }
|
assert { [string match "*cmdstat_module*" $info] }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test {test long double conversions} {
|
||||||
|
set ld [r test.ld_conversion]
|
||||||
|
assert {[string match $ld "0.00000000000000001"]}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user