• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "disallow_modify_datetime_plugin_test.h"
17 #include "disallow_modify_datetime_plugin.h"
18 #include "edm_ipc_interface_code.h"
19 #include "iplugin.h"
20 #include "utils.h"
21 
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace EDM {
26 namespace TEST {
SetUpTestSuite(void)27 void DisallowModifyDateTimePluginTest::SetUpTestSuite(void)
28 {
29     Utils::SetEdmInitialEnv();
30 }
31 
TearDownTestSuite(void)32 void DisallowModifyDateTimePluginTest::TearDownTestSuite(void)
33 {
34     Utils::ResetTokenTypeAndUid();
35     ASSERT_TRUE(Utils::IsOriginalUTEnv());
36     std::cout << "now ut process is orignal ut env : " << Utils::IsOriginalUTEnv() << std::endl;
37 }
38 
39 /**
40  * @tc.name: TestDisallowModifyDateTimePlugin
41  * @tc.desc: Test TestDisallowModifyDateTimePlugin::OnSetPolicy function.
42  * @tc.type: FUNC
43  */
44 HWTEST_F(DisallowModifyDateTimePluginTest, TestDisallowModifyDateTimePlugin001, TestSize.Level1)
45 {
46     MessageParcel data;
47     MessageParcel reply;
48     // want to disallow to modify date time.
49     data.WriteBool(true);
50     std::shared_ptr<IPlugin> plugin = DisallModifyDateTimePlugin::GetPlugin();
51     // origin policy is allow to modify date time.
52     std::uint32_t funcCode =
53         POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::DISALLOW_MODIFY_DATETIME);
54     HandlePolicyData handlePolicyData{"false", "", false};
55     ErrCode ret = plugin->OnHandlePolicy(funcCode, data, reply, handlePolicyData, DEFAULT_USER_ID);
56     ASSERT_TRUE(ret == ERR_OK);
57     // current policy is disallow to modify date time.
58     ASSERT_TRUE(handlePolicyData.policyData == "true");
59     ASSERT_TRUE(handlePolicyData.isChanged);
60 }
61 } // namespace TEST
62 } // namespace EDM
63 } // namespace OHOS