1 /*
2 * Copyright (c) 2025 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_manager_service_test.h"
17 #include "gtest/gtest.h"
18
19 #include "parameters.h"
20 #include "accesstoken_manager_service.h"
21 #include "access_token_error.h"
22 #include "atm_tools_param_info_parcel.h"
23 const char* DEVELOPER_MODE_STATE = "const.security.developermode.state";
24
25
26 using namespace testing::ext;
27 using namespace OHOS;
28
29 namespace OHOS {
30 namespace Security {
31 namespace AccessToken {
SetUpTestCase()32 void AccessTokenManagerServiceTest::SetUpTestCase()
33 {
34 }
35
TearDownTestCase()36 void AccessTokenManagerServiceTest::TearDownTestCase()
37 {
38 }
39
SetUp()40 void AccessTokenManagerServiceTest::SetUp()
41 {
42 }
43
TearDown()44 void AccessTokenManagerServiceTest::TearDown()
45 {
46 }
47
48 /**
49 * @tc.name: DumpTokenInfoFuncTest001
50 * @tc.desc: test DumpTokenInfo with DEVELOPER_MODE_STATE
51 * @tc.type: FUNC
52 * @tc.require:
53 */
54 HWTEST_F(AccessTokenManagerServiceTest, DumpTokenInfoFuncTest001, TestSize.Level1)
55 {
56 std::string dumpInfo;
57 AtmToolsParamInfoParcel infoParcel;
58 infoParcel.info.processName = "hdcd";
59
60 system::SetBoolParameter(DEVELOPER_MODE_STATE, false);
61 bool ret = system::GetBoolParameter(DEVELOPER_MODE_STATE, false);
62 ASSERT_FALSE(ret);
63
64 std::shared_ptr<AccessTokenManagerService> atManagerService_ =
65 DelayedSingleton<AccessTokenManagerService>::GetInstance();
66 atManagerService_->DumpTokenInfo(infoParcel, dumpInfo);
67 ASSERT_EQ("Developer mode not support.", dumpInfo);
68
69 system::SetBoolParameter(DEVELOPER_MODE_STATE, true);
70 ret = system::GetBoolParameter(DEVELOPER_MODE_STATE, false);
71 ASSERT_TRUE(ret);
72 atManagerService_->DumpTokenInfo(infoParcel, dumpInfo);
73 ASSERT_NE("", dumpInfo);
74 }
75
76 } // namespace AccessToken
77 } // namespace Security
78 } // namespace OHOS
79