From d0dee2e26027f866c282050457d61d6907f3263f Mon Sep 17 00:00:00 2001 From: David Steele Date: Sat, 17 Aug 2019 17:47:13 -0400 Subject: [PATCH] Add bool rendering to jsonFromVar(). --- src/common/type/json.c | 4 ++++ test/src/module/common/typeJsonTest.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/common/type/json.c b/src/common/type/json.c index 2119a51c1..7c46f199a 100644 --- a/src/common/type/json.c +++ b/src/common/type/json.c @@ -935,6 +935,10 @@ jsonFromVar(const Variant *var, unsigned int indent) { strCat(jsonStr, strPtr(NULL_STR)); } + else if (varType(var) == varTypeBool) + { + strCat(jsonStr, strPtr(jsonFromBool(varBool(var)))); + } else if (varType(var) == varTypeUInt) { strCat(jsonStr, strPtr(jsonFromUInt(varUInt(var)))); diff --git a/test/src/module/common/typeJsonTest.c b/test/src/module/common/typeJsonTest.c index a8f828cdc..fbeaf907b 100644 --- a/test/src/module/common/typeJsonTest.c +++ b/test/src/module/common/typeJsonTest.c @@ -219,7 +219,7 @@ testRun(void) // ***************************************************************************************************************************** if (testBegin("jsonFromVar()")) { - TEST_ERROR(jsonFromVar(varNewBool(true), 0), JsonFormatError, "variant type is invalid"); + TEST_ERROR(jsonFromVar(varNewInt(1), 0), JsonFormatError, "variant type is invalid"); String *json = NULL; Variant *keyValue = NULL; @@ -378,6 +378,7 @@ testRun(void) //-------------------------------------------------------------------------------------------------------------------------- TEST_RESULT_STR(strPtr(jsonFromVar(NULL, 0)), "null", "null variant"); + TEST_RESULT_STR(strPtr(jsonFromVar(varNewBool(true), 0)), "true", "bool variant"); TEST_RESULT_STR(strPtr(jsonFromVar(varNewUInt(66), 0)), "66", "uint variant"); TEST_RESULT_STR(strPtr(jsonFromVar(varNewUInt64(10000000001), 0)), "10000000001", "uint64 variant"); TEST_RESULT_STR(strPtr(jsonFromVar(varNewStrZ("test \" string"), 0)), "\"test \\\" string\"", "string variant");