1 /*
2 * Copyright (c) 2022 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
18 #include "broadcast_manager.h"
19
20 namespace OHOS {
21 namespace NetManagerStandard {
22 namespace {
23 using namespace testing::ext;
24 BroadcastInfo g_testInfo;
25 } // namespace
26
27 class BroadcastManagerTest : public testing::Test {
28 public:
29 static void SetUpTestCase();
30 static void TearDownTestCase();
31 void SetUp();
32 void TearDown();
33 };
34
SetUpTestCase()35 void BroadcastManagerTest::SetUpTestCase()
36 {
37 g_testInfo.action = "testAction";
38 g_testInfo.data = "testData";
39 }
40
TearDownTestCase()41 void BroadcastManagerTest::TearDownTestCase() {}
42
SetUp()43 void BroadcastManagerTest::SetUp() {}
44
TearDown()45 void BroadcastManagerTest::TearDown() {}
46
47 HWTEST_F(BroadcastManagerTest, SendBroadcastTest001, TestSize.Level1)
48 {
49 std::map<std::string, bool> params = {{"test1", true}, {"test2", false}, {"test3", false}};
50 bool ret = BroadcastManager::GetInstance().SendBroadcast(g_testInfo, params);
51 EXPECT_TRUE(ret);
52 }
53
54 HWTEST_F(BroadcastManagerTest, SendBroadcastTest002, TestSize.Level1)
55 {
56 std::map<std::string, int32_t> params = {{"test1", 1}, {"test2", 2}, {"test3", 3}};
57 bool ret = BroadcastManager::GetInstance().SendBroadcast(g_testInfo, params);
58 EXPECT_TRUE(ret);
59 }
60
61 HWTEST_F(BroadcastManagerTest, SendBroadcastTest003, TestSize.Level1)
62 {
63 std::map<std::string, std::string> params = {{"test1", "testMsg1"}, {"test2", "testMsg2"}, {"test3", "testMsg3"}};
64 bool ret = BroadcastManager::GetInstance().SendBroadcast(g_testInfo, params);
65 EXPECT_TRUE(ret);
66 }
67
68 HWTEST_F(BroadcastManagerTest, SendBroadcastTest004, TestSize.Level1)
69 {
70 std::map<std::string, std::string> params = {{"test1", "testMsg1"}, {"test2", "testMsg2"}, {"test3", "testMsg3"}};
71 BroadcastInfo testInfo;
72 bool ret = BroadcastManager::GetInstance().SendBroadcast(testInfo, params);
73 EXPECT_FALSE(ret);
74 }
75
76 HWTEST_F(BroadcastManagerTest, SendBroadcastTest005, TestSize.Level1)
77 {
78 std::map<std::string, int64_t> params = {{"test1", 1}, {"test2", 2}, {"test3", 3}};
79 bool ret = BroadcastManager::GetInstance().SendBroadcast(g_testInfo, params);
80 EXPECT_TRUE(ret);
81 }
82
83 HWTEST_F(BroadcastManagerTest, SendBroadcastTest006, TestSize.Level1)
84 {
85 std::map<std::string, std::string> params = {{"test1", "testMsg1"}, {"test2", "testMsg2"}, {"test3", "testMsg3"}};
86 BroadcastInfo info = {};
87 g_testInfo.permission = "ohos.permission.INTERNET";
88 bool ret = BroadcastManager::GetInstance().SendBroadcast(g_testInfo, params);
89 EXPECT_TRUE(ret);
90 }
91 } // namespace NetManagerStandard
92 } // namespace OHOS