!1 增加分支UT

Merge pull request !1 from 冯泽悟/master
This commit is contained in:
openharmony_ci
2022-09-24 11:02:57 +00:00
committed by Gitee
5 changed files with 277 additions and 0 deletions
+64
View File
@@ -199,6 +199,70 @@ ohos_unittest("imagecolorspacetest") {
resource_config_file = "//foundation/multimedia/image_framework/test/resource/image/ohos_test.xml"
external_deps = [ "c_utils:utils" ]
}
ohos_unittest("imagepluginslibjpegplugintest") {
module_out_path = module_output_path
include_dirs = [
"//foundation/multimedia/image_framework/frameworks/innerkitsimpl/converter/include",
"//foundation/multimedia/image_framework/frameworks/innerkitsimpl/utils/include",
"//foundation/multimedia/image_framework/interfaces/innerkits/include",
"//foundation/multimedia/image_framework/plugins/manager/include",
"//foundation/multimedia/utils/include",
"//foundation/graphic/graphic_2d/utils/color_manager/export",
"//third_party/googletest/googletest/include",
"//commonlibrary/c_utils/base/include",
]
cflags = [
"-DIMAGE_DEBUG_FLAG",
"-DIMAGE_COLORSPACE_FLAG",
]
sources = [ "//foundation/multimedia/image_framework/plugins/common/libs/image/libjpegplugin/src/jpeg_decoder.cpp" ]
deps = [
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//foundation/graphic/graphic_2d/utils/color_manager:color_manager",
"//foundation/multimedia/image_framework/frameworks/innerkitsimpl/utils:image_utils",
"//foundation/multimedia/image_framework/interfaces/innerkits:image_native",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
resource_config_file = "//foundation/multimedia/image_framework/test/resource/image/ohos_test.xml"
external_deps = [ "c_utils:utils" ]
}
ohos_unittest("ImageCreatorNapiTest") {
module_out_path = module_output_path
include_dirs = [
"//foundation/multimedia/image_framework/frameworks/innerkitsimpl/converter/include",
"//foundation/multimedia/image_framework/frameworks/innerkitsimpl/utils/include",
"//foundation/multimedia/image_framework/interfaces/innerkits/include",
"//foundation/multimedia/image_framework/plugins/manager/include",
"//foundation/multimedia/utils/include",
"//foundation/graphic/graphic_2d/utils/color_manager/export",
"//third_party/googletest/googletest/include",
"//commonlibrary/c_utils/base/include",
]
cflags = [
"-DIMAGE_DEBUG_FLAG",
"-DIMAGE_COLORSPACE_FLAG",
]
sources = [ "//foundation/multimedia/image_framework/kits/js/common/image_creator_napi.cpp" ]
deps = [
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//foundation/graphic/graphic_2d/utils/color_manager:color_manager",
"//foundation/multimedia/image_framework/frameworks/innerkitsimpl/utils:image_utils",
"//foundation/multimedia/image_framework/interfaces/innerkits:image_native",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
resource_config_file = "//foundation/multimedia/image_framework/test/resource/image/ohos_test.xml"
external_deps = [ "c_utils:utils" ]
}
################################################
group("unittest") {
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2021 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 "image_creator_napi.h"
#include <uv.h>
#include "media_errors.h"
#include "hilog/log.h"
#include "image_napi_utils.h"
#include "image_creator_context.h"
#include "image_napi.h"
#include "image_creator_manager.h"
using namespace testing::ext;
using namespace OHOS::Media;
namespace OHOS {
namespace Multimedia {
class ImageCreatorNapiTest : public testing::Test {
public:
ImageCreatorNapiTest() {}
~ImageCreatorNapiTest() {}
};
/**
* @tc.name: ImageCreatorNapi001
* @tc.desc: test ProcessPremulF16Pixel
* @tc.type: FUNC
*/
HWTEST_F(ImageCreatorNapiTest, ImageCreatorNapi001, TestSize.Level3)
{
GTEST_LOG_(INFO) << "ImageCreatorNapiTest: ImageCreatorNapi001 start";
/**
* @tc.steps: step1. set env, info.
* @tc.expected: step1. The new env and info are nullptr.
*/
napi_env env = nullptr;
napi_callback_info info = nullptr;
napi_value ret = ImageCreatorNapi::JsTest(env, info);
EXPECT_EQ(res, true);
GTEST_LOG_(INFO) << "ImageCreatorNapiTest: ImageCreatorNapi001 end";
}
}
}
@@ -519,6 +519,7 @@ HWTEST_F(ImagePixelMapTest, ImagePixelMap011, TestSize.Level3)
EXPECT_EQ(true, pixelmap1->IsSameImage(*pixelmap2));
GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap011 end";
}
/**
* @tc.name: ImagePixelMap012
* @tc.desc: create pixelmap with color,colorlength,offset,width and initialization options
@@ -580,5 +581,57 @@ HWTEST_F(ImagePixelMapTest, ImagePixelMap013, TestSize.Level3)
EXPECT_EQ(true, pixelmap1->IsSameImage(*pixelmap2));
GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap013 end";
}
/**
* @tc.name: ImagePixelMap014
* @tc.desc: test ProcessPremulF16Pixel
* @tc.type: FUNC
*/
HWTEST_F(ImagePixelMapTest, ImagePixelMap014, TestSize.Level3)
{
GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap014 start";
/**
* @tc.steps: step1. set mulPixel, alpha, and percent
* @tc.expected: step1. The new alpha is float zero.
*/
constexpr uint8_t RGBA_F16_R_OFFSET = 0;
uint8_t *data_ = nullptr;
const float alpha = 0.0f;
const float percent = 0.5;
float mulPixel = HalfTranslate(data_ + RGBA_F16_R_OFFSET);
float zero= PixelMap::ProcessPremulF16Pixel(mulPixel, alpha, percent);
bool res = false;
if (zero < 0.000001 && zero > -0.000001) {
res = true;
}
EXPECT_EQ(res, true);
GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap014 end";
}
/**
* @tc.name: ImagePixelMap015
* @tc.desc: test ProcessPremulF16Pixel
* @tc.type: FUNC
*/
HWTEST_F(ImagePixelMapTest, ImagePixelMap015, TestSize.Level3)
{
GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap015 start";
/**
* @tc.steps: step1. set mulPixel, alpha, and percent
* @tc.expected: step1. The new alpha is float zero.
*/
constexpr uint8_t RGBA_F16_R_OFFSET = 0;
uint8_t *data_ = nullptr;
const float alpha = 0.3;
const float percent = 0.5;
float mulPixel = HalfTranslate(data_ + RGBA_F16_R_OFFSET);
float zero= PixelMap::ProcessPremulF16Pixel(mulPixel, alpha, percent);
bool res = true;
if (zero < 0.000001 && zero > -0.000001) {
res = false;
}
EXPECT_EQ(res, true);
GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap015 end";
}
} // namespace Multimedia
} // namespace OHOS
@@ -0,0 +1,79 @@
/*
* 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 <gtest/gtest.h>
#include "jpeg_decoder.h"
#include <map>
#include "jerror.h"
#include "media_errors.h"
#include "string_ex.h"
#ifndef _WIN32
#include "securec.h"
#else
#include "memory.h"
#endif
using namespace testing::ext;
using namespace OHOS::Media;
namespace OHOS {
namespace Multimedia {
class ImagePluginsLibjpegpluginTest : public testing::Test {
public:
ImagePluginsLibjpegpluginTest() {}
~ImagePluginsLibjpegpluginTest() {}
};
/**
* @tc.name: Libjpegplugin001
* @tc.desc: test ProcessPremulF16Pixel
* @tc.type: FUNC
*/
HWTEST_F(ImagePluginsLibjpegpluginTest, Libjpegplugin001, TestSize.Level3)
{
GTEST_LOG_(INFO) << "ImagePluginsLibjpegpluginTest: Libjpegplugin001 start";
/**
* @tc.steps: step1. set index, key, value.
* @tc.expected: step1. The new value is default_exif_value.
*/
uint32_t index = 0;
std::string value = "default_exif_value";
std::string key = "BitsPerSample";
uint32_t ret = JpegDecoder::GetImagePropertyString(index, key, value);
EXPECT_EQ(res, true);
GTEST_LOG_(INFO) << "ImagePluginsLibjpegpluginTest: Libjpegplugin001 end";
}
/**
* @tc.name: Libjpegplugin001
* @tc.desc: test ProcessPremulF16Pixel
* @tc.type: FUNC
*/
HWTEST_F(ImagePluginsLibjpegpluginTest, Libjpegplugin001, TestSize.Level3)
{
GTEST_LOG_(INFO) << "ImagePluginsLibjpegpluginTest: Libjpegplugin001 start";
/**
* @tc.steps: step1. set index, key, value.
* @tc.expected: step1. The new value is 0.
*/
uint32_t index = 0;
std::string value = "0";
std::string key = "BitsPerSample";
uint32_t ret = JpegDecoder::GetImagePropertyString(index, key, value);
EXPECT_EQ(res, true);
GTEST_LOG_(INFO) << "ImagePluginsLibjpegpluginTest: Libjpegplugin001 end";
}
}
}
@@ -44,6 +44,7 @@ static constexpr OHOS::HiviewDFX::HiLogLabel LABEL_TEST = {
static constexpr uint32_t DEFAULT_DELAY_UTIME = 10000; // 10 ms.
static const std::string IMAGE_INPUT_JPEG_PATH = "/data/local/tmp/image/test.jpg";
static const std::string IMAGE_INPUT_HW_JPEG_PATH = "/data/local/tmp/image/test_hw.jpg";
static const std::string IMAGE_INPUT__PATH = "/data/local/tmp/image/test.tiff";
static const std::string IMAGE_INPUT_EXIF_JPEG_PATH = "/data/local/tmp/image/test_exif.jpg";
static const std::string IMAGE_OUTPUT_JPEG_FILE_PATH = "/data/test/test_file.jpg";
static const std::string IMAGE_OUTPUT_JPEG_BUFFER_PATH = "/data/test/test_buffer.jpg";
@@ -211,6 +212,31 @@ HWTEST_F(ImageSourceJpegTest, TC034, TestSize.Level3)
ASSERT_EQ(ret, SUCCESS);
}
/**
* @tc.name: TC034_1
* @tc.desc: Test GetImagePropertyString
* @tc.type: FUNC
*/
HWTEST_F(ImageSourceJpegTest, TC034, TestSize.Level3)
{
/**
* @tc.steps: step1. create image source by error jpeg data and jpeg format hit.
* @tc.expected: step1. create image source success.
*/
uint32_t errorCode = 0;
SourceOptions opts;
std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(IMAGE_INPUT_TIFF_PATH, opts, errorCode);
ASSERT_EQ(errorCode, SUCCESS);
ASSERT_NE(imageSource.get(), nullptr);
uint32_t index = 0;
std::string value = "BitsPerSample";
std::string key;
uint32_t ret = imageSource->GetImagePropertyString(index, key, value);
ASSERT_EQ(ret, SUCCESS);
}
/**
* @tc.name: TC035
* @tc.desc: Test CreatePixelMap