mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-27 01:03:08 +00:00
tdd compressor
Signed-off-by: xu <chenxu25@huawei.com>
This commit is contained in:
parent
a82c2a7410
commit
92339d50dd
@ -96,6 +96,7 @@
|
||||
"//foundation/arkui/ace_engine/frameworks/core/event/test:unittest",
|
||||
"//foundation/arkui/ace_engine/frameworks/core/focus/test:unittest",
|
||||
"//foundation/arkui/ace_engine/frameworks/core/gestures/test:unittest",
|
||||
"//foundation/arkui/ace_engine/frameworks/core/image/test:unittest",
|
||||
"//foundation/arkui/ace_engine/test/fuzztest:fuzztest"
|
||||
]
|
||||
}
|
||||
|
@ -144,6 +144,7 @@ ohos_unittest("ImageProviderTest") {
|
||||
configs = [
|
||||
":config_image_provider_test",
|
||||
"$ace_root:ace_test_config",
|
||||
"$ace_root:ace_test_coverage_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
@ -164,10 +165,53 @@ config("config_image_provider_test") {
|
||||
include_dirs = []
|
||||
}
|
||||
|
||||
ohos_unittest("ImageCompressorTest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [
|
||||
"$ace_root/frameworks/core/common/ace_application_info.cpp",
|
||||
"$ace_root/frameworks/core/common/ace_engine.cpp",
|
||||
"$ace_root/frameworks/core/common/container.cpp",
|
||||
"$ace_root/frameworks/core/common/container_scope.cpp",
|
||||
"$ace_root/frameworks/core/common/window.cpp",
|
||||
"$ace_root/frameworks/core/components/display/display_component.cpp",
|
||||
"$ace_root/frameworks/core/components/display/render_display.cpp",
|
||||
"$ace_root/frameworks/core/image/flutter_image_cache.cpp",
|
||||
"$ace_root/frameworks/core/image/image_cache.cpp",
|
||||
"$ace_root/frameworks/core/image/image_compressor.cpp",
|
||||
"$ace_root/frameworks/core/image/image_loader.cpp",
|
||||
"$ace_root/frameworks/core/image/image_provider.cpp",
|
||||
"$ace_root/frameworks/core/image/image_source_info.cpp",
|
||||
"$ace_root/frameworks/core/mock/mock_ace_application_info.cpp",
|
||||
"$ace_root/frameworks/core/mock/mock_ace_container.cpp",
|
||||
"image_compressor_test.cpp",
|
||||
]
|
||||
|
||||
configs = [
|
||||
":config_image_cache_test",
|
||||
"$ace_root:ace_test_config",
|
||||
"$ace_root:ace_test_coverage_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"$ace_flutter_engine_root:third_party_flutter_engine_ohos",
|
||||
"$ace_flutter_engine_root/skia:ace_skia_ohos",
|
||||
"$ace_root/adapter/ohos/osal:ace_osal_ohos",
|
||||
"$ace_root/frameworks/base:ace_base_ohos",
|
||||
"$ace_root/frameworks/base/resource:ace_resource",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//third_party/opencl-headers:libcl",
|
||||
]
|
||||
defines = [ "ENABLE_OPENCL" ]
|
||||
external_deps = [ "c_utils:utils" ]
|
||||
part_name = ace_engine_part
|
||||
resource_config_file = "//foundation/arkui/ace_engine/test/resource/graphicalbasicability/ohos_test.xml"
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
deps = [
|
||||
":ImageCacheTest",
|
||||
# ":ImageCacheTest",
|
||||
# ":ImageProviderTest",
|
||||
":ImageCompressorTest",
|
||||
]
|
||||
}
|
||||
|
229
frameworks/core/image/test/unittest/image_compressor_test.cpp
Normal file
229
frameworks/core/image/test/unittest/image_compressor_test.cpp
Normal file
@ -0,0 +1,229 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "core/image/test/unittest/image_compressor_test.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS::Ace {
|
||||
|
||||
class ImageCompressorTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase() {}
|
||||
static void TearDownTestCase() {}
|
||||
void SetUp()
|
||||
{
|
||||
instance->refCount_ = 0;
|
||||
}
|
||||
void TearDown() {}
|
||||
|
||||
std::shared_ptr<ImageCompressor> instance = ImageCompressor::GetInstance();
|
||||
};
|
||||
|
||||
static sk_sp<SkImage> LoadImage()
|
||||
{
|
||||
auto imageLoader = FileImageLoader();
|
||||
auto data = imageLoader.LoadImageData(ImageSourceInfo(FILE_JPG));
|
||||
auto image = SkImage::MakeFromEncoded(data);
|
||||
GTEST_LOG_(INFO) << "ImageCompressorTest LoadImage " << image;
|
||||
if (image) {
|
||||
return image->makeRasterImage();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ImageCompressor001
|
||||
* @tc.desc: Test partition info init
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5PFV6
|
||||
*/
|
||||
HWTEST_F(ImageCompressorTest, ImageCompressor001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. init instance
|
||||
* @tc.expected: parts inited
|
||||
*/
|
||||
instance->Init();
|
||||
ImageCompressor::PartInfo p = {};
|
||||
for (int i = 0; i < 1024; i++) {
|
||||
instance->InitPartitionInfo(&p, instance->partitions_[1], 1);
|
||||
instance->InitPartitionInfo(&p, instance->partitions_[1], 2);
|
||||
instance->InitPartitionInfo(&p, instance->partitions_[1], 3);
|
||||
}
|
||||
ASSERT_TRUE(instance->parts_.size() > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ImageCompressor002
|
||||
* @tc.desc: Test no shader file
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5PFV6
|
||||
*/
|
||||
HWTEST_F(ImageCompressorTest, ImageCompressor002, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. cache images one by one.
|
||||
*/
|
||||
std::string &path = const_cast<std::string &>(instance->shader_path_);
|
||||
path = "";
|
||||
instance->Init();
|
||||
auto image = LoadImage();
|
||||
if (image) {
|
||||
SkPixmap pixmap;
|
||||
image->peekPixels(&pixmap);
|
||||
std::string key = "key2";
|
||||
int32_t width = static_cast<int32_t>(pixmap.width());
|
||||
int32_t height = static_cast<int32_t>(pixmap.height());
|
||||
auto compressData = instance->GpuCompress(key, pixmap, width, height);
|
||||
ASSERT_TRUE(compressData == nullptr);
|
||||
instance->WriteToFile(key, compressData, {width, height});
|
||||
}
|
||||
path = "/system/bin/astc.bin";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ImageCompressor003
|
||||
* @tc.desc: Test compress success
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5PFV6
|
||||
*/
|
||||
HWTEST_F(ImageCompressorTest, ImageCompressor003, TestSize.Level1)
|
||||
{
|
||||
instance->Init();
|
||||
auto image = LoadImage();
|
||||
if (image) {
|
||||
SkPixmap pixmap;
|
||||
image->peekPixels(&pixmap);
|
||||
std::string key = "key3";
|
||||
int32_t width = static_cast<int32_t>(pixmap.width());
|
||||
int32_t height = static_cast<int32_t>(pixmap.height());
|
||||
auto compressData = instance->GpuCompress(key, pixmap, width, height);
|
||||
ASSERT_TRUE(compressData != nullptr);
|
||||
instance->WriteToFile(key, compressData, {width, height});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ImageCompressor004
|
||||
* @tc.desc: Test compress failed with quality failed
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5PFV6
|
||||
*/
|
||||
HWTEST_F(ImageCompressorTest, ImageCompressor004, TestSize.Level1)
|
||||
{
|
||||
instance->Init();
|
||||
instance->maxErr_ = 0;
|
||||
auto image = LoadImage();
|
||||
if (image) {
|
||||
SkPixmap pixmap;
|
||||
image->peekPixels(&pixmap);
|
||||
std::string key = "key4";
|
||||
int32_t width = static_cast<int32_t>(pixmap.width());
|
||||
int32_t height = static_cast<int32_t>(pixmap.height());
|
||||
auto compressData = instance->GpuCompress(key, pixmap, width, height);
|
||||
ASSERT_TRUE(compressData == nullptr);
|
||||
instance->WriteToFile(key, compressData, {width, height});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ImageCompressor005
|
||||
* @tc.desc: Test compress sucess and release context
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5PFV6
|
||||
*/
|
||||
HWTEST_F(ImageCompressorTest, ImageCompressor005, TestSize.Level1)
|
||||
{
|
||||
instance->Init();
|
||||
auto image = LoadImage();
|
||||
if (image) {
|
||||
SkPixmap pixmap;
|
||||
image->peekPixels(&pixmap);
|
||||
std::string key = "key5";
|
||||
int32_t width = static_cast<int32_t>(pixmap.width());
|
||||
int32_t height = static_cast<int32_t>(pixmap.height());
|
||||
auto compressData = instance->GpuCompress(key, pixmap, width, height);
|
||||
ASSERT_TRUE(compressData != nullptr);
|
||||
instance->WriteToFile(key, compressData, {width, height});
|
||||
auto task = instance->ScheduleReleaseTask();
|
||||
task();
|
||||
ASSERT_TRUE(instance->context_ == nullptr);
|
||||
instance->InitRecords();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ImageCompressor006
|
||||
* @tc.desc: Test compress sucess and release context
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5PFV6
|
||||
*/
|
||||
HWTEST_F(ImageCompressorTest, ImageCompressor006, TestSize.Level1)
|
||||
{
|
||||
instance->Init();
|
||||
auto image = LoadImage();
|
||||
if (image) {
|
||||
SkPixmap pixmap;
|
||||
image->peekPixels(&pixmap);
|
||||
std::string key = "key6";
|
||||
int32_t width = 0;
|
||||
int32_t height = 0;
|
||||
auto compressData = instance->GpuCompress(key, pixmap, width, height);
|
||||
ASSERT_TRUE(compressData == nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ImageCompressor007
|
||||
* @tc.desc: Test compress sucess and release context
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5PFV6
|
||||
*/
|
||||
HWTEST_F(ImageCompressorTest, ImageCompressor007, TestSize.Level1)
|
||||
{
|
||||
instance->Init();
|
||||
auto image = LoadImage();
|
||||
if (image) {
|
||||
SkPixmap pixmap;
|
||||
image->peekPixels(&pixmap);
|
||||
std::string key = "key7";
|
||||
int32_t width = static_cast<int32_t>(pixmap.width());
|
||||
int32_t height = static_cast<int32_t>(pixmap.height());
|
||||
auto compressData = instance->GpuCompress(key, pixmap, width, height);
|
||||
auto strip = instance->StripFileHeader(compressData);
|
||||
ASSERT_TRUE(strip != nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TestSwitch001
|
||||
* @tc.desc: Test switch
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5PFV6
|
||||
*/
|
||||
HWTEST_F(ImageCompressorTest, TestSwitch001, TestSize.Level1)
|
||||
{
|
||||
instance->Init();
|
||||
instance->switch_ = false;
|
||||
ASSERT_TRUE(!instance->CanCompress());
|
||||
instance->switch_ = true;
|
||||
ASSERT_TRUE(instance->CanCompress());
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace
|
30
frameworks/core/image/test/unittest/image_compressor_test.h
Normal file
30
frameworks/core/image/test/unittest/image_compressor_test.h
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_IMAGE_TEST_UNITTEST_IMAGE_COMPRESSOR_TEST_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_CORE_IMAGE_TEST_UNITTEST_IMAGE_COMPRESSOR_TEST_H
|
||||
|
||||
#define private public
|
||||
#define protected public
|
||||
#include "core/image/image_compressor.h"
|
||||
#include "core/image/image_cache.h"
|
||||
#include "core/image/image_loader.h"
|
||||
#include "third_party/skia/include/core/SkImage.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
const std::string FILE_JPG = "file:///data/test/resource/imageprovider/images/unbroken.jpg";
|
||||
} // namespace OHOS::Ace
|
||||
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_IMAGE_TEST_UNITTEST_IMAGE_COMPRESSOR_TEST_H
|
@ -23,4 +23,9 @@
|
||||
<option name="push" value="imageprovider/images -> /data/test/resource/imageprovider/" src="res"/>
|
||||
</preparer>
|
||||
</target>
|
||||
<target name="ImageCompressorTest">
|
||||
<preparer>
|
||||
<option name="push" value="imageprovider/images/unbroken.jpg -> /data/test/resource/imageprovider/images/" src="res"/>
|
||||
</preparer>
|
||||
</target>
|
||||
</configuration>
|
||||
|
Loading…
Reference in New Issue
Block a user