aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDichen Zhang <dichenzhang@google.com>2023-09-11 12:00:24 -0700
committerDichen Zhang <dichenzhang@google.com>2023-09-11 12:00:24 -0700
commit9fbbc26bb72dde593071dfa3d2eb677abdac7258 (patch)
treef983a0f380ed79faabc82dc7dd72d9527ea20468 /tests
parent030e8cf4ab0d2842181d7ed5faea100d8488a3a4 (diff)
downloadlibultrahdr-9fbbc26bb72dde593071dfa3d2eb677abdac7258.tar.gz
Add cMake files, remove liblog dependency and a few bug fixing
Diffstat (limited to 'tests')
-rw-r--r--tests/Android.bp39
-rw-r--r--tests/gainmapmath_test.cpp18
-rw-r--r--tests/icchelper_test.cpp23
-rw-r--r--tests/jpegdecoderhelper_test.cpp42
-rw-r--r--tests/jpegencoderhelper_test.cpp27
-rw-r--r--tests/jpegr_test.cpp27
6 files changed, 92 insertions, 84 deletions
diff --git a/tests/Android.bp b/tests/Android.bp
index 004a582..0979c5f 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -22,58 +22,49 @@ package {
}
cc_test {
- name: "ultrahdr_unit_test",
+ name: "ultrahdr_sample_app",
+ host_supported: true,
+ gtest: false,
test_suites: ["device-tests"],
srcs: [
- "gainmapmath_test.cpp",
- "icchelper_test.cpp",
- "jpegr_test.cpp",
+ "ultrahdr_app.cpp",
],
shared_libs: [
+ "libbase",
"libimage_io",
"libjpeg",
"liblog",
],
static_libs: [
- "libgmock",
- "libgtest",
"libjpegdecoder",
"libjpegencoder",
"libultrahdr",
- "libutils",
],
}
cc_test {
- name: "jpegencoderhelper_test",
+ name: "ultrahdr_unit_test",
test_suites: ["device-tests"],
srcs: [
+ "gainmapmath_test.cpp",
+ "icchelper_test.cpp",
+ "jpegr_test.cpp",
"jpegencoderhelper_test.cpp",
- ],
- shared_libs: [
- "libjpeg",
- "liblog",
- ],
- static_libs: [
- "libgtest",
- "libjpegencoder",
- ],
-}
-
-cc_test {
- name: "jpegdecoderhelper_test",
- test_suites: ["device-tests"],
- srcs: [
"jpegdecoderhelper_test.cpp",
],
shared_libs: [
+ "libimage_io",
"libjpeg",
"liblog",
],
static_libs: [
+ "libgmock",
"libgtest",
"libjpegdecoder",
+ "libjpegencoder",
"libultrahdr",
- "libutils",
+ ],
+ data: [
+ "./data/*.*",
],
}
diff --git a/tests/gainmapmath_test.cpp b/tests/gainmapmath_test.cpp
index 7c2d076..0f861ba 100644
--- a/tests/gainmapmath_test.cpp
+++ b/tests/gainmapmath_test.cpp
@@ -14,12 +14,12 @@
* limitations under the License.
*/
-#include <cmath>
#include <gtest/gtest.h>
#include <gmock/gmock.h>
-#include <ultrahdr/gainmapmath.h>
-namespace android::ultrahdr {
+#include "ultrahdr/gainmapmath.h"
+
+namespace ultrahdr {
class GainMapMathTest : public testing::Test {
public:
@@ -47,11 +47,11 @@ public:
}
Color ColorMin(Color e1, Color e2) {
- return {{{ fmin(e1.r, e2.r), fmin(e1.g, e2.g), fmin(e1.b, e2.b) }}};
+ return {{{ fminf(e1.r, e2.r), fminf(e1.g, e2.g), fminf(e1.b, e2.b) }}};
}
Color ColorMax(Color e1, Color e2) {
- return {{{ fmax(e1.r, e2.r), fmax(e1.g, e2.g), fmax(e1.b, e2.b) }}};
+ return {{{ fmaxf(e1.r, e2.r), fmaxf(e1.g, e2.g), fmaxf(e1.b, e2.b) }}};
}
Color RgbBlack() { return {{{ 0.0f, 0.0f, 0.0f }}}; }
@@ -836,9 +836,9 @@ TEST_F(GainMapMathTest, applyGainLUT) {
}
for (int boost = 1; boost <= 10; boost++) {
- ultrahdr_metadata_struct metadata = { .maxContentBoost = static_cast<float>(boost),
- .minContentBoost = 1.0f / pow(static_cast<float>(boost),
- 1.0f / 3.0f) };
+ ultrahdr_metadata_struct metadata = {.maxContentBoost = static_cast<float>(boost),
+ .minContentBoost = 1.0f /
+ powf(static_cast<float>(boost), 1.0f / 3.0f)};
GainLUT gainLUT(&metadata);
GainLUT gainLUTWithBoost(&metadata, metadata.maxContentBoost);
for (int idx = 0; idx < kGainFactorNumEntries; idx++) {
@@ -1356,4 +1356,4 @@ TEST_F(GainMapMathTest, ApplyMap) {
RgbWhite() / 2.0f);
}
-} // namespace android::ultrahdr
+} // namespace ultrahdr
diff --git a/tests/icchelper_test.cpp b/tests/icchelper_test.cpp
index ff61c08..081ef0e 100644
--- a/tests/icchelper_test.cpp
+++ b/tests/icchelper_test.cpp
@@ -15,11 +15,10 @@
*/
#include <gtest/gtest.h>
-#include <ultrahdr/icc.h>
-#include <ultrahdr/ultrahdr.h>
-#include <utils/Log.h>
-namespace android::ultrahdr {
+#include "ultrahdr/icc.h"
+
+namespace ultrahdr {
class IccHelperTest : public testing::Test {
public:
@@ -39,21 +38,22 @@ void IccHelperTest::SetUp() {}
void IccHelperTest::TearDown() {}
TEST_F(IccHelperTest, iccWriteThenRead) {
- sp<DataStruct> iccBt709 = IccHelper::writeIccProfile(ULTRAHDR_TF_SRGB,
- ULTRAHDR_COLORGAMUT_BT709);
+ std::shared_ptr<DataStruct> iccBt709 =
+ IccHelper::writeIccProfile(ULTRAHDR_TF_SRGB, ULTRAHDR_COLORGAMUT_BT709);
ASSERT_NE(iccBt709->getLength(), 0);
ASSERT_NE(iccBt709->getData(), nullptr);
EXPECT_EQ(IccHelper::readIccColorGamut(iccBt709->getData(), iccBt709->getLength()),
ULTRAHDR_COLORGAMUT_BT709);
- sp<DataStruct> iccP3 = IccHelper::writeIccProfile(ULTRAHDR_TF_SRGB, ULTRAHDR_COLORGAMUT_P3);
+ std::shared_ptr<DataStruct> iccP3 =
+ IccHelper::writeIccProfile(ULTRAHDR_TF_SRGB, ULTRAHDR_COLORGAMUT_P3);
ASSERT_NE(iccP3->getLength(), 0);
ASSERT_NE(iccP3->getData(), nullptr);
EXPECT_EQ(IccHelper::readIccColorGamut(iccP3->getData(), iccP3->getLength()),
ULTRAHDR_COLORGAMUT_P3);
- sp<DataStruct> iccBt2100 = IccHelper::writeIccProfile(ULTRAHDR_TF_SRGB,
- ULTRAHDR_COLORGAMUT_BT2100);
+ std::shared_ptr<DataStruct> iccBt2100 =
+ IccHelper::writeIccProfile(ULTRAHDR_TF_SRGB, ULTRAHDR_COLORGAMUT_BT2100);
ASSERT_NE(iccBt2100->getLength(), 0);
ASSERT_NE(iccBt2100->getData(), nullptr);
EXPECT_EQ(IccHelper::readIccColorGamut(iccBt2100->getData(), iccBt2100->getLength()),
@@ -61,7 +61,8 @@ TEST_F(IccHelperTest, iccWriteThenRead) {
}
TEST_F(IccHelperTest, iccEndianness) {
- sp<DataStruct> icc = IccHelper::writeIccProfile(ULTRAHDR_TF_SRGB, ULTRAHDR_COLORGAMUT_BT709);
+ std::shared_ptr<DataStruct> icc =
+ IccHelper::writeIccProfile(ULTRAHDR_TF_SRGB, ULTRAHDR_COLORGAMUT_BT709);
size_t profile_size = icc->getLength() - kICCIdentifierSize;
uint8_t* icc_bytes = reinterpret_cast<uint8_t*>(icc->getData()) + kICCIdentifierSize;
@@ -73,5 +74,5 @@ TEST_F(IccHelperTest, iccEndianness) {
EXPECT_EQ(static_cast<size_t>(encoded_size), profile_size);
}
-} // namespace android::ultrahdr
+} // namespace ultrahdr
diff --git a/tests/jpegdecoderhelper_test.cpp b/tests/jpegdecoderhelper_test.cpp
index e2da01c..838c911 100644
--- a/tests/jpegdecoderhelper_test.cpp
+++ b/tests/jpegdecoderhelper_test.cpp
@@ -14,25 +14,29 @@
* limitations under the License.
*/
-#include <ultrahdr/jpegdecoderhelper.h>
-#include <ultrahdr/icc.h>
-#include <gtest/gtest.h>
-#include <utils/Log.h>
-
#include <fcntl.h>
+#include <gtest/gtest.h>
-namespace android::ultrahdr {
-
-// No ICC or EXIF
-#define YUV_IMAGE "/sdcard/Documents/minnie-320x240-yuv.jpg"
+#include "ultrahdr/ultrahdrcommon.h"
+#include "ultrahdr/jpegdecoderhelper.h"
+#include "ultrahdr/icc.h"
+
+namespace ultrahdr {
+
+// minnie-320x240-yuv.jpg & minnie-320x240-y.jpg has no icc or exif
+// minnie-320x240-yuv-icc.jpg has icc
+#ifdef __ANDROID__
+#define YUV_IMAGE "/data/local/tmp/minnie-320x240-yuv.jpg"
+#define YUV_ICC_IMAGE "/data/local/tmp/minnie-320x240-yuv-icc.jpg"
+#define GREY_IMAGE "/data/local/tmp/minnie-320x240-y.jpg"
+#else
+#define YUV_IMAGE "./data/minnie-320x240-yuv.jpg"
+#define YUV_ICC_IMAGE "./data/minnie-320x240-yuv-icc.jpg"
+#define GREY_IMAGE "./data/minnie-320x240-y.jpg"
+#endif
#define YUV_IMAGE_SIZE 20193
-// Has ICC and EXIF
-#define YUV_ICC_IMAGE "/sdcard/Documents/minnie-320x240-yuv-icc.jpg"
#define YUV_ICC_IMAGE_SIZE 34266
-// No ICC or EXIF
-#define GREY_IMAGE "/sdcard/Documents/minnie-320x240-y.jpg"
#define GREY_IMAGE_SIZE 20193
-
#define IMAGE_WIDTH 320
#define IMAGE_HEIGHT 240
@@ -44,6 +48,7 @@ public:
};
JpegDecoderHelperTest();
~JpegDecoderHelperTest();
+
protected:
virtual void SetUp();
virtual void TearDown();
@@ -127,8 +132,8 @@ TEST_F(JpegDecoderHelperTest, getCompressedImageParameters) {
std::vector<uint8_t> icc, exif;
JpegDecoderHelper decoder;
- EXPECT_TRUE(decoder.getCompressedImageParameters(mYuvImage.buffer.get(), mYuvImage.size,
- &width, &height, &icc, &exif));
+ EXPECT_TRUE(decoder.getCompressedImageParameters(mYuvImage.buffer.get(), mYuvImage.size, &width,
+ &height, &icc, &exif));
EXPECT_EQ(width, IMAGE_WIDTH);
EXPECT_EQ(height, IMAGE_HEIGHT);
@@ -149,8 +154,7 @@ TEST_F(JpegDecoderHelperTest, getCompressedImageParametersIcc) {
EXPECT_GT(icc.size(), 0);
EXPECT_GT(exif.size(), 0);
- EXPECT_EQ(IccHelper::readIccColorGamut(icc.data(), icc.size()),
- ULTRAHDR_COLORGAMUT_BT709);
+ EXPECT_EQ(IccHelper::readIccColorGamut(icc.data(), icc.size()), ULTRAHDR_COLORGAMUT_BT709);
}
-} // namespace android::ultrahdr
+} // namespace ultrahdr
diff --git a/tests/jpegencoderhelper_test.cpp b/tests/jpegencoderhelper_test.cpp
index 33cb9f6..37aa995 100644
--- a/tests/jpegencoderhelper_test.cpp
+++ b/tests/jpegencoderhelper_test.cpp
@@ -14,21 +14,28 @@
* limitations under the License.
*/
-#include <ultrahdr/jpegencoderhelper.h>
-#include <gtest/gtest.h>
-#include <utils/Log.h>
-
#include <fcntl.h>
+#include <gtest/gtest.h>
-namespace android::ultrahdr {
-
-#define ALIGNED_IMAGE "/sdcard/Documents/minnie-320x240.yu12"
+#include "ultrahdr/ultrahdrcommon.h"
+#include "ultrahdr/ultrahdr.h"
+#include "ultrahdr/jpegencoderhelper.h"
+
+namespace ultrahdr {
+
+#ifdef __ANDROID__
+#define ALIGNED_IMAGE "/data/local/tmp/minnie-320x240.yu12"
+#define SINGLE_CHANNEL_IMAGE "/data/local/tmp/minnie-320x240.y"
+#define UNALIGNED_IMAGE "/data/local/tmp/minnie-318x240.yu12"
+#else
+#define ALIGNED_IMAGE "./data/minnie-320x240.yu12"
+#define SINGLE_CHANNEL_IMAGE "./data/minnie-320x240.y"
+#define UNALIGNED_IMAGE "./data/minnie-318x240.yu12"
+#endif
#define ALIGNED_IMAGE_WIDTH 320
#define ALIGNED_IMAGE_HEIGHT 240
-#define SINGLE_CHANNEL_IMAGE "/sdcard/Documents/minnie-320x240.y"
#define SINGLE_CHANNEL_IMAGE_WIDTH ALIGNED_IMAGE_WIDTH
#define SINGLE_CHANNEL_IMAGE_HEIGHT ALIGNED_IMAGE_HEIGHT
-#define UNALIGNED_IMAGE "/sdcard/Documents/minnie-318x240.yu12"
#define UNALIGNED_IMAGE_WIDTH 318
#define UNALIGNED_IMAGE_HEIGHT 240
#define JPEG_QUALITY 90
@@ -132,4 +139,4 @@ TEST_F(JpegEncoderHelperTest, encodeSingleChannelImage) {
ASSERT_GT(encoder.getCompressedImageSize(), static_cast<uint32_t>(0));
}
-} // namespace android::ultrahdr
+} // namespace ultrahdr
diff --git a/tests/jpegr_test.cpp b/tests/jpegr_test.cpp
index a750867..52b7136 100644
--- a/tests/jpegr_test.cpp
+++ b/tests/jpegr_test.cpp
@@ -15,24 +15,29 @@
*/
#include <sys/time.h>
+#include <gtest/gtest.h>
+
#include <fstream>
#include <iostream>
-#include <ultrahdr/gainmapmath.h>
-#include <ultrahdr/jpegr.h>
-#include <ultrahdr/jpegrutils.h>
-
-#include <gtest/gtest.h>
-#include <utils/Log.h>
+#include "ultrahdr/ultrahdrcommon.h"
+#include "ultrahdr/jpegr.h"
+#include "ultrahdr/jpegrutils.h"
//#define DUMP_OUTPUT
-namespace android::ultrahdr {
+namespace ultrahdr {
// resources used by unit tests
-const char* kYCbCrP010FileName = "raw_p010_image.p010";
-const char* kYCbCr420FileName = "raw_yuv420_image.yuv420";
-const char* kSdrJpgFileName = "jpeg_image.jpg";
+#ifdef __ANDROID__
+const char* kYCbCrP010FileName = "/data/local/tmp/raw_p010_image.p010";
+const char* kYCbCr420FileName = "/data/local/tmp/raw_yuv420_image.yuv420";
+const char* kSdrJpgFileName = "/data/local/tmp/jpeg_image.jpg";
+#else
+const char* kYCbCrP010FileName = "./data/raw_p010_image.p010";
+const char* kYCbCr420FileName = "./data/raw_yuv420_image.yuv420";
+const char* kSdrJpgFileName = "./data/jpeg_image.jpg";
+#endif
const int kImageWidth = 1280;
const int kImageHeight = 720;
const int kQuality = 90;
@@ -2032,4 +2037,4 @@ TEST(JpegRTest, ProfileGainMapFuncs) {
benchmark.BenchmarkApplyGainMap(rawImg420.getImageHandle(), &map, &metadata, &dest));
}
-} // namespace android::ultrahdr
+} // namespace ultrahdr