summaryrefslogtreecommitdiff
path: root/unittest/gtest_hal_battery.cpp
blob: b7a59463d176d8f8dfd19bf027552fcb6d8d4a01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

#include <iostream>
#include <gtest/gtest.h>
#include <system_info.h>
#include "hw/battery.h"
#include "unittest.h"

using namespace std;

/*
 * main class
 */
struct hw_info *info;
struct battery_device *battery_dev;
static bool need_featurecheck = true;

class BATTERYHalTest : public testing::Test
{
	public:
		virtual void SetUp()
		{
			int ret;

			if (need_featurecheck) {
				ret = system_info_get_platform_bool(FEATURE_BATTERY, &supported);
				EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed";
				need_featurecheck = false;
			}
		}

		virtual void TearDown()
		{

		}
};

/*
 * testcase
 */
TEST_F(BATTERYHalTest, InitP)
{
	int ret;

	if (!supported)
		return;

	ret = hw_get_info(BATTERY_HARDWARE_DEVICE_ID,
			(const struct hw_info **)&info);
	EXPECT_EQ(ret, 0) << "Fail to load battery hal (" << ret << ")";

	if (!info->open) {
		cout << "There is no function for info open" << endl;
		return;
	}
	ret = info->open(info, NULL, (struct hw_common**)&battery_dev);
	EXPECT_EQ(ret, 0) << "Fail to open battery device(" << ret << ")";
}

static void updated_cb(struct battery_info *info, void *data)
{

}

TEST_F(BATTERYHalTest, RegisterChangedEventP)
{
	int ret;

	if (!supported)
		return;

	if (!battery_dev->register_changed_event) {
		cout << "There is no function for register_changed_event" << endl;
		return;
	}
	ret = battery_dev->register_changed_event(updated_cb, NULL);
	EXPECT_EQ(ret, 0) << "Fail to register_changed_event (" << ret << ")";
}

TEST_F(BATTERYHalTest, UnregisterChangedEventP)
{
	if (!supported)
		return;

	if (!battery_dev->unregister_changed_event) {
		cout << "There is no function for unregister_changed_event" << endl;
		return;
	}
	battery_dev->unregister_changed_event(updated_cb);
}

TEST_F(BATTERYHalTest, GetCurrentStateP)
{
	int ret;

	if (!supported)
		return;

	if (!battery_dev->get_current_state) {
		cout << "There is no function for get_current_state" << endl;
		return;
	}
	ret = battery_dev->get_current_state(updated_cb, NULL);
	EXPECT_EQ(ret, 0) << "Fail to get_current_state (" << ret << ")";
}

TEST_F(BATTERYHalTest, DeinitP)
{
	int ret;

	if (!supported)
		return;

	if (!info->close) {
		cout << "There is no function for info close" << endl;
		return;
	}
	ret = info->close((struct hw_common *)battery_dev);
	EXPECT_EQ(ret, 0) << "Fail to close battery device(" << ret << ")";
}

int main(int argc, char **argv)
{
	testing::InitGoogleTest(&argc, argv);

	return RUN_ALL_TESTS();
}