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 <gtest/gtest.h>
17 
18 #include "securec.h"
19 
20 #include "adaptor_memory.h"
21 #include "idm_common.h"
22 
23 namespace OHOS {
24 namespace UserIam {
25 namespace UserAuth {
26 using namespace testing;
27 using namespace testing::ext;
28 
29 class IdmCommonTest : public testing::Test {
30 public:
SetUpTestCase()31     static void SetUpTestCase() {};
32 
TearDownTestCase()33     static void TearDownTestCase() {};
34 
SetUp()35     void SetUp() {};
36 
TearDown()37     void TearDown() {};
38 };
39 
40 HWTEST_F(IdmCommonTest, TestDestroyUserInfoNode, TestSize.Level0)
41 {
42     DestroyUserInfoNode(nullptr);
43     UserInfo *node = (UserInfo *)Malloc(sizeof(UserInfo));
44     EXPECT_NE(node, nullptr);
45     ASSERT_NE(node, nullptr);
46     (void)memset_s(node, sizeof(UserInfo), 0, sizeof(UserInfo));
47     DestroyUserInfoNode(node);
48 }
49 
50 HWTEST_F(IdmCommonTest, TestDestroyCredentialNode, TestSize.Level0)
51 {
52     DestroyCredentialNode(nullptr);
53     CredentialInfoHal *credentialInfoHal = (CredentialInfoHal *)Malloc(sizeof(CredentialInfoHal));
54     EXPECT_NE(credentialInfoHal, nullptr);
55     ASSERT_NE(credentialInfoHal, nullptr);
56     (void)memset_s(credentialInfoHal, sizeof(CredentialInfoHal), 0, sizeof(CredentialInfoHal));
57     DestroyCredentialNode(credentialInfoHal);
58 }
59 
60 HWTEST_F(IdmCommonTest, TestDestroyEnrolledNode, TestSize.Level0)
61 {
62     DestroyEnrolledNode(nullptr);
63     EnrolledInfoHal *enrolledInfoHal = (EnrolledInfoHal *)Malloc(sizeof(EnrolledInfoHal));
64     EXPECT_NE(enrolledInfoHal, nullptr);
65     ASSERT_NE(enrolledInfoHal, nullptr);
66     (void)memset_s(enrolledInfoHal, sizeof(EnrolledInfoHal), 0, sizeof(EnrolledInfoHal));
67     DestroyEnrolledNode(enrolledInfoHal);
68 }
69 } // namespace UserAuth
70 } // namespace UserIam
71 } // namespace OHOS
72