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: DatabaseTranslationTest002
47 * @tc.desc: test TranslationIntoPermissionStatus
48 * @tc.type: FUNC
49 * @tc.require:
50 */
51 HWTEST_F(AccessTokenDatabaseTest, DatabaseConverage002, TestSize.Level4)
52 {
53 DataTranslator trans;
54 GenericValues inGenericValues;
55 PermissionStatus outPermissionState;
56 outPermissionState.permissionName = ""; // empty name
57
58 EXPECT_EQ(ERR_PARAM_INVALID, trans.TranslationIntoPermissionStatus(inGenericValues, outPermissionState));
59
60 outPermissionState.permissionName = "test name"; // test name
61 inGenericValues.Put(TokenFiledConst::FIELD_DEVICE_ID, ""); // empty device id
62 EXPECT_EQ(ERR_PARAM_INVALID, trans.TranslationIntoPermissionStatus(inGenericValues, outPermissionState));
63
64 inGenericValues.Put(TokenFiledConst::FIELD_DEVICE_ID, "test dev id");
65 inGenericValues.Put(TokenFiledConst::FIELD_GRANT_FLAG, 0xffff); // 0xffff is test input
66 EXPECT_EQ(ERR_PARAM_INVALID, trans.TranslationIntoPermissionStatus(inGenericValues, outPermissionState));
67 }
68
69 } // namespace AccessToken
70 } // namespace Security
71 } // namespace OHOS
72