Merge "Add LCOV macro for coverage" into tizen
[platform/core/api/connection.git] / unittest / tct-connection-core.cpp
1 //
2 // Copyright (c) 2020 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16 #include <stdio.h>
17 #include <string.h>
18 #include "tct_common.h"
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 #include "tct-connection-core.h"
25
26 #ifdef __cplusplus
27 }
28 #endif
29
30 #include <gtest/gtest.h>
31
32 #include <malloc.h>
33 #include <unistd.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <sys/wait.h>
37 #include <stdbool.h>
38
39 TEST(connection, connection){
40         char *pszGetTCName = NULL;
41     pszGetTCName = (char*)malloc( 256 );
42     memset( pszGetTCName, 0x00, 256);
43     strcpy( pszGetTCName, "utc_connection");
44         int i=0, result=0;
45
46         PRINT_LOG(DLOG_INFO, "NativeTCT", "[%s:%d] Executing TC Name = %s", __FUNCTION__, __LINE__, pszGetTCName);
47
48     int successCnt = 0;
49     int errorCnt = 0;
50         for ( i = 0; tc_array[i].name; i++ )
51         {
52             if (COMMON_DEBUG)
53             PRINT_LOG(DLOG_INFO, "NativeTCT", "===========================================");
54         PRINT_LOG(DLOG_INFO, "NativeTCT", "[%s]", tc_array[i].name);
55                 if ( 0 == strncmp(pszGetTCName, tc_array[i].name, strlen(pszGetTCName)) )
56                 {
57                         if ( tc_array[i].startup )
58                         {
59                                 tc_array[i].startup();
60                         }
61
62                         result = tc_array[i].function();
63
64             if( result == 0 ){
65                 successCnt++;
66             }
67             else {
68                             PRINT_LOG(DLOG_INFO, "NativeTCT", "[Error][%d] %s returns value = %d", i, tc_array[i].name, result);
69                 errorCnt++;
70             }
71
72             EXPECT_EQ(result, 0);
73             // ASSERT_EQ(result, 0);
74
75                         if ( tc_array[i].cleanup )
76                         {
77                                 tc_array[i].cleanup();
78                         }
79                 }
80         else {
81                         PRINT_LOG(DLOG_INFO, "NativeTCT", "Name check error! [%s][%s]", pszGetTCName, tc_array[i].name);
82                         FREE_MEMORY_TC(pszGetTCName);
83             ASSERT_EQ(0, 1);
84         }
85         if (COMMON_DEBUG)
86             PRINT_LOG(DLOG_INFO, "NativeTCT", "===========================================");
87         }
88
89         PRINT_LOG(DLOG_INFO, "NativeTCT", "==========================");
90         PRINT_LOG(DLOG_INFO, "NativeTCT", "Success [%4d / %4d]", successCnt, successCnt + errorCnt);
91         PRINT_LOG(DLOG_INFO, "NativeTCT", "Error   [%4d / %4d]", errorCnt, successCnt + errorCnt);
92         PRINT_LOG(DLOG_INFO, "NativeTCT", "==========================");
93
94         FREE_MEMORY_TC(pszGetTCName);
95 }
96
97 int main(int argc, char** argv) {
98     ::testing::InitGoogleTest(&argc, argv);
99     return RUN_ALL_TESTS();
100 }