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 "location_policy_plugin.h"
17
18 #include <gtest/gtest.h>
19
20 #include "edm_data_ability_utils_mock.h"
21 #include "edm_ipc_interface_code.h"
22 #include "iplugin_manager.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
32 class LocationPolicyPluginTest : public testing::TestWithParam<std::pair<int32_t, int32_t>> {
33 protected:
34 static void SetUpTestSuite(void);
35
36 static void TearDownTestSuite(void);
37 };
38
SetUpTestSuite(void)39 void LocationPolicyPluginTest::SetUpTestSuite(void)
40 {
41 Utils::SetEdmServiceEnable();
42 Utils::SetEdmInitialEnv();
43 }
44
TearDownTestSuite(void)45 void LocationPolicyPluginTest::TearDownTestSuite(void)
46 {
47 LocationPolicyPlugin plugin;
48 int32_t defaultPolicy = static_cast<int32_t>(LocationPolicy::DEFAULT_LOCATION_SERVICE);
49 ErrCode code = plugin.OnSetPolicy(defaultPolicy);
50 EXPECT_TRUE(code == ERR_OK);
51 Utils::SetEdmServiceDisable();
52 Utils::ResetTokenTypeAndUid();
53 ASSERT_TRUE(Utils::IsOriginalUTEnv());
54 std::cout << "now ut process is orignal ut env : " << Utils::IsOriginalUTEnv() << std::endl;
55 }
56
57 INSTANTIATE_TEST_CASE_P(TestOnSetPolicy, LocationPolicyPluginTest,
58 testing::ValuesIn(std::vector<std::pair<int32_t, int32_t>>({
59 {-1, EdmReturnErrCode::PARAM_ERROR},
60 {0, ERR_OK},
61 {1, ERR_OK},
62 {2, ERR_OK},
63 })));
64
65 /**
66 * @tc.name: TestOnSetPolicy
67 * @tc.desc: Test OnSetPolicy function.
68 * @tc.type: FUNC
69 */
70 HWTEST_P(LocationPolicyPluginTest, TestOnSetPolicy, TestSize.Level1)
71 {
72 LocationPolicyPlugin plugin;
73 std::pair<int32_t, int32_t> keyValue = GetParam();
74 std::cout << "LocationPolicyPluginTest " << keyValue.first << " " << keyValue.second << std::endl;
75 ErrCode code = plugin.OnSetPolicy(keyValue.first);
76 EXPECT_TRUE(code == keyValue.second);
77 }
78
79 /**
80 * @tc.name: TestOnGetPolicy
81 * @tc.desc: Test OnGetPolicy function.
82 * @tc.type: FUNC
83 */
84 HWTEST_F(LocationPolicyPluginTest, TestOnGetPolicy, TestSize.Level1)
85 {
86 std::shared_ptr<IPlugin> plugin = LocationPolicyPlugin::GetPlugin();
87 std::string policyValue{"TestString"};
88 MessageParcel data;
89 MessageParcel reply;
90 ErrCode code = plugin->OnGetPolicy(policyValue, data, reply, DEFAULT_USER_ID);
91 EXPECT_TRUE(code == ERR_OK);
92 }
93
94 } // namespace TEST
95 } // namespace EDM
96 } // namespace OHOS