• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #define LOG_TAG "BroadcastSenderTest"
16 
17 #include "broadcast_sender.h"
18 #include "broadcast_sender_impl.h"
19 #include "log_print.h"
20 #include <gtest/gtest.h>
21 #include <memory>
22 
23 namespace OHOS::Test {
24 using namespace testing::ext;
25 using namespace OHOS::DistributedKv;
26 class BroadcastSenderTest : public testing::Test {
27 public:
SetUpTestCase(void)28     static void SetUpTestCase(void) {};
TearDownTestCase(void)29     static void TearDownTestCase(void) {};
SetUp()30     void SetUp() {};
TearDown()31     void TearDown() {};
32 };
33 
34 class BroadcastSenderImplTest : public testing::Test {
35 public:
SetUpTestCase(void)36     static void SetUpTestCase(void) {};
TearDownTestCase(void)37     static void TearDownTestCase(void) {};
SetUp()38     void SetUp() {};
TearDown()39     void TearDown() {};
40 };
41 
42 /**
43  * @tc.name: GetInstance001
44  * @tc.desc: Returns a non-null instance correctly.
45  * @tc.type: FUNC
46  * @tc.require:
47  * @tc.author: suoqilong
48  */
49 HWTEST_F(BroadcastSenderTest, GetInstance001, TestSize.Level0)
50 {
51     std::shared_ptr<BroadcastSender> instanceFirst = DistributedKv::BroadcastSender::GetInstance();
52     ASSERT_NE(instanceFirst, nullptr);
53     std::shared_ptr<BroadcastSender> instanceSecond = DistributedKv::BroadcastSender::GetInstance();
54     ASSERT_NE(instanceSecond, nullptr);
55 }
56 
57 /**
58  * @tc.name: SendEvent
59  * @tc.desc: Verify the SendEvent method for BroadcastSenderImpl.
60  * @tc.type: FUNC
61  * @tc.require:
62  * @tc.author: suoqilong
63  */
64 HWTEST_F(BroadcastSenderImplTest, SendEvent, TestSize.Level0)
65 {
66     std::shared_ptr<BroadcastSender> instance = DistributedKv::BroadcastSender::GetInstance();
67     ASSERT_NE(instance, nullptr);
68     EventParams params = {};
69     EXPECT_NO_FATAL_FAILURE(instance->SendEvent(params));
70 }
71 } // namespace OHOS::Test