1fb299fa2Sopenharmony_ci/* 2fb299fa2Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 3fb299fa2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fb299fa2Sopenharmony_ci * you may not use this file except in compliance with the License. 5fb299fa2Sopenharmony_ci * You may obtain a copy of the License at 6fb299fa2Sopenharmony_ci * 7fb299fa2Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fb299fa2Sopenharmony_ci * 9fb299fa2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fb299fa2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fb299fa2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fb299fa2Sopenharmony_ci * See the License for the specific language governing permissions and 13fb299fa2Sopenharmony_ci * limitations under the License. 14fb299fa2Sopenharmony_ci */ 15fb299fa2Sopenharmony_ci 16fb299fa2Sopenharmony_ci#include <gtest/gtest.h> 17fb299fa2Sopenharmony_ci#include "bzip2_adapter.h" 18fb299fa2Sopenharmony_ci#include "diffpatch.h" 19fb299fa2Sopenharmony_ci#include "lz4_adapter.h" 20fb299fa2Sopenharmony_ci#include "unittest_comm.h" 21fb299fa2Sopenharmony_ci#include "update_patch.h" 22fb299fa2Sopenharmony_ci#include "zip_adapter.h" 23fb299fa2Sopenharmony_ci 24fb299fa2Sopenharmony_ciusing namespace std; 25fb299fa2Sopenharmony_ciusing namespace Hpackage; 26fb299fa2Sopenharmony_ciusing namespace UpdatePatch; 27fb299fa2Sopenharmony_ciusing namespace testing::ext; 28fb299fa2Sopenharmony_ci 29fb299fa2Sopenharmony_cinamespace { 30fb299fa2Sopenharmony_ci#define LZ4_BLOCK_SIZE(blockId) (1 << (8 + (2 * (blockId)))) 31fb299fa2Sopenharmony_ci 32fb299fa2Sopenharmony_ciclass TestPatchWriter : public UpdatePatchWriter { 33fb299fa2Sopenharmony_cipublic: 34fb299fa2Sopenharmony_ci explicit TestPatchWriter(std::vector<uint8_t> &buffer) : UpdatePatchWriter(), buffer_(buffer) {} 35fb299fa2Sopenharmony_ci ~TestPatchWriter() override {} 36fb299fa2Sopenharmony_ci 37fb299fa2Sopenharmony_ci int32_t Init() override 38fb299fa2Sopenharmony_ci { 39fb299fa2Sopenharmony_ci return 0; 40fb299fa2Sopenharmony_ci }; 41fb299fa2Sopenharmony_ci int32_t Finish() override 42fb299fa2Sopenharmony_ci { 43fb299fa2Sopenharmony_ci return 0; 44fb299fa2Sopenharmony_ci }; 45fb299fa2Sopenharmony_ci int32_t Write(size_t start, const BlockBuffer &data, size_t len) override 46fb299fa2Sopenharmony_ci { 47fb299fa2Sopenharmony_ci if (len == 0) { 48fb299fa2Sopenharmony_ci return 0; 49fb299fa2Sopenharmony_ci } 50fb299fa2Sopenharmony_ci bufferSize += len; 51fb299fa2Sopenharmony_ci if ((start + bufferSize) > buffer_.size()) { 52fb299fa2Sopenharmony_ci buffer_.resize(IGMDIFF_LIMIT_UNIT * ((start + bufferSize) / IGMDIFF_LIMIT_UNIT + 1)); 53fb299fa2Sopenharmony_ci } 54fb299fa2Sopenharmony_ci return memcpy_s(buffer_.data() + start, buffer_.size(), data.buffer, len); 55fb299fa2Sopenharmony_ci } 56fb299fa2Sopenharmony_ciprivate: 57fb299fa2Sopenharmony_ci size_t bufferSize {0}; 58fb299fa2Sopenharmony_ci std::vector<uint8_t> &buffer_; 59fb299fa2Sopenharmony_ci}; 60fb299fa2Sopenharmony_ci 61fb299fa2Sopenharmony_ciclass BZip2AdapterUnitTest : public testing::Test { 62fb299fa2Sopenharmony_cipublic: 63fb299fa2Sopenharmony_ci BZip2AdapterUnitTest() {} 64fb299fa2Sopenharmony_ci ~BZip2AdapterUnitTest() {} 65fb299fa2Sopenharmony_ci 66fb299fa2Sopenharmony_ci static void SetUpTestCase(void) {} 67fb299fa2Sopenharmony_ci static void TearDownTestCase(void) {} 68fb299fa2Sopenharmony_ci void SetUp() {} 69fb299fa2Sopenharmony_ci void TearDown() {} 70fb299fa2Sopenharmony_ci void TestBody() {} 71fb299fa2Sopenharmony_cipublic: 72fb299fa2Sopenharmony_ci int BZip2AdapterBufferTest() const 73fb299fa2Sopenharmony_ci { 74fb299fa2Sopenharmony_ci MemMapInfo data {}; 75fb299fa2Sopenharmony_ci std::string fileName = TEST_PATH_FROM; 76fb299fa2Sopenharmony_ci fileName += "test_script.us"; 77fb299fa2Sopenharmony_ci int32_t ret = PatchMapFile(fileName, data); 78fb299fa2Sopenharmony_ci EXPECT_EQ(0, ret); 79fb299fa2Sopenharmony_ci 80fb299fa2Sopenharmony_ci std::vector<uint8_t> compressedData; 81fb299fa2Sopenharmony_ci BZipBuffer2Adapter adapter(compressedData, 0); 82fb299fa2Sopenharmony_ci adapter.Open(); 83fb299fa2Sopenharmony_ci // compress data 1 84fb299fa2Sopenharmony_ci BlockBuffer srcData = {data.memory, data.length}; 85fb299fa2Sopenharmony_ci ret = adapter.WriteData(srcData); 86fb299fa2Sopenharmony_ci EXPECT_EQ(0, ret); 87fb299fa2Sopenharmony_ci size_t compressedData1 = 0; 88fb299fa2Sopenharmony_ci ret = adapter.FlushData(compressedData1); 89fb299fa2Sopenharmony_ci EXPECT_EQ(0, ret); 90fb299fa2Sopenharmony_ci adapter.Close(); 91fb299fa2Sopenharmony_ci 92fb299fa2Sopenharmony_ci // compress data 2 93fb299fa2Sopenharmony_ci BZipBuffer2Adapter adapter2(compressedData, compressedData1); 94fb299fa2Sopenharmony_ci adapter2.Open(); 95fb299fa2Sopenharmony_ci ret = adapter2.WriteData(srcData); 96fb299fa2Sopenharmony_ci EXPECT_EQ(0, ret); 97fb299fa2Sopenharmony_ci size_t compressedData2 = 0; 98fb299fa2Sopenharmony_ci ret = adapter2.FlushData(compressedData2); 99fb299fa2Sopenharmony_ci EXPECT_EQ(0, ret); 100fb299fa2Sopenharmony_ci adapter2.Close(); 101fb299fa2Sopenharmony_ci 102fb299fa2Sopenharmony_ci PATCH_LOGI("compressedData size %zu %zu %zu", compressedData.size(), compressedData1, compressedData2); 103fb299fa2Sopenharmony_ci // decompress data 1 104fb299fa2Sopenharmony_ci BlockBuffer compressedInfo = {compressedData.data(), compressedData.size()}; 105fb299fa2Sopenharmony_ci BZip2BufferReadAdapter readAdapter(0, compressedData1, compressedInfo); 106fb299fa2Sopenharmony_ci readAdapter.Open(); 107fb299fa2Sopenharmony_ci 108fb299fa2Sopenharmony_ci std::vector<uint8_t> dataArray(data.length); 109fb299fa2Sopenharmony_ci BlockBuffer data1 = {dataArray.data(), data.length}; 110fb299fa2Sopenharmony_ci ret = readAdapter.ReadData(data1); 111fb299fa2Sopenharmony_ci EXPECT_EQ(0, ret); 112fb299fa2Sopenharmony_ci EXPECT_EQ(0, memcmp(data1.buffer, data.memory, data1.length)); 113fb299fa2Sopenharmony_ci 114fb299fa2Sopenharmony_ci // decompress data 2 115fb299fa2Sopenharmony_ci BZip2BufferReadAdapter readAdapter2(compressedData1, compressedData2, compressedInfo); 116fb299fa2Sopenharmony_ci readAdapter2.Open(); 117fb299fa2Sopenharmony_ci ret = readAdapter2.ReadData(data1); 118fb299fa2Sopenharmony_ci EXPECT_EQ(0, ret); 119fb299fa2Sopenharmony_ci EXPECT_EQ(0, memcmp(data1.buffer, data.memory, data1.length)); 120fb299fa2Sopenharmony_ci 121fb299fa2Sopenharmony_ci adapter.Close(); 122fb299fa2Sopenharmony_ci readAdapter.Close(); 123fb299fa2Sopenharmony_ci return 0; 124fb299fa2Sopenharmony_ci } 125fb299fa2Sopenharmony_ci 126fb299fa2Sopenharmony_ci int BZip2AdapterAddMoreTest() const 127fb299fa2Sopenharmony_ci { 128fb299fa2Sopenharmony_ci MemMapInfo data {}; 129fb299fa2Sopenharmony_ci std::string fileName = TEST_PATH_FROM; 130fb299fa2Sopenharmony_ci fileName += "test_script.us"; 131fb299fa2Sopenharmony_ci int32_t ret = PatchMapFile(fileName, data); 132fb299fa2Sopenharmony_ci EXPECT_EQ(0, ret); 133fb299fa2Sopenharmony_ci 134fb299fa2Sopenharmony_ci std::vector<uint8_t> compressedData; 135fb299fa2Sopenharmony_ci BZipBuffer2Adapter adapter(compressedData, 0); 136fb299fa2Sopenharmony_ci adapter.Open(); 137fb299fa2Sopenharmony_ci // compress data 1 138fb299fa2Sopenharmony_ci BlockBuffer srcData = {data.memory, data.length}; 139fb299fa2Sopenharmony_ci ret = adapter.WriteData(srcData); 140fb299fa2Sopenharmony_ci EXPECT_EQ(0, ret); 141fb299fa2Sopenharmony_ci // compress data 2 142fb299fa2Sopenharmony_ci ret = adapter.WriteData(srcData); 143fb299fa2Sopenharmony_ci EXPECT_EQ(0, ret); 144fb299fa2Sopenharmony_ci // compress data 3 145fb299fa2Sopenharmony_ci ret = adapter.WriteData(srcData); 146fb299fa2Sopenharmony_ci EXPECT_EQ(0, ret); 147fb299fa2Sopenharmony_ci size_t compressedData1 = 0; 148fb299fa2Sopenharmony_ci ret = adapter.FlushData(compressedData1); 149fb299fa2Sopenharmony_ci EXPECT_EQ(0, ret); 150fb299fa2Sopenharmony_ci adapter.Close(); 151fb299fa2Sopenharmony_ci 152fb299fa2Sopenharmony_ci PATCH_LOGI("compressedData size %zu %zu", compressedData.size(), compressedData1); 153fb299fa2Sopenharmony_ci 154fb299fa2Sopenharmony_ci BlockBuffer compressedInfo = {compressedData.data(), compressedData.size()}; 155fb299fa2Sopenharmony_ci BZip2BufferReadAdapter readAdapter(0, compressedData1, compressedInfo); 156fb299fa2Sopenharmony_ci readAdapter.Open(); 157fb299fa2Sopenharmony_ci 158fb299fa2Sopenharmony_ci // decompress data 1 159fb299fa2Sopenharmony_ci std::vector<uint8_t> dataArray(data.length); 160fb299fa2Sopenharmony_ci BlockBuffer data1 = {dataArray.data(), data.length}; 161fb299fa2Sopenharmony_ci ret = readAdapter.ReadData(data1); 162fb299fa2Sopenharmony_ci EXPECT_EQ(0, ret); 163fb299fa2Sopenharmony_ci EXPECT_EQ(0, memcmp(data1.buffer, data.memory, data1.length)); 164fb299fa2Sopenharmony_ci 165fb299fa2Sopenharmony_ci // decompress data 2 166fb299fa2Sopenharmony_ci ret = readAdapter.ReadData(data1); 167fb299fa2Sopenharmony_ci EXPECT_EQ(0, ret); 168fb299fa2Sopenharmony_ci EXPECT_EQ(0, memcmp(data1.buffer, data.memory, data1.length)); 169fb299fa2Sopenharmony_ci 170fb299fa2Sopenharmony_ci // decompress data 3 171fb299fa2Sopenharmony_ci ret = readAdapter.ReadData(data1); 172fb299fa2Sopenharmony_ci EXPECT_EQ(0, ret); 173fb299fa2Sopenharmony_ci EXPECT_EQ(0, memcmp(data1.buffer, data.memory, data1.length)); 174fb299fa2Sopenharmony_ci 175fb299fa2Sopenharmony_ci adapter.Close(); 176fb299fa2Sopenharmony_ci readAdapter.Close(); 177fb299fa2Sopenharmony_ci return 0; 178fb299fa2Sopenharmony_ci } 179fb299fa2Sopenharmony_ci 180fb299fa2Sopenharmony_ci int32_t CompressData(Hpackage::PkgManager::FileInfoPtr info, 181fb299fa2Sopenharmony_ci const BlockBuffer &buffer, std::vector<uint8_t> &outData, size_t &bufferSize) 182fb299fa2Sopenharmony_ci { 183fb299fa2Sopenharmony_ci Hpackage::PkgManager *pkgManager = Hpackage::PkgManager::CreatePackageInstance(); 184fb299fa2Sopenharmony_ci if (pkgManager == nullptr) { 185fb299fa2Sopenharmony_ci PATCH_LOGE("Can not get manager "); 186fb299fa2Sopenharmony_ci return -1; 187fb299fa2Sopenharmony_ci } 188fb299fa2Sopenharmony_ci Hpackage::PkgManager::StreamPtr stream1 = nullptr; 189fb299fa2Sopenharmony_ci pkgManager->CreatePkgStream(stream1, "gzip", [&outData, &bufferSize](const PkgBuffer &data, 190fb299fa2Sopenharmony_ci size_t size, size_t start, bool isFinish, const void *context) ->int { 191fb299fa2Sopenharmony_ci if (isFinish) { 192fb299fa2Sopenharmony_ci return 0; 193fb299fa2Sopenharmony_ci } 194fb299fa2Sopenharmony_ci bufferSize += size; 195fb299fa2Sopenharmony_ci if ((start + bufferSize) > outData.size()) { 196fb299fa2Sopenharmony_ci outData.resize(IGMDIFF_LIMIT_UNIT * ((start + bufferSize) / IGMDIFF_LIMIT_UNIT + 1)); 197fb299fa2Sopenharmony_ci } 198fb299fa2Sopenharmony_ci return memcpy_s(outData.data() + start, outData.size(), data.buffer, size); 199fb299fa2Sopenharmony_ci }, nullptr); 200fb299fa2Sopenharmony_ci if (pkgManager->CompressBuffer(info, {buffer.buffer, buffer.length}, stream1) != 0) { 201fb299fa2Sopenharmony_ci PATCH_LOGE("Can not Compress buff "); 202fb299fa2Sopenharmony_ci Hpackage::PkgManager::ReleasePackageInstance(pkgManager); 203fb299fa2Sopenharmony_ci return -1; 204fb299fa2Sopenharmony_ci } 205fb299fa2Sopenharmony_ci PATCH_DEBUG("UpdateDiff::MakePatch totalSize: %zu", bufferSize); 206fb299fa2Sopenharmony_ci Hpackage::PkgManager::ReleasePackageInstance(pkgManager); 207fb299fa2Sopenharmony_ci return 0; 208fb299fa2Sopenharmony_ci } 209fb299fa2Sopenharmony_ci 210fb299fa2Sopenharmony_ci int DeflateAdapterTest(const std::string &fileName, Hpackage::PkgManager::FileInfoPtr info) 211fb299fa2Sopenharmony_ci { 212fb299fa2Sopenharmony_ci std::vector<uint8_t> outData; 213fb299fa2Sopenharmony_ci size_t dataSize = 0; 214fb299fa2Sopenharmony_ci std::unique_ptr<TestPatchWriter> testPatchWriter(new TestPatchWriter(outData)); 215fb299fa2Sopenharmony_ci if (testPatchWriter == nullptr) { 216fb299fa2Sopenharmony_ci PATCH_LOGE("Failed to create data writer"); 217fb299fa2Sopenharmony_ci return -1; 218fb299fa2Sopenharmony_ci } 219fb299fa2Sopenharmony_ci 220fb299fa2Sopenharmony_ci MemMapInfo memInfo {}; 221fb299fa2Sopenharmony_ci if (PatchMapFile(TEST_PATH_FROM + fileName, memInfo) != 0) { 222fb299fa2Sopenharmony_ci PATCH_LOGE("Failed to map file"); 223fb299fa2Sopenharmony_ci return -1; 224fb299fa2Sopenharmony_ci } 225fb299fa2Sopenharmony_ci 226fb299fa2Sopenharmony_ci std::vector<uint8_t> outData1; 227fb299fa2Sopenharmony_ci size_t dataSize1 = 0; 228fb299fa2Sopenharmony_ci if (CompressData(info, {memInfo.memory, memInfo.length}, outData1, dataSize1) != 0) { 229fb299fa2Sopenharmony_ci PATCH_LOGE("Failed to compress file"); 230fb299fa2Sopenharmony_ci return -1; 231fb299fa2Sopenharmony_ci } 232fb299fa2Sopenharmony_ci 233fb299fa2Sopenharmony_ci info->unpackedSize = memInfo.length; 234fb299fa2Sopenharmony_ci 235fb299fa2Sopenharmony_ci std::unique_ptr<DeflateAdapter> deflateAdapter; 236fb299fa2Sopenharmony_ci if (info->packMethod == PKG_COMPRESS_METHOD_ZIP) { 237fb299fa2Sopenharmony_ci deflateAdapter.reset(new ZipAdapter(testPatchWriter.get(), 0, info)); 238fb299fa2Sopenharmony_ci } else if (info->packMethod == PKG_COMPRESS_METHOD_LZ4) { 239fb299fa2Sopenharmony_ci deflateAdapter.reset(new Lz4FrameAdapter(testPatchWriter.get(), 0, info)); 240fb299fa2Sopenharmony_ci } else if (info->packMethod == PKG_COMPRESS_METHOD_LZ4_BLOCK) { 241fb299fa2Sopenharmony_ci deflateAdapter.reset(new Lz4BlockAdapter(testPatchWriter.get(), 0, info)); 242fb299fa2Sopenharmony_ci } 243fb299fa2Sopenharmony_ci if (deflateAdapter == nullptr) { 244fb299fa2Sopenharmony_ci PATCH_LOGE("Failed to create deflate adapter"); 245fb299fa2Sopenharmony_ci return -1; 246fb299fa2Sopenharmony_ci } 247fb299fa2Sopenharmony_ci deflateAdapter->Open(); 248fb299fa2Sopenharmony_ci 249fb299fa2Sopenharmony_ci size_t offset = 0; 250fb299fa2Sopenharmony_ci while (offset < memInfo.length) { 251fb299fa2Sopenharmony_ci size_t writeSize = (memInfo.length > (offset + DeflateAdapter::BUFFER_SIZE)) ? 252fb299fa2Sopenharmony_ci DeflateAdapter::BUFFER_SIZE : (memInfo.length - offset); 253fb299fa2Sopenharmony_ci BlockBuffer data = {memInfo.memory + offset, writeSize}; 254fb299fa2Sopenharmony_ci if (deflateAdapter->WriteData(data) != 0) { 255fb299fa2Sopenharmony_ci PATCH_LOGE("Failed to compress data"); 256fb299fa2Sopenharmony_ci return -1; 257fb299fa2Sopenharmony_ci } 258fb299fa2Sopenharmony_ci offset += writeSize; 259fb299fa2Sopenharmony_ci } 260fb299fa2Sopenharmony_ci deflateAdapter->FlushData(dataSize); 261fb299fa2Sopenharmony_ci 262fb299fa2Sopenharmony_ci // compare 263fb299fa2Sopenharmony_ci if (dataSize == dataSize1 && memcmp(outData.data(), outData1.data(), dataSize1) == 0) { 264fb299fa2Sopenharmony_ci return 0; 265fb299fa2Sopenharmony_ci } 266fb299fa2Sopenharmony_ci return 1; 267fb299fa2Sopenharmony_ci } 268fb299fa2Sopenharmony_ci}; 269fb299fa2Sopenharmony_ci 270fb299fa2Sopenharmony_ciHWTEST_F(BZip2AdapterUnitTest, BZip2AdapterBufferTest, TestSize.Level1) 271fb299fa2Sopenharmony_ci{ 272fb299fa2Sopenharmony_ci BZip2AdapterUnitTest test; 273fb299fa2Sopenharmony_ci EXPECT_EQ(0, test.BZip2AdapterBufferTest()); 274fb299fa2Sopenharmony_ci} 275fb299fa2Sopenharmony_ci 276fb299fa2Sopenharmony_ciHWTEST_F(BZip2AdapterUnitTest, BZip2AdapterAddMoreTest, TestSize.Level1) 277fb299fa2Sopenharmony_ci{ 278fb299fa2Sopenharmony_ci BZip2AdapterUnitTest test; 279fb299fa2Sopenharmony_ci EXPECT_EQ(0, test.BZip2AdapterAddMoreTest()); 280fb299fa2Sopenharmony_ci} 281fb299fa2Sopenharmony_ci 282fb299fa2Sopenharmony_ciHWTEST_F(BZip2AdapterUnitTest, DeflateAdapterTestForZip, TestSize.Level1) 283fb299fa2Sopenharmony_ci{ 284fb299fa2Sopenharmony_ci ZipFileInfo zipInfo {}; 285fb299fa2Sopenharmony_ci zipInfo.fileInfo.packMethod = PKG_COMPRESS_METHOD_ZIP; 286fb299fa2Sopenharmony_ci zipInfo.method = 8; 287fb299fa2Sopenharmony_ci zipInfo.level = 6; 288fb299fa2Sopenharmony_ci zipInfo.windowBits = -15; 289fb299fa2Sopenharmony_ci zipInfo.memLevel = 8; 290fb299fa2Sopenharmony_ci zipInfo.strategy = 0; 291fb299fa2Sopenharmony_ci BZip2AdapterUnitTest test; 292fb299fa2Sopenharmony_ci EXPECT_EQ(0, test.DeflateAdapterTest("../diffpatch/patchtest.new", &zipInfo.fileInfo)); 293fb299fa2Sopenharmony_ci} 294fb299fa2Sopenharmony_ci 295fb299fa2Sopenharmony_ciHWTEST_F(BZip2AdapterUnitTest, DeflateAdapterTestForLz4, TestSize.Level1) 296fb299fa2Sopenharmony_ci{ 297fb299fa2Sopenharmony_ci Lz4FileInfo lz4Info {}; 298fb299fa2Sopenharmony_ci lz4Info.fileInfo.packMethod = PKG_COMPRESS_METHOD_LZ4; 299fb299fa2Sopenharmony_ci lz4Info.compressionLevel = 2; 300fb299fa2Sopenharmony_ci lz4Info.blockIndependence = 0; 301fb299fa2Sopenharmony_ci lz4Info.contentChecksumFlag = 0; 302fb299fa2Sopenharmony_ci lz4Info.blockSizeID = 0; 303fb299fa2Sopenharmony_ci BZip2AdapterUnitTest test; 304fb299fa2Sopenharmony_ci EXPECT_EQ(0, test.DeflateAdapterTest("../diffpatch/patchtest.test", &lz4Info.fileInfo)); 305fb299fa2Sopenharmony_ci} 306fb299fa2Sopenharmony_ci 307fb299fa2Sopenharmony_ciHWTEST_F(BZip2AdapterUnitTest, DeflateAdapterTestForLz4_2, TestSize.Level1) 308fb299fa2Sopenharmony_ci{ 309fb299fa2Sopenharmony_ci Lz4FileInfo lz4Info {}; 310fb299fa2Sopenharmony_ci lz4Info.fileInfo.packMethod = PKG_COMPRESS_METHOD_LZ4; 311fb299fa2Sopenharmony_ci lz4Info.compressionLevel = 2; 312fb299fa2Sopenharmony_ci lz4Info.blockIndependence = 0; 313fb299fa2Sopenharmony_ci lz4Info.contentChecksumFlag = 0; 314fb299fa2Sopenharmony_ci lz4Info.blockSizeID = 7; 315fb299fa2Sopenharmony_ci BZip2AdapterUnitTest test; 316fb299fa2Sopenharmony_ci EXPECT_EQ(0, test.DeflateAdapterTest("../diffpatch/patchtest.test", &lz4Info.fileInfo)); 317fb299fa2Sopenharmony_ci} 318fb299fa2Sopenharmony_ci 319fb299fa2Sopenharmony_ciHWTEST_F(BZip2AdapterUnitTest, DeflateAdapterTestForLz4_3, TestSize.Level1) 320fb299fa2Sopenharmony_ci{ 321fb299fa2Sopenharmony_ci Lz4FileInfo lz4Info {}; 322fb299fa2Sopenharmony_ci lz4Info.fileInfo.packMethod = PKG_COMPRESS_METHOD_LZ4; 323fb299fa2Sopenharmony_ci lz4Info.compressionLevel = 2; 324fb299fa2Sopenharmony_ci lz4Info.blockIndependence = 0; 325fb299fa2Sopenharmony_ci lz4Info.contentChecksumFlag = 0; 326fb299fa2Sopenharmony_ci lz4Info.blockSizeID = 4; 327fb299fa2Sopenharmony_ci BZip2AdapterUnitTest test; 328fb299fa2Sopenharmony_ci EXPECT_EQ(0, test.DeflateAdapterTest("../diffpatch/patchtest.test", &lz4Info.fileInfo)); 329fb299fa2Sopenharmony_ci} 330fb299fa2Sopenharmony_ci 331fb299fa2Sopenharmony_ciHWTEST_F(BZip2AdapterUnitTest, DeflateAdapterTestForLz4_4, TestSize.Level1) 332fb299fa2Sopenharmony_ci{ 333fb299fa2Sopenharmony_ci Lz4FileInfo lz4Info {}; 334fb299fa2Sopenharmony_ci lz4Info.fileInfo.packMethod = PKG_COMPRESS_METHOD_LZ4; 335fb299fa2Sopenharmony_ci lz4Info.compressionLevel = 2; 336fb299fa2Sopenharmony_ci lz4Info.blockIndependence = 0; 337fb299fa2Sopenharmony_ci lz4Info.contentChecksumFlag = 0; 338fb299fa2Sopenharmony_ci lz4Info.blockSizeID = 5; 339fb299fa2Sopenharmony_ci BZip2AdapterUnitTest test; 340fb299fa2Sopenharmony_ci EXPECT_EQ(0, test.DeflateAdapterTest("../diffpatch/patchtest.test", &lz4Info.fileInfo)); 341fb299fa2Sopenharmony_ci} 342fb299fa2Sopenharmony_ci 343fb299fa2Sopenharmony_ciHWTEST_F(BZip2AdapterUnitTest, DeflateAdapterTestForLz4_5, TestSize.Level1) 344fb299fa2Sopenharmony_ci{ 345fb299fa2Sopenharmony_ci Lz4FileInfo lz4Info {}; 346fb299fa2Sopenharmony_ci lz4Info.fileInfo.packMethod = PKG_COMPRESS_METHOD_LZ4; 347fb299fa2Sopenharmony_ci lz4Info.compressionLevel = 2; 348fb299fa2Sopenharmony_ci lz4Info.blockIndependence = 0; 349fb299fa2Sopenharmony_ci lz4Info.contentChecksumFlag = 0; 350fb299fa2Sopenharmony_ci lz4Info.blockSizeID = 5; 351fb299fa2Sopenharmony_ci lz4Info.autoFlush = 0; 352fb299fa2Sopenharmony_ci BZip2AdapterUnitTest test; 353fb299fa2Sopenharmony_ci EXPECT_EQ(0, test.DeflateAdapterTest("../diffpatch/patchtest.test", &lz4Info.fileInfo)); 354fb299fa2Sopenharmony_ci} 355fb299fa2Sopenharmony_ci 356fb299fa2Sopenharmony_ciHWTEST_F(BZip2AdapterUnitTest, DeflateAdapterTestForLz4Block, TestSize.Level1) 357fb299fa2Sopenharmony_ci{ 358fb299fa2Sopenharmony_ci Lz4FileInfo lz4Info {}; 359fb299fa2Sopenharmony_ci lz4Info.fileInfo.packMethod = PKG_COMPRESS_METHOD_LZ4_BLOCK; 360fb299fa2Sopenharmony_ci lz4Info.compressionLevel = 2; 361fb299fa2Sopenharmony_ci lz4Info.blockIndependence = 1; 362fb299fa2Sopenharmony_ci lz4Info.contentChecksumFlag = 1; 363fb299fa2Sopenharmony_ci lz4Info.blockSizeID = 5; 364fb299fa2Sopenharmony_ci BZip2AdapterUnitTest test; 365fb299fa2Sopenharmony_ci EXPECT_EQ(0, test.DeflateAdapterTest("../diffpatch/patchtest.test", &lz4Info.fileInfo)); 366fb299fa2Sopenharmony_ci} 367fb299fa2Sopenharmony_ci 368fb299fa2Sopenharmony_ciHWTEST_F(BZip2AdapterUnitTest, DeflateAdapterTestForLz4Block_2, TestSize.Level1) 369fb299fa2Sopenharmony_ci{ 370fb299fa2Sopenharmony_ci Lz4FileInfo lz4Info {}; 371fb299fa2Sopenharmony_ci lz4Info.fileInfo.packMethod = PKG_COMPRESS_METHOD_LZ4_BLOCK; 372fb299fa2Sopenharmony_ci lz4Info.compressionLevel = 5; 373fb299fa2Sopenharmony_ci lz4Info.blockIndependence = 1; 374fb299fa2Sopenharmony_ci lz4Info.contentChecksumFlag = 1; 375fb299fa2Sopenharmony_ci lz4Info.blockSizeID = 5; 376fb299fa2Sopenharmony_ci BZip2AdapterUnitTest test; 377fb299fa2Sopenharmony_ci EXPECT_EQ(0, test.DeflateAdapterTest("../diffpatch/patchtest.test", &lz4Info.fileInfo)); 378fb299fa2Sopenharmony_ci} 379fb299fa2Sopenharmony_ci 380fb299fa2Sopenharmony_ciHWTEST_F(BZip2AdapterUnitTest, DeflateAdapterTestForLz4Block_3, TestSize.Level1) 381fb299fa2Sopenharmony_ci{ 382fb299fa2Sopenharmony_ci Lz4FileInfo lz4Info {}; 383fb299fa2Sopenharmony_ci lz4Info.fileInfo.packMethod = PKG_COMPRESS_METHOD_LZ4_BLOCK; 384fb299fa2Sopenharmony_ci lz4Info.compressionLevel = 5; 385fb299fa2Sopenharmony_ci lz4Info.blockIndependence = 1; 386fb299fa2Sopenharmony_ci lz4Info.contentChecksumFlag = 1; 387fb299fa2Sopenharmony_ci lz4Info.blockSizeID = 0; 388fb299fa2Sopenharmony_ci BZip2AdapterUnitTest test; 389fb299fa2Sopenharmony_ci EXPECT_EQ(0, test.DeflateAdapterTest("../diffpatch/patchtest.test", &lz4Info.fileInfo)); 390fb299fa2Sopenharmony_ci} 391fb299fa2Sopenharmony_ci 392fb299fa2Sopenharmony_ciHWTEST_F(BZip2AdapterUnitTest, DeflateAdapterTestForLz4Block_4, TestSize.Level1) 393fb299fa2Sopenharmony_ci{ 394fb299fa2Sopenharmony_ci DeflateAdapter adapterTest; 395fb299fa2Sopenharmony_ci BlockBuffer srcTestData; 396fb299fa2Sopenharmony_ci size_t offTest = 0; 397fb299fa2Sopenharmony_ci adapterTest.Open(); 398fb299fa2Sopenharmony_ci EXPECT_EQ(0, adapterTest.WriteData(srcTestData)); 399fb299fa2Sopenharmony_ci EXPECT_EQ(0, adapterTest.FlushData(offTest)); 400fb299fa2Sopenharmony_ci} 401fb299fa2Sopenharmony_ci} 402