From f2aa3828787312022a590a824d115bcbc6c7d1ae Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Szczekutek?= Date: Thu, 14 Jul 2016 13:18:03 +0200 Subject: [PATCH] [UTC][Base-utils][ACR-661][MeasureFormat additional tests added] Related base-utils sources: https://review.tizen.org/gerrit/#/c/72978/ Change-Id: I26f2b348f5b4af53e195c2dbc0fbe108e52f4b53 Signed-off-by: Beata Stefaniuk Signed-off-by: Damian Pietruchowski Signed-off-by: Jakub Siewierski --- src/utc/base-utils/tct-base-utils-core_mobile.h | 20 ++ src/utc/base-utils/tct-base-utils-core_wearable.h | 20 ++ .../utc-capi-base-utils-measure-format.c | 292 ++++++++++++++++++++- 3 files changed, 327 insertions(+), 5 deletions(-) diff --git a/src/utc/base-utils/tct-base-utils-core_mobile.h b/src/utc/base-utils/tct-base-utils-core_mobile.h index 7fcc27c..1aefbdd 100755 --- a/src/utc/base-utils/tct-base-utils-core_mobile.h +++ b/src/utc/base-utils/tct-base-utils-core_mobile.h @@ -1312,6 +1312,16 @@ extern int utc_capi_base_utils_i18n_measure_format_create_p2(void); extern int utc_capi_base_utils_i18n_measure_format_create_p3(void); extern int utc_capi_base_utils_i18n_measure_format_create_n(void); extern int utc_capi_base_utils_i18n_measure_format_create_n2(void); +extern int utc_capi_base_utils_i18n_measure_format_format_p(void); +extern int utc_capi_base_utils_i18n_measure_format_format_n(void); +extern int utc_capi_base_utils_i18n_measure_format_format_n2(void); +extern int utc_capi_base_utils_i18n_measure_format_format_n3(void); +extern int utc_capi_base_utils_i18n_measure_format_format_n4(void); +extern int utc_capi_base_utils_i18n_measure_format_parse_object_p(void); +extern int utc_capi_base_utils_i18n_measure_format_parse_object_n(void); +extern int utc_capi_base_utils_i18n_measure_format_parse_object_n2(void); +extern int utc_capi_base_utils_i18n_measure_format_parse_object_n3(void); +extern int utc_capi_base_utils_i18n_measure_format_parse_object_n4(void); extern int utc_capi_base_utils_i18n_format_get_locale_p(void); extern int utc_capi_base_utils_i18n_format_get_locale_n(void); extern int utc_capi_base_utils_i18n_format_get_locale_n2(void); @@ -2625,6 +2635,16 @@ testcase tc_array[] = { {"utc_capi_base_utils_i18n_measure_format_create_p3", utc_capi_base_utils_i18n_measure_format_create_p3, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, {"utc_capi_base_utils_i18n_measure_format_create_n", utc_capi_base_utils_i18n_measure_format_create_n, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, {"utc_capi_base_utils_i18n_measure_format_create_n2", utc_capi_base_utils_i18n_measure_format_create_n2, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, + {"utc_capi_base_utils_i18n_measure_format_format_p", utc_capi_base_utils_i18n_measure_format_format_p, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, + {"utc_capi_base_utils_i18n_measure_format_format_n", utc_capi_base_utils_i18n_measure_format_format_n, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, + {"utc_capi_base_utils_i18n_measure_format_format_n2", utc_capi_base_utils_i18n_measure_format_format_n2, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, + {"utc_capi_base_utils_i18n_measure_format_format_n3", utc_capi_base_utils_i18n_measure_format_format_n3, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, + {"utc_capi_base_utils_i18n_measure_format_format_n4", utc_capi_base_utils_i18n_measure_format_format_n4, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, + {"utc_capi_base_utils_i18n_measure_format_parse_object_p", utc_capi_base_utils_i18n_measure_format_parse_object_p, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, + {"utc_capi_base_utils_i18n_measure_format_parse_object_n", utc_capi_base_utils_i18n_measure_format_parse_object_n, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, + {"utc_capi_base_utils_i18n_measure_format_parse_object_n2", utc_capi_base_utils_i18n_measure_format_parse_object_n2, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, + {"utc_capi_base_utils_i18n_measure_format_parse_object_n3", utc_capi_base_utils_i18n_measure_format_parse_object_n3, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, + {"utc_capi_base_utils_i18n_measure_format_parse_object_n4", utc_capi_base_utils_i18n_measure_format_parse_object_n4, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, {"utc_capi_base_utils_i18n_format_get_locale_p", utc_capi_base_utils_i18n_format_get_locale_p, utc_capi_base_utils_format_startup, utc_capi_base_utils_format_cleanup}, {"utc_capi_base_utils_i18n_format_get_locale_n", utc_capi_base_utils_i18n_format_get_locale_n, utc_capi_base_utils_format_startup, utc_capi_base_utils_format_cleanup}, {"utc_capi_base_utils_i18n_format_get_locale_n2", utc_capi_base_utils_i18n_format_get_locale_n2, utc_capi_base_utils_format_startup, utc_capi_base_utils_format_cleanup}, diff --git a/src/utc/base-utils/tct-base-utils-core_wearable.h b/src/utc/base-utils/tct-base-utils-core_wearable.h index ce98088..622877d 100755 --- a/src/utc/base-utils/tct-base-utils-core_wearable.h +++ b/src/utc/base-utils/tct-base-utils-core_wearable.h @@ -1305,6 +1305,16 @@ extern int utc_capi_base_utils_i18n_measure_format_create_p2(void); extern int utc_capi_base_utils_i18n_measure_format_create_p3(void); extern int utc_capi_base_utils_i18n_measure_format_create_n(void); extern int utc_capi_base_utils_i18n_measure_format_create_n2(void); +extern int utc_capi_base_utils_i18n_measure_format_format_p(void); +extern int utc_capi_base_utils_i18n_measure_format_format_n(void); +extern int utc_capi_base_utils_i18n_measure_format_format_n2(void); +extern int utc_capi_base_utils_i18n_measure_format_format_n3(void); +extern int utc_capi_base_utils_i18n_measure_format_format_n4(void); +extern int utc_capi_base_utils_i18n_measure_format_parse_object_p(void); +extern int utc_capi_base_utils_i18n_measure_format_parse_object_n(void); +extern int utc_capi_base_utils_i18n_measure_format_parse_object_n2(void); +extern int utc_capi_base_utils_i18n_measure_format_parse_object_n3(void); +extern int utc_capi_base_utils_i18n_measure_format_parse_object_n4(void); extern int utc_capi_base_utils_i18n_format_get_locale_p(void); extern int utc_capi_base_utils_i18n_format_get_locale_n(void); extern int utc_capi_base_utils_i18n_format_get_locale_n2(void); @@ -2609,6 +2619,16 @@ testcase tc_array[] = { {"utc_capi_base_utils_i18n_measure_format_create_p3", utc_capi_base_utils_i18n_measure_format_create_p3, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, {"utc_capi_base_utils_i18n_measure_format_create_n", utc_capi_base_utils_i18n_measure_format_create_n, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, {"utc_capi_base_utils_i18n_measure_format_create_n2", utc_capi_base_utils_i18n_measure_format_create_n2, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, + {"utc_capi_base_utils_i18n_measure_format_format_p", utc_capi_base_utils_i18n_measure_format_format_p, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, + {"utc_capi_base_utils_i18n_measure_format_format_n", utc_capi_base_utils_i18n_measure_format_format_n, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, + {"utc_capi_base_utils_i18n_measure_format_format_n2", utc_capi_base_utils_i18n_measure_format_format_n2, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, + {"utc_capi_base_utils_i18n_measure_format_format_n3", utc_capi_base_utils_i18n_measure_format_format_n3, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, + {"utc_capi_base_utils_i18n_measure_format_format_n4", utc_capi_base_utils_i18n_measure_format_format_n4, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, + {"utc_capi_base_utils_i18n_measure_format_parse_object_p", utc_capi_base_utils_i18n_measure_format_parse_object_p, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, + {"utc_capi_base_utils_i18n_measure_format_parse_object_n", utc_capi_base_utils_i18n_measure_format_parse_object_n, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, + {"utc_capi_base_utils_i18n_measure_format_parse_object_n2", utc_capi_base_utils_i18n_measure_format_parse_object_n2, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, + {"utc_capi_base_utils_i18n_measure_format_parse_object_n3", utc_capi_base_utils_i18n_measure_format_parse_object_n3, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, + {"utc_capi_base_utils_i18n_measure_format_parse_object_n4", utc_capi_base_utils_i18n_measure_format_parse_object_n4, utc_capi_base_utils_measure_format_startup, utc_capi_base_utils_measure_format_cleanup}, {"utc_capi_base_utils_i18n_format_get_locale_p", utc_capi_base_utils_i18n_format_get_locale_p, utc_capi_base_utils_format_startup, utc_capi_base_utils_format_cleanup}, {"utc_capi_base_utils_i18n_format_get_locale_n", utc_capi_base_utils_i18n_format_get_locale_n, utc_capi_base_utils_format_startup, utc_capi_base_utils_format_cleanup}, {"utc_capi_base_utils_i18n_format_get_locale_n2", utc_capi_base_utils_i18n_format_get_locale_n2, utc_capi_base_utils_format_startup, utc_capi_base_utils_format_cleanup}, diff --git a/src/utc/base-utils/utc-capi-base-utils-measure-format.c b/src/utc/base-utils/utc-capi-base-utils-measure-format.c index a9ef6d9..4034b01 100644 --- a/src/utc/base-utils/utc-capi-base-utils-measure-format.c +++ b/src/utc/base-utils/utc-capi-base-utils-measure-format.c @@ -89,6 +89,9 @@ int utc_capi_base_utils_i18n_measure_format_create_currency_format_from_locale_p assert_neq(measure_format, NULL); assert_eq(ret, I18N_ERROR_NONE); + i18n_measure_format_destroy(measure_format); + measure_format = NULL; + return 0; } @@ -241,7 +244,7 @@ int utc_capi_base_utils_i18n_measure_format_create_p2(void) const char *country = "KR"; i18n_umeasure_format_width_e format_width = I18N_UMEASFMT_WIDTH_WIDE; - int ret = i18n_measure_format_create(NULL, country, format_width, &measure_format); + ret = i18n_measure_format_create(NULL, country, format_width, &measure_format); assert_neq(measure_format, NULL); assert_eq(ret, I18N_ERROR_NONE); @@ -265,7 +268,7 @@ int utc_capi_base_utils_i18n_measure_format_create_p3(void) const char *language = I18N_ULOCALE_KOREAN; i18n_umeasure_format_width_e format_width = I18N_UMEASFMT_WIDTH_WIDE; - int ret = i18n_measure_format_create(language, NULL, format_width, &measure_format); + ret = i18n_measure_format_create(language, NULL, format_width, &measure_format); assert_neq(measure_format, NULL); assert_eq(ret, I18N_ERROR_NONE); @@ -292,8 +295,8 @@ int utc_capi_base_utils_i18n_measure_format_create_n(void) ret = i18n_measure_format_create(language, country, format_width, &measure_format); - assert_neq(measure_format, NULL); - assert_eq(ret, I18N_ERROR_NONE); + assert_eq(measure_format, NULL); + assert_eq(ret, I18N_ERROR_INVALID_PARAMETER); return 0; } @@ -310,7 +313,286 @@ int utc_capi_base_utils_i18n_measure_format_create_n2(void) const char *country = "KR"; i18n_umeasure_format_width_e format_width = I18N_UMEASFMT_WIDTH_WIDE; - int ret = i18n_measure_format_create(language, country, format_width, NULL); + ret = i18n_measure_format_create(language, country, format_width, NULL); + + assert_eq(measure_format, NULL); + assert_eq(ret, I18N_ERROR_INVALID_PARAMETER); + + return 0; +} + +/** + * @testcase utc_capi_base_utils_i18n_measure_format_format_p + * @since_tizen 3.0 + * @description Calls i18n_measure_format_format and checks whether function + * succeeded. + */ +int utc_capi_base_utils_i18n_measure_format_format_p(void) +{ + i18n_measure_format_h measure_format = NULL; + i18n_measure_format_create_currency_format(&measure_format); + assert_neq(measure_format, NULL); + + double double_to_set = 13.0; + i18n_formattable_h formattable = NULL; + i18n_formattable_create_with_double(double_to_set, &formattable); + assert_neq(formattable, NULL); + + char *append_to = "Price: "; + + i18n_field_position_h field_position = NULL; + i18n_field_position_create_for_field(0, &field_position); + i18n_field_position_set_field(field_position, 1); + assert_neq(field_position, NULL); + + ret = i18n_measure_format_format(measure_format, formattable, &append_to, field_position); + + assert_eq(ret, I18N_ERROR_NONE); + assert_eq(strcmp(append_to, "Price: $13.00"), 0); + + return 0; +} + +/** + * @testcase utc_capi_base_utils_i18n_measure_format_format_n + * @since_tizen 3.0 + * @description Calls i18n_measure_format_format passing invalid measure_format and + * checks for an invalid parameter error code. + */ +int utc_capi_base_utils_i18n_measure_format_format_n(void) +{ + i18n_formattable_h formattable = NULL; + double double_to_set = 13.0; + i18n_formattable_create_with_double(double_to_set, &formattable); + assert_neq(formattable, NULL); + + char *append_to = "Price: "; + + i18n_field_position_h field_position = NULL; + i18n_field_position_create(&field_position); + assert_neq(field_position, NULL); + + ret = i18n_measure_format_format(NULL, formattable, &append_to, field_position); + + assert_eq(ret, I18N_ERROR_INVALID_PARAMETER); + assert_eq(strcmp(append_to, "Price: "), 0); + + return 0; +} + +/** + * @testcase utc_capi_base_utils_i18n_measure_format_format_n2 + * @since_tizen 3.0 + * @description Calls i18n_measure_format_format passing invalid formattable and + * checks for an invalid parameter error code. + */ +int utc_capi_base_utils_i18n_measure_format_format_n2(void) +{ + i18n_measure_format_h measure_format = NULL; + ret = i18n_measure_format_create_currency_format(&measure_format); + assert_eq(ret, I18N_ERROR_NONE); + assert_neq(measure_format, NULL); + + char *append_to = "Price: "; + + i18n_field_position_h field_position = NULL; + ret = i18n_field_position_create(&field_position); + assert_eq(ret, I18N_ERROR_NONE); + assert_neq(field_position, NULL); + + ret = i18n_measure_format_format(measure_format, NULL, &append_to, field_position); + + assert_eq(ret, I18N_ERROR_INVALID_PARAMETER); + + return 0; +} + +/** + * @testcase utc_capi_base_utils_i18n_measure_format_format_n3 + * @since_tizen 3.0 + * @description Calls i18n_measure_format_format passing invalid append_to and + * checks for an invalid parameter error code. + */ +int utc_capi_base_utils_i18n_measure_format_format_n3(void) +{ + i18n_measure_format_h measure_format = NULL; + ret = i18n_measure_format_create_currency_format(&measure_format); + assert_eq(ret, I18N_ERROR_NONE); + assert_neq(measure_format, NULL); + + i18n_formattable_h formattable = NULL; + double double_to_set = 13.0; + ret = i18n_formattable_create_with_double(double_to_set, &formattable); + assert_eq(ret, I18N_ERROR_NONE); + assert_neq(formattable, NULL); + + i18n_field_position_h field_position = NULL; + ret = i18n_field_position_create(&field_position); + assert_eq(ret, I18N_ERROR_NONE); + assert_neq(field_position, NULL); + + ret = i18n_measure_format_format(measure_format, formattable, NULL, field_position); + + i18n_field_position_destroy(field_position); + + assert_eq(ret, I18N_ERROR_INVALID_PARAMETER); + + return 0; +} + +/** + * @testcase utc_capi_base_utils_i18n_measure_format_format_n4 + * @since_tizen 3.0 + * @description Calls i18n_measure_format_format passing invalid field_position and + * checks for an invalid parameter error code. + */ +int utc_capi_base_utils_i18n_measure_format_format_n4(void) +{ + i18n_measure_format_h measure_format = NULL; + ret = i18n_measure_format_create_currency_format(&measure_format); + assert_eq(ret, I18N_ERROR_NONE); + assert_neq(measure_format, NULL); + + i18n_formattable_h formattable = NULL; + double double_to_set = 13.0; + ret = i18n_formattable_create_with_double(double_to_set, &formattable); + assert_eq(ret, I18N_ERROR_NONE); + assert_neq(formattable, NULL); + + char *append_to = "Price: "; + + ret = i18n_measure_format_format(measure_format, formattable, &append_to, NULL); + + assert_eq(ret, I18N_ERROR_INVALID_PARAMETER); + + return 0; +} + +/** + * @testcase utc_capi_base_utils_i18n_measure_format_parse_object_p + * @since_tizen 3.0 + * @description Calls i18n_measure_format_parse_object and checks whether function + * succeeded. + */ +int utc_capi_base_utils_i18n_measure_format_parse_object_p(void) +{ + assert_eq(ret, I18N_ERROR_NONE); + assert_neq(measure_format, NULL); + + const char *source = "$1,234.56"; + + i18n_formattable_h result = NULL; + + i18n_parse_position_h parse_position = NULL; + i18n_parse_position_create(&parse_position); + assert_neq(parse_position, NULL); + + ret = i18n_measure_format_parse_object(measure_format, source, &result, parse_position); + + i18n_parse_position_destroy(parse_position); + + assert_eq(ret, I18N_ERROR_NONE); + assert_neq(result, NULL); + + return 0; +} + +/** + * @testcase utc_capi_base_utils_i18n_measure_format_parse_object_n + * @since_tizen 3.0 + * @description Calls i18n_measure_format_parse_object passing invalid measure_format and + * checks for an invalid parameter error code. + */ +int utc_capi_base_utils_i18n_measure_format_parse_object_n(void) +{ + assert_neq(measure_format, NULL); + + const char *source = "$1,234.56"; + + i18n_formattable_h result = NULL; + + i18n_parse_position_h parse_position = NULL; + i18n_parse_position_create(&parse_position); + assert_neq(parse_position, NULL); + + ret = i18n_measure_format_parse_object(NULL, source, &result, parse_position); + + i18n_parse_position_destroy(parse_position); + + assert_eq(ret, I18N_ERROR_INVALID_PARAMETER); + + return 0; +} + +/** + * @testcase utc_capi_base_utils_i18n_measure_format_parse_object_n2 + * @since_tizen 3.0 + * @description Calls i18n_measure_format_parse_object passing invalid source and + * checks for an invalid parameter error code. + */ +int utc_capi_base_utils_i18n_measure_format_parse_object_n2(void) +{ + assert_eq(ret, I18N_ERROR_NONE); + assert_neq(measure_format, NULL); + + i18n_formattable_h result = NULL; + + i18n_parse_position_h parse_position = NULL; + i18n_parse_position_create(&parse_position); + assert_neq(parse_position, NULL); + + ret = i18n_measure_format_parse_object(measure_format, NULL, &result, parse_position); + + i18n_parse_position_destroy(parse_position); + + assert_eq(ret, I18N_ERROR_INVALID_PARAMETER); + + return 0; +} + +/** + * @testcase utc_capi_base_utils_i18n_measure_format_parse_object_n3 + * @since_tizen 3.0 + * @description Calls i18n_measure_format_parse_object passing invalid result and + * checks for an invalid parameter error code. + */ +int utc_capi_base_utils_i18n_measure_format_parse_object_n3(void) +{ + assert_eq(ret, I18N_ERROR_NONE); + assert_neq(measure_format, NULL); + + const char *source = "$1,234.56"; + + i18n_parse_position_h parse_position = NULL; + ret = i18n_parse_position_create(&parse_position); + assert_eq(ret, I18N_ERROR_NONE); + assert_neq(parse_position, NULL); + + ret = i18n_measure_format_parse_object(measure_format, source, NULL, parse_position); + + i18n_parse_position_destroy(parse_position); + + assert_eq(ret, I18N_ERROR_INVALID_PARAMETER); + + return 0; +} + +/** + * @testcase utc_capi_base_utils_i18n_measure_format_parse_object_n4 + * @since_tizen 3.0 + * @description Calls i18n_measure_format_parse_object passing invalid parse_position and + * checks for an invalid parameter error code. + */ +int utc_capi_base_utils_i18n_measure_format_parse_object_n4(void) +{ + assert_eq(ret, I18N_ERROR_NONE); + assert_neq(measure_format, NULL); + + const char *source = "$1,234.56"; + + i18n_formattable_h result = NULL; + + ret = i18n_measure_format_parse_object(measure_format, source, &result, NULL); assert_eq(ret, I18N_ERROR_INVALID_PARAMETER); -- 2.7.4