2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
20 #include <sys/types.h>
24 #include "tct_common.h"
37 #include "tct-base-utils-core_mobile.h"
41 #include "tct-base-utils-core_wearable.h"
44 #include "tct-base-utils-core_tizeniot.h"
48 #include "tct-base-utils-core_tv.h"
56 #include <gtest/gtest.h>
60 static bool app_create(void *data)
65 static void app_control(app_control_h app_control, void *data)
67 char* pszGetTCName = NULL;
68 int i=0, result=0, nRet=0;
69 nRet = app_control_get_extra_data(app_control, "testcase_name", &pszGetTCName);
70 if(nRet != APP_CONTROL_ERROR_NONE)
72 dlog_print(DLOG_ERROR, "NativeTCT", "[%s:%d] app_control_get_extra_data returns error = %d", __FUNCTION__, __LINE__, nRet);
73 PRINT_UTC_LOG("\\n[%s][Line : %d]Unable to fetch test case name: app_control_get_extra_data API call fails\\n", __FILE__, __LINE__);
74 PRINT_TC_RESULT("%d",1);
75 FREE_MEMORY_TC(pszGetTCName);
79 dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] Executing TC Name = %s", __FUNCTION__, __LINE__, pszGetTCName);
80 for ( i = 0; tc_array[i].name; i++ )
82 if ( 0 == strncmp(pszGetTCName, tc_array[i].name, strlen(pszGetTCName)) )
85 dlog_print(DLOG_INFO, "NativeTCT", "%s : Startup begin", pszGetTCName);
86 if ( tc_array[i].startup )
88 tc_array[i].startup();
90 dlog_print(DLOG_INFO, "NativeTCT", "%s : Startup end", pszGetTCName);
92 dlog_print(DLOG_INFO, "NativeTCT", "%s : Body begin", pszGetTCName);
93 result = tc_array[i].function();
94 dlog_print(DLOG_INFO, "NativeTCT", "%s returns value = %d", pszGetTCName, result);
95 dlog_print(DLOG_INFO, "NativeTCT", "%s : Body end", pszGetTCName);
97 dlog_print(DLOG_INFO, "NativeTCT", "%s : Cleanup begin", pszGetTCName);
98 if ( tc_array[i].cleanup )
100 tc_array[i].cleanup();
102 dlog_print(DLOG_INFO, "NativeTCT", "%s : Cleanup end", pszGetTCName);
105 PRINT_TC_RESULT("%d",result);
106 FREE_MEMORY_TC(pszGetTCName);
111 dlog_print(DLOG_ERROR, "NativeTCT", "[%s:%d] Unable to execute %s : Unknown Test Case Name", __FUNCTION__, __LINE__, pszGetTCName);
112 PRINT_UTC_LOG("\\n[%s][Line : %d]Unable to execute %s : Unknown Test Case Name\\n", __FILE__, __LINE__, pszGetTCName);
113 PRINT_TC_RESULT("%d",1);
114 FREE_MEMORY_TC(pszGetTCName);
118 static void app_terminate(void *data)
120 dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] Application Package is now Terminating", __FUNCTION__, __LINE__);
123 int main(int argc, char *argv[])
128 ui_app_lifecycle_callback_s event_callback = {0,};
129 event_callback.create = app_create;
130 event_callback.terminate = app_terminate;
131 event_callback.app_control = app_control;
133 //setting gcda file location for coverage
134 setenv("GCOV_PREFIX","/tmp",1);
135 dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] Coverage *.gcda File location set to /tmp/home/abuild/rpmbuild/BUILD/ ", __FUNCTION__, __LINE__);
137 dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] Application Main Function is Invoked", __FUNCTION__, __LINE__);
138 ret = ui_app_main(argc, argv, &event_callback, NULL);
139 if (ret != APP_ERROR_NONE)
141 dlog_print(DLOG_ERROR, "NativeTCT", "Application ui_app_main call gets failed. err = %d", ret);
142 PRINT_UTC_LOG("\\n[%s][Line : %d]Application ui_app_main call gets failed. err = %d\\n", __FILE__, __LINE__, ret);
143 PRINT_TC_RESULT("%d",1);
147 dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] Application Package is Terminated", __FUNCTION__, __LINE__);
152 TEST(base_utils, base_utils){
153 char *pszGetTCName = NULL;
154 pszGetTCName = (char*)malloc( 256 );
155 memset( pszGetTCName, 0x00, 256);
156 strcpy( pszGetTCName, "utc_capi_base");
157 int i=0, result=0, nRet=0;
159 dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] Executing TC Name = %s", __FUNCTION__, __LINE__, pszGetTCName);
163 for ( i = 0; tc_array[i].name; i++ )
165 if ( 0 == strncmp(pszGetTCName, tc_array[i].name, strlen(pszGetTCName)) )
167 if ( tc_array[i].startup )
169 tc_array[i].startup();
172 result = tc_array[i].function();
178 dlog_print(DLOG_INFO, "NativeTCT", "[Error][%d] %s returns value = %d", i, tc_array[i].name, result);
182 EXPECT_EQ(result, 0);
183 // ASSERT_EQ(result, 0);
185 if ( tc_array[i].cleanup )
187 tc_array[i].cleanup();
191 dlog_print(DLOG_INFO, "NativeTCT", "Name check error! [%s][%s]", pszGetTCName, tc_array[i].name);
196 dlog_print(DLOG_INFO, "NativeTCT", "==========================");
197 dlog_print(DLOG_INFO, "NativeTCT", "Success [%4d / %4d]", successCnt, successCnt + errorCnt);
198 dlog_print(DLOG_INFO, "NativeTCT", "Error [%4d / %4d]", errorCnt, successCnt + errorCnt);
199 dlog_print(DLOG_INFO, "NativeTCT", "==========================");
201 FREE_MEMORY_TC(pszGetTCName);
204 int main(int argc, char** argv) {
205 ::testing::InitGoogleTest(&argc, argv);
206 return RUN_ALL_TESTS();