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 25using namespace testing; 26using namespace testing::ext; 27 28namespace OHOS { 29namespace UserIam { 30namespace FaceAuth { 31class FaceAuthServiceTest : public testing::Test { 32public: 33 static void SetUpTestCase(); 34 static void TearDownTestCase(); 35 void SetUp(); 36 void TearDown(); 37}; 38 39void 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 57void FaceAuthServiceTest::TearDownTestCase() 58{ 59} 60 61void FaceAuthServiceTest::SetUp() 62{ 63} 64 65void FaceAuthServiceTest::TearDown() 66{ 67} 68 69HWTEST_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 78HWTEST_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