diff options
author | Jonathan Wright <jonathan.wright@arm.com> | 2020-06-29 10:59:36 +0100 |
---|---|---|
committer | Jonathan Wright <jonathan.wright@arm.com> | 2020-07-15 11:58:32 +0100 |
commit | 0f96902cfd49039cb19f15dc5dc883f3b911e63a (patch) | |
tree | 14e394c2b785200e072b4c767dca0845180968d0 /gtest | |
parent | 62ba1598d53cd38fcb369762a952ba3445d1ecc7 (diff) |
Move gtest files to separate folder
Move gtest files to a separate 'gtest' folder to separate the
libjpeg-turbo C code and the gtest C++ code.
Bug: 993876
Change-Id: I2d7511237a9cfdc0ccafd076e1881d32f5eb64f0
Diffstat (limited to 'gtest')
-rw-r--r-- | gtest/cjpeg-gtest-wrapper.cpp | 446 | ||||
-rw-r--r-- | gtest/djpeg-gtest-wrapper.cpp | 935 | ||||
-rw-r--r-- | gtest/jpegtran-gtest-wrapper.cpp | 166 | ||||
-rw-r--r-- | gtest/tjbench-gtest-wrapper.cpp | 190 | ||||
-rw-r--r-- | gtest/tjunittest-gtest-wrapper.cpp | 201 |
5 files changed, 1938 insertions, 0 deletions
diff --git a/gtest/cjpeg-gtest-wrapper.cpp b/gtest/cjpeg-gtest-wrapper.cpp new file mode 100644 index 0000000..c4ba600 --- /dev/null +++ b/gtest/cjpeg-gtest-wrapper.cpp @@ -0,0 +1,446 @@ +/* + * Copyright 2020 The Chromium Authors. All Rights Reserved. + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + +#include "base/files/file.h" +#include "base/files/file_util.h" +#include "base/hash/md5.h" +#include "base/path_service.h" + +#include <gtest/gtest.h> +#include <string> + +extern "C" int cjpeg(int argc, char *argv[]); + +static std::string GetTargetDirectory() { +#if defined(ANDROID) + return "/sdcard"; +#else + base::FilePath path; + base::PathService::Get(base::DIR_CURRENT, &path); + return path.MaybeAsASCII(); +#endif +} + +static void GetTestFilePath(base::FilePath* path, std::string filename) { + ASSERT_TRUE(base::PathService::Get(base::DIR_SOURCE_ROOT, path)); + *path = path->AppendASCII("third_party"); + *path = path->AppendASCII("libjpeg_turbo"); + *path = path->AppendASCII("testimages"); + *path = path->AppendASCII(filename); + ASSERT_TRUE(base::PathExists(*path)); +} + +static bool CompareFileAndMD5(const base::FilePath& path, + const std::string expected_md5) { + // Read the output file and compute the MD5. + std::string output; + if (!base::ReadFileToString(path, &output)) { + return false; + } + const std::string md5 = base::MD5String(output); + return expected_md5 == md5; +} + +TEST(CJPEGTest, RGBISlow) { + + base::FilePath icc_path; + GetTestFilePath(&icc_path, "test1.icc"); + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testorig.ppm"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_rgb_islow.jpg"); + + std::string prog_name = "cjpeg"; + std::string arg1 = "-rgb"; + std::string arg2 = "-dct"; + std::string arg3 = "int"; + std::string arg4 = "-icc"; + std::string arg5 = icc_path.MaybeAsASCII(); + std::string arg6 = "-outfile"; + std::string arg7 = output_path.MaybeAsASCII(); + std::string arg8 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0], + }; + // Generate test image file. + EXPECT_EQ(cjpeg(9, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "1d44a406f61da743b5fd31c0a9abdca3"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(CJPEGTest, IFastOpt422) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testorig.ppm"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_422_ifast_opt.jpg"); + + std::string prog_name = "cjpeg"; + std::string arg1 = "-sample"; + std::string arg2 = "2x1"; + std::string arg3 = "-dct"; + std::string arg4 = "fast"; + std::string arg5 = "-opt"; + std::string arg6 = "-outfile"; + std::string arg7 = output_path.MaybeAsASCII(); + std::string arg8 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0], + }; + // Generate test image file. + EXPECT_EQ(cjpeg(9, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "2540287b79d913f91665e660303ab2c8"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(CJPEGTest, IFastProg420Q100) { + + base::FilePath scans_path; + GetTestFilePath(&scans_path, "test.scan"); + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testorig.ppm"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_420_q100_ifast_prog.jpg"); + + std::string prog_name = "cjpeg"; + std::string arg1 = "-sample"; + std::string arg2 = "2x2"; + std::string arg3 = "-quality"; + std::string arg4 = "100"; + std::string arg5 = "-dct"; + std::string arg6 = "fast"; + std::string arg7 = "-scans"; + std::string arg8 = scans_path.MaybeAsASCII(); + std::string arg9 = "-outfile"; + std::string arg10 = output_path.MaybeAsASCII(); + std::string arg11 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0], &arg9[0], &arg10[0], + &arg11[0] + }; + // Generate test image file. + EXPECT_EQ(cjpeg(12, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "e59bb462016a8d9a748c330a3474bb55"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(CJPEGTest, GrayISlow) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testorig.ppm"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_gray_islow.jpg"); + + std::string prog_name = "cjpeg"; + std::string arg1 = "-gray"; + std::string arg2 = "-dct"; + std::string arg3 = "int"; + std::string arg4 = "-outfile"; + std::string arg5 = output_path.MaybeAsASCII(); + std::string arg6 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], + }; + // Generate test image file. + EXPECT_EQ(cjpeg(7, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "72b51f894b8f4a10b3ee3066770aa38d"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(CJPEGTest, IFastOpt420S) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testorig.ppm"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_420s_ifast_opt.jpg"); + + std::string prog_name = "cjpeg"; + std::string arg1 = "-sample"; + std::string arg2 = "2x2"; + std::string arg3 = "-smooth"; + std::string arg4 = "1"; + std::string arg5 = "-dct"; + std::string arg6 = "int"; + std::string arg7 = "-opt"; + std::string arg8 = "-outfile"; + std::string arg9 = output_path.MaybeAsASCII(); + std::string arg10 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0], &arg9[0], &arg10[0] + }; + // Generate test image file. + EXPECT_EQ(cjpeg(11, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "388708217ac46273ca33086b22827ed8"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(CJPEGTest, FloatProg3x2) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testorig.ppm"); + base::FilePath output_path(GetTargetDirectory()); + output_path = output_path.AppendASCII("testout_3x2_float_prog.jpg"); + + std::string prog_name = "cjpeg"; + std::string arg1 = "-sample"; + std::string arg2 = "3x2"; + std::string arg3 = "-dct"; + std::string arg4 = "float"; + std::string arg5 = "-prog"; + std::string arg6 = "-outfile"; + std::string arg7 = output_path.MaybeAsASCII(); + std::string arg8 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0] + }; + // Generate test image file. + EXPECT_EQ(cjpeg(9, command_line), 0); + + // Compare expected MD5 sum against that of test image. +#if defined(__arm__) || defined(__aarch64__) + const std::string EXPECTED_MD5 = "9bca803d2042bd1eb03819e2bf92b3e5"; +#else + const std::string EXPECTED_MD5 = "343e3f8caf8af5986ebaf0bdc13b5c71"; +#endif + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(CJPEGTest, IFastProg3x2) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testorig.ppm"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_3x2_ifast_prog.jpg"); + + std::string prog_name = "cjpeg"; + std::string arg1 = "-sample"; + std::string arg2 = "3x2"; + std::string arg3 = "-dct"; + std::string arg4 = "fast"; + std::string arg5 = "-prog"; + std::string arg6 = "-outfile"; + std::string arg7 = output_path.MaybeAsASCII(); + std::string arg8 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0] + }; + // Generate test image file. + EXPECT_EQ(cjpeg(9, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "1ee5d2c1a77f2da495f993c8c7cceca5"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +#ifdef C_ARITH_CODING_SUPPORTED +TEST(CJPEGTest, ISlowAri420) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testorig.ppm"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_420_islow_ari.jpg"); + + std::string prog_name = "cjpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-arithmetic"; + std::string arg4 = "-outfile"; + std::string arg5 = output_path.MaybeAsASCII(); + std::string arg6 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0] + }; + // Generate test image file. + EXPECT_EQ(cjpeg(7, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "e986fb0a637a8d833d96e8a6d6d84ea1"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(CJPEGTest, ISlowProgAri444) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testorig.ppm"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_444_islow_progari.jpg"); + + std::string prog_name = "cjpeg"; + std::string arg1 = "-sample"; + std::string arg2 = "1x1"; + std::string arg3 = "-dct"; + std::string arg4 = "int"; + std::string arg5 = "-prog"; + std::string arg6 = "-arithmetic"; + std::string arg7 = "-outfile"; + std::string arg8 = output_path.MaybeAsASCII(); + std::string arg9 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0], &arg9[0] + }; + // Generate test image file. + EXPECT_EQ(cjpeg(10, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "0a8f1c8f66e113c3cf635df0a475a617"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(CJPEGTest, ISlowAri444) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testorig.ppm"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_444_islow_ari.jpg"); + + std::string prog_name = "cjpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-arithmetic"; + std::string arg4 = "-sample"; + std::string arg5 = "1x1"; + std::string arg6 = "-outfile"; + std::string arg7 = output_path.MaybeAsASCII(); + std::string arg8 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0] + }; + // Generate test image file. + EXPECT_EQ(cjpeg(9, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "dd1b827fc504feb0259894e7132585b4"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} +#endif + +TEST(CJPEGTest, ISlowProg420) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testorig.ppm"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_420_islow_prog.jpg"); + + std::string prog_name = "cjpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-prog"; + std::string arg4 = "-outfile"; + std::string arg5 = output_path.MaybeAsASCII(); + std::string arg6 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0] + }; + // Generate test image file. + EXPECT_EQ(cjpeg(7, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "1c4afddc05c0a43489ee54438a482d92"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(CJPEGTest, ISlow444) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testorig.ppm"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_444_islow.jpg"); + + std::string prog_name = "cjpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-sample"; + std::string arg4 = "1x1"; + std::string arg5 = "-outfile"; + std::string arg6 = output_path.MaybeAsASCII(); + std::string arg7 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0] + }; + // Generate test image file. + EXPECT_EQ(cjpeg(8, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "62a8665a2e08e90c6fffa3a94b894ce2"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(CJPEGTest, ISlowProg444) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testorig.ppm"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_444_islow_prog.jpg"); + + std::string prog_name = "cjpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-prog"; + std::string arg4 = "-sample"; + std::string arg5 = "1x1"; + std::string arg6 = "-outfile"; + std::string arg7 = output_path.MaybeAsASCII(); + std::string arg8 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0] + }; + // Generate test image file. + EXPECT_EQ(cjpeg(9, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "666ef192fff72570e332db7610e1a7d1"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} diff --git a/gtest/djpeg-gtest-wrapper.cpp b/gtest/djpeg-gtest-wrapper.cpp new file mode 100644 index 0000000..9e14f0f --- /dev/null +++ b/gtest/djpeg-gtest-wrapper.cpp @@ -0,0 +1,935 @@ +/* + * Copyright 2020 The Chromium Authors. All Rights Reserved. + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + +#include "base/files/file.h" +#include "base/files/file_util.h" +#include "base/hash/md5.h" +#include "base/path_service.h" + +#include <gtest/gtest.h> +#include <string> + +extern "C" int djpeg(int argc, char *argv[]); + +static std::string GetTargetDirectory() { +#if defined(ANDROID) + return "/sdcard"; +#else + base::FilePath path; + base::PathService::Get(base::DIR_CURRENT, &path); + return path.MaybeAsASCII(); +#endif +} + +static void GetTestFilePath(base::FilePath* path, std::string filename) { + ASSERT_TRUE(base::PathService::Get(base::DIR_SOURCE_ROOT, path)); + *path = path->AppendASCII("third_party"); + *path = path->AppendASCII("libjpeg_turbo"); + *path = path->AppendASCII("testimages"); + *path = path->AppendASCII(filename); + ASSERT_TRUE(base::PathExists(*path)); +} + +static bool CompareFileAndMD5(const base::FilePath& path, + const std::string expected_md5) { + // Read the output file and compute the MD5. + std::string output; + if (!base::ReadFileToString(path, &output)) { + return false; + } + const std::string md5 = base::MD5String(output); + return expected_md5 == md5; +} + +const static std::vector<std::tuple<const std::string, + const std::string, + const std::string>> SCALE_IMAGE_MD5 = { + std::make_tuple("2/1", "testout_420m_islow_2_1.ppm", + "9f9de8c0612f8d06869b960b05abf9c9"), + std::make_tuple("15/8", "testout_420m_islow_15_8.ppm", + "b6875bc070720b899566cc06459b63b7"), + std::make_tuple("13/8", "testout_420m_islow_13_8.ppm", + "bc3452573c8152f6ae552939ee19f82f"), + std::make_tuple("11/8", "testout_420m_islow_11_8.ppm", + "d8cc73c0aaacd4556569b59437ba00a5"), + std::make_tuple("9/8", "testout_420m_islow_9_8.ppm", + "d25e61bc7eac0002f5b393aa223747b6"), + std::make_tuple("7/8", "testout_420m_islow_7_8.ppm", + "ddb564b7c74a09494016d6cd7502a946"), + std::make_tuple("3/4", "testout_420m_islow_3_4.ppm", + "8ed8e68808c3fbc4ea764fc9d2968646"), + std::make_tuple("5/8", "testout_420m_islow_5_8.ppm", + "a3363274999da2366a024efae6d16c9b"), + std::make_tuple("1/2", "testout_420m_islow_1_2.ppm", + "e692a315cea26b988c8e8b29a5dbcd81"), + std::make_tuple("3/8", "testout_420m_islow_3_8.ppm", + "79eca9175652ced755155c90e785a996"), + std::make_tuple("1/4", "testout_420m_islow_1_4.ppm", + "79cd778f8bf1a117690052cacdd54eca"), + std::make_tuple("1/8", "testout_420m_islow_1_8.ppm", + "391b3d4aca640c8567d6f8745eb2142f") +}; + +class DJPEGTestScalingDCT : public + ::testing::TestWithParam<std::tuple<const std::string, + const std::string, + const std::string>> {}; + +TEST_P(DJPEGTestScalingDCT, Test) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testorig.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII(std::get<1>(GetParam())); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-scale"; + std::string arg4 = std::get<0>(GetParam()); + std::string arg5 = "-nosmooth"; + std::string arg6 = "-ppm"; + std::string arg7 = "-outfile"; + std::string arg8 = output_path.MaybeAsASCII(); + std::string arg9 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0], &arg9[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(10, command_line), 0); + + // Compare expected MD5 sum against that of test image. + EXPECT_TRUE(CompareFileAndMD5(output_path, std::get<2>(GetParam()))); +} + +INSTANTIATE_TEST_SUITE_P(TestScalingDCT, + DJPEGTestScalingDCT, + ::testing::ValuesIn(SCALE_IMAGE_MD5)); + +TEST(DJPEGTest, ISlow420256) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testorig.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_420_islow_256.bmp"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-colors"; + std::string arg4 = "256"; + std::string arg5 = "-bmp"; + std::string arg6 = "-outfile"; + std::string arg7 = output_path.MaybeAsASCII(); + std::string arg8 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(9, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "4980185e3776e89bd931736e1cddeee6"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(DJPEGTest, ISlow420565) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testorig.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_420_islow_565.bmp"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-rgb565"; + std::string arg4 = "-dither"; + std::string arg5 = "none"; + std::string arg6 = "-bmp"; + std::string arg7 = "-outfile"; + std::string arg8 = output_path.MaybeAsASCII(); + std::string arg9 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0], &arg9[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(10, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "bf9d13e16c4923b92e1faa604d7922cb"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(DJPEGTest, ISlow420565D) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testorig.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_420_islow_565D.bmp"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-rgb565"; + std::string arg4 = "-bmp"; + std::string arg5 = "-outfile"; + std::string arg6 = output_path.MaybeAsASCII(); + std::string arg7 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(8, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "6bde71526acc44bcff76f696df8638d2"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(DJPEGTest, ISlow420M565) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testorig.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_420m_islow_565.bmp"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-nosmooth"; + std::string arg4 = "-rgb565"; + std::string arg5 = "-dither"; + std::string arg6 = "none"; + std::string arg7 = "-bmp"; + std::string arg8 = "-outfile"; + std::string arg9 = output_path.MaybeAsASCII(); + std::string arg10 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0], &arg9[0], &arg10[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(11, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "8dc0185245353cfa32ad97027342216f"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(DJPEGTest, ISlow420M565D) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testorig.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_420m_islow_565D.bmp"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-nosmooth"; + std::string arg4 = "-rgb565"; + std::string arg5 = "-bmp"; + std::string arg6 = "-outfile"; + std::string arg7 = output_path.MaybeAsASCII(); + std::string arg8 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(9, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "ce034037d212bc403330df6f915c161b"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(DJPEGTest, ISlow420Skip1531) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testorig.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_420_islow_skip15_31.ppm"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-skip"; + std::string arg4 = "15,31"; + std::string arg5 = "-ppm"; + std::string arg6 = "-outfile"; + std::string arg7 = output_path.MaybeAsASCII(); + std::string arg8 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(9, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "c4c65c1e43d7275cd50328a61e6534f0"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +#ifdef C_ARITH_CODING_SUPPORTED +TEST(DJPEGTest, ISlow420AriSkip16139) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testimgari.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII( + "testout_420_islow_ari_skip16_139.ppm"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-skip"; + std::string arg4 = "16,139"; + std::string arg5 = "-ppm"; + std::string arg6 = "-outfile"; + std::string arg7 = output_path.MaybeAsASCII(); + std::string arg8 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(9, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "087c6b123db16ac00cb88c5b590bb74a"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(DJPEGTest, ISlow420AriCrop53x5344) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testimgari.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII( + "testout_420_islow_ari_crop53x53_4_4.ppm"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-crop"; + std::string arg4 = "53x53+4+4"; + std::string arg5 = "-ppm"; + std::string arg6 = "-outfile"; + std::string arg7 = output_path.MaybeAsASCII(); + std::string arg8 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(9, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "886c6775af22370257122f8b16207e6d"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(DJPEGTest, IFast420MAri) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testimgari.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_420m_ifast_ari.ppm"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-fast"; + std::string arg2 = "-ppm"; + std::string arg3 = "-outfile"; + std::string arg4 = output_path.MaybeAsASCII(); + std::string arg5 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(6, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "72b59a99bcf1de24c5b27d151bde2437"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(DJPEGTest, ISlow444AriCrop37x3700) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testout_444_islow_ari.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII( + "testout_444_islow_ari_crop37x37_0_0.ppm"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-crop"; + std::string arg4 = "37x37+0+0"; + std::string arg5 = "-ppm"; + std::string arg6 = "-outfile"; + std::string arg7 = output_path.MaybeAsASCII(); + std::string arg8 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(9, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "cb57b32bd6d03e35432362f7bf184b6d"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} +#endif + +TEST(DJPEGTest, RGBISlow) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testout_rgb_islow.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_rgb_islow.ppm"); + base::FilePath output_icc_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_icc_path = output_icc_path.AppendASCII("testout_rgb_islow.icc"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-ppm"; + std::string arg4 = "-icc"; + std::string arg5 = output_icc_path.MaybeAsASCII(); + std::string arg6 = "-outfile"; + std::string arg7 = output_path.MaybeAsASCII(); + std::string arg8 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(9, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "00a257f5393fef8821f2b88ac7421291"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); + const std::string ICC_EXPECTED_MD5 = "b06a39d730129122e85c1363ed1bbc9e"; + EXPECT_TRUE(CompareFileAndMD5(output_icc_path, ICC_EXPECTED_MD5)); +} + +TEST(DJPEGTest, RGBISlow565) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testout_rgb_islow.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_rgb_islow_565.bmp"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-rgb565"; + std::string arg4 = "-dither"; + std::string arg5 = "none"; + std::string arg6 = "-bmp"; + std::string arg7 = "-outfile"; + std::string arg8 = output_path.MaybeAsASCII(); + std::string arg9 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0], &arg9[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(10, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "f07d2e75073e4bb10f6c6f4d36e2e3be"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(DJPEGTest, RGBISlow565D) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testout_rgb_islow.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_rgb_islow_565D.bmp"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-rgb565"; + std::string arg4 = "-bmp"; + std::string arg5 = "-outfile"; + std::string arg6 = output_path.MaybeAsASCII(); + std::string arg7 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(8, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "4cfa0928ef3e6bb626d7728c924cfda4"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(DJPEGTest, IFast422) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testout_422_ifast_opt.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_422_ifast.ppm"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "fast"; + std::string arg3 = "-outfile"; + std::string arg4 = output_path.MaybeAsASCII(); + std::string arg5 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(6, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "35bd6b3f833bad23de82acea847129fa"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(DJPEGTest, IFast422M) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testout_422_ifast_opt.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_422m_ifast.ppm"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "fast"; + std::string arg3 = "-nosmooth"; + std::string arg4 = "-outfile"; + std::string arg5 = output_path.MaybeAsASCII(); + std::string arg6 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(7, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "8dbc65323d62cca7c91ba02dd1cfa81d"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(DJPEGTest, IFast422M565) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testout_422_ifast_opt.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_422m_ifast_565.bmp"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-nosmooth"; + std::string arg4 = "-rgb565"; + std::string arg5 = "-dither"; + std::string arg6 = "none"; + std::string arg7 = "-bmp"; + std::string arg8 = "-outfile"; + std::string arg9 = output_path.MaybeAsASCII(); + std::string arg10 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0], &arg9[0], &arg10[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(11, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "3294bd4d9a1f2b3d08ea6020d0db7065"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(DJPEGTest, IFast422M565D) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testout_422_ifast_opt.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_422m_ifast_565D.bmp"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-nosmooth"; + std::string arg4 = "-rgb565"; + std::string arg5 = "-bmp"; + std::string arg6 = "-outfile"; + std::string arg7 = output_path.MaybeAsASCII(); + std::string arg8 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(9, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "da98c9c7b6039511be4a79a878a9abc1"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(DJPEGTest, IFastProg420Q100) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testout_420_q100_ifast_prog.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_420_q100_ifast.ppm"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "fast"; + std::string arg3 = "-outfile"; + std::string arg4 = output_path.MaybeAsASCII(); + std::string arg5 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(6, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "5a732542015c278ff43635e473a8a294"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(DJPEGTest, IFastProg420MQ100) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testout_420_q100_ifast_prog.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_420m_q100_ifast.ppm"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "fast"; + std::string arg3 = "-nosmooth"; + std::string arg4 = "-outfile"; + std::string arg5 = output_path.MaybeAsASCII(); + std::string arg6 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(7, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "ff692ee9323a3b424894862557c092f1"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(DJPEGTest, GrayISlow) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testout_gray_islow.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_gray_islow.ppm"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-outfile"; + std::string arg4 = output_path.MaybeAsASCII(); + std::string arg5 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(6, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "8d3596c56eace32f205deccc229aa5ed"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(DJPEGTest, GrayISlowRGB) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testout_gray_islow.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_gray_islow_rgb.ppm"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-rgb"; + std::string arg4 = "-outfile"; + std::string arg5 = output_path.MaybeAsASCII(); + std::string arg6 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(7, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "116424ac07b79e5e801f00508eab48ec"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(DJPEGTest, GrayISlow565) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testout_gray_islow.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_gray_islow_565.bmp"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-rgb565"; + std::string arg4 = "-dither"; + std::string arg5 = "none"; + std::string arg6 = "-bmp"; + std::string arg7 = "-outfile"; + std::string arg8 = output_path.MaybeAsASCII(); + std::string arg9 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0], &arg9[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(10, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "12f78118e56a2f48b966f792fedf23cc"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(DJPEGTest, GrayISlow565D) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testout_gray_islow.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_gray_islow_565D.bmp"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-rgb565"; + std::string arg4 = "-bmp"; + std::string arg5 = "-outfile"; + std::string arg6 = output_path.MaybeAsASCII(); + std::string arg7 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(8, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "bdbbd616441a24354c98553df5dc82db"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(DJPEGTest, FloatProg3x2) { + + base::FilePath input_image_path; +#if defined(__arm__) || defined(__aarch64__) + GetTestFilePath(&input_image_path, "testout_3x2_float_prog_arm.jpg"); +#elif defined(__i386__) || defined(__x86_64__) + GetTestFilePath(&input_image_path, "testout_3x2_float_prog_intel.jpg"); +#else +#error "Unknown platform." +#endif + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_3x2_float.ppm"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "float"; + std::string arg3 = "-outfile"; + std::string arg4 = output_path.MaybeAsASCII(); + std::string arg5 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(6, command_line), 0); + + // Compare expected MD5 sum against that of test image. +#if defined(__arm__) || defined(__aarch64__) + const std::string EXPECTED_MD5 = "f6bfab038438ed8f5522fbd33595dcdc"; +#elif defined(__i386__) || defined(__x86_64__) + const std::string EXPECTED_MD5 = "1a75f36e5904d6fc3a85a43da9ad89bb"; +#else +#error "Unknown platform." +#endif + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(DJPEGTest, IFastProg3x2) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testout_3x2_ifast_prog.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_3x2_ifast.ppm"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "fast"; + std::string arg3 = "-outfile"; + std::string arg4 = output_path.MaybeAsASCII(); + std::string arg5 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(6, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "fd283664b3b49127984af0a7f118fccd"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(DJPEGTest, ISlowProgCrop62x627171) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testout_420_islow_prog.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII( + "testout_420_islow_prog_crop62x62_71_71.ppm"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-crop"; + std::string arg4 = "62x62+71+71"; + std::string arg5 = "-ppm"; + std::string arg6 = "-outfile"; + std::string arg7 = output_path.MaybeAsASCII(); + std::string arg8 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(9, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "26eb36ccc7d1f0cb80cdabb0ac8b5d99"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(DJPEGTest, ISlow444Skip16) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testout_444_islow.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_444_islow_skip1_6.ppm"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-skip"; + std::string arg4 = "1,6"; + std::string arg5 = "-ppm"; + std::string arg6 = "-outfile"; + std::string arg7 = output_path.MaybeAsASCII(); + std::string arg8 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(9, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "5606f86874cf26b8fcee1117a0a436a6"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(DJPEGTest, ISlowProg444Crop98x981313) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testout_444_islow_prog.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII( + "testout_444_islow_prog_crop98x98_13_13.ppm"); + + std::string prog_name = "djpeg"; + std::string arg1 = "-dct"; + std::string arg2 = "int"; + std::string arg3 = "-crop"; + std::string arg4 = "98x98+13+13"; + std::string arg5 = "-ppm"; + std::string arg6 = "-outfile"; + std::string arg7 = output_path.MaybeAsASCII(); + std::string arg8 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0] + }; + // Generate test image file. + EXPECT_EQ(djpeg(9, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "db87dc7ce26bcdc7a6b56239ce2b9d6c"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} diff --git a/gtest/jpegtran-gtest-wrapper.cpp b/gtest/jpegtran-gtest-wrapper.cpp new file mode 100644 index 0000000..28ab161 --- /dev/null +++ b/gtest/jpegtran-gtest-wrapper.cpp @@ -0,0 +1,166 @@ +/* + * Copyright 2020 The Chromium Authors. All Rights Reserved. + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + +#include "base/files/file.h" +#include "base/files/file_util.h" +#include "base/hash/md5.h" +#include "base/path_service.h" + +#include <gtest/gtest.h> +#include <string> + +extern "C" int jpegtran(int argc, char *argv[]); + +static std::string GetTargetDirectory() { +#if defined(ANDROID) + return "/sdcard"; +#else + base::FilePath path; + base::PathService::Get(base::DIR_CURRENT, &path); + return path.MaybeAsASCII(); +#endif +} + +static void GetTestFilePath(base::FilePath* path, std::string filename) { + ASSERT_TRUE(base::PathService::Get(base::DIR_SOURCE_ROOT, path)); + *path = path->AppendASCII("third_party"); + *path = path->AppendASCII("libjpeg_turbo"); + *path = path->AppendASCII("testimages"); + *path = path->AppendASCII(filename); + ASSERT_TRUE(base::PathExists(*path)); +} + +static bool CompareFileAndMD5(const base::FilePath& path, + const std::string expected_md5) { + // Read the output file and compute the MD5. + std::string output; + if (!base::ReadFileToString(path, &output)) { + return false; + } + const std::string md5 = base::MD5String(output); + return expected_md5 == md5; +} + +TEST(JPEGTranTest, ICC) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testout_rgb_islow.jpg"); + base::FilePath icc_path; + GetTestFilePath(&icc_path, "test2.icc"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_rgb_islow2.jpg"); + + std::string prog_name = "jpegtran"; + std::string arg1 = "-copy"; + std::string arg2 = "all"; + std::string arg3 = "-icc"; + std::string arg4 = icc_path.MaybeAsASCII(); + std::string arg5 = "-outfile"; + std::string arg6 = output_path.MaybeAsASCII(); + std::string arg7 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0] + }; + // Generate test image file. + EXPECT_EQ(jpegtran(8, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "31d121e57b6c2934c890a7fc7763bcd4"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(JPEGTranTest, Crop) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testorig.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_crop.jpg"); + + std::string prog_name = "jpegtran"; + std::string arg1 = "-crop"; + std::string arg2 = "120x90+20+50"; + std::string arg3 = "-transpose"; + std::string arg4 = "-perfect"; + std::string arg5 = "-outfile"; + std::string arg6 = output_path.MaybeAsASCII(); + std::string arg7 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0] + }; + // Generate test image file. + EXPECT_EQ(jpegtran(8, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "b4197f377e621c4e9b1d20471432610d"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +#ifdef C_ARITH_CODING_SUPPORTED +TEST(JPEGTranTest, ISlow420Ari) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testimgint.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_420_islow_ari2.jpg"); + + std::string prog_name = "jpegtran"; + std::string arg1 = "-arithmetic"; + std::string arg2 = "-outfile"; + std::string arg3 = output_path.MaybeAsASCII(); + std::string arg4 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0] + }; + // Generate test image file. + EXPECT_EQ(jpegtran(5, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "e986fb0a637a8d833d96e8a6d6d84ea1"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} + +TEST(JPEGTranTest, ISlow420) { + + base::FilePath input_image_path; + GetTestFilePath(&input_image_path, "testimgari.jpg"); + base::FilePath output_path(FILE_PATH_LITERAL(GetTargetDirectory())); + output_path = output_path.AppendASCII("testout_420_islow.jpg"); + + std::string prog_name = "jpegtran"; + std::string arg1 = "-outfile"; + std::string arg2 = output_path.MaybeAsASCII(); + std::string arg3 = input_image_path.MaybeAsASCII(); + + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0] + }; + // Generate test image file. + EXPECT_EQ(jpegtran(4, command_line), 0); + + // Compare expected MD5 sum against that of test image. + const std::string EXPECTED_MD5 = "9a68f56bc76e466aa7e52f415d0f4a5f"; + EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5)); +} +#endif diff --git a/gtest/tjbench-gtest-wrapper.cpp b/gtest/tjbench-gtest-wrapper.cpp new file mode 100644 index 0000000..ec4c850 --- /dev/null +++ b/gtest/tjbench-gtest-wrapper.cpp @@ -0,0 +1,190 @@ +/* + * Copyright 2020 The Chromium Authors. All Rights Reserved. + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + +#include "base/files/file.h" +#include "base/files/file_util.h" +#include "base/hash/md5.h" +#include "base/path_service.h" + +#include <gtest/gtest.h> +#include <string> + +extern "C" int tjbench(int argc, char *argv[]); + +static std::string GetTargetDirectory() { +#if defined(ANDROID) + return "/sdcard"; +#else + base::FilePath path; + base::PathService::Get(base::DIR_CURRENT, &path); + return path.MaybeAsASCII(); +#endif +} + +// Test image files and their expected MD5 sums. +const static std::vector<std::pair<const std::string, + const std::string>> IMAGE_MD5_BASELINE = { + { "testout_tile_GRAY_Q95_8x8.ppm", "89d3ca21213d9d864b50b4e4e7de4ca6" }, + { "testout_tile_420_Q95_8x8.ppm", "847fceab15c5b7b911cb986cf0f71de3" }, + { "testout_tile_422_Q95_8x8.ppm", "d83dacd9fc73b0a6f10c09acad64eb1e" }, + { "testout_tile_444_Q95_8x8.ppm", "7964e41e67cfb8d0a587c0aa4798f9c3" }, + { "testout_tile_GRAY_Q95_16x16.ppm", "89d3ca21213d9d864b50b4e4e7de4ca6" }, + { "testout_tile_420_Q95_16x16.ppm", "ca45552a93687e078f7137cc4126a7b0" }, + { "testout_tile_422_Q95_16x16.ppm", "35077fb610d72dd743b1eb0cbcfe10fb" }, + { "testout_tile_444_Q95_16x16.ppm", "7964e41e67cfb8d0a587c0aa4798f9c3" }, + { "testout_tile_GRAY_Q95_32x32.ppm", "89d3ca21213d9d864b50b4e4e7de4ca6" }, + { "testout_tile_420_Q95_32x32.ppm", "d8676f1d6b68df358353bba9844f4a00" }, + { "testout_tile_422_Q95_32x32.ppm", "e6902ed8a449ecc0f0d6f2bf945f65f7" }, + { "testout_tile_444_Q95_32x32.ppm", "7964e41e67cfb8d0a587c0aa4798f9c3" }, + { "testout_tile_GRAY_Q95_64x64.ppm", "89d3ca21213d9d864b50b4e4e7de4ca6" }, + { "testout_tile_420_Q95_64x64.ppm", "4e4c1a3d7ea4bace4f868bcbe83b7050" }, + { "testout_tile_422_Q95_64x64.ppm", "2b4502a8f316cedbde1da7bce3d2231e" }, + { "testout_tile_444_Q95_64x64.ppm", "7964e41e67cfb8d0a587c0aa4798f9c3" }, + { "testout_tile_GRAY_Q95_128x128.ppm", "89d3ca21213d9d864b50b4e4e7de4ca6" }, + { "testout_tile_420_Q95_128x128.ppm", "f24c3429c52265832beab9df72a0ceae" }, + { "testout_tile_422_Q95_128x128.ppm", "f0b5617d578f5e13c8eee215d64d4877" }, + { "testout_tile_444_Q95_128x128.ppm", "7964e41e67cfb8d0a587c0aa4798f9c3" } +}; + +class TJBenchTest : public + ::testing::TestWithParam<std::pair<const std::string, const std::string>> { + + protected: + + static void SetUpTestSuite() { + base::FilePath resource_path; + ASSERT_TRUE(base::PathService::Get(base::DIR_SOURCE_ROOT, &resource_path)); + resource_path = resource_path.AppendASCII("third_party"); + resource_path = resource_path.AppendASCII("libjpeg_turbo"); + resource_path = resource_path.AppendASCII("testimages"); + resource_path = resource_path.AppendASCII("testorig.ppm"); + ASSERT_TRUE(base::PathExists(resource_path)); + + base::FilePath target_path(FILE_PATH_LITERAL(GetTargetDirectory())); + target_path = target_path.AppendASCII("testout_tile.ppm"); + + ASSERT_TRUE(base::CopyFile(resource_path, target_path)); + + std::string prog_name = "tjbench"; + std::string arg1 = target_path.MaybeAsASCII(); + std::string arg2 = "95"; + std::string arg3 = "-rgb"; + std::string arg4 = "-quiet"; + std::string arg5 = "-tile"; + std::string arg6 = "-benchtime"; + std::string arg7 = "0.01"; + std::string arg8 = "-warmup"; + std::string arg9 = "0"; + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0], &arg9[0], + }; + // Generate test image tiles. + EXPECT_EQ(tjbench(10, command_line), 0); + } + +}; + +TEST_P(TJBenchTest, TestTileBaseline) { + // Construct path for test image file. + base::FilePath test_image_path(FILE_PATH_LITERAL(GetTargetDirectory())); + test_image_path = test_image_path.AppendASCII(std::get<0>(GetParam())); + // Read test image as string and compute MD5 sum. + std::string test_image_data; + ASSERT_TRUE(base::ReadFileToString(test_image_path, &test_image_data)); + const std::string md5 = base::MD5String(test_image_data); + // Compare expected MD5 sum against that of test image. + EXPECT_EQ(std::get<1>(GetParam()), md5); +} + +INSTANTIATE_TEST_SUITE_P(TestTileBaseline, + TJBenchTest, + ::testing::ValuesIn(IMAGE_MD5_BASELINE)); + +// Test image files and their expected MD5 sums. +const static std::vector<std::pair<const std::string, + const std::string>> IMAGE_MD5_MERGED = { + { "testout_tilem_420_Q95_8x8.ppm", "bc25320e1f4c31ce2e610e43e9fd173c" }, + { "testout_tilem_422_Q95_8x8.ppm", "828941d7f41cd6283abd6beffb7fd51d" }, + { "testout_tilem_420_Q95_16x16.ppm", "75ffdf14602258c5c189522af57fa605" }, + { "testout_tilem_422_Q95_16x16.ppm", "e877ae1324c4a280b95376f7f018172f" }, + { "testout_tilem_420_Q95_32x32.ppm", "75ffdf14602258c5c189522af57fa605" }, + { "testout_tilem_422_Q95_32x32.ppm", "e877ae1324c4a280b95376f7f018172f" }, + { "testout_tilem_420_Q95_64x64.ppm", "75ffdf14602258c5c189522af57fa605" }, + { "testout_tilem_422_Q95_64x64.ppm", "e877ae1324c4a280b95376f7f018172f" }, + { "testout_tilem_420_Q95_128x128.ppm", "75ffdf14602258c5c189522af57fa605" }, + { "testout_tilem_422_Q95_128x128.ppm", "e877ae1324c4a280b95376f7f018172f" } +}; + +class TJBenchTestMerged : public + ::testing::TestWithParam<std::pair<const std::string, const std::string>> { + + protected: + + static void SetUpTestSuite() { + base::FilePath resource_path; + ASSERT_TRUE(base::PathService::Get(base::DIR_SOURCE_ROOT, &resource_path)); + resource_path = resource_path.AppendASCII("third_party"); + resource_path = resource_path.AppendASCII("libjpeg_turbo"); + resource_path = resource_path.AppendASCII("testimages"); + resource_path = resource_path.AppendASCII("testorig.ppm"); + ASSERT_TRUE(base::PathExists(resource_path)); + + base::FilePath target_path(FILE_PATH_LITERAL(GetTargetDirectory())); + target_path = target_path.AppendASCII("testout_tilem.ppm"); + + ASSERT_TRUE(base::CopyFile(resource_path, target_path)); + + std::string prog_name = "tjbench"; + std::string arg1 = target_path.MaybeAsASCII(); + std::string arg2 = "95"; + std::string arg3 = "-rgb"; + std::string arg4 = "-fastupsample"; + std::string arg5 = "-quiet"; + std::string arg6 = "-tile"; + std::string arg7 = "-benchtime"; + std::string arg8 = "0.01"; + std::string arg9 = "-warmup"; + std::string arg10 = "0"; + char *command_line[] = { &prog_name[0], + &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], + &arg6[0], &arg7[0], &arg8[0], &arg9[0], &arg10[0] + }; + // Generate test image output tiles. + EXPECT_EQ(tjbench(11, command_line), 0); + } + +}; + +TEST_P(TJBenchTestMerged, TestTileMerged) { + // Construct path for test image file. + base::FilePath test_image_path(FILE_PATH_LITERAL(GetTargetDirectory())); + test_image_path = test_image_path.AppendASCII(std::get<0>(GetParam())); + // Read test image as string and compute MD5 sum. + std::string test_image_data; + ASSERT_TRUE(base::ReadFileToString(test_image_path, &test_image_data)); + const std::string md5 = base::MD5String(test_image_data); + // Compare expected MD5 sum against that of test image. + EXPECT_EQ(std::get<1>(GetParam()), md5); +} + +INSTANTIATE_TEST_SUITE_P(TestTileMerged, + TJBenchTestMerged, + ::testing::ValuesIn(IMAGE_MD5_MERGED)); diff --git a/gtest/tjunittest-gtest-wrapper.cpp b/gtest/tjunittest-gtest-wrapper.cpp new file mode 100644 index 0000000..bef4e94 --- /dev/null +++ b/gtest/tjunittest-gtest-wrapper.cpp @@ -0,0 +1,201 @@ +/* + * Copyright 2020 The Chromium Authors. All Rights Reserved. + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + +#include <gtest/gtest.h> + +extern "C" int testBmp(int yuv, int noyuvpad, int autoalloc); +extern "C" int testThreeByte444(int yuv, int noyuvpad, int autoalloc); +extern "C" int testFourByte444(int yuv, int noyuvpad, int autoalloc); +extern "C" int testThreeByte422(int yuv, int noyuvpad, int autoalloc); +extern "C" int testFourByte422(int yuv, int noyuvpad, int autoalloc); +extern "C" int testThreeByte420(int yuv, int noyuvpad, int autoalloc); +extern "C" int testFourByte420(int yuv, int noyuvpad, int autoalloc); +extern "C" int testThreeByte440(int yuv, int noyuvpad, int autoalloc); +extern "C" int testFourByte440(int yuv, int noyuvpad, int autoalloc); +extern "C" int testThreeByte411(int yuv, int noyuvpad, int autoalloc); +extern "C" int testFourByte411(int yuv, int noyuvpad, int autoalloc); +extern "C" int testOnlyGray(int yuv, int noyuvpad, int autoalloc); +extern "C" int testThreeByteGray(int yuv, int noyuvpad, int autoalloc); +extern "C" int testFourByteGray(int yuv, int noyuvpad, int autoalloc); +extern "C" int testBufSize(int yuv, int noyuvpad, int autoalloc); +extern "C" int testYUVOnlyRGB444(int noyuvpad, int autoalloc); +extern "C" int testYUVOnlyRGB422(int noyuvpad, int autoalloc); +extern "C" int testYUVOnlyRGB420(int noyuvpad, int autoalloc); +extern "C" int testYUVOnlyRGB440(int noyuvpad, int autoalloc); +extern "C" int testYUVOnlyRGB411(int noyuvpad, int autoalloc); +extern "C" int testYUVOnlyRGBGray(int noyuvpad, int autoalloc); +extern "C" int testYUVOnlyGrayGray(int noyuvpad, int autoalloc); + +const int YUV = 1; +const int NO_YUV = 0; +const int NO_YUV_PAD = 1; +const int YUV_PAD = 0; +const int AUTO_ALLOC = 1; +const int NO_AUTO_ALLOC = 0; + +class TJUnitTest : public + ::testing::TestWithParam<std::tuple<int, int, int>> {}; + +TEST_P(TJUnitTest, BMP) { + EXPECT_EQ(testBmp(std::get<0>(GetParam()), + std::get<1>(GetParam()), + std::get<2>(GetParam())), 0); +} + +TEST_P(TJUnitTest, ThreeByte444) { + EXPECT_EQ(testThreeByte444(std::get<0>(GetParam()), + std::get<1>(GetParam()), + std::get<2>(GetParam())), 0); +} + +TEST_P(TJUnitTest, FourByte444) { + EXPECT_EQ(testFourByte444(std::get<0>(GetParam()), + std::get<1>(GetParam()), + std::get<2>(GetParam())), 0); +} + +TEST_P(TJUnitTest, ThreeByte422) { + EXPECT_EQ(testThreeByte422(std::get<0>(GetParam()), + std::get<1>(GetParam()), + std::get<2>(GetParam())), 0); +} + +TEST_P(TJUnitTest, FourByte422) { + EXPECT_EQ(testFourByte422(std::get<0>(GetParam()), + std::get<1>(GetParam()), + std::get<2>(GetParam())), 0); +} + +TEST_P(TJUnitTest, ThreeByte420) { + EXPECT_EQ(testThreeByte420(std::get<0>(GetParam()), + std::get<1>(GetParam()), + std::get<2>(GetParam())), 0); +} + +TEST_P(TJUnitTest, FourByte420) { + EXPECT_EQ(testFourByte420(std::get<0>(GetParam()), + std::get<1>(GetParam()), + std::get<2>(GetParam())), 0); +} + +TEST_P(TJUnitTest, ThreeByte440) { + EXPECT_EQ(testThreeByte440(std::get<0>(GetParam()), + std::get<1>(GetParam()), + std::get<2>(GetParam())), 0); +} + +TEST_P(TJUnitTest, FourByte440) { + EXPECT_EQ(testFourByte440(std::get<0>(GetParam()), + std::get<1>(GetParam()), + std::get<2>(GetParam())), 0); +} + +TEST_P(TJUnitTest, ThreeByte411) { + EXPECT_EQ(testThreeByte411(std::get<0>(GetParam()), + std::get<1>(GetParam()), + std::get<2>(GetParam())), 0); +} + +TEST_P(TJUnitTest, FourByte411) { + EXPECT_EQ(testFourByte411(std::get<0>(GetParam()), + std::get<1>(GetParam()), + std::get<2>(GetParam())), 0); +} + +TEST_P(TJUnitTest, OnlyGray) { + EXPECT_EQ(testOnlyGray(std::get<0>(GetParam()), + std::get<1>(GetParam()), + std::get<2>(GetParam())), 0); +} + +TEST_P(TJUnitTest, ThreeByteGray) { + EXPECT_EQ(testThreeByteGray(std::get<0>(GetParam()), + std::get<1>(GetParam()), + std::get<2>(GetParam())), 0); +} + +TEST_P(TJUnitTest, FourByteGray) { + EXPECT_EQ(testFourByteGray(std::get<0>(GetParam()), + std::get<1>(GetParam()), + std::get<2>(GetParam())), 0); +} + +TEST_P(TJUnitTest, BufSize) { + EXPECT_EQ(testBufSize(std::get<0>(GetParam()), + std::get<1>(GetParam()), + std::get<2>(GetParam())), 0); +} + +INSTANTIATE_TEST_SUITE_P( + TJUnitTests, + TJUnitTest, + ::testing::Values(std::make_tuple(NO_YUV, YUV_PAD, NO_AUTO_ALLOC), + std::make_tuple(NO_YUV, YUV_PAD, AUTO_ALLOC), + std::make_tuple(NO_YUV, NO_YUV_PAD, NO_AUTO_ALLOC), + std::make_tuple(NO_YUV, NO_YUV_PAD, AUTO_ALLOC), + std::make_tuple(YUV, YUV_PAD, NO_AUTO_ALLOC), + std::make_tuple(YUV, YUV_PAD, AUTO_ALLOC), + std::make_tuple(YUV, NO_YUV_PAD, NO_AUTO_ALLOC), + std::make_tuple(YUV, NO_YUV_PAD, AUTO_ALLOC))); + +class TJUnitTestYUV : public ::testing::TestWithParam<std::tuple<int, int>> {}; + +TEST_P(TJUnitTestYUV, YUVOnlyRGB444) { + EXPECT_EQ(testYUVOnlyRGB444(std::get<0>(GetParam()), + std::get<1>(GetParam())), 0); +} + +TEST_P(TJUnitTestYUV, YUVOnlyRGB422) { + EXPECT_EQ(testYUVOnlyRGB422(std::get<0>(GetParam()), + std::get<1>(GetParam())), 0); +} + +TEST_P(TJUnitTestYUV, YUVOnlyRGB420) { + EXPECT_EQ(testYUVOnlyRGB420(std::get<0>(GetParam()), + std::get<1>(GetParam())), 0); +} + +TEST_P(TJUnitTestYUV, YUVOnlyRGB440) { + EXPECT_EQ(testYUVOnlyRGB440(std::get<0>(GetParam()), + std::get<1>(GetParam())), 0); +} + +TEST_P(TJUnitTestYUV, YUVOnlyRGB411) { + EXPECT_EQ(testYUVOnlyRGB411(std::get<0>(GetParam()), + std::get<1>(GetParam())), 0); +} + +TEST_P(TJUnitTestYUV, YUVOnlyRGBGray) { + EXPECT_EQ(testYUVOnlyRGBGray(std::get<0>(GetParam()), + std::get<1>(GetParam())), 0); +} + +TEST_P(TJUnitTestYUV, YUVOnlyGrayGray) { + EXPECT_EQ(testYUVOnlyGrayGray(std::get<0>(GetParam()), + std::get<1>(GetParam())), 0); +} + +INSTANTIATE_TEST_SUITE_P( + TJUnitTestsYUV, + TJUnitTestYUV, + ::testing::Values(std::make_tuple(YUV_PAD, NO_AUTO_ALLOC), + std::make_tuple(YUV_PAD, AUTO_ALLOC), + std::make_tuple(NO_YUV_PAD, NO_AUTO_ALLOC), + std::make_tuple(NO_YUV_PAD, AUTO_ALLOC))); |