[ITC][battery-monitor][ACR-1533][Changed TC Names for APIs] 14/231014/1
authorMOHIT MIGLANI <mohit.m@samsung.com>
Thu, 16 Apr 2020 12:13:16 +0000 (17:43 +0530)
committershobhit verma <shobhit.v@samsung.com>
Thu, 16 Apr 2020 15:19:01 +0000 (15:19 +0000)
Change-Id: I24e15dbd106ff26ffd5929847c2349ab011fcf47
Signed-off-by: MOHIT MIGLANI <mohit.m@samsung.com>
(cherry picked from commit 6b4a9d61dfde58a94029c9b56a84a6f26d29035b)

src/itc/battery-monitor/ITs-battery-monitor-common.c
src/itc/battery-monitor/ITs-battery-monitor-common.h
src/itc/battery-monitor/ITs-battery-monitor.c
src/itc/battery-monitor/tct-battery-monitor-native_mobile.h
src/itc/battery-monitor/tct-battery-monitor-native_tizeniot.h
src/itc/battery-monitor/tct-battery-monitor-native_wearable.h

index 2174f0a838dd38ace881a1e716fcbb0fb3b62b03..4328a16a9cc7ee9de0f456efac4c7aca22ed435c 100755 (executable)
@@ -46,5 +46,32 @@ char* BatteryMonitorGetError(int nRet)
 
        return szErrorVal;
 }
+/**
+* @function             BatteryMonitorGetTime
+* @description          returns start and end time
+* @parameter            start and end pointers
+* @return               integer value 0 on success and 1 on failure
+*/
+
+int BatteryMonitorGetTime(time_t *start, time_t *end)
+{
+        time_t ret_time;
+        long int crr_time = 0;
+        int tmin = 604800;
+        time_t start_time;
+        time_t end_time;
+        time(&ret_time);
+        if (ret_time == -1) {
+                return 1;
+        }
+        crr_time = ret_time;
+        start_time = 0;
+        end_time = 0;
+        start_time = (crr_time - tmin/2);
+        end_time = (crr_time - 1);
+        *start = start_time;
+        *end = end_time;
+        return 0;
+}
 
 /** @} */
index a051f2e2de2b690d3564a51fdc8a8b486ca7ccc4..a3d7c9b89a8a6ef658bec65617a4972c0d0c54e4 100755 (executable)
@@ -26,6 +26,7 @@
 #include <system_info.h>
 #include "battery_monitor.h"
 #include <app.h>
+#include <time.h>
 
 /** @addtogroup itc-battery-monitor
 *  @ingroup itc
@@ -43,6 +44,6 @@
 bool g_bBatteryFeatureNotSupported;
 
 char* BatteryMonitorGetError(int nRet);
-
+int BatteryMonitorGetTime(time_t *start, time_t *end);
 /** @} */
 #endif  //_ITS_BATTERY_MONITOR_COMMON_H_
index e67d8d52af5f5244c560709c65f947c6c36c0c00..d1b995136f5f36487531b13eadbb04e2ff9b1bba 100755 (executable)
@@ -66,7 +66,7 @@ void ITs_battery_monitor_cleanup(void)
 //& type : auto
 //& purpose: Creates and Destroy a handle to the Battery Consumption for getting resource based usage.
 /**
-* @testcase                    ITc_battery_monitor_create_destroy_p
+* @testcase                    ITc_battery_monitor_battery_usage_data_destroy_p
 * @since_tizen                 5.5
 * @author                      SRID(j.abhishek)
 * @reviewer                    SRID(shobhit.v)
@@ -74,32 +74,39 @@ void ITs_battery_monitor_cleanup(void)
 * @description                 Creates and Destroy a handle to the Battery Consumption for getting resource based usage.
 * @scenario                    Create battery monitor handle and destroy created handle\n
 *                              and check for Pass/Fail.
-* @apicovered                  battery_monitor_create, battery_monitor_destroy
-* @passcase                    battery_monitor_create, battery_monitor_destroy are successful and return correct value
-* @failcase                    battery_monitor_create, battery_monitor_destroy gets failed or return null value
+* @apicovered                  battery_monitor_create, battery_monitor_battery_usage_data_destroy
+* @passcase                    battery_monitor_create, battery_monitor_battery_usage_data_destroy are successful and return correct value
+* @failcase                    battery_monitor_create, battery_monitor_battery_usage_data_destroy gets failed or return null value
 * @precondition                        N/A
 * @postcondition               N/A
 */
-int ITc_battery_monitor_create_destroy_p(void)
+int ITc_battery_monitor_battery_usage_data_destroy_p(void)
 {
        START_TEST_NO_CHECK;
 
        int nRet = -1;
-       battery_monitor_h hBatteryMonitor = NULL;
-
-       //Targer API
-       nRet = battery_monitor_create(&hBatteryMonitor);
-       if ( g_bBatteryFeatureNotSupported )
-       {
-               PRINT_RESULT(BATTERY_MONITOR_ERROR_NOT_SUPPORTED, nRet, "battery_monitor_create", BatteryMonitorGetError(nRet));
-               return 0;
-       }
-       PRINT_RESULT(BATTERY_MONITOR_ERROR_NONE, nRet, "battery_monitor_create", BatteryMonitorGetError(nRet));
-       CHECK_HANDLE(hBatteryMonitor, "battery_monitor_create");
-
-       //Targer API
-       nRet = battery_monitor_destroy(hBatteryMonitor);
-       PRINT_RESULT(BATTERY_MONITOR_ERROR_NONE, nRet, "battery_monitor_destroy", BatteryMonitorGetError(nRet));
+        battery_usage_data_h hBatteryMonitorAPP = NULL;
+        time_t start_time;
+        time_t end_time;
+        nRet = BatteryMonitorGetTime(&start_time, &end_time);
+        if(nRet == 1)
+        {
+                FPRINTF("[Line : %d][%s] error returned = failed precondition, time\\n", __LINE__, API_NAMESPACE);
+                return 1;
+        }
+        nRet = battery_monitor_get_power_usage_by_app_for_all_resources(TEST_APP_ID, start_time, end_time, &hBatteryMonitorAPP);
+        if ( g_bBatteryFeatureNotSupported )
+        {
+                PRINT_RESULT(BATTERY_MONITOR_ERROR_NOT_SUPPORTED, nRet, "battery_monitor_get_power_usage_by_app_for_all_resources", BatteryMonitorGetError(nRet));
+                return 0;
+        }
+
+
+       PRINT_RESULT(BATTERY_MONITOR_ERROR_NONE, nRet, "battery_monitor_get_power_usage_by_app_for_all_resources", BatteryMonitorGetError(nRet));
+       CHECK_HANDLE(hBatteryMonitorAPP, "battery_monitor_get_power_usage_by_app_for_all_resources");
+
+       nRet = battery_monitor_battery_usage_data_destroy(hBatteryMonitorAPP);
+       PRINT_RESULT(BATTERY_MONITOR_ERROR_NONE, nRet, "battery_monitor_battery_usage_data_destroy", BatteryMonitorGetError(nRet));
 
        return 0;
 }
@@ -107,7 +114,7 @@ int ITc_battery_monitor_create_destroy_p(void)
 //& type : auto
 //& purpose: Gets the battery-percent for specific resource from available data.
 /**
-* @testcase                    ITc_battery_monitor_get_usage_for_resource_id_p
+* @testcase                     ITc_battery_monitor_usage_data_get_power_usage_per_resource_p
 * @since_tizen                 5.5
 * @author                      SRID(j.abhishek)
 * @reviewer                    SRID(shobhit.v)
@@ -115,19 +122,28 @@ int ITc_battery_monitor_create_destroy_p(void)
 * @description                 Gets the battery-percent for specific resource from available data.
 * @scenario                    Create battery monitor handle\n
 *                              get battery percent using this handle and check for Pass/Fail.
-* @apicovered                  battery_monitor_create, battery_monitor_get_usage_for_resource_id, battery_monitor_destroy
-* @passcase                    battery_monitor_create, battery_monitor_get_usage_for_resource_id are successful and return correct value
-* @failcase                    battery_monitor_create, battery_monitor_get_usage_for_resource_id gets failed or return null value
+* @apicovered                  battery_monitor_create, battery_monitor_usage_data_get_power_usage_per_resource, battery_monitor_battery_usage_data_destroy
+* @passcase                    battery_monitor_create, battery_monitor_usage_data_get_power_usage_per_resource are successful and return correct value
+* @failcase                    battery_monitor_create, battery_monitor_usage_data_get_power_usage_per_resource gets failed or return null value
 * @precondition                        N/A
 * @postcondition               Destroy battery monitor handle.
 */
-int ITc_battery_monitor_get_usage_for_resource_id_p(void)
+int ITc_battery_monitor_usage_data_get_power_usage_per_resource_p(void)
 {
        START_TEST_NO_CHECK;
 
        int nRet = -1;
-       int nBatteryUsage = 0;
-       battery_monitor_h hBatteryMonitor = NULL;
+       double nBatteryUsage = 0.0;
+       battery_usage_data_h hBatteryMonitorAPP = NULL;
+        time_t start_time;
+        time_t end_time;
+        nRet = BatteryMonitorGetTime(&start_time, &end_time);
+        if(nRet == 1)
+        {
+                FPRINTF("[Line : %d][%s] error returned = failed precondition, time\\n", __LINE__, API_NAMESPACE);
+                return 1;
+        }
+
 
        battery_monitor_resource_id_e eResourceID[] = {
                BATTERY_MONITOR_RESOURCE_ID_BLE,
@@ -136,64 +152,74 @@ int ITc_battery_monitor_get_usage_for_resource_id_p(void)
                BATTERY_MONITOR_RESOURCE_ID_DISPLAY,
                BATTERY_MONITOR_RESOURCE_ID_DEVICE_NETWORK,
                BATTERY_MONITOR_RESOURCE_ID_GPS_SENSOR,
-               BATTERY_MONITOR_RESOURCE_ID_HRM_SENSOR
+               BATTERY_MONITOR_RESOURCE_ID_MAX
        };
 
+        nRet = battery_monitor_get_power_usage_by_app_for_all_resources(TEST_APP_ID, start_time, end_time, &hBatteryMonitorAPP);
+        if ( g_bBatteryFeatureNotSupported )
+        {
+                PRINT_RESULT(BATTERY_MONITOR_ERROR_NOT_SUPPORTED, nRet, "battery_monitor_get_power_usage_by_app_for_all_resources", BatteryMonitorGetError(nRet));
+                return 0;
+        }
+
+        if(nRet == BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND)
+        {
+                FPRINTF("[Line : %d][%s] record is not found\\n", __LINE__, API_NAMESPACE);
+                return 0;
+        }
+        PRINT_RESULT(BATTERY_MONITOR_ERROR_NONE, nRet, "battery_monitor_get_power_usage_by_app_for_all_resources", BatteryMonitorGetError(nRet));
+        CHECK_HANDLE(hBatteryMonitorAPP, "battery_monitor_get_power_usage_by_app_for_all_resources");
        int nEnumSize = sizeof(eResourceID) / sizeof(eResourceID[0]);
        int nEnumCounter;
 
-       nRet = battery_monitor_create(&hBatteryMonitor);
-       if ( g_bBatteryFeatureNotSupported )
-       {
-               PRINT_RESULT(BATTERY_MONITOR_ERROR_NOT_SUPPORTED, nRet, "battery_monitor_create", BatteryMonitorGetError(nRet));
-               return 0;
-       }
-       PRINT_RESULT(BATTERY_MONITOR_ERROR_NONE, nRet, "battery_monitor_create", BatteryMonitorGetError(nRet));
-       CHECK_HANDLE(hBatteryMonitor, "battery_monitor_create");
-
        for(nEnumCounter = 0; nEnumCounter < nEnumSize; nEnumCounter++)
        {
                //Targer API
-               nRet = battery_monitor_get_usage_for_resource_id(hBatteryMonitor, eResourceID[nEnumCounter], &nBatteryUsage);
-               PRINT_RESULT_CLEANUP(BATTERY_MONITOR_ERROR_NONE, nRet, "battery_monitor_get_usage_for_resource_id", BatteryMonitorGetError(nRet), battery_monitor_destroy(hBatteryMonitor));
-               FPRINTF("[Line : %d][%s] battery_monitor_get_usage_for_resource_id returned battary usage[%d] for resource ID [%d] \\n", __LINE__, API_NAMESPACE, nBatteryUsage, eResourceID[nEnumCounter]);
+               nRet = battery_monitor_usage_data_get_power_usage_per_resource(hBatteryMonitorAPP, eResourceID[nEnumCounter], &nBatteryUsage);
+               PRINT_RESULT_CLEANUP(BATTERY_MONITOR_ERROR_NONE, nRet, "battery_monitor_usage_data_get_power_usage_per_resource", BatteryMonitorGetError(nRet), battery_monitor_battery_usage_data_destroy(hBatteryMonitorAPP));
+               FPRINTF("[Line : %d][%s] battery_monitor_usage_data_get_power_usage_per_resource returned battary usage[%f] for resource ID [%d] \\n", __LINE__, API_NAMESPACE, nBatteryUsage, eResourceID[nEnumCounter]);
        }
 
-       nRet = battery_monitor_destroy(hBatteryMonitor);
-       PRINT_RESULT_NORETURN(BATTERY_MONITOR_ERROR_NONE, nRet, "battery_monitor_destroy", BatteryMonitorGetError(nRet));
+        nRet = battery_monitor_battery_usage_data_destroy(hBatteryMonitorAPP);
+        PRINT_RESULT_NORETURN(BATTERY_MONITOR_ERROR_NONE, nRet, "battery_monitor_battery_usage_data_destroy", BatteryMonitorGetError(nRet));
 
        return 0;
 }
 
 //& type : auto
-//& purpose: Gets the battery_monitor_h with battery consumption by the specified application.
+//& purpose: Gets the battery_data_usage_h with battery consumption by the specified application.
 /**
-* @testcase                    ITc_battery_monitor_get_usage_by_app_id_for_all_resource_id_p
+* @testcase                    ITc_battery_monitor_get_power_usage_by_app_for_all_resources_p
 * @since_tizen                 5.5
 * @author                      SRID(j.abhishek)
 * @reviewer                    SRID(shobhit.v)
 * @type                                auto
-* @description                 Gets the battery_monitor_h with battery consumption by the specified application.
-* @scenario                    Gets the battery monitor handle and call battery_monitor_get_usage_for_resource_id\n
+* @description                 Gets the battery_data_usage_h with battery consumption by the specified application.
+* @scenario                    Gets the battery monitor handle and call battery_monitor_usage_data_get_power_usage_per_resource\n
 *                              battery consumption by the specified application and check for Pass/Fail.
-* @apicovered                  battery_monitor_get_usage_by_app_id_for_all_resource_id, battery_monitor_destroy
-* @passcase                    battery_monitor_get_usage_by_app_id_for_all_resource_id is successful and return correct value
-* @failcase                    battery_monitor_get_usage_by_app_id_for_all_resource_id gets failed or return null value
+* @apicovered                  battery_monitor_get_power_usage_by_app_for_all_resources, battery_monitor_battery_usage_data_destroy
+* @passcase                    battery_monitor_get_power_usage_by_app_for_all_resources is successful and return correct value
+* @failcase                    battery_monitor_get_power_usage_by_app_for_all_resources gets failed or return null value
 * @precondition                        N/A
 * @postcondition               Destroy gathered battery monitor handle.
 */
-int ITc_battery_monitor_get_usage_by_app_id_for_all_resource_id_p(void)
+int ITc_battery_monitor_get_power_usage_by_app_for_all_resources_p(void)
 {
        START_TEST_NO_CHECK;
 
        int nRet = -1;
-       int nBatteryUsage = 0;
-       battery_monitor_h hBatteryMonitorAPP = NULL;
+       double nBatteryUsage = 0.0;
+       battery_usage_data_h hBatteryMonitorAPP = NULL;
+        time_t start_time;
+        time_t end_time;
+        nRet = BatteryMonitorGetTime(&start_time, &end_time);
+        if(nRet == 1)
+        {
+                FPRINTF("[Line : %d][%s] error returned = failed precondition, time\\n", __LINE__, API_NAMESPACE);
+                return 1;
+        }
+
 
-       battery_monitor_duration_type_e eMonitorDuration[] = {
-               BATTERY_MONITOR_DURATION_TYPE_1DAY,
-               BATTERY_MONITOR_DURATION_TYPE_1WEEK
-       };
 
        battery_monitor_resource_id_e eResourceID[] = {
                BATTERY_MONITOR_RESOURCE_ID_BLE,
@@ -202,37 +228,38 @@ int ITc_battery_monitor_get_usage_by_app_id_for_all_resource_id_p(void)
                BATTERY_MONITOR_RESOURCE_ID_DISPLAY,
                BATTERY_MONITOR_RESOURCE_ID_DEVICE_NETWORK,
                BATTERY_MONITOR_RESOURCE_ID_GPS_SENSOR,
-               BATTERY_MONITOR_RESOURCE_ID_HRM_SENSOR
+               BATTERY_MONITOR_RESOURCE_ID_MAX
        };
 
-       int nDurationEnumSize = sizeof(eMonitorDuration) / sizeof(eMonitorDuration[0]);
-       int nDurationEnumCounter;
 
        int nIDEnumSize = sizeof(eResourceID) / sizeof(eResourceID[0]);
        int nIDEnumCounter;
 
-       for(nDurationEnumCounter = 0; nDurationEnumCounter < nDurationEnumSize; nDurationEnumCounter++)
+        //Targer API
+       nRet = battery_monitor_get_power_usage_by_app_for_all_resources(TEST_APP_ID, start_time, end_time, &hBatteryMonitorAPP);
+       if ( g_bBatteryFeatureNotSupported )
        {
-               //Targer API
-               nRet = battery_monitor_get_usage_by_app_id_for_all_resource_id(TEST_APP_ID, eMonitorDuration[nDurationEnumCounter], &hBatteryMonitorAPP);
-               if ( g_bBatteryFeatureNotSupported )
-               {
-                       PRINT_RESULT(BATTERY_MONITOR_ERROR_NOT_SUPPORTED, nRet, "battery_monitor_get_usage_by_app_id_for_all_resource_id", BatteryMonitorGetError(nRet));
-                       return 0;
-               }
-               PRINT_RESULT(BATTERY_MONITOR_ERROR_NONE, nRet, "battery_monitor_get_usage_by_app_id_for_all_resource_id", BatteryMonitorGetError(nRet));
-               CHECK_HANDLE(hBatteryMonitorAPP, "battery_monitor_get_usage_by_app_id_for_all_resource_id");
+               PRINT_RESULT(BATTERY_MONITOR_ERROR_NOT_SUPPORTED, nRet, "battery_monitor_get_power_usage_by_app_for_all_resources", BatteryMonitorGetError(nRet));
+               return 0;
+       }
+        if(nRet == BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND)
+        {
+                FPRINTF("[Line : %d][%s] record not found\\n", __LINE__, API_NAMESPACE);
+                return 0;
+        }
+       PRINT_RESULT(BATTERY_MONITOR_ERROR_NONE, nRet, "battery_monitor_get_power_usage_by_app_for_all_resources", BatteryMonitorGetError(nRet));
+       CHECK_HANDLE(hBatteryMonitorAPP, "battery_monitor_get_power_usage_by_app_for_all_resources");
 
-               for(nIDEnumCounter = 0; nIDEnumCounter < nIDEnumSize; nIDEnumCounter++)
-               {
-                       nRet = battery_monitor_get_usage_for_resource_id(hBatteryMonitorAPP, eResourceID[nIDEnumCounter], &nBatteryUsage);
-                       PRINT_RESULT_CLEANUP(BATTERY_MONITOR_ERROR_NONE, nRet, "battery_monitor_get_usage_for_resource_id", BatteryMonitorGetError(nRet), battery_monitor_destroy(hBatteryMonitorAPP));
-                       FPRINTF("[Line : %d][%s] battery_monitor_get_usage_for_resource_id returned battary usage[%d] for Monitor duration[%d] and resource ID [%d] \\n", __LINE__, API_NAMESPACE, nBatteryUsage, eMonitorDuration[nDurationEnumCounter], eResourceID[nIDEnumCounter]);
-               }
-               nRet = battery_monitor_destroy(hBatteryMonitorAPP);
-               PRINT_RESULT_NORETURN(BATTERY_MONITOR_ERROR_NONE, nRet, "battery_monitor_destroy", BatteryMonitorGetError(nRet));
-               hBatteryMonitorAPP = NULL;
+       for(nIDEnumCounter = 0; nIDEnumCounter < nIDEnumSize; nIDEnumCounter++)
+       {
+               nRet = battery_monitor_usage_data_get_power_usage_per_resource(hBatteryMonitorAPP, eResourceID[nIDEnumCounter], &nBatteryUsage);
+               PRINT_RESULT_CLEANUP(BATTERY_MONITOR_ERROR_NONE, nRet, "battery_monitor_usage_data_get_power_usage_per_resource", BatteryMonitorGetError(nRet), battery_monitor_battery_usage_data_destroy(hBatteryMonitorAPP));
+               FPRINTF("[Line : %d][%s] battery_monitor_usage_data_get_power_usage_per_resource returned battary usage[%f] for resource ID [%d] \\n", __LINE__, API_NAMESPACE, nBatteryUsage, eResourceID[nIDEnumCounter]);
        }
+       nRet = battery_monitor_battery_usage_data_destroy(hBatteryMonitorAPP);
+       PRINT_RESULT_NORETURN(BATTERY_MONITOR_ERROR_NONE, nRet, "battery_monitor_battery_usage_data_destroy", BatteryMonitorGetError(nRet));
+       hBatteryMonitorAPP = NULL;
+
 
        return 0;
 }
@@ -240,7 +267,7 @@ int ITc_battery_monitor_get_usage_by_app_id_for_all_resource_id_p(void)
 //& type : auto
 //& purpose: Gets the battery consumption for the specific resource for the given application.
 /**
-* @testcase                    ITc_battery_monitor_get_usage_by_app_id_for_resource_id_p
+* @testcase                    ITc_battery_monitor_get_power_usage_by_app_per_resource_p
 * @since_tizen                 5.5
 * @author                      SRID(j.abhishek)
 * @reviewer                    SRID(shobhit.v)
@@ -248,23 +275,27 @@ int ITc_battery_monitor_get_usage_by_app_id_for_all_resource_id_p(void)
 * @description                 Gets the battery consumption for the specific resource for the given application.
 * @scenario                    Get battery usage using different recource id for different duration\n
 *                              check for Pass/Fail.
-* @apicovered                  battery_monitor_get_usage_by_app_id_for_resource_id
-* @passcase                    battery_monitor_get_usage_by_app_id_for_resource_id is successful and return correct value
-* @failcase                    battery_monitor_get_usage_by_app_id_for_resource_id gets failed or return null value
+* @apicovered                  battery_monitor_get_power_usage_by_app_per_resource
+* @passcase                    battery_monitor_get_power_usage_by_app_per_resource is successful and return correct value
+* @failcase                    battery_monitor_get_power_usage_by_app_per_resource gets failed or return null value
 * @precondition                        N/A
 * @postcondition               N/A
 */
-int ITc_battery_monitor_get_usage_by_app_id_for_resource_id_p(void)
+int ITc_battery_monitor_get_power_usage_by_app_per_resource_p(void)
 {
        START_TEST_NO_CHECK;
 
        int nRet = -1;
-       int nBatteryUsage = 0;
+       double nBatteryUsage = 0.0;
+        time_t start_time;
+        time_t end_time;
+        nRet = BatteryMonitorGetTime(&start_time, &end_time);
+        if(nRet == 1)
+        {
+                FPRINTF("[Line : %d][%s] error returned = failed precondition, time\\n", __LINE__, API_NAMESPACE);
+                return 1;
+        }
 
-       battery_monitor_duration_type_e eMonitorDuration[] = {
-               BATTERY_MONITOR_DURATION_TYPE_1DAY,
-               BATTERY_MONITOR_DURATION_TYPE_1WEEK
-       };
 
        battery_monitor_resource_id_e eResourceID[] = {
                BATTERY_MONITOR_RESOURCE_ID_BLE,
@@ -273,29 +304,29 @@ int ITc_battery_monitor_get_usage_by_app_id_for_resource_id_p(void)
                BATTERY_MONITOR_RESOURCE_ID_DISPLAY,
                BATTERY_MONITOR_RESOURCE_ID_DEVICE_NETWORK,
                BATTERY_MONITOR_RESOURCE_ID_GPS_SENSOR,
-               BATTERY_MONITOR_RESOURCE_ID_HRM_SENSOR
+               BATTERY_MONITOR_RESOURCE_ID_MAX
        };
 
-       int nDurationEnumSize = sizeof(eMonitorDuration) / sizeof(eMonitorDuration[0]);
-       int nDurationEnumCounter;
-
        int nIDEnumSize = sizeof(eResourceID) / sizeof(eResourceID[0]);
        int nIDEnumCounter;
 
        for(nIDEnumCounter = 0; nIDEnumCounter < nIDEnumSize; nIDEnumCounter++)
        {
-               for(nDurationEnumCounter = 0; nDurationEnumCounter < nDurationEnumSize; nDurationEnumCounter++)
+                //Targer API
+               nRet = battery_monitor_get_power_usage_by_app_per_resource(TEST_APP_ID, eResourceID[nIDEnumCounter], start_time, end_time, &nBatteryUsage);
+               if ( g_bBatteryFeatureNotSupported )
                {
-                       //Targer API
-                       nRet = battery_monitor_get_usage_by_app_id_for_resource_id(TEST_APP_ID, eResourceID[nIDEnumCounter], eMonitorDuration[nDurationEnumCounter], &nBatteryUsage);
-                       if ( g_bBatteryFeatureNotSupported )
-                       {
-                               PRINT_RESULT(BATTERY_MONITOR_ERROR_NOT_SUPPORTED, nRet, "battery_monitor_get_usage_by_app_id_for_resource_id", BatteryMonitorGetError(nRet));
-                               return 0;
-                       }
-                       PRINT_RESULT(BATTERY_MONITOR_ERROR_NONE, nRet, "battery_monitor_get_usage_by_app_id_for_resource_id", BatteryMonitorGetError(nRet));
-                       FPRINTF("[Line : %d][%s] battery_monitor_get_usage_by_app_id_for_resource_id returned battary usage[%d] for Monitor duration[%d] and resource ID [%d] \\n", __LINE__, API_NAMESPACE, nBatteryUsage, eMonitorDuration[nDurationEnumCounter], eResourceID[nIDEnumCounter]);
+                       PRINT_RESULT(BATTERY_MONITOR_ERROR_NOT_SUPPORTED, nRet, "battery_monitor_get_power_usage_by_app_per_resource", BatteryMonitorGetError(nRet));
+                       return 0;
                }
+                if(nRet == BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND)
+                {
+                        FPRINTF("[Line : %d][%s] record is not found\\n", __LINE__, API_NAMESPACE);
+                        return 0;
+                }
+               PRINT_RESULT(BATTERY_MONITOR_ERROR_NONE, nRet, "battery_monitor_get_power_usage_by_app_per_resource", BatteryMonitorGetError(nRet));
+               FPRINTF("[Line : %d][%s] battery_monitor_get_power_usage_by_app_per_resource returned battary usage[%f] resource ID [%d] \\n", __LINE__, API_NAMESPACE, nBatteryUsage, eResourceID[nIDEnumCounter]);
+
        }
 
        return 0;
@@ -304,7 +335,7 @@ int ITc_battery_monitor_get_usage_by_app_id_for_resource_id_p(void)
 //& type : auto
 //& purpose: Gets the total battery usage in percent by an application for certain time duration
 /**
-* @testcase                    ITc_battery_monitor_get_total_usage_by_app_id_p
+* @testcase                    ITc_battery_monitor_get_power_usage_by_app_p
 * @since_tizen                 5.5
 * @author                      SRID(j.abhishek)
 * @reviewer                    SRID(shobhit.v)
@@ -312,47 +343,50 @@ int ITc_battery_monitor_get_usage_by_app_id_for_resource_id_p(void)
 * @description                 Gets the total battery usage in percent by an application for certain time duration.
 * @scenario                    Use test app id and different duration to get battery usage\n
 *                              check for Pass/Fail.
-* @apicovered                  battery_monitor_get_total_usage_by_app_id
-* @passcase                    battery_monitor_get_total_usage_by_app_id is successful and return correct value
-* @failcase                    battery_monitor_get_total_usage_by_app_id gets failed or return null value
+* @apicovered                  battery_monitor_get_power_usage_by_app
+* @passcase                    battery_monitor_get_power_usage_by_app is successful and return correct value
+* @failcase                    battery_monitor_get_power_usage_by_app gets failed or return null value
 * @precondition                        N/A
 * @postcondition               N/A
 */
-int ITc_battery_monitor_get_total_usage_by_app_id_p(void)
+int ITc_battery_monitor_get_power_usage_by_app_p(void)
 {
        START_TEST_NO_CHECK;
 
        int nRet = -1;
-       int nBatteryUsage = 0;
-
-       battery_monitor_duration_type_e eMonitorDuration[] = {
-               BATTERY_MONITOR_DURATION_TYPE_1DAY,
-               BATTERY_MONITOR_DURATION_TYPE_1WEEK
-       };
+       double nBatteryUsage = 0.0;
+        time_t start_time;
+        time_t end_time;
+        nRet = BatteryMonitorGetTime(&start_time, &end_time);
+        if(nRet == 1)
+        {
+                FPRINTF("[Line : %d][%s] error returned = failed precondition, time\\n", __LINE__, API_NAMESPACE);
+                return 1;
+        }
 
-       int nEnumSize = sizeof(eMonitorDuration) / sizeof(eMonitorDuration[0]);
-       int nEnumCounter;
 
-       for(nEnumCounter = 0; nEnumCounter < nEnumSize; nEnumCounter++)
+       //Targer API
+       nRet = battery_monitor_get_power_usage_by_app(TEST_APP_ID, start_time, end_time, &nBatteryUsage);
+        if ( g_bBatteryFeatureNotSupported )
        {
-               //Targer API
-               nRet = battery_monitor_get_total_usage_by_app_id(TEST_APP_ID, eMonitorDuration[nEnumCounter], &nBatteryUsage);
-               if ( g_bBatteryFeatureNotSupported )
-               {
-                       PRINT_RESULT(BATTERY_MONITOR_ERROR_NOT_SUPPORTED, nRet, "battery_monitor_get_total_usage_by_app_id", BatteryMonitorGetError(nRet));
-                       return 0;
-               }
-               PRINT_RESULT(BATTERY_MONITOR_ERROR_NONE, nRet, "battery_monitor_get_total_usage_by_app_id", BatteryMonitorGetError(nRet));
-               FPRINTF("[Line : %d][%s] battery_monitor_get_total_usage_by_app_id returned battary usage[%d] for Monitor duration[%d] \\n", __LINE__, API_NAMESPACE, nBatteryUsage, eMonitorDuration[nEnumCounter]);
+               PRINT_RESULT(BATTERY_MONITOR_ERROR_NOT_SUPPORTED, nRet, "battery_monitor_get_power_usage_by_app", BatteryMonitorGetError(nRet));
+               return 0;
        }
-
-       return 0;
+        if(nRet == BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND)
+        {
+                FPRINTF("[Line : %d][%s] record not found\\n", __LINE__, API_NAMESPACE);
+                return 0;
+        }
+       PRINT_RESULT(BATTERY_MONITOR_ERROR_NONE, nRet, "battery_monitor_get_power_usage_by_app", BatteryMonitorGetError(nRet));
+        FPRINTF("[Line : %d][%s] battery_monitor_get_power_usage_by_app returned battary usage[%f] \\n", __LINE__, API_NAMESPACE, nBatteryUsage);
+
+        return 0;
 }
 
 //& type : auto
 //& purpose: Gets the battery-percent usage by a resource for certain time duration.
 /**
-* @testcase                    ITc_battery_monitor_get_total_usage_by_resource_id_p
+* @testcase                    ITc_battery_monitor_get_power_usage_by_resource_p
 * @since_tizen                 5.5
 * @author                      SRID(j.abhishek)
 * @reviewer                    SRID(shobhit.v)
@@ -361,23 +395,26 @@ int ITc_battery_monitor_get_total_usage_by_app_id_p(void)
 * @description                 Gets the battery-percent usage by a resource for certain time duration.
 * @scenario                    Based on different resource ID get battery usage for different duration\n
 *                              check for Pass/Fail.
-* @apicovered                  battery_monitor_get_total_usage_by_resource_id
-* @passcase                    battery_monitor_get_total_usage_by_resource_id is successful and return correct value
-* @failcase                    battery_monitor_get_total_usage_by_resource_id gets failed or return null value
+* @apicovered                  battery_monitor_get_power_usage_by_resource
+* @passcase                    battery_monitor_get_power_usage_by_resource is successful and return correct value
+* @failcase                    battery_monitor_get_power_usage_by_resource gets failed or return null value
 * @precondition                        N/A
 * @postcondition               N/A
 */
-int ITc_battery_monitor_get_total_usage_by_resource_id_p(void)
+int ITc_battery_monitor_get_power_usage_by_resource_p(void)
 {
        START_TEST_NO_CHECK;
 
        int nRet = -1;
-       int nBatteryUsage = 0;
-
-       battery_monitor_duration_type_e eMonitorDuration[] = {
-               BATTERY_MONITOR_DURATION_TYPE_1DAY,
-               BATTERY_MONITOR_DURATION_TYPE_1WEEK
-       };
+       double nBatteryUsage = 0.0;
+        time_t start_time;
+        time_t end_time;
+        nRet = BatteryMonitorGetTime(&start_time, &end_time);
+        if(nRet == 1)
+        {
+                FPRINTF("[Line : %d][%s] error returned = failed precondition, time\\n", __LINE__, API_NAMESPACE);
+                return 1;
+        }
 
        battery_monitor_resource_id_e eResourceID[] = {
                BATTERY_MONITOR_RESOURCE_ID_BLE,
@@ -386,28 +423,27 @@ int ITc_battery_monitor_get_total_usage_by_resource_id_p(void)
                BATTERY_MONITOR_RESOURCE_ID_DISPLAY,
                BATTERY_MONITOR_RESOURCE_ID_DEVICE_NETWORK,
                BATTERY_MONITOR_RESOURCE_ID_GPS_SENSOR,
+                BATTERY_MONITOR_RESOURCE_ID_MAX
        };
 
-       int nDurationEnumSize = sizeof(eMonitorDuration) / sizeof(eMonitorDuration[0]);
-       int nDurationEnumCounter;
-
        int nIDEnumSize = sizeof(eResourceID) / sizeof(eResourceID[0]);
        int nIDEnumCounter;
 
        for(nIDEnumCounter = 0; nIDEnumCounter < nIDEnumSize; nIDEnumCounter++)
        {
-               for(nDurationEnumCounter = 0; nDurationEnumCounter < nDurationEnumSize; nDurationEnumCounter++)
+               nRet = battery_monitor_get_power_usage_by_resource(eResourceID[nIDEnumCounter], start_time, end_time, &nBatteryUsage);
+               if ( g_bBatteryFeatureNotSupported )
                {
-                       //Targer API
-                       nRet = battery_monitor_get_total_usage_by_resource_id(eResourceID[nIDEnumCounter], eMonitorDuration[nDurationEnumCounter], &nBatteryUsage);
-                       if ( g_bBatteryFeatureNotSupported )
-                       {
-                               PRINT_RESULT(BATTERY_MONITOR_ERROR_NOT_SUPPORTED, nRet, "battery_monitor_get_total_usage_by_resource_id", BatteryMonitorGetError(nRet));
-                               return 0;
-                       }
-                       PRINT_RESULT(BATTERY_MONITOR_ERROR_NONE, nRet, "battery_monitor_get_total_usage_by_resource_id", BatteryMonitorGetError(nRet));
-                       FPRINTF("[Line : %d][%s] battery_monitor_get_total_usage_by_resource_id returned battary usage[%d] for Monitor duration[%d] and resource ID [%d] \\n", __LINE__, API_NAMESPACE, nBatteryUsage, eMonitorDuration[nDurationEnumCounter], eResourceID[nIDEnumCounter]);
+                       PRINT_RESULT(BATTERY_MONITOR_ERROR_NOT_SUPPORTED, nRet, "battery_monitor_get_power_usage_by_resource", BatteryMonitorGetError(nRet));
+                       return 0;
                }
+                if(nRet == BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND)
+                {
+                        FPRINTF("[Line : %d][%s] record not found\\n", __LINE__, API_NAMESPACE);
+                        return 0;
+                }
+               PRINT_RESULT(BATTERY_MONITOR_ERROR_NONE, nRet, "battery_monitor_get_power_usage_by_resource", BatteryMonitorGetError(nRet));
+               FPRINTF("[Line : %d][%s] battery_monitor_get_power_usage_by_resource returned battary usage[%f] for resource ID [%d] \\n", __LINE__, API_NAMESPACE, nBatteryUsage, eResourceID[nIDEnumCounter]);
        }
 
        return 0;
index fe2c8073cb20d7a77b4f3c2aac6b0c807d1bc323..9e13ce80b80461491f82d2192b015879b1ecf7dd 100755 (executable)
 extern void ITs_battery_monitor_startup(void);
 extern void ITs_battery_monitor_cleanup(void);
 
-extern int ITc_battery_monitor_create_destroy_p(void);
-extern int ITc_battery_monitor_get_usage_for_resource_id_p(void);
-extern int ITc_battery_monitor_get_usage_by_app_id_for_all_resource_id_p(void);
-extern int ITc_battery_monitor_get_usage_by_app_id_for_resource_id_p(void);
-extern int ITc_battery_monitor_get_total_usage_by_app_id_p(void);
-extern int ITc_battery_monitor_get_total_usage_by_resource_id_p(void);
+extern int ITc_battery_monitor_battery_usage_data_destroy_p(void);
+extern int ITc_battery_monitor_usage_data_get_power_usage_per_resource_p(void);
+extern int ITc_battery_monitor_get_power_usage_by_app_for_all_resources_p(void);
+extern int ITc_battery_monitor_get_power_usage_by_app_per_resource_p(void);
+extern int ITc_battery_monitor_get_power_usage_by_app_p(void);
+extern int ITc_battery_monitor_get_power_usage_by_resource_p(void);
 
 testcase tc_array[] = {
-       {"ITc_battery_monitor_create_destroy_p", ITc_battery_monitor_create_destroy_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
-       {"ITc_battery_monitor_get_usage_for_resource_id_p", ITc_battery_monitor_get_usage_for_resource_id_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
+       {"ITc_battery_monitor_battery_usage_data_destroy_p", ITc_battery_monitor_battery_usage_data_destroy_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
+       {"ITc_battery_monitor_usage_data_get_power_usage_per_resource_p", ITc_battery_monitor_usage_data_get_power_usage_per_resource_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
        {"ITc_battery_monitor_get_usage_by_app_id_for_all_resource_id_p", ITc_battery_monitor_get_usage_by_app_id_for_all_resource_id_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
        {"ITc_battery_monitor_get_usage_by_app_id_for_resource_id_p", ITc_battery_monitor_get_usage_by_app_id_for_resource_id_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
-       {"ITc_battery_monitor_get_total_usage_by_app_id_p", ITc_battery_monitor_get_total_usage_by_app_id_p, ITs_battery_monitor_startup,ITs_battery_monitor_cleanup},
-       {"ITc_battery_monitor_get_total_usage_by_resource_id_p", ITc_battery_monitor_get_total_usage_by_resource_id_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
+       {"ITc_battery_monitor_get_power_usage_by_app_p", ITc_battery_monitor_get_power_usage_by_app_p, ITs_battery_monitor_startup,ITs_battery_monitor_cleanup},
+       {"ITc_battery_monitor_get_power_usage_by_resource_p", ITc_battery_monitor_get_power_usage_by_resource_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
        {NULL, NULL, NULL, NULL}
 };
 
index fe2c8073cb20d7a77b4f3c2aac6b0c807d1bc323..96af27dc4dfa689f7e0c7f93430efc9265ed200e 100755 (executable)
 extern void ITs_battery_monitor_startup(void);
 extern void ITs_battery_monitor_cleanup(void);
 
-extern int ITc_battery_monitor_create_destroy_p(void);
-extern int ITc_battery_monitor_get_usage_for_resource_id_p(void);
-extern int ITc_battery_monitor_get_usage_by_app_id_for_all_resource_id_p(void);
-extern int ITc_battery_monitor_get_usage_by_app_id_for_resource_id_p(void);
-extern int ITc_battery_monitor_get_total_usage_by_app_id_p(void);
-extern int ITc_battery_monitor_get_total_usage_by_resource_id_p(void);
+extern int ITc_battery_monitor_battery_usage_data_destroy_p(void);
+extern int ITc_battery_monitor_usage_data_get_power_usage_per_resource_p(void);
+extern int ITc_battery_monitor_get_power_usage_by_app_for_all_resources_p(void);
+extern int ITc_battery_monitor_get_power_usage_by_app_per_resource_p(void);
+extern int ITc_battery_monitor_get_power_usage_by_app_p(void);
+extern int ITc_battery_monitor_get_power_usage_by_resource_p(void);
 
 testcase tc_array[] = {
-       {"ITc_battery_monitor_create_destroy_p", ITc_battery_monitor_create_destroy_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
-       {"ITc_battery_monitor_get_usage_for_resource_id_p", ITc_battery_monitor_get_usage_for_resource_id_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
-       {"ITc_battery_monitor_get_usage_by_app_id_for_all_resource_id_p", ITc_battery_monitor_get_usage_by_app_id_for_all_resource_id_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
-       {"ITc_battery_monitor_get_usage_by_app_id_for_resource_id_p", ITc_battery_monitor_get_usage_by_app_id_for_resource_id_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
-       {"ITc_battery_monitor_get_total_usage_by_app_id_p", ITc_battery_monitor_get_total_usage_by_app_id_p, ITs_battery_monitor_startup,ITs_battery_monitor_cleanup},
-       {"ITc_battery_monitor_get_total_usage_by_resource_id_p", ITc_battery_monitor_get_total_usage_by_resource_id_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
+       {"ITc_battery_monitor_battery_usage_data_destroy_p", ITc_battery_monitor_battery_usage_data_destroy_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
+       {"ITc_battery_monitor_usage_data_get_power_usage_per_resource_p", ITc_battery_monitor_usage_data_get_power_usage_per_resource_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
+       {"ITc_battery_monitor_get_power_usage_by_app_for_all_resources_p", ITc_battery_monitor_get_power_usage_by_app_for_all_resources_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
+       {"ITc_battery_monitor_get_power_usage_by_app_per_resource_p", ITc_battery_monitor_get_power_usage_by_app_per_resource_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
+       {"ITc_battery_monitor_get_power_usage_by_app_p", ITc_battery_monitor_get_power_usage_by_app_p, ITs_battery_monitor_startup,ITs_battery_monitor_cleanup},
+       {"ITc_battery_monitor_get_power_usage_by_resource_p", ITc_battery_monitor_get_power_usage_by_resource_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
        {NULL, NULL, NULL, NULL}
 };
 
index fe2c8073cb20d7a77b4f3c2aac6b0c807d1bc323..96af27dc4dfa689f7e0c7f93430efc9265ed200e 100755 (executable)
 extern void ITs_battery_monitor_startup(void);
 extern void ITs_battery_monitor_cleanup(void);
 
-extern int ITc_battery_monitor_create_destroy_p(void);
-extern int ITc_battery_monitor_get_usage_for_resource_id_p(void);
-extern int ITc_battery_monitor_get_usage_by_app_id_for_all_resource_id_p(void);
-extern int ITc_battery_monitor_get_usage_by_app_id_for_resource_id_p(void);
-extern int ITc_battery_monitor_get_total_usage_by_app_id_p(void);
-extern int ITc_battery_monitor_get_total_usage_by_resource_id_p(void);
+extern int ITc_battery_monitor_battery_usage_data_destroy_p(void);
+extern int ITc_battery_monitor_usage_data_get_power_usage_per_resource_p(void);
+extern int ITc_battery_monitor_get_power_usage_by_app_for_all_resources_p(void);
+extern int ITc_battery_monitor_get_power_usage_by_app_per_resource_p(void);
+extern int ITc_battery_monitor_get_power_usage_by_app_p(void);
+extern int ITc_battery_monitor_get_power_usage_by_resource_p(void);
 
 testcase tc_array[] = {
-       {"ITc_battery_monitor_create_destroy_p", ITc_battery_monitor_create_destroy_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
-       {"ITc_battery_monitor_get_usage_for_resource_id_p", ITc_battery_monitor_get_usage_for_resource_id_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
-       {"ITc_battery_monitor_get_usage_by_app_id_for_all_resource_id_p", ITc_battery_monitor_get_usage_by_app_id_for_all_resource_id_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
-       {"ITc_battery_monitor_get_usage_by_app_id_for_resource_id_p", ITc_battery_monitor_get_usage_by_app_id_for_resource_id_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
-       {"ITc_battery_monitor_get_total_usage_by_app_id_p", ITc_battery_monitor_get_total_usage_by_app_id_p, ITs_battery_monitor_startup,ITs_battery_monitor_cleanup},
-       {"ITc_battery_monitor_get_total_usage_by_resource_id_p", ITc_battery_monitor_get_total_usage_by_resource_id_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
+       {"ITc_battery_monitor_battery_usage_data_destroy_p", ITc_battery_monitor_battery_usage_data_destroy_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
+       {"ITc_battery_monitor_usage_data_get_power_usage_per_resource_p", ITc_battery_monitor_usage_data_get_power_usage_per_resource_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
+       {"ITc_battery_monitor_get_power_usage_by_app_for_all_resources_p", ITc_battery_monitor_get_power_usage_by_app_for_all_resources_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
+       {"ITc_battery_monitor_get_power_usage_by_app_per_resource_p", ITc_battery_monitor_get_power_usage_by_app_per_resource_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
+       {"ITc_battery_monitor_get_power_usage_by_app_p", ITc_battery_monitor_get_power_usage_by_app_p, ITs_battery_monitor_startup,ITs_battery_monitor_cleanup},
+       {"ITc_battery_monitor_get_power_usage_by_resource_p", ITc_battery_monitor_get_power_usage_by_resource_p, ITs_battery_monitor_startup, ITs_battery_monitor_cleanup},
        {NULL, NULL, NULL, NULL}
 };