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 "stream_update_test.h" 17 #include "updater/updater.h" 18 #include "bin_chunk_update.h" 19 #include "log/log.h" 20 #include "scope_guard.h" 21 #include "securec.h" 22 #include "updater/updater_const.h" 23 #include "utils.h" 24 #include <thread> 25 #include <atomic> 26 #include <algorithm> 27 28 #include "gtest/gtest.h" 29 30 using namespace testing::ext; 31 using namespace std; 32 33 namespace OHOS { 34 namespace SysInstaller { 35 36 HWTEST_F(StreamInstallProcesserTest, StartStopTest, TestSize.Level1) 37 { 38 StreamInstallProcesser::GetInstance().Start(); 39 EXPECT_TRUE(StreamInstallProcesser::GetInstance().IsRunning()); 40 StreamInstallProcesser::GetInstance().Stop(); 41 EXPECT_FALSE(StreamInstallProcesser::GetInstance().IsRunning()); 42 } 43 44 HWTEST_F(StreamInstallProcesserTest, ProcessStreamDataSuccess, TestSize.Level1) 45 { 46 EXPECT_EQ(StreamInstallProcesser::GetInstance().Start(), 0); 47 48 uint8_t data[1024] = {0}; 49 std::fill_n(data, sizeof(data), 0x55); 50 51 EXPECT_EQ(StreamInstallProcesser::GetInstance().ProcessStreamData(data, sizeof(data)), 0); 52 StreamInstallProcesser::GetInstance().Stop(); 53 } 54 55 HWTEST_F(StreamInstallProcesserTest, UpdateResultTest, TestSize.Level1) 56 { 57 // 预期 UpdateCallback 方法被调用 58 EXPECT_CALL(*statusManager, UpdateCallback(UpdateStatus::UPDATE_STATE_INIT, 0, "Initializing")).Times(1); 59 StreamInstallProcesser::GetInstance().UpdateResult(UpdateStatus::UPDATE_STATE_INIT, 0, "Initializing"); 60 } 61 62 } // namespace SysInstaller 63 } // namespace OHOS 64