1 /*
2  * Copyright (c) 2024 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 "accesstoken_database_test.h"
17 #include "gtest/gtest.h"
18 
19 #include "access_token_error.h"
20 #include "data_translator.h"
21 #include "token_field_const.h"
22 
23 using namespace testing::ext;
24 using namespace OHOS;
25 
26 namespace OHOS {
27 namespace Security {
28 namespace AccessToken {
SetUpTestCase()29 void AccessTokenDatabaseTest::SetUpTestCase()
30 {
31 }
32 
TearDownTestCase()33 void AccessTokenDatabaseTest::TearDownTestCase()
34 {
35 }
36 
SetUp()37 void AccessTokenDatabaseTest::SetUp()
38 {
39 }
40 
TearDown()41 void AccessTokenDatabaseTest::TearDown()
42 {
43 }
44 
45 /**
46  * @tc.name: DatabaseTranslationTest001
47  * @tc.desc: test TranslationIntoGenericValues
48  * @tc.type: FUNC
49  * @tc.require:
50  */
51 HWTEST_F(AccessTokenDatabaseTest, DatabaseTranslationTest001, TestSize.Level1)
52 {
53     DataTranslator trans;
54     PermissionStateFull inPermissionDef;
55     inPermissionDef.resDeviceID.resize(0); // 0 is the size
56 
57     unsigned int grantIndex = 1; // 1 is a test input
58     GenericValues outGenericValues;
59 
60     EXPECT_EQ(ERR_PARAM_INVALID, trans.TranslationIntoGenericValues(inPermissionDef, grantIndex, outGenericValues));
61 }
62 
63 /**
64  * @tc.name: DatabaseTranslationTest002
65  * @tc.desc: test TranslationIntoPermissionStateFull
66  * @tc.type: FUNC
67  * @tc.require:
68  */
69 HWTEST_F(AccessTokenDatabaseTest, DatabaseConverage002, TestSize.Level1)
70 {
71     DataTranslator trans;
72     GenericValues inGenericValues;
73     PermissionStateFull outPermissionState;
74     outPermissionState.permissionName = ""; // empty name
75 
76     EXPECT_EQ(ERR_PARAM_INVALID, trans.TranslationIntoPermissionStateFull(inGenericValues, outPermissionState));
77 
78     outPermissionState.permissionName = "test name"; // test name
79     inGenericValues.Put(TokenFiledConst::FIELD_DEVICE_ID, ""); // empty device id
80     EXPECT_EQ(ERR_PARAM_INVALID, trans.TranslationIntoPermissionStateFull(inGenericValues, outPermissionState));
81 
82     inGenericValues.Put(TokenFiledConst::FIELD_DEVICE_ID, "test dev id");
83     inGenericValues.Put(TokenFiledConst::FIELD_GRANT_FLAG, 0xffff); // 0xffff is test input
84     EXPECT_EQ(ERR_PARAM_INVALID, trans.TranslationIntoPermissionStateFull(inGenericValues, outPermissionState));
85 }
86 
87 } // namespace AccessToken
88 } // namespace Security
89 } // namespace OHOS
90