Add cpp files for HAL test
[platform/core/system/libdevice-node.git] / unittest / gtest_hal_cpu.cpp
1
2 #include <iostream>
3 #include <gtest/gtest.h>
4 #include "hw/cpu.h"
5
6 using namespace std;
7
8 /*
9  * main class
10  */
11
12 #define LOWBATTERY "LowBattery"
13
14 struct hw_info *info;
15 struct cpu_device *cpu_dev;
16
17 class CPUHalTest : public testing::Test
18 {
19         public:
20                 virtual void SetUp()
21                 {
22
23                 }
24
25                 virtual void TearDown()
26                 {
27
28                 }
29 };
30
31 /*
32  * testcase
33  */
34 TEST_F(CPUHalTest, InitP)
35 {
36         int ret;
37
38         ret = hw_get_info(CPU_HARDWARE_DEVICE_ID,
39                         (const struct hw_info **)&info);
40         if (ret < 0) {
41                 cout << "There is no device for cpu " << ret << endl;
42                 return;
43         } else {
44                 EXPECT_EQ(ret, 0) << "Fail to load cpu hal (" << ret << ")";
45         }
46         if (!info || !info->open) {
47                 cout << "There is no function for info open" << endl;
48                 return;
49         }
50         ret = info->open(info, NULL, (struct hw_common**)&cpu_dev);
51         EXPECT_EQ(ret, 0) << "Fail to open cpu device (" << ret << ")";
52 }
53
54 TEST_F(CPUHalTest, StartBoostP)
55 {
56         int ret;
57
58         if (!cpu_dev || !cpu_dev->start_boost) {
59                 cout << "There is no function for start_boost" << endl;
60                 return;
61         }
62
63         // prprpr TODO
64         ret = cpu_dev->start_boost((void *)LOWBATTERY);
65         EXPECT_EQ(ret, 0) << "Fail to start_boost (" << ret << ")";
66 }
67
68 TEST_F(CPUHalTest, StopBoostP)
69 {
70         int ret;
71
72         if (!cpu_dev || !cpu_dev->stop_boost) {
73                 cout << "There is no function for stop_boost" << endl;
74                 return;
75         }
76
77         // prprpr TODO
78         ret = cpu_dev->stop_boost((void *)LOWBATTERY);
79         EXPECT_EQ(ret, 0) << "Fail to stop_boost (" << ret << ")";
80 }
81
82 TEST_F(CPUHalTest, DeinitP)
83 {
84         int ret;
85
86         if (!info || !info->close) {
87                 cout << "There is no function for info close" << endl;
88                 return;
89         }
90
91         ret = info->close((struct hw_common *)cpu_dev);
92         EXPECT_EQ(ret, 0) << "Fail to open cpu device (" << ret << ")";
93 }
94
95 int main(int argc, char **argv)
96 {
97         testing::InitGoogleTest(&argc, argv);
98
99         return RUN_ALL_TESTS();
100 }