This commit is contained in:
Alexandra Latysheva 2020-10-01 16:49:59 +00:00
parent 477de3b6b7
commit 2869fba479
5 changed files with 78 additions and 61 deletions

View File

@ -27,26 +27,37 @@ constexpr std::array<uint8_t, 6> kCluster0 = {0, 0, 2, 0, 138, 139};
constexpr std::array<uint8_t, 6> kCluster64 = {0, 0, 9, 6, 134, 119}; constexpr std::array<uint8_t, 6> kCluster64 = {0, 0, 9, 6, 134, 119};
constexpr std::array<uint8_t, 6> kCluster128 = {44, 40, 63, 59, 230, 95}; constexpr std::array<uint8_t, 6> kCluster128 = {44, 40, 63, 59, 230, 95};
constexpr unsigned kRawTileNumber = 9;
namespace { namespace {
absl::Status CheckCluster(int cluster, const sapi::v::Array<uint8_t>& buffer, absl::Status CheckCluster(int cluster, const sapi::v::Array<uint8_t>& buffer,
const std::array<uint8_t, 6>& expected_cluster) { const std::array<uint8_t, 6>& expected_cluster) {
if (buffer.GetSize() <= cluster * 6) {
return absl::InternalError("Buffer overrun\n");
}
uint8_t* target = buffer.GetData() + cluster * 6; uint8_t* target = buffer.GetData() + cluster * 6;
if (!std::memcmp(target, expected_cluster.data(), 6)) { if (!std::memcmp(target, expected_cluster.data(), 6)) {
return absl::OkStatus(); return absl::OkStatus();
} }
// the image is split on 6-bit clusters because it has YCbCr color format
return absl::InternalError( return absl::InternalError(
absl::StrCat("Cluster ", cluster, " did not match expected results.\n", absl::StrCat("Cluster ", cluster, " did not match expected results.\n",
"Expect: ", expected_cluster[0], "\t", expected_cluster[1], "Expect: ", expected_cluster[0], "\t", expected_cluster[1],
"\t", expected_cluster[4], "\t", expected_cluster[5], "\t", "\t", expected_cluster[2], "\t", expected_cluster[3], "\t",
expected_cluster[2], "\t", expected_cluster[3], "\n")); expected_cluster[4], "\t", expected_cluster[5], "\n",
"Got: ", target[0], "\t", target[1], "\t", target[2], "\t",
target[3], "\t", target[4], "\t", target[5], "\n"));
} }
absl::Status CheckRgbPixel(int pixel, int min_red, int max_red, int min_green, absl::Status CheckRgbPixel(int pixel, int min_red, int max_red, int min_green,
int max_green, int min_blue, int max_blue, int max_green, int min_blue, int max_blue,
const sapi::v::Array<uint8_t>& buffer) { const sapi::v::Array<uint8_t>& buffer) {
if (buffer.GetSize() <= pixel * 3) {
return absl::InternalError("Buffer overrun\n");
}
uint8_t* rgb = buffer.GetData() + 3 * pixel; uint8_t* rgb = buffer.GetData() + 3 * pixel;
if (rgb[0] >= min_red && rgb[0] <= max_red && rgb[1] >= min_green && if (rgb[0] >= min_red && rgb[0] <= max_red && rgb[1] >= min_green &&
@ -56,9 +67,9 @@ absl::Status CheckRgbPixel(int pixel, int min_red, int max_red, int min_green,
return absl::InternalError(absl::StrCat( return absl::InternalError(absl::StrCat(
"Pixel ", pixel, " did not match expected results.\n", "Got R=", rgb[0], "Pixel ", pixel, " did not match expected results.\n", "Got R=", rgb[0],
" (expected ", min_red, "..", max_red, "), G=", rgb[1], " (expected ", " (expected ", min_red, "..=", max_red, "), G=", rgb[1], " (expected ",
min_green, "..", max_green, "), B=", rgb[2], " (expected ", min_blue, min_green, "..=", max_green, "), B=", rgb[2], " (expected ", min_blue,
"..", max_blue, ")\n")); "..=", max_blue, ")\n"));
} }
absl::Status CheckRgbaPixel(int pixel, int min_red, int max_red, int min_green, absl::Status CheckRgbaPixel(int pixel, int min_red, int max_red, int min_green,
@ -67,6 +78,10 @@ absl::Status CheckRgbaPixel(int pixel, int min_red, int max_red, int min_green,
const sapi::v::Array<unsigned>& buffer) { const sapi::v::Array<unsigned>& buffer) {
// RGBA images are upside down - adjust for normal ordering // RGBA images are upside down - adjust for normal ordering
int adjusted_pixel = pixel % 128 + (127 - (pixel / 128)) * 128; int adjusted_pixel = pixel % 128 + (127 - (pixel / 128)) * 128;
if (buffer.GetSize() <= adjusted_pixel) {
return absl::InternalError("Buffer overrun\n");
}
uint32 rgba = buffer[adjusted_pixel]; uint32 rgba = buffer[adjusted_pixel];
if (TIFFGetR(rgba) >= (uint32)min_red && TIFFGetR(rgba) <= (uint32)max_red && if (TIFFGetR(rgba) >= (uint32)min_red && TIFFGetR(rgba) <= (uint32)max_red &&
@ -81,10 +96,10 @@ absl::Status CheckRgbaPixel(int pixel, int min_red, int max_red, int min_green,
return absl::InternalError(absl::StrCat( return absl::InternalError(absl::StrCat(
"Pixel ", pixel, " did not match expected results.\n", "Pixel ", pixel, " did not match expected results.\n",
"Got R=", TIFFGetR(rgba), " (expected ", min_red, "..", max_red, "Got R=", TIFFGetR(rgba), " (expected ", min_red, "..=", max_red,
"), G=", TIFFGetG(rgba), " (expected ", min_green, "..", max_green, "), G=", TIFFGetG(rgba), " (expected ", min_green, "..=", max_green,
"), B=", TIFFGetB(rgba), " (expected ", min_blue, "..", max_blue, "), A=", "), B=", TIFFGetB(rgba), " (expected ", min_blue, "..=", max_blue, "), A=",
TIFFGetA(rgba), " (expected ", min_alpha, "..", max_alpha, ")\n")); TIFFGetA(rgba), " (expected ", min_alpha, "..=", max_alpha, ")\n"));
} }
} // namespace } // namespace
@ -101,7 +116,8 @@ std::string GetFilePath(const std::string filename) {
if (find == std::string::npos) { if (find == std::string::npos) {
LOG(ERROR) << "Something went wrong: CWD don't contain build dir. " LOG(ERROR) << "Something went wrong: CWD don't contain build dir. "
<< "Please run tests from build dir or send project dir as a " << "Please run tests from build dir or send project dir as a "
<< "parameter: ./sandboxed /absolute/path/to/project/dir \n"; << "parameter: ./sandboxed /absolute/path/to/project/dir .\n"
<< "Falling back to using current working directory as root dir.\n";
project_path = cwd; project_path = cwd;
} else { } else {
project_path = cwd.substr(0, find); project_path = cwd.substr(0, find);
@ -141,30 +157,30 @@ absl::Status LibTIFFMain(const std::string& srcfile) {
return absl::InternalError(absl::StrCat("Could not open ", srcfile)); return absl::InternalError(absl::StrCat("Could not open ", srcfile));
} }
SAPI_ASSIGN_OR_RETURN(status_or_int, SAPI_ASSIGN_OR_RETURN(auto return_value,
api.TIFFGetField2(&tif, TIFFTAG_YCBCRSUBSAMPLING, api.TIFFGetField2(&tif, TIFFTAG_YCBCRSUBSAMPLING,
h.PtrBoth(), v.PtrBoth())); h.PtrBoth(), v.PtrBoth()));
if (status_or_int.value() == 0 || h.GetValue() != 2 || v.GetValue() != 2) { if (return_value == 0 || h.GetValue() != 2 || v.GetValue() != 2) {
return absl::InternalError("Could not retrieve subsampling tag"); return absl::InternalError("Could not retrieve subsampling tag");
} }
SAPI_ASSIGN_OR_RETURN(status_or_long, api.TIFFTileSize(&tif)); SAPI_ASSIGN_OR_RETURN(tsize_t sz, api.TIFFTileSize(&tif));
if (status_or_long.value() != 24576) { if (sz != 24576) {
return absl::InternalError( return absl::InternalError(
absl::StrCat("tiles are ", status_or_long.value(), " bytes\n")); absl::StrCat("tiles are ", sz, " bytes\n"));
} }
tsize_t sz = status_or_long.value();
sapi::v::Array<uint8_t> buffer_(sz); sapi::v::Array<uint8_t> buffer_(sz);
// Read a tile in decompressed form, but still YCbCr subsampled
SAPI_ASSIGN_OR_RETURN( SAPI_ASSIGN_OR_RETURN(
status_or_long, api.TIFFReadEncodedTile(&tif, 9, buffer_.PtrBoth(), sz)); tsize_t new_sz, api.TIFFReadEncodedTile(&tif, kRawTileNumber, buffer_.PtrBoth(), sz));
if (status_or_long.value() != sz) { if (new_sz != sz) {
return absl::InternalError(absl::StrCat( return absl::InternalError(absl::StrCat(
"Did not get expected result code from TIFFReadEncodedTile(): ", "Did not get expected result code from TIFFReadEncodedTile(): ",
status_or_long.value(), " instead of ", sz)); status_or_long.value(), " instead of ", sz));
} }
unsigned pixel_status = 1; bool pixel_status = true;
if (status = CheckCluster(0, buffer_, kCluster0); !status.ok()) { if (status = CheckCluster(0, buffer_, kCluster0); !status.ok()) {
LOG(ERROR) << "CheckCluster failed:\n" << status.ToString(); LOG(ERROR) << "CheckCluster failed:\n" << status.ToString();
} }
@ -187,28 +203,28 @@ absl::Status LibTIFFMain(const std::string& srcfile) {
SAPI_ASSIGN_OR_RETURN( SAPI_ASSIGN_OR_RETURN(
status_or_int, status_or_int,
api.TIFFSetFieldU1(&tif, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB)); api.TIFFSetFieldU1(&tif, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB));
if (!status_or_int.value()) { if (return_value == 0) {
return absl::InternalError("TIFFSetFieldU1 not available"); return absl::InternalError("TIFFSetFieldU1 not available");
} }
SAPI_ASSIGN_OR_RETURN(status_or_long, api.TIFFTileSize(&tif)); SAPI_ASSIGN_OR_RETURN(sz, api.TIFFTileSize(&tif));
if (status_or_long.value() != 128 * 128 * 3) { if (sz != 128 * 128 * 3) {
return absl::InternalError( return absl::InternalError(
absl::StrCat("tiles are ", status_or_long.value(), " bytes")); absl::StrCat("tiles are ", sz, " bytes"));
} }
sz = status_or_long.value();
sapi::v::Array<uint8_t> buffer2_(sz); sapi::v::Array<uint8_t> buffer2_(sz);
SAPI_ASSIGN_OR_RETURN( SAPI_ASSIGN_OR_RETURN(
status_or_long, api.TIFFReadEncodedTile(&tif, 9, buffer2_.PtrBoth(), sz)); new_sz, api.TIFFReadEncodedTile(&tif, kRawTileNumber, buffer2_.PtrBoth(), sz));
if (status_or_long.value() != sz) { if (new_sz != sz) {
return absl::InternalError(absl::StrCat( return absl::InternalError(absl::StrCat(
"Did not get expected result code from TIFFReadEncodedTile(): ", "Did not get expected result code from TIFFReadEncodedTile(): ",
status_or_long.value(), " instead of ", sz)); new_sz, " instead of ", sz));
} }
pixel_status = 1; pixel_status = true;
// Checking specific pixels from the test data, 0th, 64th and 512th
if (status = CheckRgbPixel(0, 15, 18, 0, 0, 18, 41, buffer2_); !status.ok()) { if (status = CheckRgbPixel(0, 15, 18, 0, 0, 18, 41, buffer2_); !status.ok()) {
LOG(ERROR) << "CheckRgbPixel failed:\n" << status.ToString(); LOG(ERROR) << "CheckRgbPixel failed:\n" << status.ToString();
} }
@ -231,19 +247,21 @@ absl::Status LibTIFFMain(const std::string& srcfile) {
status_or_tif, api.TIFFOpen(srcfile_var.PtrBefore(), r_var.PtrBefore())); status_or_tif, api.TIFFOpen(srcfile_var.PtrBefore(), r_var.PtrBefore()));
sapi::v::RemotePtr tif2(status_or_tif.value()); sapi::v::RemotePtr tif2(status_or_tif.value());
if (!tif2.GetValue()) { // tif is NULL if (!tif2.GetValue()) {
return absl::InternalError(absl::StrCat("Could not reopen ", srcfile)); return absl::InternalError(absl::StrCat("Could not reopen ", srcfile));
} }
sapi::v::Array<uint32> rgba_buffer_(128 * 128); sapi::v::Array<uint32> rgba_buffer_(128 * 128);
// read as rgba
SAPI_ASSIGN_OR_RETURN( SAPI_ASSIGN_OR_RETURN(
status_or_int, return_value,
api.TIFFReadRGBATile(&tif2, 1 * 128, 2 * 128, rgba_buffer_.PtrBoth())); api.TIFFReadRGBATile(&tif2, 1 * 128, 2 * 128, rgba_buffer_.PtrBoth()));
if (!status_or_int.value()) { if (return_value == 0) {
return absl::InternalError("TIFFReadRGBATile() returned failure code"); return absl::InternalError("TIFFReadRGBATile() returned failure code");
} }
// Checking specific pixels from the test data, 0th, 64th and 512th
if (status = CheckRgbaPixel(0, 15, 18, 0, 0, 18, 41, 255, 255, rgba_buffer_); if (status = CheckRgbaPixel(0, 15, 18, 0, 0, 18, 41, 255, 255, rgba_buffer_);
!status.ok()) { !status.ok()) {
LOG(ERROR) << "CheckRgbaPixel failed:\n" << status.ToString(); LOG(ERROR) << "CheckRgbaPixel failed:\n" << status.ToString();
@ -276,7 +294,6 @@ int main(int argc, char** argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true); gflags::ParseCommandLineFlags(&argc, &argv, true);
std::string srcfile; std::string srcfile;
// "test/images/quad-tile.jpg.tiff"
std::string srcfilerel = "quad-tile.jpg.tiff"; std::string srcfilerel = "quad-tile.jpg.tiff";
if (argc < 2) { if (argc < 2) {

View File

@ -19,7 +19,7 @@
namespace { namespace {
#define TBS 256 // kTileBufferSize constexpr unsigned kTileBufferSize = 256;
constexpr uint16_t kWidth = 1; constexpr uint16_t kWidth = 1;
constexpr uint16_t kBps = 8; constexpr uint16_t kBps = 8;
constexpr uint16_t kRowsPerStrip = 1; constexpr uint16_t kRowsPerStrip = 1;
@ -207,15 +207,15 @@ void TestWriting(const char* mode, int tiled, int height) {
if (tiled) { if (tiled) {
for (int i = 0; i < (height + 15) / 16; ++i) { for (int i = 0; i < (height + 15) / 16; ++i) {
std::array<unsigned char, TBS> tilebuffer; std::array<unsigned char, kTileBufferSize> tilebuffer;
tilebuffer.fill(i); tilebuffer.fill(i);
sapi::v::Array<unsigned char> tilebuffer_(tilebuffer.data(), TBS); sapi::v::Array<unsigned char> tilebuffer_(tilebuffer.data(), kTileBufferSize);
status_or_int = status_or_int =
api.TIFFWriteEncodedTile(&tif, i, tilebuffer_.PtrBoth(), TBS); api.TIFFWriteEncodedTile(&tif, i, tilebuffer_.PtrBoth(), kTileBufferSize);
ASSERT_THAT(status_or_int, IsOk()) << "TIFFWriteEncodedTile fatal error"; ASSERT_THAT(status_or_int, IsOk()) << "TIFFWriteEncodedTile fatal error";
EXPECT_THAT(status_or_int.value(), Eq(TBS)) EXPECT_THAT(status_or_int.value(), Eq(kTileBufferSize))
<< "line " << i << ": expected " << TBS << ", got " << "line " << i << ": expected " << kTileBufferSize << ", got "
<< status_or_int.value(); << status_or_int.value();
} }
} else { } else {
@ -245,17 +245,17 @@ void TestWriting(const char* mode, int tiled, int height) {
if (tiled) { if (tiled) {
for (int i = 0; i < (height + 15) / 16; ++i) { for (int i = 0; i < (height + 15) / 16; ++i) {
for (int retry = 0; retry < 2; ++retry) { for (int retry = 0; retry < 2; ++retry) {
std::array<unsigned char, TBS> tilebuffer; std::array<unsigned char, kTileBufferSize> tilebuffer;
unsigned char expected_c = (unsigned char)i; unsigned char expected_c = (unsigned char)i;
tilebuffer.fill(0); tilebuffer.fill(0);
sapi::v::Array<unsigned char> tilebuffer_(tilebuffer.data(), TBS); sapi::v::Array<unsigned char> tilebuffer_(tilebuffer.data(), kTileBufferSize);
status_or_long = status_or_long =
api.TIFFReadEncodedTile(&tif2, i, tilebuffer_.PtrBoth(), TBS); api.TIFFReadEncodedTile(&tif2, i, tilebuffer_.PtrBoth(), kTileBufferSize);
ASSERT_THAT(status_or_long, IsOk()) ASSERT_THAT(status_or_long, IsOk())
<< "TIFFReadEncodedTile fatal error"; << "TIFFReadEncodedTile fatal error";
EXPECT_THAT(status_or_long.value(), Eq(TBS)) EXPECT_THAT(status_or_long.value(), Eq(kTileBufferSize))
<< "line " << i << ": expected " << TBS << ", got " << "line " << i << ": expected " << kTileBufferSize << ", got "
<< status_or_long.value(); << status_or_long.value();
bool cmp = tilebuffer[0] != expected_c || tilebuffer[255] != expected_c; bool cmp = tilebuffer[0] != expected_c || tilebuffer[255] != expected_c;

View File

@ -28,7 +28,7 @@ struct LongTag {
constexpr std::array<LongTag, 1> kLongTags = { constexpr std::array<LongTag, 1> kLongTags = {
{TIFFTAG_SUBFILETYPE, 1, {TIFFTAG_SUBFILETYPE, 1,
FILETYPE_REDUCEDIMAGE | FILETYPE_PAGE | FILETYPE_MASK}}; FILETYPE_REDUCEDIMAGE | FILETYPE_PAGE | FILETYPE_MASK}};
#define SPP 3 // kSamplePerPixel constexpr unsigned kSamplePerPixel = 3;
constexpr unsigned kWidth = 1; constexpr unsigned kWidth = 1;
constexpr unsigned kLength = 1; constexpr unsigned kLength = 1;
constexpr unsigned kBps = 8; constexpr unsigned kBps = 8;
@ -45,8 +45,8 @@ TEST(SandboxTest, LongTag) {
TiffSapiSandbox sandbox(srcfile); TiffSapiSandbox sandbox(srcfile);
ASSERT_THAT(sandbox.Init(), IsOk()) << "Couldn't initialize Sandboxed API"; ASSERT_THAT(sandbox.Init(), IsOk()) << "Couldn't initialize Sandboxed API";
std::array<uint8_t, SPP> buffer = {0, 127, 255}; std::array<uint8_t, kSamplePerPixel> buffer = {0, 127, 255};
sapi::v::Array<uint8_t> buffer_(buffer.data(), SPP); sapi::v::Array<uint8_t> buffer_(buffer.data(), kSamplePerPixel);
sapi::StatusOr<int> status_or_int; sapi::StatusOr<int> status_or_int;
sapi::StatusOr<TIFF*> status_or_tif; sapi::StatusOr<TIFF*> status_or_tif;
@ -74,7 +74,7 @@ TEST(SandboxTest, LongTag) {
ASSERT_THAT(status_or_int, IsOk()) << "TIFFSetFieldU1 fatal error"; ASSERT_THAT(status_or_int, IsOk()) << "TIFFSetFieldU1 fatal error";
EXPECT_THAT(status_or_int.value(), IsTrue()) << "Can't set BitsPerSample tag"; EXPECT_THAT(status_or_int.value(), IsTrue()) << "Can't set BitsPerSample tag";
status_or_int = api.TIFFSetFieldU1(&tif, TIFFTAG_SAMPLESPERPIXEL, SPP); status_or_int = api.TIFFSetFieldU1(&tif, TIFFTAG_SAMPLESPERPIXEL, kSamplePerPixel);
ASSERT_THAT(status_or_int, IsOk()) << "TIFFSetFieldU1 fatal error"; ASSERT_THAT(status_or_int, IsOk()) << "TIFFSetFieldU1 fatal error";
EXPECT_THAT(status_or_int.value(), IsTrue()) EXPECT_THAT(status_or_int.value(), IsTrue())
<< "Can't set SamplesPerPixel tag"; << "Can't set SamplesPerPixel tag";

View File

@ -47,7 +47,7 @@ bool CheckCluster(int cluster, const sapi::v::Array<uint8_t>& buffer,
<< "\t" << expected_cluster[2] << "\t" << expected_cluster[3] << "\t" << "\t" << expected_cluster[2] << "\t" << expected_cluster[3] << "\t"
<< expected_cluster[4] << "\t" << expected_cluster[5] << "\n" << expected_cluster[4] << "\t" << expected_cluster[5] << "\n"
<< "Got: " << target[0] << "\t" << target[1] << "\t" << target[2] << "\t" << "Got: " << target[0] << "\t" << target[1] << "\t" << target[2] << "\t"
<< target[3] << "\t" << target[4] << "\t" << target[4]; << target[3] << "\t" << target[4] << "\t" << target[5];
return comp; return comp;
} }
@ -70,9 +70,9 @@ bool CheckRgbPixel(int pixel, int min_red, int max_red, int min_green,
EXPECT_THAT(comp, IsFalse()) EXPECT_THAT(comp, IsFalse())
<< "Pixel " << pixel << " did not match expected results.\n" << "Pixel " << pixel << " did not match expected results.\n"
<< "Got R=" << rgb[0] << " (expected " << min_red << ".." << max_red << "Got R=" << rgb[0] << " (expected " << min_red << "..=" << max_red
<< "), G=" << rgb[1] << " (expected " << min_green << ".." << max_green << "), G=" << rgb[1] << " (expected " << min_green << "..=" << max_green
<< "), B=" << rgb[2] << " (expected " << min_blue << ".." << max_blue << "), B=" << rgb[2] << " (expected " << min_blue << "..=" << max_blue
<< ")"; << ")";
return comp; return comp;
} }
@ -103,11 +103,11 @@ bool CheckRgbaPixel(int pixel, int min_red, int max_red, int min_green,
EXPECT_THAT(comp, IsFalse()) EXPECT_THAT(comp, IsFalse())
<< "Pixel " << pixel << " did not match expected results.\n" << "Pixel " << pixel << " did not match expected results.\n"
<< "Got R=" << TIFFGetR(rgba) << " (expected " << min_red << ".." << "Got R=" << TIFFGetR(rgba) << " (expected " << min_red << "..="
<< max_red << "), G=" << TIFFGetG(rgba) << " (expected " << min_green << max_red << "), G=" << TIFFGetG(rgba) << " (expected " << min_green
<< ".." << max_green << "), B=" << TIFFGetB(rgba) << " (expected " << "..=" << max_green << "), B=" << TIFFGetB(rgba) << " (expected "
<< min_blue << ".." << max_blue << "), A=" << TIFFGetA(rgba) << min_blue << "..=" << max_blue << "), A=" << TIFFGetA(rgba)
<< " (expected " << min_alpha << ".." << max_alpha << ")"; << " (expected " << min_alpha << "..=" << max_alpha << ")";
return comp; return comp;
} }

View File

@ -20,7 +20,7 @@
namespace { namespace {
#define SPP 3 // kSamplePerPixel constexpr unsigned kSamplePerPixel = 3;
constexpr uint16_t kWidth = 1; constexpr uint16_t kWidth = 1;
constexpr uint16_t kLength = 1; constexpr uint16_t kLength = 1;
constexpr uint16_t kBps = 8; constexpr uint16_t kBps = 8;
@ -46,7 +46,7 @@ constexpr std::array<SingleTag, 9> kShortSingleTags = {
{TIFFTAG_MINSAMPLEVALUE, 23}, {TIFFTAG_MINSAMPLEVALUE, 23},
{TIFFTAG_MAXSAMPLEVALUE, 241}, {TIFFTAG_MAXSAMPLEVALUE, 241},
{TIFFTAG_INKSET, INKSET_MULTIINK}, {TIFFTAG_INKSET, INKSET_MULTIINK},
{TIFFTAG_NUMBEROFINKS, SPP}, {TIFFTAG_NUMBEROFINKS, kSamplePerPixel},
{TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT}}}; {TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT}}};
constexpr std::array<PairedTag, 4> kShortPairedTags = { constexpr std::array<PairedTag, 4> kShortPairedTags = {
@ -66,8 +66,8 @@ TEST(SandboxTest, ShortTag) {
TiffSapiSandbox sandbox(srcfile); TiffSapiSandbox sandbox(srcfile);
ASSERT_THAT(sandbox.Init(), IsOk()) << "Couldn't initialize Sandboxed API"; ASSERT_THAT(sandbox.Init(), IsOk()) << "Couldn't initialize Sandboxed API";
std::array<uint8_t, SPP> buffer = {0, 127, 255}; std::array<uint8_t, kSamplePerPixel> buffer = {0, 127, 255};
sapi::v::Array<uint8_t> buffer_(buffer.data(), SPP); sapi::v::Array<uint8_t> buffer_(buffer.data(), kSamplePerPixel);
sapi::StatusOr<int> status_or_int; sapi::StatusOr<int> status_or_int;
sapi::StatusOr<TIFF*> status_or_tif; sapi::StatusOr<TIFF*> status_or_tif;
@ -95,7 +95,7 @@ TEST(SandboxTest, ShortTag) {
ASSERT_THAT(status_or_int, IsOk()) << "TIFFSetFieldUShort1 fatal error"; ASSERT_THAT(status_or_int, IsOk()) << "TIFFSetFieldUShort1 fatal error";
EXPECT_THAT(status_or_int.value(), IsTrue()) << "Can't set BitsPerSample tag"; EXPECT_THAT(status_or_int.value(), IsTrue()) << "Can't set BitsPerSample tag";
status_or_int = api.TIFFSetFieldUShort1(&tif, TIFFTAG_SAMPLESPERPIXEL, SPP); status_or_int = api.TIFFSetFieldUShort1(&tif, TIFFTAG_SAMPLESPERPIXEL, kSamplePerPixel);
ASSERT_THAT(status_or_int, IsOk()) << "TIFFSetFieldUShort1 fatal error"; ASSERT_THAT(status_or_int, IsOk()) << "TIFFSetFieldUShort1 fatal error";
EXPECT_THAT(status_or_int.value(), IsTrue()) EXPECT_THAT(status_or_int.value(), IsTrue())
<< "Can't set SamplesPerPixel tag"; << "Can't set SamplesPerPixel tag";
@ -148,7 +148,7 @@ TEST(SandboxTest, ShortTag) {
CheckLongField(api, tif2, TIFFTAG_IMAGELENGTH, kLength); CheckLongField(api, tif2, TIFFTAG_IMAGELENGTH, kLength);
CheckShortField(api, tif2, TIFFTAG_BITSPERSAMPLE, kBps); CheckShortField(api, tif2, TIFFTAG_BITSPERSAMPLE, kBps);
CheckShortField(api, tif2, TIFFTAG_PHOTOMETRIC, kPhotometric); CheckShortField(api, tif2, TIFFTAG_PHOTOMETRIC, kPhotometric);
CheckShortField(api, tif2, TIFFTAG_SAMPLESPERPIXEL, SPP); CheckShortField(api, tif2, TIFFTAG_SAMPLESPERPIXEL, kSamplePerPixel);
CheckLongField(api, tif2, TIFFTAG_ROWSPERSTRIP, kRowsPerStrip); CheckLongField(api, tif2, TIFFTAG_ROWSPERSTRIP, kRowsPerStrip);
CheckShortField(api, tif2, TIFFTAG_PLANARCONFIG, kPlanarConfig); CheckShortField(api, tif2, TIFFTAG_PLANARCONFIG, kPlanarConfig);