• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "gtest/gtest.h"
17 
18 #include "accesstoken_kit.h"
19 #include "message_parcel.h"
20 #include "nativetoken_kit.h"
21 #include "token_setproc.h"
22 
23 #include "face_auth_service.h"
24 
25 using namespace testing;
26 using namespace testing::ext;
27 
28 namespace OHOS {
29 namespace UserIam {
30 namespace FaceAuth {
31 class FaceAuthServiceTest : public testing::Test {
32 public:
33     static void SetUpTestCase();
34     static void TearDownTestCase();
35     void SetUp();
36     void TearDown();
37 };
38 
SetUpTestCase()39 void FaceAuthServiceTest::SetUpTestCase()
40 {
41     static const char *PERMS[] = {
42         "ohos.permission.MANAGE_USER_IDM"
43     };
44     NativeTokenInfoParams infoInstance = {
45         .dcapsNum = 0,
46         .permsNum = 1,
47         .aclsNum = 0,
48         .dcaps = nullptr,
49         .perms = PERMS,
50         .acls = nullptr,
51         .processName = "face_auth_service_test",
52         .aplStr = "system_core",
53     };
54     uint64_t tokenId = GetAccessTokenId(&infoInstance);
55     SetSelfTokenID(tokenId);
56     Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
57 }
58 
TearDownTestCase()59 void FaceAuthServiceTest::TearDownTestCase()
60 {
61 }
62 
SetUp()63 void FaceAuthServiceTest::SetUp()
64 {
65 }
66 
TearDown()67 void FaceAuthServiceTest::TearDown()
68 {
69 }
70 
71 HWTEST_F(FaceAuthServiceTest, FaceAuthServiceTest_001, TestSize.Level0)
72 {
73     auto service = FaceAuthService::GetInstance();
74     EXPECT_NE(service, nullptr);
75     service->OnStart();
76     sptr<IBufferProducer> producer = nullptr;
77     int32_t ret = service->SetBufferProducer(producer);
78     EXPECT_EQ(ret, FACE_AUTH_ERROR);
79 }
80 
81 HWTEST_F(FaceAuthServiceTest, FaceAuthServiceTest_002, TestSize.Level0)
82 {
83     MessageParcel data;
84     MessageParcel reply;
85     MessageOption option(MessageOption::TF_SYNC);
86     uint32_t code = IFaceAuth::FACE_AUTH_SET_BUFFER_PRODUCER;
87 
88     auto service = FaceAuthService::GetInstance();
89     EXPECT_NE(service, nullptr);
90     service->OnStart();
91     EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), 1);
92     EXPECT_TRUE(data.WriteInterfaceToken(IFaceAuth::GetDescriptor()));
93     EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), 0);
94     int32_t result = -1;
95     EXPECT_TRUE(reply.ReadInt32(result));
96     EXPECT_EQ(result, FACE_AUTH_ERROR);
97 }
98 } // namespace FaceAuth
99 } // namespace UserIam
100 } // namespace OHOS
101