• 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 
16 #include "svc_distributed_connection_test.h"
17 
18 #include "test_log.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 namespace DistributedSchedule {
SetUpTestCase()25 void SvcDistributedConnectionTest::SetUpTestCase()
26 {
27     disconnectedCon_ = sptr(new SvcDistributedConnection("com.example.dms_extension"));
28     DTEST_LOG << "SvcDistributedConnectionTest::SetUpTestCase" << std::endl;
29 }
30 
TearDownTestCase()31 void SvcDistributedConnectionTest::TearDownTestCase()
32 {
33     disconnectedCon_ = nullptr;
34     DTEST_LOG << "SvcDistributedConnectionTest::TearDownTestCase" << std::endl;
35 }
36 
TearDown()37 void SvcDistributedConnectionTest::TearDown()
38 {
39     DTEST_LOG << "SvcDistributedConnectionTest::TearDown" << std::endl;
40 }
41 
SetUp()42 void SvcDistributedConnectionTest::SetUp()
43 {
44     DTEST_LOG << "SvcDistributedConnectionTest::SetUp" << std::endl;
45 }
46 
47 /**
48  * @tc.name: OnAbilityConnectDone_001
49  * @tc.desc: OnAbilityConnectDone
50  * @tc.type: FUNC
51  */
52 HWTEST_F(SvcDistributedConnectionTest, OnAbilityConnectDone_001, TestSize.Level3)
53 {
54     DTEST_LOG << "SvcDistributedConnectionTest OnAbilityConnectDone_001 begin" << std::endl;
55     int resultCode = 0;
56     AppExecFwk::ElementName element;
57     EXPECT_NO_FATAL_FAILURE(disconnectedCon_->OnAbilityConnectDone(element, nullptr, resultCode));
58     DTEST_LOG << "SvcDistributedConnectionTest OnAbilityConnectDone_001 remoteObject is nullptr " << std::endl;
59 }
60 
61 /**
62  * @tc.name: OnAbilityConnectDone_002
63  * @tc.desc: OnAbilityConnectDone
64  * @tc.type: FUNC
65  */
66 HWTEST_F(SvcDistributedConnectionTest, OnAbilityConnectDone_002, TestSize.Level3)
67 {
68     DTEST_LOG << "SvcDistributedConnectionTest OnAbilityConnectDone_001 begin" << std::endl;
69     int resultCode = 0;
70     AppExecFwk::ElementName element;
71     EXPECT_TRUE(disconnectedCon_ != nullptr);
72     sptr<IRemoteObject> remoteObject;
73 
74     string bundleName = "com.example.dms_extension";
75     element.SetBundleName(bundleName);
76     disconnectedCon_->OnAbilityConnectDone(element, remoteObject, resultCode);
77     EXPECT_NO_FATAL_FAILURE(disconnectedCon_->OnAbilityConnectDone(element, remoteObject, resultCode));
78     DTEST_LOG << "SvcDistributedConnectionTest OnAbilityConnectDone_002 end" << std::endl;
79 }
80 
81 /**
82  * @tc.name: OnAbilityDisconnectDone_001
83  * @tc.desc: OnAbilityDisconnectDone
84  * @tc.type: FUNC
85  */
86 HWTEST_F(SvcDistributedConnectionTest, OnAbilityDisconnectDone_001, TestSize.Level3)
87 {
88     DTEST_LOG << "SvcDistributedConnectionTest OnAbilityDisconnectDone_001 begin" << std::endl;
89 
90     AppExecFwk::ElementName element;
91     string bundleName = "";
92     element.SetBundleName(bundleName);
93     int resultCode = 1;
94 
95     EXPECT_TRUE(disconnectedCon_ != nullptr);
96     disconnectedCon_->isConnectCalled_ = false;
97     disconnectedCon_->OnAbilityDisconnectDone(element, resultCode);
98     EXPECT_NO_FATAL_FAILURE(disconnectedCon_->OnAbilityDisconnectDone(element, resultCode));
99     bool ret = disconnectedCon_->IsExtAbilityConnected();
100     EXPECT_FALSE(ret);
101 
102     disconnectedCon_->isConnectCalled_ = true;
103     bundleName = "com.example.dms_extension";
104     element.SetBundleName(bundleName);
105     disconnectedCon_->OnAbilityDisconnectDone(element, resultCode);
106     EXPECT_NO_FATAL_FAILURE(disconnectedCon_->OnAbilityDisconnectDone(element, resultCode));
107     ret = disconnectedCon_->IsExtAbilityConnected();
108     EXPECT_FALSE(ret);
109 
110     DTEST_LOG << "SvcDistributedConnectionTest OnAbilityDisconnectDone_001 end" << std::endl;
111 }
112 
113 /**
114  * @tc.name: GetDistributedExtProxy_001
115  * @tc.desc: GetDistributedExtProxy
116  * @tc.type: FUNC
117  */
118 HWTEST_F(SvcDistributedConnectionTest, GetDistributedExtProxy_001, TestSize.Level3)
119 {
120     DTEST_LOG << "SvcDistributedConnectionTest GetDistributedExtProxy_001 begin" << std::endl;
121     EXPECT_TRUE(disconnectedCon_ != nullptr);
122     auto proxy = disconnectedCon_->GetDistributedExtProxy();
123     EXPECT_EQ(proxy, nullptr);
124     DTEST_LOG << "SvcDistributedConnectionTest GetDistributedExtProxy_001 end" << std::endl;
125 }
126 }
127 }
128