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 "ntp_server_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 NTPServerPluginTest : public testing::TestWithParam<std::pair<std::string, int32_t>> {
33 protected:
34 static void SetUpTestSuite(void);
35
36 static void TearDownTestSuite(void);
37 };
38
SetUpTestSuite(void)39 void NTPServerPluginTest::SetUpTestSuite(void)
40 {
41 Utils::SetEdmServiceEnable();
42 Utils::SetEdmInitialEnv();
43 }
44
TearDownTestSuite(void)45 void NTPServerPluginTest::TearDownTestSuite(void)
46 {
47 Utils::SetEdmServiceDisable();
48 Utils::ResetTokenTypeAndUid();
49 ASSERT_TRUE(Utils::IsOriginalUTEnv());
50 std::cout << "now ut process is orignal ut env : " << Utils::IsOriginalUTEnv() << std::endl;
51 }
52
53 /**
54 * @tc.name: TestOnGetPolicy
55 * @tc.desc: Test OnGetPolicy function.
56 * @tc.type: FUNC
57 */
58 HWTEST_F(NTPServerPluginTest, TestOnGetPolicy, TestSize.Level1)
59 {
60 std::shared_ptr<IPlugin> plugin = NTPServerPlugin::GetPlugin();
61 std::string policyValue{"TestString"};
62 MessageParcel data;
63 MessageParcel reply;
64
65 plugin->OnGetPolicy(policyValue, data, reply, DEFAULT_USER_ID);
66 EXPECT_TRUE(reply.ReadInt32() == ERR_OK);
67 EXPECT_TRUE(reply.ReadString() == "");
68 }
69
70 } // namespace TEST
71 } // namespace EDM
72 } // namespace OHOS