mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
cJSON_ConfigurationChangeCaseSensitivity
This commit is contained in:
parent
78b5bed9a0
commit
eeaaaac63e
21
cJSON.c
21
cJSON.c
@ -2929,16 +2929,6 @@ CJSON_PUBLIC(cJSON_Configuration) cJSON_CreateConfiguration(const cJSON * const
|
||||
|
||||
/* then overwrite with other options if they exist */
|
||||
|
||||
option = get_object_item(json, "case_sensitive", &global_configuration);
|
||||
if (cJSON_IsTrue(option))
|
||||
{
|
||||
configuration->case_sensitive = true;
|
||||
}
|
||||
else if (cJSON_IsFalse(option))
|
||||
{
|
||||
configuration->case_sensitive = false;
|
||||
}
|
||||
|
||||
option = get_object_item(json, "allow_data_after_json", &global_configuration);
|
||||
if (cJSON_IsTrue(option))
|
||||
{
|
||||
@ -3031,6 +3021,17 @@ CJSON_PUBLIC(cJSON_Configuration) cJSON_ConfigurationChangeFormat(cJSON_Configur
|
||||
return configuration;
|
||||
}
|
||||
|
||||
CJSON_PUBLIC(cJSON_Configuration) cJSON_ConfigurationChangeCaseSensitivity(cJSON_Configuration configuration, cJSON_bool case_sensitive)
|
||||
{
|
||||
if (configuration == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((internal_configuration*)configuration)->case_sensitive = case_sensitive;
|
||||
return configuration;
|
||||
}
|
||||
|
||||
static cJSON_bool compare(const cJSON * const a, const cJSON * const b, const internal_configuration * const configuration)
|
||||
{
|
||||
if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) || cJSON_IsInvalid(a))
|
||||
|
2
cJSON.h
2
cJSON.h
@ -185,6 +185,8 @@ CJSON_PUBLIC(cJSON_Configuration) cJSON_ConfigurationChangePrebufferSize(cJSON_C
|
||||
typedef enum { CJSON_FORMAT_MINIFIED = 0, CJSON_FORMAT_DEFAULT = 1 } cJSON_Format;
|
||||
/* Change the format for printing */
|
||||
CJSON_PUBLIC(cJSON_Configuration) cJSON_ConfigurationChangeFormat(cJSON_Configuration configuration, cJSON_Format format);
|
||||
/* Change the case sensitivity */
|
||||
CJSON_PUBLIC(cJSON_Configuration) cJSON_ConfigurationChangeCaseSensitivity(cJSON_Configuration configuration, cJSON_bool case_sensitive);
|
||||
|
||||
/* Supply malloc and free functions to cJSON globally */
|
||||
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
|
||||
|
@ -34,7 +34,7 @@ static void create_configuration_should_create_a_configuration(void)
|
||||
internal_configuration *configuration = NULL;
|
||||
int userdata = 1;
|
||||
|
||||
json = cJSON_Parse("{\"case_sensitive\":false,\"allow_data_after_json\":false}");
|
||||
json = cJSON_Parse("{\"allow_data_after_json\":false}");
|
||||
TEST_ASSERT_NOT_NULL(json);
|
||||
configuration = (internal_configuration*)cJSON_CreateConfiguration(json, NULL, &userdata);
|
||||
cJSON_Delete(json);
|
||||
@ -42,7 +42,7 @@ static void create_configuration_should_create_a_configuration(void)
|
||||
TEST_ASSERT_NOT_NULL(configuration);
|
||||
TEST_ASSERT_EQUAL_MESSAGE(configuration->buffer_size, 256, "buffer_size has an incorrect value.");
|
||||
TEST_ASSERT_TRUE_MESSAGE(configuration->format, "format has an incorrect value.");
|
||||
TEST_ASSERT_FALSE_MESSAGE(configuration->case_sensitive, "case_sensitive has an incorrect value.");
|
||||
TEST_ASSERT_TRUE_MESSAGE(configuration->case_sensitive, "case_sensitive has an incorrect value.");
|
||||
TEST_ASSERT_FALSE_MESSAGE(configuration->allow_data_after_json, "allow_data_after_json has an incorrect value.");
|
||||
TEST_ASSERT_TRUE_MESSAGE(configuration->userdata == &userdata, "Incorrect userdata");
|
||||
TEST_ASSERT_TRUE_MESSAGE(global_allocate_wrapper == configuration->allocators.allocate, "Wrong malloc.");
|
||||
@ -184,6 +184,19 @@ static void configuration_change_format_should_change_format(void)
|
||||
free(configuration);
|
||||
}
|
||||
|
||||
static void configuration_change_case_sensitivity_should_change_case_sensitivity(void)
|
||||
{
|
||||
internal_configuration *configuration = (internal_configuration*)cJSON_CreateConfiguration(NULL, NULL, NULL);
|
||||
TEST_ASSERT_NOT_NULL(configuration);
|
||||
|
||||
configuration = (internal_configuration*)cJSON_ConfigurationChangeCaseSensitivity(configuration, false);
|
||||
TEST_ASSERT_NOT_NULL(configuration);
|
||||
|
||||
TEST_ASSERT_FALSE_MESSAGE(configuration->case_sensitive, "Didn't set the case sensitivity correctly.");
|
||||
|
||||
free(configuration);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
UNITY_BEGIN();
|
||||
@ -197,6 +210,7 @@ int main(void)
|
||||
RUN_TEST(configuration_change_prebuffer_size_should_change_buffer_size);
|
||||
RUN_TEST(configuration_change_prebuffer_size_should_not_allow_empty_sizes);
|
||||
RUN_TEST(configuration_change_format_should_change_format);
|
||||
RUN_TEST(configuration_change_case_sensitivity_should_change_case_sensitivity);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user