summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpr.jung <pr.jung@samsung.com>2018-04-04 04:58:44 (GMT)
committerpr.jung <pr.jung@samsung.com>2018-04-04 04:58:44 (GMT)
commit9ef88c98641c6f0136a03360de688ddc9a33a639 (patch)
tree9f63e656b2ac76fe380573e7279ccdb4f4ee024d
parentd7c2cbd3f80d31eedef47ce57f55e73af08b88d1 (diff)
downloadlibdevice-node-9ef88c98641c6f0136a03360de688ddc9a33a639.zip
libdevice-node-9ef88c98641c6f0136a03360de688ddc9a33a639.tar.gz
libdevice-node-9ef88c98641c6f0136a03360de688ddc9a33a639.tar.bz2
gtest: Add gtest for battery, cpu, display, extcon, and touchscreenrefs/changes/62/174762/1
Change-Id: I733890ff1261e3e45e11129ea82f6e7e12a65a9e Signed-off-by: pr.jung <pr.jung@samsung.com>
-rw-r--r--unittest/gtest_hal_battery.cpp127
-rw-r--r--unittest/gtest_hal_cpu.cpp120
-rw-r--r--unittest/gtest_hal_display.cpp204
-rw-r--r--unittest/gtest_hal_extcon.cpp128
-rw-r--r--unittest/gtest_hal_touchscreen.cpp85
5 files changed, 664 insertions, 0 deletions
diff --git a/unittest/gtest_hal_battery.cpp b/unittest/gtest_hal_battery.cpp
new file mode 100644
index 0000000..731d881
--- /dev/null
+++ b/unittest/gtest_hal_battery.cpp
@@ -0,0 +1,127 @@
+
+#include <iostream>
+#include <gtest/gtest.h>
+#include "hw/common.h"
+#include "hw/battery.h"
+
+using namespace std;
+
+/*
+ * main class
+ */
+struct battery_device *battery_dev;
+
+class BATTERYHalTest : public testing::Test
+{
+ public:
+ virtual void SetUp()
+ {
+ struct hw_info *info;
+ int ret;
+ ret = hw_get_info(BATTERY_HARDWARE_DEVICE_ID,
+ (const struct hw_info **)&info);
+
+ if (ret < 0) {
+ cout << "Fail to load battery hal(" << ret << ")" << endl;
+ assert(true);
+ return;
+ }
+ if (!info->open) {
+ cout << "Failed to open battery device; open(NULL)" << endl;
+ assert(true);
+ return;
+ }
+
+ ret = info->open(info, NULL, (struct hw_common**)&battery_dev);
+ if (ret < 0 || !battery_dev) {
+ cout << "Failed to get battery device structure (" << ret << ")" << endl;
+ assert(true);
+ return;
+ }
+
+ return;
+ }
+
+ virtual void TearDown()
+ {
+ struct hw_info *info;
+
+ info = battery_dev->common.info;
+ if (!info)
+ free(battery_dev);
+ else
+ info->close((struct hw_common *)battery_dev);
+ battery_dev = NULL;
+
+ return;
+ }
+};
+
+/*
+ * testcase
+ */
+TEST_F(BATTERYHalTest, InitP)
+{
+ EXPECT_NE(battery_dev, nullptr);
+}
+
+TEST_F(BATTERYHalTest, DeinitP)
+{
+ struct battery_device *tmp;
+ struct hw_info *info;
+ int ret;
+
+ hw_get_info(BATTERY_HARDWARE_DEVICE_ID,
+ (const struct hw_info **)&info);
+
+ EXPECT_NE(info, nullptr);
+ if (!info->open || !info->close)
+ return;
+ info->open(info, NULL, (struct hw_common**)&tmp);
+
+ ret = info->close((struct hw_common *)tmp);
+ EXPECT_EQ(ret, 0);
+}
+
+static void updated_cb(struct battery_info *info, void *data)
+{
+}
+
+TEST_F(BATTERYHalTest, RegisterChangedEventP)
+{
+ int ret;
+
+ EXPECT_NE(battery_dev, nullptr);
+ if (!battery_dev->register_changed_event)
+ return;
+ ret = battery_dev->register_changed_event(updated_cb, NULL);
+ battery_dev->unregister_changed_event(updated_cb);
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(BATTERYHalTest, UnregisterChangedEventP)
+{
+ EXPECT_NE(battery_dev, nullptr);
+ if (!battery_dev->unregister_changed_event)
+ return;
+ battery_dev->register_changed_event(updated_cb, NULL);
+ battery_dev->unregister_changed_event(updated_cb);
+}
+
+TEST_F(BATTERYHalTest, GetCurrentStateP)
+{
+ int ret;
+
+ EXPECT_NE(battery_dev, nullptr);
+ if (!battery_dev->get_current_state)
+ return;
+ ret = battery_dev->get_current_state(updated_cb, NULL);
+ EXPECT_EQ(ret, 0);
+}
+
+int main(int argc, char **argv)
+{
+ testing::InitGoogleTest(&argc, argv);
+
+ return RUN_ALL_TESTS();
+}
diff --git a/unittest/gtest_hal_cpu.cpp b/unittest/gtest_hal_cpu.cpp
new file mode 100644
index 0000000..5747865
--- /dev/null
+++ b/unittest/gtest_hal_cpu.cpp
@@ -0,0 +1,120 @@
+
+#include <iostream>
+#include <gtest/gtest.h>
+#include "hw/common.h"
+#include "hw/cpu.h"
+
+using namespace std;
+
+/*
+ * main class
+ */
+
+#define LOWBATTERY "LowBattery"
+
+struct cpu_device *cpu_dev;
+
+class CPUHalTest : public testing::Test
+{
+ public:
+ virtual void SetUp()
+ {
+ struct hw_info *info;
+ int ret;
+ ret = hw_get_info(CPU_HARDWARE_DEVICE_ID,
+ (const struct hw_info **)&info);
+
+ if (ret < 0) {
+ cout << "Fail to load cpu hal(" << ret << ")" << endl;
+ assert(true);
+ return;
+ }
+ if (!info->open) {
+ cout << "Failed to open cpu device; open(NULL)" << endl;
+ assert(true);
+ return;
+ }
+
+ ret = info->open(info, NULL, (struct hw_common**)&cpu_dev);
+ if (ret < 0 || !cpu_dev) {
+ cout << "Failed to get cpu device structure (" << ret << ")" << endl;
+ assert(true);
+ return;
+ }
+
+ return;
+ }
+
+ virtual void TearDown()
+ {
+ struct hw_info *info;
+
+ info = cpu_dev->common.info;
+ if (!info)
+ free(cpu_dev);
+ else
+ info->close((struct hw_common *)cpu_dev);
+ cpu_dev = NULL;
+
+ return;
+ }
+};
+
+/*
+ * testcase
+ */
+TEST_F(CPUHalTest, InitP)
+{
+ EXPECT_NE(cpu_dev, nullptr);
+}
+
+TEST_F(CPUHalTest, DeinitP)
+{
+ struct cpu_device *tmp;
+ struct hw_info *info;
+ int ret;
+
+ hw_get_info(CPU_HARDWARE_DEVICE_ID,
+ (const struct hw_info **)&info);
+
+ EXPECT_NE(info, nullptr);
+ if (!info->open || !info->close)
+ return;
+ info->open(info, NULL, (struct hw_common**)&tmp);
+
+ ret = info->close((struct hw_common *)tmp);
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(CPUHalTest, StartBoostP)
+{
+ int ret;
+
+ EXPECT_NE(cpu_dev, nullptr);
+ if (!cpu_dev->start_boost)
+ return;
+ // prprpr TODO
+ ret = cpu_dev->start_boost((void *)LOWBATTERY);
+ cpu_dev->stop_boost((void *)LOWBATTERY);
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(CPUHalTest, StopBoostP)
+{
+ int ret;
+
+ EXPECT_NE(cpu_dev, nullptr);
+ if (!cpu_dev->stop_boost)
+ return;
+ // prprpr TODO
+ cpu_dev->start_boost((void *)LOWBATTERY);
+ ret = cpu_dev->stop_boost((void *)LOWBATTERY);
+ EXPECT_EQ(ret, 0);
+}
+
+int main(int argc, char **argv)
+{
+ testing::InitGoogleTest(&argc, argv);
+
+ return RUN_ALL_TESTS();
+}
diff --git a/unittest/gtest_hal_display.cpp b/unittest/gtest_hal_display.cpp
new file mode 100644
index 0000000..8e76036
--- /dev/null
+++ b/unittest/gtest_hal_display.cpp
@@ -0,0 +1,204 @@
+
+#include <iostream>
+#include <gtest/gtest.h>
+#include "hw/common.h"
+#include "hw/display.h"
+
+using namespace std;
+
+/*
+ * main class
+ */
+
+#define LOWBATTERY "LowBattery"
+
+struct display_device *display_dev;
+
+class DISPLAYHalTest : public testing::Test
+{
+ public:
+ virtual void SetUp()
+ {
+ struct hw_info *info;
+ int ret;
+ ret = hw_get_info(DISPLAY_HARDWARE_DEVICE_ID,
+ (const struct hw_info **)&info);
+
+ if (ret < 0) {
+ cout << "Fail to load cpu hal(" << ret << ")" << endl;
+ assert(true);
+ return;
+ }
+ if (!info->open) {
+ cout << "Failed to open cpu device; open(NULL)" << endl;
+ assert(true);
+ return;
+ }
+
+ ret = info->open(info, NULL, (struct hw_common**)&display_dev);
+ if (ret < 0 || !display_dev) {
+ cout << "Failed to get cpu device structure (" << ret << ")" << endl;
+ assert(true);
+ return;
+ }
+
+ return;
+ }
+
+ virtual void TearDown()
+ {
+ struct hw_info *info;
+
+ info = display_dev->common.info;
+ if (!info)
+ free(display_dev);
+ else
+ info->close((struct hw_common *)display_dev);
+ display_dev = NULL;
+
+ return;
+ }
+};
+
+/*
+ * testcase
+ */
+TEST_F(DISPLAYHalTest, InitP)
+{
+ EXPECT_NE(display_dev, nullptr);
+}
+
+TEST_F(DISPLAYHalTest, DeinitP)
+{
+ struct display_device *tmp;
+ struct hw_info *info;
+ int ret;
+
+ hw_get_info(DISPLAY_HARDWARE_DEVICE_ID,
+ (const struct hw_info **)&info);
+
+ EXPECT_NE(info, nullptr);
+ if (!info->open || !info->close)
+ return;
+ info->open(info, NULL, (struct hw_common**)&tmp);
+
+ ret = info->close((struct hw_common *)tmp);
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(DISPLAYHalTest, GetMaxBrightnessP)
+{
+ int ret;
+ int max;
+
+ EXPECT_NE(display_dev, nullptr);
+ if (!display_dev->get_max_brightness)
+ return;
+ ret = display_dev->get_max_brightness(&max);
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(DISPLAYHalTest, GetBrightnessP)
+{
+ int ret;
+ int brt;
+
+ EXPECT_NE(display_dev, nullptr);
+ if (!display_dev->get_brightness)
+ return;
+ ret = display_dev->get_brightness(&brt);
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(DISPLAYHalTest, SetBrightnessP)
+{
+ int ret;
+ int max;
+
+ EXPECT_NE(display_dev, nullptr);
+ if (!display_dev->set_brightness)
+ return;
+ ret = display_dev->get_max_brightness(&max);
+ ret = display_dev->set_brightness(max);
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(DISPLAYHalTest, GetAutoBrightnessP)
+{
+ int ret;
+ int brt;
+ float lmax = 0, lmin = 0, light = 0;
+
+ EXPECT_NE(display_dev, nullptr);
+ if (!display_dev->get_auto_brightness)
+ return;
+ ret = display_dev->get_auto_brightness(lmax, lmin, light, &brt);
+ EXPECT_GE(ret, 0);
+}
+
+TEST_F(DISPLAYHalTest, GetStateP)
+{
+ int ret;
+ enum display_state state;
+
+ EXPECT_NE(display_dev, nullptr);
+ if (!display_dev->get_state)
+ return;
+ ret = display_dev->get_state(&state);
+ EXPECT_GE(ret, 0);
+}
+
+TEST_F(DISPLAYHalTest, SetStateP)
+{
+ int ret;
+
+ EXPECT_NE(display_dev, nullptr);
+ if (!display_dev->set_state)
+ return;
+ ret = display_dev->set_state(DISPLAY_ON);
+ EXPECT_GE(ret, 0);
+}
+
+TEST_F(DISPLAYHalTest, GetMaxFrameRateP)
+{
+ int ret;
+ int max;
+
+ EXPECT_NE(display_dev, nullptr);
+ if (!display_dev->get_max_frame_rate)
+ return;
+ ret = display_dev->get_max_frame_rate(&max);
+ EXPECT_GE(ret, 0);
+}
+
+TEST_F(DISPLAYHalTest, GetMinFrameRateP)
+{
+ int ret;
+ int min;
+
+ EXPECT_NE(display_dev, nullptr);
+ if (!display_dev->get_min_frame_rate)
+ return;
+ ret = display_dev->get_min_frame_rate(&min);
+ EXPECT_GE(ret, 0);
+}
+
+TEST_F(DISPLAYHalTest, SetFrameRateP)
+{
+ int ret;
+ int max;
+
+ EXPECT_NE(display_dev, nullptr);
+ if (!display_dev->set_frame_rate)
+ return;
+ ret = display_dev->get_max_frame_rate(&max);
+ ret = display_dev->set_frame_rate(max);
+ EXPECT_GE(ret, 0);
+}
+
+int main(int argc, char **argv)
+{
+ testing::InitGoogleTest(&argc, argv);
+
+ return RUN_ALL_TESTS();
+}
diff --git a/unittest/gtest_hal_extcon.cpp b/unittest/gtest_hal_extcon.cpp
new file mode 100644
index 0000000..86e023c
--- /dev/null
+++ b/unittest/gtest_hal_extcon.cpp
@@ -0,0 +1,128 @@
+
+#include <iostream>
+#include <gtest/gtest.h>
+#include "hw/common.h"
+#include "hw/external_connection.h"
+
+using namespace std;
+
+/*
+ * main class
+ */
+struct external_connection_device *ext_dev;
+
+class EXTCONHalTest : public testing::Test
+{
+ public:
+ virtual void SetUp()
+ {
+ struct hw_info *info;
+ int ret;
+ ret = hw_get_info(EXTERNAL_CONNECTION_HARDWARE_DEVICE_ID,
+ (const struct hw_info **)&info);
+
+ if (ret < 0) {
+ // access(EXTCON_PATH, R_OK)?
+ cout << "Fail to load extcon hal(" << ret << ")" << endl;
+ assert(true);
+ return;
+ }
+ if (!info->open) {
+ cout << "Failed to open extcon device; open(NULL)" << endl;
+ assert(true);
+ return;
+ }
+
+ ret = info->open(info, NULL, (struct hw_common**)&ext_dev);
+ if (ret < 0 || !ext_dev) {
+ cout << "Failed to get extcon device structure (" << ret << ")" << endl;
+ assert(true);
+ return;
+ }
+
+ return;
+ }
+
+ virtual void TearDown()
+ {
+ struct hw_info *info;
+
+ info = ext_dev->common.info;
+ if (!info)
+ free(ext_dev);
+ else
+ info->close((struct hw_common *)ext_dev);
+ ext_dev = NULL;
+
+ return;
+ }
+};
+
+/*
+ * testcase
+ */
+TEST_F(EXTCONHalTest, InitP)
+{
+ EXPECT_NE(ext_dev, nullptr);
+}
+
+TEST_F(EXTCONHalTest, DeinitP)
+{
+ struct external_connection_device *tmp;
+ struct hw_info *info;
+ int ret;
+
+ hw_get_info(EXTERNAL_CONNECTION_HARDWARE_DEVICE_ID,
+ (const struct hw_info **)&info);
+
+ EXPECT_NE(info, nullptr);
+ if (!info->open || !info->close)
+ return;
+ info->open(info, NULL, (struct hw_common**)&tmp);
+
+ ret = info->close((struct hw_common *)tmp);
+ EXPECT_EQ(ret, 0);
+}
+
+static void updated_cb(struct connection_info *info, void *data)
+{
+}
+
+TEST_F(EXTCONHalTest, RegisterChangedEventP)
+{
+ int ret;
+
+ EXPECT_NE(ext_dev, nullptr);
+ if (!ext_dev->register_changed_event)
+ return;
+ ret = ext_dev->register_changed_event(updated_cb, NULL);
+ ext_dev->unregister_changed_event(updated_cb);
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(EXTCONHalTest, UnregisterChangedEventP)
+{
+ EXPECT_NE(ext_dev, nullptr);
+ if (!ext_dev->unregister_changed_event)
+ return;
+ ext_dev->register_changed_event(updated_cb, NULL);
+ ext_dev->unregister_changed_event(updated_cb);
+}
+
+TEST_F(EXTCONHalTest, GetCurrentStateP)
+{
+ int ret;
+
+ EXPECT_NE(ext_dev, nullptr);
+ if (!ext_dev->get_current_state)
+ return;
+ ret = ext_dev->get_current_state(updated_cb, NULL);
+ EXPECT_EQ(ret, 0);
+}
+
+int main(int argc, char **argv)
+{
+ testing::InitGoogleTest(&argc, argv);
+
+ return RUN_ALL_TESTS();
+}
diff --git a/unittest/gtest_hal_touchscreen.cpp b/unittest/gtest_hal_touchscreen.cpp
new file mode 100644
index 0000000..07cf6dc
--- /dev/null
+++ b/unittest/gtest_hal_touchscreen.cpp
@@ -0,0 +1,85 @@
+
+#include <iostream>
+#include <gtest/gtest.h>
+#include "hw/common.h"
+#include "hw/touchscreen.h"
+
+using namespace std;
+
+/*
+ * main class
+ */
+struct touchscreen_device *touchscreen_dev;
+
+class TOUCHSCREENHalTest : public testing::Test
+{
+ public:
+ virtual void SetUp()
+ {
+ struct hw_info *info;
+ int ret;
+ ret = hw_get_info(TOUCHSCREEN_HARDWARE_DEVICE_ID,
+ (const struct hw_info **)&info);
+
+ if (ret < 0) {
+ cout << "Fail to load touchscreen hal(" << ret << ")" << endl;
+ assert(true);
+ return;
+ }
+ if (!info->open) {
+ cout << "Failed to open touchscreen device; open(NULL)" << endl;
+ assert(true);
+ return;
+ }
+
+ ret = info->open(info, NULL, (struct hw_common**)&touchscreen_dev);
+ if (ret < 0 || !touchscreen_dev) {
+ cout << "Failed to get touchscreen device structure (" << ret << ")" << endl;
+ assert(true);
+ return;
+ }
+
+ return;
+ }
+
+ virtual void TearDown()
+ {
+ struct hw_info *info;
+
+ info = touchscreen_dev->common.info;
+ if (!info)
+ free(touchscreen_dev);
+ else
+ info->close((struct hw_common *)touchscreen_dev);
+ touchscreen_dev = NULL;
+
+ return;
+ }
+};
+
+/*
+ * testcase
+ */
+TEST_F(TOUCHSCREENHalTest, InitP)
+{
+ EXPECT_NE(touchscreen_dev, nullptr);
+}
+
+TEST_F(TOUCHSCREENHalTest, SetstateP)
+{
+ enum touchscreen_state state = TOUCHSCREEN_ON;
+ int ret;
+
+ EXPECT_NE(touchscreen_dev, nullptr);
+ if (!touchscreen_dev->set_state)
+ return;
+ ret = touchscreen_dev->set_state(state);
+ EXPECT_EQ(ret, 0) << "Failed to enable touchscreen (" << ret << ")";
+}
+
+int main(int argc, char **argv)
+{
+ testing::InitGoogleTest(&argc, argv);
+
+ return RUN_ALL_TESTS();
+}