1 /*
2 * Copyright (c) 2021-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 "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[] = { "ohos.permission.MANAGE_USER_IDM" };
42 NativeTokenInfoParams infoInstance = {
43 .dcapsNum = 0,
44 .permsNum = 1,
45 .aclsNum = 0,
46 .dcaps = nullptr,
47 .perms = perms,
48 .acls = nullptr,
49 .processName = "face_auth_service_test",
50 .aplStr = "system_core",
51 };
52 uint64_t tokenId = GetAccessTokenId(&infoInstance);
53 SetSelfTokenID(tokenId);
54 Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
55 }
56
TearDownTestCase()57 void FaceAuthServiceTest::TearDownTestCase()
58 {
59 }
60
SetUp()61 void FaceAuthServiceTest::SetUp()
62 {
63 }
64
TearDown()65 void FaceAuthServiceTest::TearDown()
66 {
67 }
68
69 HWTEST_F(FaceAuthServiceTest, FaceAuthServiceTest_001, TestSize.Level0)
70 {
71 auto service = FaceAuthService::GetInstance();
72 EXPECT_NE(service, nullptr);
73 sptr<IBufferProducer> producer(nullptr);
74 int32_t ret = service->SetBufferProducer(producer);
75 EXPECT_EQ(ret, FACE_AUTH_SUCCESS);
76 }
77
78 HWTEST_F(FaceAuthServiceTest, FaceAuthServiceTest_002, TestSize.Level0)
79 {
80 MessageParcel data;
81 MessageParcel reply;
82 MessageOption option(MessageOption::TF_SYNC);
83 uint32_t code = IFaceAuthInterfaceCode::FACE_AUTH_SET_BUFFER_PRODUCER;
84
85 auto service = FaceAuthService::GetInstance();
86 EXPECT_NE(service, nullptr);
87 EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), 1);
88 EXPECT_TRUE(data.WriteInterfaceToken(IFaceAuth::GetDescriptor()));
89 EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), 0);
90 int32_t result = -1;
91 EXPECT_TRUE(reply.ReadInt32(result));
92 EXPECT_EQ(result, FACE_AUTH_SUCCESS);
93 }
94 } // namespace FaceAuth
95 } // namespace UserIam
96 } // namespace OHOS
97