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 "ipc_common.h"
17 #include "widget_schedule_node_impl.h"
18 
19 #include <future>
20 #include "iam_check.h"
21 #include "widget_json.h"
22 #include "widget_callback_interface.h"
23 
24 #include "mock_authentication.h"
25 #include "mock_context.h"
26 #include "user_auth_service.h"
27 
28 #include "mock_resource_node.h"
29 #include "mock_schedule_node.h"
30 #include "schedule_node_impl.h"
31 #include "user_auth_callback_proxy.h"
32 #include "widget_schedule_node.h"
33 
34 
35 using namespace testing;
36 using namespace testing::ext;
37 namespace OHOS {
38 namespace UserIam {
39 namespace UserAuth {
40 constexpr int32_t USER_ID_MAIN = 100;
41 constexpr int32_t USER_TYPE_PRIVATE = 2;
42 
43 class IpcCommonTest : public testing::Test {
44 public:
45     static void SetUpTestCase();
46 
47     static void TearDownTestCase();
48 
49     void SetUp() override;
50 
51     void TearDown() override;
52 };
53 
SetUpTestCase()54 void IpcCommonTest::SetUpTestCase()
55 {
56 }
57 
TearDownTestCase()58 void IpcCommonTest::TearDownTestCase()
59 {
60 }
61 
SetUp()62 void IpcCommonTest::SetUp()
63 {
64 }
65 
TearDown()66 void IpcCommonTest::TearDown()
67 {
68 }
69 
70 HWTEST_F(IpcCommonTest, IpcCommonTestGetTokenId, TestSize.Level0)
71 {
72     UserAuthService service;
73     service.Notice(NoticeType::WIDGET_NOTICE, "PIN");
74     EXPECT_NE(IpcCommon::GetTokenId(service), (uint32_t)0);
75 }
76 
77 HWTEST_F(IpcCommonTest, IpcCommonTestGetUserTypeByUserId, TestSize.Level0)
78 {
79     int32_t userType = USER_TYPE_PRIVATE;
80     EXPECT_EQ(IpcCommon::GetUserTypeByUserId(USER_ID_MAIN, userType), SUCCESS);
81     EXPECT_NE(userType, USER_TYPE_PRIVATE);
82 }
83 } // namespace UserAuth
84 } // namespace UserIam
85 } // namespace OHOS