• 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 #define protected public
17 #include "disable_microphone_plugin.h"
18 #undef protected
19 
20 #include <gtest/gtest.h>
21 
22 #include "parameters.h"
23 #include "utils.h"
24 
25 using namespace testing::ext;
26 using namespace testing;
27 
28 namespace OHOS {
29 namespace EDM {
30 namespace TEST {
31 const std::string PARAM_EDM_MIC_DISABLE = "persist.edm.mic_disable";
32 class DisableMicrophonePluginTest : public testing::Test {
33 protected:
34     static void SetUpTestSuite(void);
35 
36     static void TearDownTestSuite(void);
37 };
38 
SetUpTestSuite(void)39 void DisableMicrophonePluginTest::SetUpTestSuite(void)
40 {
41     Utils::SetEdmInitialEnv();
42 }
43 
TearDownTestSuite(void)44 void DisableMicrophonePluginTest::TearDownTestSuite(void)
45 {
46     Utils::ResetTokenTypeAndUid();
47     ASSERT_TRUE(Utils::IsOriginalUTEnv());
48     std::cout << "now ut process is orignal ut env : " << Utils::IsOriginalUTEnv() << std::endl;
49 }
50 
51 /**
52  * @tc.name: TestDisableMicrophonePluginTestSetTrue
53  * @tc.desc: Test DisableMicrophonePluginTest::OnSetPolicy function.
54  * @tc.type: FUNC
55  */
56 HWTEST_F(DisableMicrophonePluginTest, TestDisableMicrophonePluginTestSetTrue, TestSize.Level1)
57 {
58     bool isDisallow = true;
59     bool currentdata = false;
60     bool mergeData = false;
61     DisableMicrophonePlugin plugin;
62     plugin.persistParam_ = "persist.edm.mic_disable";
63     ErrCode ret = plugin.OnSetPolicy(isDisallow, currentdata, mergeData, DEFAULT_USER_ID);
64     ASSERT_TRUE(ret == ERR_OK);
65     ASSERT_TRUE(system::GetBoolParameter(PARAM_EDM_MIC_DISABLE, false));
66 }
67 
68 /**
69  * @tc.name: TestDisableMicrophonePluginTestSetFalse
70  * @tc.desc: Test DisableMicrophonePluginTest::OnSetPolicy function and audioSystemManager::SetMicrophoneMute.
71  * @tc.type: FUNC
72  */
73 HWTEST_F(DisableMicrophonePluginTest, TestDisableMicrophonePluginTestSetFalse, TestSize.Level1)
74 {
75     bool isDisallow = false;
76     bool currentdata = false;
77     bool mergeData = false;
78     DisableMicrophonePlugin plugin;
79     plugin.persistParam_ = "persist.edm.mic_disable";
80     ErrCode ret = plugin.OnSetPolicy(isDisallow, currentdata, mergeData, DEFAULT_USER_ID);
81     ASSERT_TRUE(ret == ERR_OK);
82     ASSERT_FALSE(system::GetBoolParameter(PARAM_EDM_MIC_DISABLE, true));
83 }
84 
85 /**
86  * @tc.name: TestDisableMicrophonePluginTestGet
87  * @tc.desc: Test DisableMicrophonePluginTest::OnGetPolicy function.
88  * @tc.type: FUNC
89  */
90 HWTEST_F(DisableMicrophonePluginTest, TestDisableMicrophonePluginTestGet, TestSize.Level1)
91 {
92     std::string policyData;
93     MessageParcel data;
94     MessageParcel reply;
95     int32_t userId = 0;
96     DisableMicrophonePlugin plugin;
97     ErrCode ret = plugin.OnGetPolicy(policyData, data, reply, userId);
98     ASSERT_TRUE(ret == ERR_OK);
99     ASSERT_TRUE(reply.ReadInt32() == ERR_OK);
100     ASSERT_FALSE(reply.ReadBool());
101 }
102 } // namespace TEST
103 } // namespace EDM
104 } // namespace OHOS
105