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