Add unit tests for watch control API 19/283619/2
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 31 Oct 2022 10:32:41 +0000 (10:32 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 31 Oct 2022 10:39:35 +0000 (10:39 +0000)
To refactor watch control API, unit tests are added

Change-Id: If1517e2d70e90f65897165430acbcde010e82a08
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
test/unit_tests/test_watch_control.cc [new file with mode: 0644]

diff --git a/test/unit_tests/test_watch_control.cc b/test/unit_tests/test_watch_control.cc
new file mode 100644 (file)
index 0000000..84721e1
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <aul.h>
+#include <aul_watch_control.h>
+#include <gtest/gtest.h>
+
+namespace {
+
+void WatchControlCb(bundle* b, void* user_data) {}
+
+}  // namespace
+
+class WatchControlTest : public ::testing::Test {
+ public:
+  WatchControlTest() {}
+
+  virtual void SetUp() {
+    int ret = aul_watch_control_add_handler(WatchControlCb, nullptr,
+        &remove_handler_);
+    EXPECT_EQ(ret, AUL_R_OK);
+    EXPECT_NE(remove_handler_, nullptr);
+  }
+
+  virtual void TearDown() {
+    aul_watch_control_remove_handler(add_handler_);
+    add_handler_ = nullptr;
+    aul_watch_control_remove_handler(remove_handler_);
+    remove_handler_ = nullptr;
+  }
+
+  aul_watch_control_h add_handler_ = nullptr;
+  aul_watch_control_h remove_handler_ = nullptr;
+};
+
+TEST_F(WatchControlTest, aul_watch_control_add_handler_P) {
+  int ret = aul_watch_control_add_handler(WatchControlCb, nullptr,
+      &add_handler_);
+  EXPECT_EQ(ret, AUL_R_OK);
+  EXPECT_NE(add_handler_, nullptr);
+}
+
+TEST_F(WatchControlTest, aul_watch_control_add_handler_N) {
+  int ret = aul_watch_control_add_handler(nullptr, nullptr,
+      &add_handler_);
+  EXPECT_EQ(ret, AUL_R_EINVAL);
+
+  ret = aul_watch_control_add_handler(WatchControlCb, nullptr, nullptr);
+  EXPECT_EQ(ret, AUL_R_EINVAL);
+}
+
+TEST_F(WatchControlTest, aul_watch_control_remove_handler_P) {
+  int ret = aul_watch_control_remove_handler(remove_handler_);
+  EXPECT_EQ(ret, AUL_R_OK);
+  remove_handler_ = nullptr;
+}
+
+TEST_F(WatchControlTest, aul_watch_control_remove_handler_N) {
+  int ret = aul_watch_control_remove_handler(nullptr);
+  EXPECT_EQ(ret, AUL_R_EINVAL);
+
+  aul_watch_control_remove_handler(remove_handler_);
+  ret = aul_watch_control_remove_handler(remove_handler_);
+  EXPECT_EQ(ret, AUL_R_EINVAL);
+  remove_handler_ = nullptr;
+}