1 /*
2 * Copyright (C) 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 "pin_db_ops_test.h"
17
18 #include "adaptor_memory.h"
19 #include "pin_db_ops.h"
20 #include "securec.h"
21
22 namespace OHOS {
23 namespace UserIam {
24 namespace PinAuth {
25 using namespace testing;
26 using namespace testing::ext;
27
SetUpTestCase()28 void PinDataOpsTest::SetUpTestCase()
29 {
30 }
31
TearDownTestCase()32 void PinDataOpsTest::TearDownTestCase()
33 {
34 }
35
SetUp()36 void PinDataOpsTest::SetUp()
37 {
38 }
39
TearDown()40 void PinDataOpsTest::TearDown()
41 {
42 }
43
44 /**
45 * @tc.name: GetPinDbV1 test
46 * @tc.desc: verify GetPinDbV1
47 * @tc.type: FUNC
48 * @tc.require: #I7SPE1
49 */
50 HWTEST_F(PinDataOpsTest, ReadPinDb_test, TestSize.Level1)
51 {
52 PinDbV1 *result = ReadPinDb();
53 EXPECT_NE(result, nullptr);
54 }
55
56 /**
57 * @tc.name: WritePinDb test
58 * @tc.desc: verify WritePinDb
59 * @tc.type: FUNC
60 * @tc.require: #I7SPE1
61 */
62 HWTEST_F(PinDataOpsTest, WritePinDb_test, TestSize.Level1)
63 {
64 PinDbV1 *pinDbV1 = (PinDbV1 *)Malloc(sizeof(PinDbV1));
65 EXPECT_NE(pinDbV1, NULL);
66
67 pinDbV1->dbVersion = 0;
68 pinDbV1->pinIndexLen = 1;
69 pinDbV1->pinIndex = (PinIndexV1 *)Malloc(sizeof(PinIndexV1) * pinDbV1->pinIndexLen);
70 EXPECT_NE(pinDbV1->pinIndex, NULL);
71 pinDbV1->pinIndex[0].pinInfo.algoVersion = 1;
72 pinDbV1->pinIndex[0].pinInfo.templateId = 123;
73 pinDbV1->pinIndex[0].pinInfo.subType = 10010;
74
75 ResultCode result = WritePinDb(NULL);
76 EXPECT_EQ(result, RESULT_BAD_PARAM);
77 result = WritePinDb(pinDbV1);
78 EXPECT_EQ(result, RESULT_BAD_PARAM);
79 pinDbV1->dbVersion = 1;
80 pinDbV1->pinIndexLen = 0;
81 result = WritePinDb(pinDbV1);
82 EXPECT_EQ(result, RESULT_BAD_PARAM);
83 pinDbV1->pinIndexLen = 50;
84 result = WritePinDb(pinDbV1);
85 EXPECT_EQ(result, RESULT_BAD_PARAM);
86
87 FreePinDbV1((void**)(&pinDbV1));
88 }
89 } // namespace PinAuth
90 } // namespace UserIam
91 } // namespace OHOS
92