From 9708eb8748647fb5274c6e411448dcf1a4f4e246 Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Tue, 18 Aug 2020 08:56:53 +0900 Subject: [PATCH] [Testsuite] replace constant number with ARRAY_SIZE() Change-Id: I86615bd708f1a26a7b5463b0db06b2ee6239ebbe Signed-off-by: Tae-Young Chung --- test/testsuites/barcode/barcode_test_suite.c | 62 ++++++++++++++-------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/test/testsuites/barcode/barcode_test_suite.c b/test/testsuites/barcode/barcode_test_suite.c index 431ad7e..e46f245 100644 --- a/test/testsuites/barcode/barcode_test_suite.c +++ b/test/testsuites/barcode/barcode_test_suite.c @@ -39,6 +39,8 @@ #define MININTERVAL 0 #define MAXINTERVAL 9 +#define ARRAY_SIZE(x) (sizeof((x)) / sizeof((x)[0])) + typedef struct { mv_barcode_type_e type; mv_barcode_qr_ecc_e ecc; @@ -926,14 +928,14 @@ mv_barcode_type_e select_type(void) { mv_barcode_type_e selected_type = MV_BARCODE_UNKNOWN; int sel_opt = 0; - const int options[14] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; - const char *names[14] = { "qr", "upca", "upce", "ean8", "ean13", "code39", "code128", "interleave25", + const int options[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; + const char *names[] = { "qr", "upca", "upce", "ean8", "ean13", "code39", "code128", "interleave25", "ean2", "ean5", "code93", "codabar", "databar", "databarExpand" }; MEDIA_VISION_FUNCTION_ENTER(); while (sel_opt == 0) { - sel_opt = show_menu("Select barcode type : ", options, names, 14); + sel_opt = show_menu("Select barcode type : ", options, names, ARRAY_SIZE(options)); switch (sel_opt) { case 1: @@ -993,13 +995,13 @@ mv_barcode_qr_mode_e select_mode(void) { mv_barcode_qr_mode_e selected_mode = MV_BARCODE_QR_MODE_UNAVAILABLE; int sel_opt = 0; - const int options[4] = { 1, 2, 3, 4 }; - const char *names[4] = { "numeric", "alphanumeric", "byte", "utf8" }; + const int options[] = { 1, 2, 3, 4 }; + const char *names[] = { "numeric", "alphanumeric", "byte", "utf8" }; MEDIA_VISION_FUNCTION_ENTER(); while (sel_opt == 0) { - sel_opt = show_menu("Select encoding mode : ", options, names, 4); + sel_opt = show_menu("Select encoding mode : ", options, names, ARRAY_SIZE(options)); switch (sel_opt) { case 1: selected_mode = MV_BARCODE_QR_MODE_NUMERIC; @@ -1028,13 +1030,13 @@ mv_barcode_qr_ecc_e select_ecc(void) { mv_barcode_qr_ecc_e selected_ecc = MV_BARCODE_QR_ECC_UNAVAILABLE; int sel_opt = 0; - const int options[4] = { 1, 2, 3, 4 }; - const char *names[4] = { "low", "medium", "quartile", "high" }; + const int options[] = { 1, 2, 3, 4 }; + const char *names[] = { "low", "medium", "quartile", "high" }; MEDIA_VISION_FUNCTION_ENTER(); while (sel_opt == 0) { - sel_opt = show_menu("Select ECC level : ", options, names, 4); + sel_opt = show_menu("Select ECC level : ", options, names, ARRAY_SIZE(options)); switch (sel_opt) { case 1: selected_ecc = MV_BARCODE_QR_ECC_LOW; @@ -1065,11 +1067,11 @@ int select_attribute_text(void) int sel_opt = 0; int selected_attr = 0; - const int options[2] = { 1, 2 }; - const char *names[2] = { "Invisible", "Visible" }; + const int options[] = { 1, 2 }; + const char *names[] = { "Invisible", "Visible" }; while (sel_opt == 0) { - sel_opt = show_menu("Select attribute text", options, names, 2); + sel_opt = show_menu("Select attribute text", options, names, ARRAY_SIZE(options)); switch (sel_opt) { case 1: selected_attr = 0; @@ -1094,9 +1096,9 @@ int select_version(void) int sel_opt = 0; while (sel_opt == 0) { - const int options[2] = {1, 40}; - const char *names[2] = { "1..", "..40" }; - sel_opt = show_menu("Select QR version : ", options, names, 2); + const int options[] = {1, 40}; + const char *names[] = { "1..", "..40" }; + sel_opt = show_menu("Select QR version : ", options, names, ARRAY_SIZE(options)); if (sel_opt < 1 || sel_opt > 40) sel_opt = 0; } @@ -1110,13 +1112,13 @@ generation_fcn_e select_gen_function(void) { generation_fcn_e ret_fcn_type = MV_TS_GENERATE_TO_IMAGE_FCN; int sel_opt = 0; - const int options[2] = { 1, 2 }; - const char *names[2] = { "Generate to file", "Generate to source" }; + const int options[] = { 1, 2 }; + const char *names[] = { "Generate to file", "Generate to source" }; MEDIA_VISION_FUNCTION_ENTER(); while (sel_opt == 0) { - sel_opt = show_menu("Select API function : ", options, names, 2); + sel_opt = show_menu("Select API function : ", options, names, ARRAY_SIZE(options)); switch (sel_opt) { case 1: ret_fcn_type = MV_TS_GENERATE_TO_IMAGE_FCN; @@ -1139,13 +1141,13 @@ mv_barcode_image_format_e select_file_format(void) { mv_barcode_image_format_e image_format = MV_BARCODE_IMAGE_FORMAT_JPG; int sel_opt = 0; - const int options[3] = { 1, 2, 3 }; - const char *names[3] = { "BMP", "JPG", "PNG" }; + const int options[] = { 1, 2, 3 }; + const char *names[] = { "BMP", "JPG", "PNG" }; MEDIA_VISION_FUNCTION_ENTER(); while (sel_opt == 0) { - sel_opt = show_menu("Select file format : ", options, names, 3); + sel_opt = show_menu("Select file format : ", options, names, ARRAY_SIZE(options)); switch (sel_opt) { case 1: image_format = MV_BARCODE_IMAGE_FORMAT_BMP; @@ -1207,7 +1209,7 @@ int perform_detect() LOGI("Barcode output image has been specified"); - const int options[11] = { MEDIA_VISION_COLORSPACE_Y800, + const int options[] = { MEDIA_VISION_COLORSPACE_Y800, MEDIA_VISION_COLORSPACE_I420, MEDIA_VISION_COLORSPACE_NV12, MEDIA_VISION_COLORSPACE_YV12, @@ -1218,12 +1220,12 @@ int perform_detect() MEDIA_VISION_COLORSPACE_RGB565, MEDIA_VISION_COLORSPACE_RGB888, MEDIA_VISION_COLORSPACE_RGBA }; - const char *names[11] = { "Y800", "I420", "NV12", "YV12", "NV21", + const char *names[] = { "Y800", "I420", "NV12", "YV12", "NV21", "YUYV", "UYVY", "422P", "RGB565", "RGB888", "RGBA" }; while (true) { - int sel_opt = show_menu("Select colorspace to test detector on : ", options, names, 11); + int sel_opt = show_menu("Select colorspace to test detector on : ", options, names, ARRAY_SIZE(options)); if (sel_opt < MEDIA_VISION_COLORSPACE_Y800 || sel_opt > MEDIA_VISION_COLORSPACE_RGBA) continue; @@ -1390,8 +1392,8 @@ int main(int argc, char *argv[]) int err = MEDIA_VISION_ERROR_NONE; int sel_opt = 0; - const int options[2] = { 1, 2 }; - const char *names[2] = { "Generate", "Detect" }; + const int options[] = { 1, 2 }; + const char *names[] = { "Generate", "Detect" }; struct arguments arguments; arguments.mode = 0; @@ -1416,7 +1418,7 @@ int main(int argc, char *argv[]) initscr(); while (sel_opt == 0) { - sel_opt = show_menu("Select action : ", options, names, 2); + sel_opt = show_menu("Select action : ", options, names, ARRAY_SIZE(options)); switch (sel_opt) { case 1: LOGI("Start the barcode generation flow"); @@ -1437,11 +1439,11 @@ int main(int argc, char *argv[]) mvprintw(current_y++, MINX, "ERROR : Action is finished with error code : %i", err); sel_opt = 0; - const int options_last[2] = { 1, 2 }; - const char *names_last[2] = { "YES", "NO" }; + const int options_last[] = { 1, 2 }; + const char *names_last[] = { "YES", "NO" }; while (sel_opt == 0) { - sel_opt = show_menu("Perform another action?", options_last, names_last, 2); + sel_opt = show_menu("Perform another action?", options_last, names_last, ARRAY_SIZE(options)); switch (sel_opt) { case 1: do_another = 1; -- 2.7.4