/* * Copyright (c) 2021-2022 Huawei Device 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 "ability_context_impl.h" #include "window.h" #include "mock_window_adapter.h" #include "singleton_mocker.h" using namespace testing; using namespace testing::ext; namespace OHOS { namespace Rosen { using Mocker = SingletonMocker; class WindowTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); virtual void SetUp() override; virtual void TearDown() override; static inline std::shared_ptr abilityContext_; }; void WindowTest::SetUpTestCase() { abilityContext_ = std::make_shared(); } void WindowTest::TearDownTestCase() { } void WindowTest::SetUp() { } void WindowTest::TearDown() { } namespace { /** * @tc.name: Create01 * @tc.desc: Create window with no WindowName and no abilityToken * @tc.type: FUNC */ HWTEST_F(WindowTest, Create01, Function | SmallTest | Level2) { sptr option = new WindowOption(); ASSERT_EQ(nullptr, Window::Create("", option)); } /** * @tc.name: Create02 * @tc.desc: Create window with WindowName and no abilityToken * @tc.type: FUNC */ HWTEST_F(WindowTest, Create02, Function | SmallTest | Level2) { std::unique_ptr m = std::make_unique(); sptr option = new WindowOption(); EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); auto window = Window::Create("WindowTest02", option); ASSERT_NE(nullptr, window); EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); ASSERT_EQ(WMError::WM_OK, window->Destroy()); } /** * @tc.name: Create03 * @tc.desc: Mock CreateWindow return WM_ERROR_SAMGR, create window with WindowName and no abilityToken * @tc.type: FUNC */ HWTEST_F(WindowTest, Create03, Function | SmallTest | Level2) { std::unique_ptr m = std::make_unique(); sptr option = new WindowOption(); EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR)); ASSERT_EQ(nullptr, Window::Create("WindowTest03", option)); } /** * @tc.name: Create06 * @tc.desc: Create window with WindowName and no option * @tc.type: FUNC */ HWTEST_F(WindowTest, Create06, Function | SmallTest | Level2) { sptr option = nullptr; ASSERT_EQ(nullptr, Window::Create("", option)); } /** * @tc.name: Find01 * @tc.desc: Find with no name * @tc.type: FUNC */ HWTEST_F(WindowTest, Find01, Function | SmallTest | Level2) { ASSERT_EQ(nullptr, Window::Find("")); } /** * @tc.name: Find02 * @tc.desc: Find with name * @tc.type: FUNC */ HWTEST_F(WindowTest, Find02, Function | SmallTest | Level2) { std::unique_ptr m = std::make_unique(); sptr option = new WindowOption(); EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); auto window = Window::Create("WindowTest03", option); ASSERT_NE(nullptr, window); ASSERT_NE(nullptr, Window::Find("WindowTest03")); EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); ASSERT_EQ(WMError::WM_OK, window->Destroy()); } } } // namespace Rosen } // namespace OHOS