1 /*
2 * Copyright (C) 2023 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 "widget_callback_service_test.h"
17
18 #include "iam_ptr.h"
19 #include "widget_callback_service.h"
20 #include "mock_iuser_auth_widget_callback.h"
21
22 namespace OHOS {
23 namespace UserIam {
24 namespace UserAuth {
25 using namespace testing;
26 using namespace testing::ext;
27
SetUpTestCase()28 void WidgetCallbackServiceTest::SetUpTestCase()
29 {
30 }
31
TearDownTestCase()32 void WidgetCallbackServiceTest::TearDownTestCase()
33 {
34 }
35
SetUp()36 void WidgetCallbackServiceTest::SetUp()
37 {
38 }
39
TearDown()40 void WidgetCallbackServiceTest::TearDown()
41 {
42 }
43
44 HWTEST_F(WidgetCallbackServiceTest, WidgetCallbackServiceSendCommand001, TestSize.Level0)
45 {
46 std::shared_ptr<IUserAuthWidgetCallback> impl = nullptr;
47 auto service = Common::MakeShared<WidgetCallbackService>(impl);
48
49 std::string cmdData = "cmd";
50 service->SendCommand(cmdData);
51 EXPECT_NE(service, nullptr);
52 }
53
54 HWTEST_F(WidgetCallbackServiceTest, WidgetCallbackServiceSendCommand002, TestSize.Level0)
55 {
56 std::string testData = "cmd";
57 auto widgetCallback = Common::MakeShared<MockIUserAuthWidgetCallback>();
58 EXPECT_NE(widgetCallback, nullptr);
59 EXPECT_CALL(*widgetCallback, SendCommand(_)).Times(1);
60 ON_CALL(*widgetCallback, SendCommand)
61 .WillByDefault(
__anone8f603c50102(const std::string &cmdData) 62 [&testData](const std::string &cmdData) {
63 EXPECT_EQ(cmdData, testData);
64 }
65 );
66
67 auto service = Common::MakeShared<WidgetCallbackService>(widgetCallback);
68 EXPECT_NE(service, nullptr);
69 service->SendCommand(testData);
70 }
71 } // namespace UserAuth
72 } // namespace UserIam
73 } // namespace OHOS