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 "pin_auth_service_test.h"
17
18 #include "accesstoken_kit.h"
19 #include "nativetoken_kit.h"
20 #include "token_setproc.h"
21
22 #include "iam_ptr.h"
23 #include "mock_inputer_get_data.h"
24 #include "pin_auth_service.h"
25
26 namespace OHOS {
27 namespace UserIam {
28 namespace PinAuth {
29 using namespace testing;
30 using namespace testing::ext;
31
SetUpTestCase()32 void PinAuthServiceTest::SetUpTestCase()
33 {
34 static const char *PERMS[] = {
35 "ohos.permission.ACCESS_PIN_AUTH"
36 };
37 NativeTokenInfoParams infoInstance = {
38 .dcapsNum = 0,
39 .permsNum = 1,
40 .aclsNum = 0,
41 .dcaps = nullptr,
42 .perms = PERMS,
43 .acls = nullptr,
44 .processName = "pin_auth_service_test",
45 .aplStr = "system_core",
46 };
47 uint64_t tokenId = GetAccessTokenId(&infoInstance);
48 SetSelfTokenID(tokenId);
49 Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
50 }
51
TearDownTestCase()52 void PinAuthServiceTest::TearDownTestCase()
53 {
54 }
55
SetUp()56 void PinAuthServiceTest::SetUp()
57 {
58 }
59
TearDown()60 void PinAuthServiceTest::TearDown()
61 {
62 }
63
64 HWTEST_F(PinAuthServiceTest, PinAuthServiceTest001, TestSize.Level0)
65 {
66 auto service = Common::MakeShared<PinAuthService>();
67 EXPECT_NE(service, nullptr);
68 sptr<InputerGetData> testInputerGetData = nullptr;
69 EXPECT_EQ(service->RegisterInputer(testInputerGetData), false);
70 service->UnRegisterInputer();
71 }
72
73 HWTEST_F(PinAuthServiceTest, PinAuthServiceTest002, TestSize.Level0)
74 {
75 auto service = Common::MakeShared<PinAuthService>();
76 EXPECT_NE(service, nullptr);
77 sptr<InputerGetData> testInputerGetData = new MockInputerGetData();
78 EXPECT_NE(testInputerGetData, nullptr);
79 EXPECT_EQ(service->RegisterInputer(testInputerGetData), true);
80 service->UnRegisterInputer();
81 }
82 } // namespace PinAuth
83 } // namespace UserIam
84 } // namespace OHOS
85