1 /*
2 * Copyright (c) 2024 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 "enterprise_admin_stub_mock.h"
19 #include "enterprise_update_connection.h"
20 #include "func_code.h"
21
22 using namespace testing::ext;
23 using namespace testing;
24
25 namespace OHOS {
26 namespace EDM {
27 namespace TEST {
28 const std::string TEST_BUNDLE_NAME = "com.edm.test.demo";
29 const std::string TEST_ABILITY_NAME = "com.edm.test.demo.Ability";
30 constexpr int32_t DEFAULT_USER_ID = 100;
31 class EnterpriseUpdateConnectionTest : public testing::Test {
32 protected:
33 void SetUp() override;
34
35 std::shared_ptr<EnterpriseUpdateConnection> enterpriseUpdateConnection {nullptr};
36 sptr<EnterpriseAdminStubMock> remoteObject {nullptr};
37 };
38
SetUp()39 void EnterpriseUpdateConnectionTest::SetUp()
40 {
41 remoteObject = new (std::nothrow) EnterpriseAdminStubMock();
42 }
43
44 /**
45 * @tc.name: TestOnAbilityConnectDone
46 * @tc.desc: Test EnterpriseUpdateConnection::OnAbilityConnectDone func.
47 * @tc.type: FUNC
48 */
49 HWTEST_F(EnterpriseUpdateConnectionTest, TestOnAbilityConnectDone, TestSize.Level1)
50 {
51 AppExecFwk::ElementName admin;
52 admin.SetBundleName(TEST_BUNDLE_NAME);
53 admin.SetAbilityName(TEST_ABILITY_NAME);
54 UpdateInfo updateInfo;
55 AAFwk::Want connectWant;
56 connectWant.SetElementName(TEST_BUNDLE_NAME, TEST_ABILITY_NAME);
57 int32_t resultCode = 0;
58 enterpriseUpdateConnection =
59 std::make_shared<EnterpriseUpdateConnection>(connectWant,
60 IEnterpriseAdmin::COMMAND_ON_SYSTEM_UPDATE, DEFAULT_USER_ID, updateInfo);
61 EXPECT_CALL(*remoteObject, SendRequest(_, _, _, _))
62 .Times(1)
63 .WillOnce(Invoke(remoteObject.GetRefPtr(), &EnterpriseAdminStubMock::InvokeSendRequest));
64 enterpriseUpdateConnection->OnAbilityConnectDone(admin, remoteObject, resultCode);
65 enterpriseUpdateConnection->OnAbilityDisconnectDone(admin, resultCode);
66
67 EXPECT_TRUE(true);
68 }
69 } // namespace TEST
70 } // namespace EDM
71 } // namespace OHOS
72