summaryrefslogtreecommitdiff
path: root/unittest/gtest_hal_ir.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittest/gtest_hal_ir.cpp')
-rwxr-xr-x[-rw-r--r--]unittest/gtest_hal_ir.cpp105
1 files changed, 55 insertions, 50 deletions
diff --git a/unittest/gtest_hal_ir.cpp b/unittest/gtest_hal_ir.cpp
index 144a4c0..4b77f20 100644..100755
--- a/unittest/gtest_hal_ir.cpp
+++ b/unittest/gtest_hal_ir.cpp
@@ -1,59 +1,36 @@
#include <iostream>
#include <gtest/gtest.h>
-#include "hw/common.h"
+#include <system_info.h>
#include "hw/ir.h"
+#include "unittest.h"
using namespace std;
/*
* main class
*/
+struct hw_info *info;
struct ir_device *ir_dev;
+static bool need_featurecheck = true;
class IRHalTest : public testing::Test
{
public:
virtual void SetUp()
{
- struct hw_info *info;
int ret;
- ret = hw_get_info(IR_HARDWARE_DEVICE_ID,
- (const struct hw_info **)&info);
- if (ret < 0) {
- cout << "Fail to load ir hal(" << ret << ")" << endl;
- assert(true);
- return;
+ if (need_featurecheck) {
+ ret = system_info_get_platform_bool(FEATURE_IR, &supported);
+ EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed";
+ need_featurecheck = false;
}
- if (!info->open) {
- cout << "Failed to open ir device; open(NULL)" << endl;
- assert(true);
- return;
- }
-
- ret = info->open(info, NULL, (struct hw_common**)&ir_dev);
- if (ret < 0 || !ir_dev) {
- cout << "Failed to get ir device structure (" << ret << ")" << endl;
- assert(true);
- return;
- }
-
- return;
}
virtual void TearDown()
{
- struct hw_info *info;
-
- info = ir_dev->common.info;
- if (!info)
- free(ir_dev);
- else
- info->close((struct hw_common *)ir_dev);
- ir_dev = NULL;
- return;
}
};
@@ -62,40 +39,68 @@ class IRHalTest : public testing::Test
*/
TEST_F(IRHalTest, InitP)
{
- EXPECT_NE(ir_dev, nullptr);
-}
-
-TEST_F(IRHalTest, DeinitP)
-{
- struct ir_device *tmp;
- struct hw_info *info;
int ret;
- hw_get_info(IR_HARDWARE_DEVICE_ID,
- (const struct hw_info **)&info);
-
- EXPECT_NE(info, nullptr);
- EXPECT_NE(info->open, nullptr);
- info->open(info, NULL, (struct hw_common**)&tmp);
+ if (!supported)
+ return;
- ret = info->close((struct hw_common *)tmp);
- EXPECT_EQ(ret, 0);
+ ret = hw_get_info(IR_HARDWARE_DEVICE_ID,
+ (const struct hw_info **)&info);
+ EXPECT_EQ(ret, 0) << "Fail to get hal for ir (" << ret << ")";
+
+ if (!info->open) {
+ cout << "There is no function for info open" << endl;
+ return;
+ }
+ ret = info->open(info, NULL, (struct hw_common**)&ir_dev);
+ EXPECT_EQ(ret, 0) << "Fail to open ir device (" << ret << ")";
}
TEST_F(IRHalTest, IsAvailableP)
{
+ int ret;
bool val;
- EXPECT_NE(ir_dev, nullptr);
- ir_dev->is_available(&val);
+ if (!supported)
+ return;
+
+ if (!ir_dev->is_available) {
+ cout << "There is no function for is_available" << endl;
+ return;
+ }
+ ret = ir_dev->is_available(&val);
+ EXPECT_EQ(ret, 0) << "Fail to is_available (" << ret << ")";
}
TEST_F(IRHalTest, TransmitP)
{
+ int ret;
int pattern[5] = {100, 200, 300, 400, 500};
- EXPECT_NE(ir_dev, nullptr);
- ir_dev->transmit(pattern, 5);
+ if (!supported)
+ return;
+
+ if (!ir_dev->transmit) {
+ cout << "There is no function for transmit" << endl;
+ return;
+ }
+ ret = ir_dev->transmit(pattern, 5);
+ EXPECT_EQ(ret, 0) << "Fail to transmit (" << ret << ")";
+}
+
+TEST_F(IRHalTest, 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 *)ir_dev);
+ EXPECT_EQ(ret, 0) << "Fail to close ir device (" << ret << ")";
}
int main(int argc, char **argv)