From: Hwankyu Jhun Date: Mon, 31 Oct 2022 10:32:41 +0000 (+0000) Subject: Add unit tests for watch control API X-Git-Tag: accepted/tizen/unified/20221108.163848~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d5d29aa091cf2be76ec4b532a477b4e1ad397929;p=platform%2Fcore%2Fappfw%2Faul-1.git Add unit tests for watch control API To refactor watch control API, unit tests are added Change-Id: If1517e2d70e90f65897165430acbcde010e82a08 Signed-off-by: Hwankyu Jhun --- diff --git a/test/unit_tests/test_watch_control.cc b/test/unit_tests/test_watch_control.cc new file mode 100644 index 0000000..84721e1 --- /dev/null +++ b/test/unit_tests/test_watch_control.cc @@ -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 +#include +#include + +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; +}