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 <gtest/gtest.h>
17 #include "disable_camera_plugin.h"
18 #include "utils.h"
19
20 using namespace testing::ext;
21 using namespace testing;
22
23 namespace OHOS {
24 namespace EDM {
25 namespace TEST {
26 class DisableCameraPluginTest : public testing::Test {
27 protected:
28 static void SetUpTestSuite(void);
29
30 static void TearDownTestSuite(void);
31 };
32
SetUpTestSuite(void)33 void DisableCameraPluginTest::SetUpTestSuite(void)
34 {
35 Utils::SetEdmInitialEnv();
36 }
37
TearDownTestSuite(void)38 void DisableCameraPluginTest::TearDownTestSuite(void)
39 {
40 Utils::ResetTokenTypeAndUid();
41 ASSERT_TRUE(Utils::IsOriginalUTEnv());
42 std::cout << "now ut process is orignal ut env : " << Utils::IsOriginalUTEnv() << std::endl;
43 }
44
45 /**
46 * @tc.name: TestDisableCameraPluginTestSet
47 * @tc.desc: Test DisableCameraPluginTest::OnSetPolicy function.
48 * @tc.type: FUNC
49 */
50 HWTEST_F(DisableCameraPluginTest, TestDisableCameraPluginTestSet, TestSize.Level1)
51 {
52 bool data = true;
53 DisableCameraPlugin plugin;
54 HandlePolicyData handlePolicyData;
55 ErrCode ret = plugin.OnSetPolicy(data);
56 ASSERT_TRUE(ret == ERR_OK);
57 ASSERT_TRUE(data);
58
59 data = false;
60 ret = plugin.OnSetPolicy(data);
61 ASSERT_TRUE(ret == ERR_OK);
62 ASSERT_FALSE(data);
63 }
64
65 /**
66 * @tc.name: TestDisableCameraPluginTestGet
67 * @tc.desc: Test DisableCameraPluginTest::OnGetPolicy function.
68 * @tc.type: FUNC
69 */
70 HWTEST_F(DisableCameraPluginTest, TestDisableCameraPluginTestGet, TestSize.Level1)
71 {
72 MessageParcel data;
73 MessageParcel reply;
74 std::string policyData = "true";
75 DisableCameraPlugin plugin;
76 ErrCode ret = plugin.OnGetPolicy(policyData, data, reply, 100);
77 ASSERT_TRUE(ret == ERR_OK);
78 ASSERT_TRUE(reply.ReadInt32() == ERR_OK);
79 ASSERT_FALSE(reply.ReadBool());
80 }
81
82 } // namespace TEST
83 } // namespace EDM
84 } // namespace OHOS