From 01713e6700253930a15ba8fd0ca6185425fbb16c Mon Sep 17 00:00:00 2001 From: Dewal Agarwal Date: Thu, 27 Feb 2020 15:07:01 +0530 Subject: [PATCH] Correct format specifiers in test app Change-Id: Ie150ee419dc7fd8f4e6a201d2753101e43895005 Signed-off-by: Dewal Agarwal --- test/test_cli_app/src/bmt_usage.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/test/test_cli_app/src/bmt_usage.c b/test/test_cli_app/src/bmt_usage.c index b20c9c7..6861a5d 100644 --- a/test/test_cli_app/src/bmt_usage.c +++ b/test/test_cli_app/src/bmt_usage.c @@ -46,22 +46,24 @@ static gboolean bmt_testapp_get_total_usage_by_app_id() * battery_usage - battery usage consumption for the app-id */ - char app_name[56]; + char app_name[56] = {0, }; int duration = -1; int error_code = BATTERY_MONITOR_ERROR_NONE; int battery_usage = -1; testapp_print("\n Input AppID using Look Up table:\n"); - if (0 >= scanf("%55[^\n]", app_name)) { + if (0 >= scanf("%55s", app_name)) { testapp_print("Invalid input "); return FALSE; } + testapp_print("\n AppID: %s \n", app_name); testapp_print("\n Input Duration using Look Up table:\n"); if (0 >= scanf("%d", &duration)) { testapp_print("Invalid input "); return FALSE; } + testapp_print("\n Duration: %d \n", duration); error_code = battery_monitor_get_total_usage_by_app_id(app_name, duration, &battery_usage); if (error_code == BATTERY_MONITOR_ERROR_NONE) @@ -89,12 +91,14 @@ static gboolean bmt_testapp_get_total_usage_by_resource_id() testapp_print("Invalid input "); return FALSE; } + testapp_print("\n ResourceID: %d \n", resource_id); testapp_print("\n Input Duration using Look Up table:\n"); if (0 >= scanf("%d", &duration)) { testapp_print("Invalid input "); return FALSE; } + testapp_print("\n Duration: %d \n", duration); error_code = battery_monitor_get_total_usage_by_resource_id(resource_id, duration, &battery_usage); if (error_code == BATTERY_MONITOR_ERROR_NONE) @@ -113,22 +117,24 @@ static gboolean bmt_testapp_get_total_usage_by_app_id_for_all_resource_id() */ int duration = -1; - char app_name[56]; + char app_name[56] = {0, }; int error_code = BATTERY_MONITOR_ERROR_NONE; battery_monitor_h data_handle = NULL; testapp_print("\n Input AppID using Look Up table:\n"); - if (0 >= scanf("%55[^\n]", app_name)) { + if (0 >= scanf("%55s", app_name)) { testapp_print("Invalid input "); return FALSE; } + testapp_print("\n AppID: %s \n", app_name); testapp_print("\n Input Duration using Look Up table:\n"); if (0 >= scanf("%d", &duration)) { testapp_print("Invalid input "); return FALSE; } + testapp_print("\n Duration: %d \n", duration); error_code = battery_monitor_get_usage_by_app_id_for_all_resource_id(app_name, duration, &data_handle); @@ -195,28 +201,31 @@ static gboolean bmt_testapp_get_total_usage_by_app_id_for_resource_id() */ int duration = -1; - char app_name[56]; + char app_name[56] = {0, }; int battery_usage = -1; int resource_id = -1; int error_code = BATTERY_MONITOR_ERROR_NONE; testapp_print("\n Input AppID using Look Up table:\n"); - if (0 >= scanf("%55[^\n]", app_name)) { - testapp_print("Invalid input "); + if (0 >= scanf("%55s", app_name)) { + testapp_print("Invalid input"); return FALSE; } + testapp_print("\n AppID: %s \n", app_name); testapp_print("\n Input Duration using Look Up table:\n"); if (0 >= scanf("%d", &duration)) { testapp_print("Invalid input "); return FALSE; } + testapp_print("\n Duration: %d \n", duration); testapp_print("\n Input Resource Id using Look Up Table: \n"); if (0 >= scanf("%d", &resource_id)) { testapp_print("Invalid input "); return FALSE; } + testapp_print("\n ResourceID: %d \n", resource_id); error_code = battery_monitor_get_usage_by_app_id_for_resource_id(app_name, resource_id, duration, &battery_usage); -- 2.34.1