From 9c7f8ce7984234ff85009b15ed4cba8465512656 Mon Sep 17 00:00:00 2001 From: Oleg Efimov Date: Sat, 22 Mar 2014 21:40:02 +0400 Subject: [PATCH] t/: add test case for Issue #129 from Oleg Efimov --- t/generated-code2/test-generated-code2.c | 23 +++++++++++++++++++++++ t/test-full.proto | 7 +++++++ 2 files changed, 30 insertions(+) diff --git a/t/generated-code2/test-generated-code2.c b/t/generated-code2/test-generated-code2.c index 0adf412..1ce0a83 100644 --- a/t/generated-code2/test-generated-code2.c +++ b/t/generated-code2/test-generated-code2.c @@ -1406,6 +1406,27 @@ test_optional_default_values (void) foo__default_optional_values__free_unpacked (mess2, NULL); } +static void +assert_optional_lowercase_enum_default_value_is_default (Foo__LowerCase *mess) +{ + assert (!mess->has_value); + assert (mess->value == 2); +} + +static void +test_optional_lowercase_enum_default_value (void) +{ + Foo__LowerCase mess = FOO__LOWER_CASE__INIT; + Foo__LowerCase *mess2; + size_t len; uint8_t *data; + assert_optional_lowercase_enum_default_value_is_default (&mess); + mess2 = test_compare_pack_methods (&mess.base, &len, &data); + assert (len == 0); /* no non-default values */ + free (data); + assert_optional_lowercase_enum_default_value_is_default (mess2); + foo__lower_case__free_unpacked (mess2, NULL); +} + static void test_field_merge (void) { @@ -1672,6 +1693,8 @@ static Test tests[] = { "test required default values", test_required_default_values }, { "test optional default values", test_optional_default_values }, + { "test optional lowercase enum default value", test_optional_lowercase_enum_default_value }, + { "test field merge", test_field_merge }, { "test free unpacked", test_alloc_free_all }, diff --git a/t/test-full.proto b/t/test-full.proto index 2ebb885..0f144ad 100644 --- a/t/test-full.proto +++ b/t/test-full.proto @@ -207,6 +207,13 @@ message DefaultOptionalValues { optional string v_string = 7 [default = "hi mom\n"]; optional bytes v_bytes = 8 [default = "a \0 character"]; } +message LowerCase { + enum CaseEnum { + UPPER = 1; + lower = 2; + } + optional CaseEnum value = 1 [default = lower]; +} message AllocValues { optional bytes o_bytes = 1; repeated string r_string = 2;