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 <gtest/gtest.h>
17 #include "mock_bundle_mgr.h"
18 #include "scan_service_ability.h"
19 #include "scan_constant.h"
20 #include "system_ability_definition.h"
21 #include "scan_utils.h"
22 #include "mock_scan_callback_proxy.h"
23 #include "scan_mdns_service.h"
24 
25 namespace OHOS {
26 namespace Scan {
27 class ScanMdnsServiceTest : public testing::Test {
28 public:
29     static void SetUpTestCase(void);
30     static void TearDownTestCase(void);
31     void SetUp();
32     void TearDown();
33     std::shared_ptr<ScanMdnsService> scanMdnsPtr;
34     std::shared_ptr<ScanServiceAbility> scanServicePtr;
35 };
36 
SetUpTestCase(void)37 void ScanMdnsServiceTest::SetUpTestCase(void) {}
38 
TearDownTestCase(void)39 void ScanMdnsServiceTest::TearDownTestCase(void) {}
40 
SetUp(void)41 void ScanMdnsServiceTest::SetUp(void)
42 {
43     scanMdnsPtr = ScanMdnsService::GetInstance();
44     scanServicePtr = ScanServiceAbility::GetInstance();
45     EXPECT_NE(scanMdnsPtr, nullptr);
46     EXPECT_NE(scanServicePtr, nullptr);
47 }
48 
TearDown(void)49 void ScanMdnsServiceTest::TearDown(void) {}
50 
51 /**
52  * @tc.name: ScanMdnsServiceTest_0001
53  * @tc.desc: Verify the capability function.
54  * @tc.type: FUNC
55  * @tc.require:
56  */
HWTEST_F(ScanMdnsServiceTest, ScanMdnsServiceTest_0001, TestSize.Level1)57 HWTEST_F(ScanMdnsServiceTest, ScanMdnsServiceTest_0001, TestSize.Level1)
58 {
59     scanMdnsPtr->SetServiceType("_scanner._tcp");
60     scanMdnsPtr->onStartDiscoverService();
61     EXPECT_NE(scanServicePtr->scanDeviceInfoTCPMap_.size(), 0);
62 }
63 
64 /**
65  * @tc.name: ScanMdnsServiceTest_0002
66  * @tc.desc: Verify the capability function.
67  * @tc.type: FUNC
68  * @tc.require:
69  */
HWTEST_F(ScanMdnsServiceTest, ScanMdnsServiceTest_0002, TestSize.Level1)70 HWTEST_F(ScanMdnsServiceTest, ScanMdnsServiceTest_0002, TestSize.Level1)
71 {
72     scanMdnsPtr->SetServiceType("_scanner._tcp");
73     scanMdnsPtr->onStartDiscoverService();
74     EXPECT_NE(scanServicePtr->_scanMDnsDiscoveryCallBack, nullptr);
75 }
76 
77 /**
78  * @tc.name: ScanMdnsServiceTest_0003
79  * @tc.desc: Verify the capability function.
80  * @tc.type: FUNC
81  * @tc.require:
82  */
HWTEST_F(ScanMdnsServiceTest, ScanMdnsServiceTest_0003, TestSize.Level1)83 HWTEST_F(ScanMdnsServiceTest, ScanMdnsServiceTest_0003, TestSize.Level1)
84 {
85     scanMdnsPtr->SetServiceType("_scanner._tcp");
86     scanMdnsPtr->onStartDiscoverService();
87     EXPECT_NE(scanServicePtr->_scanMDnsResolveCallBack, nullptr);
88 }
89 
90 } // namespace Scan
91 } // namespace OHOS