1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <memory>
17
18 #include "gtest/gtest.h"
19
20 #include "base/memory/referenced.h"
21 #include "base/subwindow/subwindow_manager.h"
22 #include "base/test/mock/mock_container.h"
23 #include "base/test/mock/mock_subwindow_ohos.h"
24
25 using namespace testing;
26 using namespace testing::ext;
27
28 namespace OHOS::Ace {
29 namespace {
30 const std::string TEST_STRING = "";
31 const int32_t TEST_INT_TEAM_ONE = 1;
32 const int32_t TEST_INT_TEAM_TWO = 2;
33 const int32_t TEST_INT_TEAM_THREE = 3;
34 const bool TEST_BOOL = true;
35 } // namespace
36
37 class SubwindowManagerTest : public testing::Test {
38 public:
39 static void SetUpTestCase();
40 static void TearDownTestCase();
41 void SetUp() override;
42 void TearDown() override;
43 };
44
SetUpTestCase()45 void SubwindowManagerTest::SetUpTestCase()
46 {
47 GTEST_LOG_(INFO) << "SubwindowManagerTest SetUpTestCase";
48 }
49
TearDownTestCase()50 void SubwindowManagerTest::TearDownTestCase()
51 {
52 GTEST_LOG_(INFO) << "SubwindowManagerTest TearDownTestCase";
53 }
54
SetUp()55 void SubwindowManagerTest::SetUp()
56 {
57 GTEST_LOG_(INFO) << "SubwindowManagerTest SetUp";
58 }
59
TearDown()60 void SubwindowManagerTest::TearDown()
61 {
62 GTEST_LOG_(INFO) << "SubwindowManagerTest TearDown";
63 }
64
65 /**
66 * @tc.name: Subwindow_Manager_ShowToast_001
67 * @tc.desc: Call ShowToast interface when Subwindow is null.
68 * @tc.type: FUNC
69 * @tc.require: RM017
70 * @tc.author: Wutm
71 */
72 HWTEST_F(SubwindowManagerTest, Subwindow_Manager_ShowToast_001, TestSize.Level1)
73 {
74 Container::SetCurrentId(TEST_INT_TEAM_ONE);
75 std::shared_ptr<SubwindowManager> subwindow = SubwindowManager::GetInstance();
76 subwindow->ShowToast(TEST_STRING, TEST_INT_TEAM_ONE, TEST_STRING);
77 auto resultPtr = subwindow->GetDialogSubwindow(TEST_INT_TEAM_ONE);
78 ASSERT_TRUE(resultPtr != nullptr);
79 }
80
81 /**
82 * @tc.name: Subwindow_Manager_ShowToast_002
83 * @tc.desc: Call ShowToast interface when Subwindow is not null.
84 * @tc.type: FUNC
85 * @tc.require: RM017
86 * @tc.author: Wutm
87 */
88 HWTEST_F(SubwindowManagerTest, Subwindow_Manager_ShowToast_002, TestSize.Level1)
89 {
90 std::shared_ptr<SubwindowManager> subwindow = SubwindowManager::GetInstance();
91 subwindow->ShowToast(TEST_STRING, TEST_INT_TEAM_ONE, TEST_STRING);
92 auto resultPtr = subwindow->GetDialogSubwindow(TEST_INT_TEAM_ONE);
93 ASSERT_TRUE(resultPtr != nullptr);
94 }
95
96 /**
97 * @tc.name: Subwindow_Manager_ShowDialog_001
98 * @tc.desc: Call ShowDialog interface when Subwindow is null.
99 * @tc.type: FUNC
100 * @tc.require: RM017
101 * @tc.author: Wutm
102 */
103 HWTEST_F(SubwindowManagerTest, Subwindow_Manager_ShowDialog_001, TestSize.Level1)
104 {
105 Container::SetCurrentId(TEST_INT_TEAM_TWO);
106 std::shared_ptr<SubwindowManager> subwindow = SubwindowManager::GetInstance();
107 std::vector<ButtonInfo> buttons;
108 std::set<std::string> callbacks;
__anon78e86fdd0202(int32_t callbackType, int32_t successType) 109 auto callback = [](int32_t callbackType, int32_t successType) {};
110 subwindow->ShowDialog(TEST_STRING, TEST_STRING, buttons, TEST_BOOL, callback, callbacks);
111 auto resultPtr = subwindow->GetDialogSubwindow(TEST_INT_TEAM_TWO);
112 ASSERT_TRUE(resultPtr != nullptr);
113 }
114
115 /**
116 * @tc.name: Subwindow_Manager_ShowDialog_002
117 * @tc.desc: Call ShowDialog interface when Subwindow is not null.
118 * @tc.type: FUNC
119 * @tc.require: RM017
120 * @tc.author: Wutm
121 */
122 HWTEST_F(SubwindowManagerTest, Subwindow_Manager_ShowDialog_002, TestSize.Level1)
123 {
124 std::shared_ptr<SubwindowManager> subwindow = SubwindowManager::GetInstance();
125 std::vector<ButtonInfo> buttons;
126 std::set<std::string> callbacks;
__anon78e86fdd0302(int32_t callbackType, int32_t successType) 127 auto callback = [](int32_t callbackType, int32_t successType) {};
128 subwindow->ShowDialog(TEST_STRING, TEST_STRING, buttons, TEST_BOOL, callback, callbacks);
129 auto resultPtr = subwindow->GetDialogSubwindow(TEST_INT_TEAM_TWO);
130 ASSERT_TRUE(resultPtr != nullptr);
131 }
132
133 /**
134 * @tc.name: Subwindow_Manager_ShowActionMenu_001
135 * @tc.desc: Call ShowActionMenu interface when Subwindow is null.
136 * @tc.type: FUNC
137 * @tc.require: RM017
138 * @tc.author: Wutm
139 */
140 HWTEST_F(SubwindowManagerTest, Subwindow_Manager_ShowActionMenu_001, TestSize.Level1)
141 {
142 Container::SetCurrentId(TEST_INT_TEAM_THREE);
143 std::shared_ptr<SubwindowManager> subwindow = SubwindowManager::GetInstance();
144 std::vector<ButtonInfo> buttons;
__anon78e86fdd0402(int32_t callbackType, int32_t successType) 145 auto callback = [](int32_t callbackType, int32_t successType) {};
146 subwindow->ShowActionMenu(TEST_STRING, buttons, callback);
147 auto resultPtr = subwindow->GetDialogSubwindow(TEST_INT_TEAM_THREE);
148 ASSERT_TRUE(resultPtr != nullptr);
149 }
150
151 /**
152 * @tc.name: Subwindow_Manager_ShowActionMenu_002
153 * @tc.desc: Call ShowActionMenu interface when Subwindow is null.
154 * @tc.type: FUNC
155 * @tc.require: RM017
156 * @tc.author: Wutm
157 */
158 HWTEST_F(SubwindowManagerTest, Subwindow_Manager_ShowActionMenu_002, TestSize.Level1)
159 {
160 std::shared_ptr<SubwindowManager> subwindow = SubwindowManager::GetInstance();
161 std::vector<ButtonInfo> buttons;
__anon78e86fdd0502(int32_t callbackType, int32_t successType) 162 auto callback = [](int32_t callbackType, int32_t successType) {};
163 subwindow->ShowActionMenu(TEST_STRING, buttons, callback);
164 auto resultPtr = subwindow->GetDialogSubwindow(TEST_INT_TEAM_THREE);
165 ASSERT_TRUE(resultPtr != nullptr);
166 }
167 } // namespace OHOS::Ace
168