chromium/third_party/libjpeg_turbo/gtest/djpeg-gtest-wrapper.cpp

/*
 * 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/path_service.h"
#include "gtest-utils.h"

#include <gtest/gtest.h>
#include <string>

extern "C" int djpeg(int argc, char *argv[]);

const static std::vector<std::tuple<const std::string,
                                    const std::string,
                                    const std::string>> SCALE_IMAGE_MD5 =;

class DJPEGTestScalingDCT : public
  ::testing::TestWithParam<std::tuple<const std::string,
                                      const std::string,
                                      const std::string>> {};

TEST_P(DJPEGTestScalingDCT, Test) {}

INSTANTIATE_TEST_SUITE_P();

TEST(DJPEGTest, ISlow420256) {}

TEST(DJPEGTest, ISlow420565) {}

TEST(DJPEGTest, ISlow420565D) {}

TEST(DJPEGTest, ISlow420M565) {}

TEST(DJPEGTest, ISlow420M565D) {}

TEST(DJPEGTest, ISlow420Skip1531) {}

#ifdef C_ARITH_CODING_SUPPORTED
TEST(DJPEGTest, ISlow420AriSkip16139) {

  base::FilePath input_image_path;
  GetTestFilePath(&input_image_path, "testimgari.jpg");
  base::FilePath output_path(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(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(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(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) {}

TEST(DJPEGTest, RGBISlow565) {}

TEST(DJPEGTest, RGBISlow565D) {}

TEST(DJPEGTest, IFast422) {}

TEST(DJPEGTest, IFast422M) {}

TEST(DJPEGTest, IFast422M565) {}

TEST(DJPEGTest, IFast422M565D) {}

TEST(DJPEGTest, IFastProg420Q100) {}

TEST(DJPEGTest, IFastProg420MQ100) {}

TEST(DJPEGTest, GrayISlow) {}

TEST(DJPEGTest, GrayISlowRGB) {}

TEST(DJPEGTest, GrayISlow565) {}

TEST(DJPEGTest, GrayISlow565D) {}

TEST(DJPEGTest, FloatProg3x2) {}

TEST(DJPEGTest, IFastProg3x2) {}

TEST(DJPEGTest, ISlowProgCrop62x627171) {}

TEST(DJPEGTest, ISlow444Skip16) {}

TEST(DJPEGTest, ISlowProg444Crop98x981313) {}