fix: fix invalid cleanup logic 12/273912/1
authorDongHun Kwak <dh0128.kwak@samsung.com>
Fri, 15 Apr 2022 03:09:00 +0000 (12:09 +0900)
committerDongHun Kwak <dh0128.kwak@samsung.com>
Fri, 15 Apr 2022 05:50:58 +0000 (14:50 +0900)
- does not called i18n_uidna_destroy() at cleanup

Change-Id: Ia0a863cc7dac0ca85cb658c4d704ce6b2db9292a

tests/utc-capi-base-utils-uidna.c

index bde708c..b00eff8 100644 (file)
 #include <utils_i18n.h>
 #include <string.h>
 
-#define I18N_UPRV_LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
+#define I18N_UPRV_LENGTHOF(array) (int32_t)(sizeof(array) / sizeof((array)[0]))
 
 static int ret = I18N_ERROR_NONE;
 static i18n_uidna_h uidna;
 
 /**
-* @function        utc_capi_base_utils_uidna_startup
-* @description     Called before each test
-* @parameter       NA
-* @return          NA
-*/
+ * @function        utc_capi_base_utils_uidna_startup
+ * @description     Called before each test
+ * @parameter       NA
+ * @return          NA
+ */
 void utc_capi_base_utils_uidna_startup(void)
 {
+       uidna = NULL;
+       ret = i18n_uidna_create(I18N_UIDNA_DEFAULT, &uidna);
 }
 
 /**
-* @function        utc_capi_base_utils_uidna_cleanup
-* @description     Called after each test
-* @parameter       NA
-* @return          NA
-*/
+ * @function        utc_capi_base_utils_uidna_cleanup
+ * @description     Called after each test
+ * @parameter       NA
+ * @return          NA
+ */
 void utc_capi_base_utils_uidna_cleanup(void)
 {
-       if (!uidna)
+       if (uidna != NULL)
+       {
                i18n_uidna_destroy(uidna);
+               uidna = NULL;
+       }
 }
 
 /**
@@ -51,15 +56,12 @@ void utc_capi_base_utils_uidna_cleanup(void)
  */
 int utc_capi_base_utils_i18n_uidna_label_to_ascii_p(void)
 {
-    static const i18n_uchar fA_sharps16[] = { 0x66, 0x41, 0xdf, 0 };
+       static const i18n_uchar fA_sharps16[] = {0x66, 0x41, 0xdf, 0};
 
        i18n_uchar dest[10];
        i18n_uidna_info_h info;
        int32_t length;
 
-       ret = i18n_uidna_create(I18N_UIDNA_DEFAULT, &uidna);
-       assert_eq(ret, I18N_ERROR_NONE);
-
        ret = i18n_uidna_label_to_ascii(uidna, fA_sharps16, -1, dest, I18N_UPRV_LENGTHOF(dest), &info, &length);
        assert_eq(ret, I18N_ERROR_NONE);
        assert_eq(length, 4);
@@ -74,14 +76,11 @@ int utc_capi_base_utils_i18n_uidna_label_to_ascii_p(void)
  */
 int utc_capi_base_utils_i18n_uidna_label_to_ascii_n(void)
 {
-    static const i18n_uchar fA_sharps16[] = { 0x66, 0x41, 0xdf, 0 };
+       static const i18n_uchar fA_sharps16[] = {0x66, 0x41, 0xdf, 0};
        i18n_uchar dest[10];
        i18n_uidna_info_h info;
        int32_t length;
 
-       ret = i18n_uidna_create(I18N_UIDNA_DEFAULT, &uidna);
-       assert_eq(ret, I18N_ERROR_NONE);
-
        ret = i18n_uidna_label_to_ascii(uidna, NULL, -3, dest, I18N_UPRV_LENGTHOF(dest), &info, &length);
        assert_eq(ret, I18N_ERROR_INVALID_PARAMETER);
 
@@ -104,14 +103,11 @@ int utc_capi_base_utils_i18n_uidna_label_to_ascii_n(void)
  */
 int utc_capi_base_utils_i18n_uidna_label_to_unicode_p(void)
 {
-    static const i18n_uchar fA_sharps16[] = { 0x66, 0x41, 0xdf, 0 };
+       static const i18n_uchar fA_sharps16[] = {0x66, 0x41, 0xdf, 0};
        i18n_uchar dest[10];
        i18n_uidna_info_h info;
        int32_t length;
 
-       ret = i18n_uidna_create(I18N_UIDNA_DEFAULT, &uidna);
-       assert_eq(ret, I18N_ERROR_NONE);
-
        ret = i18n_uidna_label_to_unicode(uidna, fA_sharps16, i18n_ustring_get_length(fA_sharps16), dest, I18N_UPRV_LENGTHOF(dest), &info, &length);
        assert_eq(ret, I18N_ERROR_NONE);
        assert_eq(length, 4);
@@ -126,14 +122,11 @@ int utc_capi_base_utils_i18n_uidna_label_to_unicode_p(void)
  */
 int utc_capi_base_utils_i18n_uidna_label_to_unicode_n(void)
 {
-    static const i18n_uchar fA_sharps16[] = { 0x66, 0x41, 0xdf, 0 };
+       static const i18n_uchar fA_sharps16[] = {0x66, 0x41, 0xdf, 0};
        i18n_uchar dest[10];
        i18n_uidna_info_h info;
        int32_t length;
 
-       ret = i18n_uidna_create(I18N_UIDNA_DEFAULT, &uidna);
-       assert_eq(ret, I18N_ERROR_NONE);
-
        ret = i18n_uidna_label_to_unicode(uidna, NULL, -3, dest, I18N_UPRV_LENGTHOF(dest), &info, &length);
        assert_eq(ret, I18N_ERROR_INVALID_PARAMETER);
 
@@ -156,15 +149,12 @@ int utc_capi_base_utils_i18n_uidna_label_to_unicode_n(void)
  */
 int utc_capi_base_utils_i18n_uidna_name_to_ascii_p(void)
 {
-    static const i18n_uchar fA_sharps16[] = { 0x66, 0x41, 0xdf, 0 };
+       static const i18n_uchar fA_sharps16[] = {0x66, 0x41, 0xdf, 0};
 
        i18n_uchar dest[10];
        i18n_uidna_info_h info;
        int32_t length;
 
-       ret = i18n_uidna_create(I18N_UIDNA_DEFAULT, &uidna);
-       assert_eq(ret, I18N_ERROR_NONE);
-
        ret = i18n_uidna_name_to_ascii(uidna, fA_sharps16, i18n_ustring_get_length(fA_sharps16), dest, I18N_UPRV_LENGTHOF(dest), &info, &length);
        assert_eq(ret, I18N_ERROR_NONE);
        assert_eq(length, 4);
@@ -179,14 +169,11 @@ int utc_capi_base_utils_i18n_uidna_name_to_ascii_p(void)
  */
 int utc_capi_base_utils_i18n_uidna_name_to_ascii_n(void)
 {
-    static const i18n_uchar fA_sharps16[] = { 0x66, 0x41, 0xdf, 0 };
+       static const i18n_uchar fA_sharps16[] = {0x66, 0x41, 0xdf, 0};
        i18n_uchar dest[10];
        i18n_uidna_info_h info;
        int32_t length;
 
-       ret = i18n_uidna_create(I18N_UIDNA_DEFAULT, &uidna);
-       assert_eq(ret, I18N_ERROR_NONE);
-
        ret = i18n_uidna_name_to_ascii(uidna, NULL, -3, dest, I18N_UPRV_LENGTHOF(dest), &info, &length);
        assert_eq(ret, I18N_ERROR_INVALID_PARAMETER);
 
@@ -209,14 +196,11 @@ int utc_capi_base_utils_i18n_uidna_name_to_ascii_n(void)
  */
 int utc_capi_base_utils_i18n_uidna_name_to_unicode_p(void)
 {
-    static const i18n_uchar fA_sharps16[] = { 0x66, 0x41, 0xdf, 0 };
+       static const i18n_uchar fA_sharps16[] = {0x66, 0x41, 0xdf, 0};
        i18n_uchar dest[10];
        i18n_uidna_info_h info;
        int32_t length;
 
-       ret = i18n_uidna_create(I18N_UIDNA_DEFAULT, &uidna);
-       assert_eq(ret, I18N_ERROR_NONE);
-
        ret = i18n_uidna_name_to_unicode(uidna, fA_sharps16, -1, dest, I18N_UPRV_LENGTHOF(dest), &info, &length);
        assert_eq(ret, I18N_ERROR_NONE);
        assert_eq(length, 4);
@@ -231,14 +215,11 @@ int utc_capi_base_utils_i18n_uidna_name_to_unicode_p(void)
  */
 int utc_capi_base_utils_i18n_uidna_name_to_unicode_n(void)
 {
-    static const i18n_uchar fA_sharps16[] = { 0x66, 0x41, 0xdf, 0 };
+       static const i18n_uchar fA_sharps16[] = {0x66, 0x41, 0xdf, 0};
        i18n_uchar dest[10];
        i18n_uidna_info_h info;
        int32_t length;
 
-       ret = i18n_uidna_create(I18N_UIDNA_DEFAULT, &uidna);
-       assert_eq(ret, I18N_ERROR_NONE);
-
        ret = i18n_uidna_name_to_unicode(uidna, NULL, -3, dest, I18N_UPRV_LENGTHOF(dest), &info, &length);
        assert_eq(ret, I18N_ERROR_INVALID_PARAMETER);
 
@@ -261,14 +242,11 @@ int utc_capi_base_utils_i18n_uidna_name_to_unicode_n(void)
  */
 int utc_capi_base_utils_i18n_uidna_label_to_ascii_UTF8_p(void)
 {
-    static const char fA_sharps8[] = { 0x66, 0x41, (char)0xc3, (char)0x9f, 0 };
+       static const char fA_sharps8[] = {0x66, 0x41, (char)0xc3, (char)0x9f, 0};
        char dest[10];
        i18n_uidna_info_h info;
        int32_t length;
 
-       ret = i18n_uidna_create(I18N_UIDNA_DEFAULT, &uidna);
-       assert_eq(ret, I18N_ERROR_NONE);
-
        ret = i18n_uidna_label_to_ascii_UTF8(uidna, fA_sharps8, -1, dest, I18N_UPRV_LENGTHOF(dest), &info, &length);
        assert_eq(ret, I18N_ERROR_NONE);
        assert_eq(length, 4);
@@ -283,14 +261,11 @@ int utc_capi_base_utils_i18n_uidna_label_to_ascii_UTF8_p(void)
  */
 int utc_capi_base_utils_i18n_uidna_label_to_ascii_UTF8_n(void)
 {
-    static const char fA_sharps8[] = { 0x66, 0x41, (char)0xc3, (char)0x9f, 0 };
+       static const char fA_sharps8[] = {0x66, 0x41, (char)0xc3, (char)0x9f, 0};
        char dest[10];
        i18n_uidna_info_h info;
        int32_t length;
 
-       ret = i18n_uidna_create(I18N_UIDNA_DEFAULT, &uidna);
-       assert_eq(ret, I18N_ERROR_NONE);
-
        ret = i18n_uidna_label_to_ascii_UTF8(uidna, NULL, -3, dest, I18N_UPRV_LENGTHOF(dest), &info, &length);
        assert_eq(ret, I18N_ERROR_INVALID_PARAMETER);
 
@@ -313,14 +288,11 @@ int utc_capi_base_utils_i18n_uidna_label_to_ascii_UTF8_n(void)
  */
 int utc_capi_base_utils_i18n_uidna_label_to_unicode_UTF8_p(void)
 {
-    static const char fA_sharps8[] = { 0x66, 0x41, (char)0xc3, (char)0x9f, 0 };
+       static const char fA_sharps8[] = {0x66, 0x41, (char)0xc3, (char)0x9f, 0};
        char dest[10];
        i18n_uidna_info_h info;
        int32_t length;
 
-       ret = i18n_uidna_create(I18N_UIDNA_DEFAULT, &uidna);
-       assert_eq(ret, I18N_ERROR_NONE);
-
        ret = i18n_uidna_label_to_unicode_UTF8(uidna, fA_sharps8, (int32_t)strlen(fA_sharps8), dest, I18N_UPRV_LENGTHOF(dest), &info, &length);
        assert_eq(ret, I18N_ERROR_NONE);
        assert_eq(length, 4);
@@ -335,14 +307,11 @@ int utc_capi_base_utils_i18n_uidna_label_to_unicode_UTF8_p(void)
  */
 int utc_capi_base_utils_i18n_uidna_label_to_unicode_UTF8_n(void)
 {
-    static const char fA_sharps8[] = { 0x66, 0x41, (char)0xc3, (char)0x9f, 0 };
+       static const char fA_sharps8[] = {0x66, 0x41, (char)0xc3, (char)0x9f, 0};
        char dest[10];
        i18n_uidna_info_h info;
        int32_t length;
 
-       ret = i18n_uidna_create(I18N_UIDNA_DEFAULT, &uidna);
-       assert_eq(ret, I18N_ERROR_NONE);
-
        ret = i18n_uidna_label_to_unicode_UTF8(uidna, NULL, -3, dest, I18N_UPRV_LENGTHOF(dest), &info, &length);
        assert_eq(ret, I18N_ERROR_INVALID_PARAMETER);
 
@@ -365,14 +334,11 @@ int utc_capi_base_utils_i18n_uidna_label_to_unicode_UTF8_n(void)
  */
 int utc_capi_base_utils_i18n_uidna_name_to_ascii_UTF8_p(void)
 {
-    static const char fA_sharps8[] = { 0x66, 0x41, (char)0xc3, (char)0x9f, 0 };
+       static const char fA_sharps8[] = {0x66, 0x41, (char)0xc3, (char)0x9f, 0};
        char dest[10];
        i18n_uidna_info_h info;
        int32_t length;
 
-       ret = i18n_uidna_create(I18N_UIDNA_DEFAULT, &uidna);
-       assert_eq(ret, I18N_ERROR_NONE);
-
        ret = i18n_uidna_name_to_ascii_UTF8(uidna, fA_sharps8, (int32_t)strlen(fA_sharps8), dest, I18N_UPRV_LENGTHOF(dest), &info, &length);
        assert_eq(ret, I18N_ERROR_NONE);
        assert_eq(length, 4);
@@ -387,14 +353,11 @@ int utc_capi_base_utils_i18n_uidna_name_to_ascii_UTF8_p(void)
  */
 int utc_capi_base_utils_i18n_uidna_name_to_ascii_UTF8_n(void)
 {
-    static const char fA_sharps8[] = { 0x66, 0x41, (char)0xc3, (char)0x9f, 0 };
+       static const char fA_sharps8[] = {0x66, 0x41, (char)0xc3, (char)0x9f, 0};
        char dest[10];
        i18n_uidna_info_h info;
        int32_t length;
 
-       ret = i18n_uidna_create(I18N_UIDNA_DEFAULT, &uidna);
-       assert_eq(ret, I18N_ERROR_NONE);
-
        ret = i18n_uidna_name_to_ascii_UTF8(uidna, NULL, -3, dest, I18N_UPRV_LENGTHOF(dest), &info, &length);
        assert_eq(ret, I18N_ERROR_INVALID_PARAMETER);
 
@@ -417,14 +380,11 @@ int utc_capi_base_utils_i18n_uidna_name_to_ascii_UTF8_n(void)
  */
 int utc_capi_base_utils_i18n_uidna_name_to_unicode_UTF8_p(void)
 {
-    static const char fA_sharps8[] = { 0x66, 0x41, (char)0xc3, (char)0x9f, 0 };
+       static const char fA_sharps8[] = {0x66, 0x41, (char)0xc3, (char)0x9f, 0};
        char dest[10];
        i18n_uidna_info_h info;
        int32_t length;
 
-       ret = i18n_uidna_create(I18N_UIDNA_DEFAULT, &uidna);
-       assert_eq(ret, I18N_ERROR_NONE);
-
        ret = i18n_uidna_name_to_unicode_UTF8(uidna, fA_sharps8, -1, dest, I18N_UPRV_LENGTHOF(dest), &info, &length);
        assert_eq(ret, I18N_ERROR_NONE);
        assert_eq(length, 4);
@@ -439,14 +399,11 @@ int utc_capi_base_utils_i18n_uidna_name_to_unicode_UTF8_p(void)
  */
 int utc_capi_base_utils_i18n_uidna_name_to_unicode_UTF8_n(void)
 {
-    static const char fA_sharps8[] = { 0x66, 0x41, (char)0xc3, (char)0x9f, 0 };
+       static const char fA_sharps8[] = {0x66, 0x41, (char)0xc3, (char)0x9f, 0};
        char dest[10];
        i18n_uidna_info_h info;
        int32_t length;
 
-       ret = i18n_uidna_create(I18N_UIDNA_DEFAULT, &uidna);
-       assert_eq(ret, I18N_ERROR_NONE);
-
        ret = i18n_uidna_name_to_unicode_UTF8(uidna, NULL, -3, dest, I18N_UPRV_LENGTHOF(dest), &info, &length);
        assert_eq(ret, I18N_ERROR_INVALID_PARAMETER);
 
@@ -469,14 +426,11 @@ int utc_capi_base_utils_i18n_uidna_name_to_unicode_UTF8_n(void)
  */
 int utc_capi_base_utils_i18n_uidna_info_get_is_trans_different_p(void)
 {
-    static const char fA_sharps8[] = { 0x66, 0x41, (char)0xc3, (char)0x9f, 0 };
+       static const char fA_sharps8[] = {0x66, 0x41, (char)0xc3, (char)0x9f, 0};
        char dest[10];
        i18n_uidna_info_h info;
        int32_t length;
 
-       ret = i18n_uidna_create(I18N_UIDNA_DEFAULT, &uidna);
-       assert_eq(ret, I18N_ERROR_NONE);
-
        ret = i18n_uidna_name_to_unicode_UTF8(uidna, fA_sharps8, -1, dest, I18N_UPRV_LENGTHOF(dest), &info, &length);
        assert_eq(ret, I18N_ERROR_NONE);
 
@@ -495,14 +449,11 @@ int utc_capi_base_utils_i18n_uidna_info_get_is_trans_different_p(void)
  */
 int utc_capi_base_utils_i18n_uidna_info_get_is_trans_different_n(void)
 {
-    static const char fA_sharps8[] = { 0x66, 0x41, (char)0xc3, (char)0x9f, 0 };
+       static const char fA_sharps8[] = {0x66, 0x41, (char)0xc3, (char)0x9f, 0};
        char dest[10];
        i18n_uidna_info_h info;
        int32_t length;
 
-       ret = i18n_uidna_create(I18N_UIDNA_DEFAULT, &uidna);
-       assert_eq(ret, I18N_ERROR_NONE);
-
        ret = i18n_uidna_name_to_unicode_UTF8(uidna, fA_sharps8, -1, dest, I18N_UPRV_LENGTHOF(dest), &info, &length);
        assert_eq(ret, I18N_ERROR_NONE);
 
@@ -523,14 +474,11 @@ int utc_capi_base_utils_i18n_uidna_info_get_is_trans_different_n(void)
  */
 int utc_capi_base_utils_i18n_uidna_info_get_errors_p(void)
 {
-    static const char fA_sharps8[] = { 0x66, 0x41, (char)0xc3, (char)0x9f, 0 };
+       static const char fA_sharps8[] = {0x66, 0x41, (char)0xc3, (char)0x9f, 0};
        char dest[10];
        i18n_uidna_info_h info;
        int32_t length;
 
-       ret = i18n_uidna_create(I18N_UIDNA_DEFAULT, &uidna);
-       assert_eq(ret, I18N_ERROR_NONE);
-
        ret = i18n_uidna_name_to_unicode_UTF8(uidna, fA_sharps8, -1, dest, I18N_UPRV_LENGTHOF(dest), &info, &length);
        assert_eq(ret, I18N_ERROR_NONE);
 
@@ -548,14 +496,11 @@ int utc_capi_base_utils_i18n_uidna_info_get_errors_p(void)
  */
 int utc_capi_base_utils_i18n_uidna_info_get_errors_n(void)
 {
-    static const char fA_sharps8[] = { 0x66, 0x41, (char)0xc3, (char)0x9f, 0 };
+       static const char fA_sharps8[] = {0x66, 0x41, (char)0xc3, (char)0x9f, 0};
        char dest[10];
        i18n_uidna_info_h info;
        int32_t length;
 
-       ret = i18n_uidna_create(I18N_UIDNA_DEFAULT, &uidna);
-       assert_eq(ret, I18N_ERROR_NONE);
-
        ret = i18n_uidna_name_to_unicode_UTF8(uidna, fA_sharps8, -1, dest, I18N_UPRV_LENGTHOF(dest), &info, &length);
        assert_eq(ret, I18N_ERROR_NONE);
 
@@ -576,14 +521,11 @@ int utc_capi_base_utils_i18n_uidna_info_get_errors_n(void)
  */
 int utc_capi_base_utils_i18n_uidna_info_destroy_p(void)
 {
-    static const char fA_sharps8[] = { 0x66, 0x41, (char)0xc3, (char)0x9f, 0 };
+       static const char fA_sharps8[] = {0x66, 0x41, (char)0xc3, (char)0x9f, 0};
        char dest[10];
        i18n_uidna_info_h info;
        int32_t length;
 
-       ret = i18n_uidna_create(I18N_UIDNA_DEFAULT, &uidna);
-       assert_eq(ret, I18N_ERROR_NONE);
-
        ret = i18n_uidna_name_to_unicode_UTF8(uidna, fA_sharps8, -1, dest, I18N_UPRV_LENGTHOF(dest), &info, &length);
        assert_eq(ret, I18N_ERROR_NONE);
 
@@ -605,4 +547,3 @@ int utc_capi_base_utils_i18n_uidna_info_destroy_n(void)
 
        return 0;
 }
-