This commit is contained in:
Alexandra Latysheva 2020-10-01 16:56:45 +00:00
parent 2869fba479
commit fea40e017f
6 changed files with 40 additions and 34 deletions

View File

@ -43,13 +43,12 @@ absl::Status CheckCluster(int cluster, const sapi::v::Array<uint8_t>& buffer,
} }
// the image is split on 6-bit clusters because it has YCbCr color format // the image is split on 6-bit clusters because it has YCbCr color format
return absl::InternalError( return absl::InternalError(absl::StrCat(
absl::StrCat("Cluster ", cluster, " did not match expected results.\n", "Cluster ", cluster, " did not match expected results.\n", "Expect: ",
"Expect: ", expected_cluster[0], "\t", expected_cluster[1], expected_cluster[0], "\t", expected_cluster[1], "\t", expected_cluster[2],
"\t", expected_cluster[2], "\t", expected_cluster[3], "\t", "\t", expected_cluster[3], "\t", expected_cluster[4], "\t",
expected_cluster[4], "\t", expected_cluster[5], "\n", expected_cluster[5], "\n", "Got: ", target[0], "\t", target[1], "\t",
"Got: ", target[0], "\t", target[1], "\t", target[2], "\t", target[2], "\t", target[3], "\t", target[4], "\t", target[5], "\n"));
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,
@ -98,8 +97,9 @@ absl::Status CheckRgbaPixel(int pixel, int min_red, int max_red, int min_green,
"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,
TIFFGetA(rgba), " (expected ", min_alpha, "..=", max_alpha, ")\n")); "), A=", TIFFGetA(rgba), " (expected ", min_alpha, "..=", max_alpha,
")\n"));
} }
} // namespace } // namespace
@ -114,10 +114,11 @@ std::string GetFilePath(const std::string filename) {
std::string project_path; std::string project_path;
if (find == std::string::npos) { if (find == std::string::npos) {
LOG(ERROR) << "Something went wrong: CWD don't contain build dir. " LOG(ERROR)
<< "Please run tests from build dir or send project dir as a " << "Something went wrong: CWD don't contain build dir. "
<< "parameter: ./sandboxed /absolute/path/to/project/dir .\n" << "Please run tests from build dir or send project dir as a "
<< "Falling back to using current working directory as root 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);
@ -166,14 +167,14 @@ absl::Status LibTIFFMain(const std::string& srcfile) {
SAPI_ASSIGN_OR_RETURN(tsize_t sz, api.TIFFTileSize(&tif)); SAPI_ASSIGN_OR_RETURN(tsize_t sz, api.TIFFTileSize(&tif));
if (sz != 24576) { if (sz != 24576) {
return absl::InternalError( return absl::InternalError(absl::StrCat("tiles are ", sz, " bytes\n"));
absl::StrCat("tiles are ", sz, " bytes\n"));
} }
sapi::v::Array<uint8_t> buffer_(sz); sapi::v::Array<uint8_t> buffer_(sz);
// Read a tile in decompressed form, but still YCbCr subsampled // Read a tile in decompressed form, but still YCbCr subsampled
SAPI_ASSIGN_OR_RETURN( SAPI_ASSIGN_OR_RETURN(
tsize_t new_sz, api.TIFFReadEncodedTile(&tif, kRawTileNumber, buffer_.PtrBoth(), sz)); tsize_t new_sz,
api.TIFFReadEncodedTile(&tif, kRawTileNumber, buffer_.PtrBoth(), sz));
if (new_sz != 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(): ",
@ -209,18 +210,18 @@ absl::Status LibTIFFMain(const std::string& srcfile) {
SAPI_ASSIGN_OR_RETURN(sz, api.TIFFTileSize(&tif)); SAPI_ASSIGN_OR_RETURN(sz, api.TIFFTileSize(&tif));
if (sz != 128 * 128 * 3) { if (sz != 128 * 128 * 3) {
return absl::InternalError( return absl::InternalError(absl::StrCat("tiles are ", sz, " bytes"));
absl::StrCat("tiles are ", sz, " bytes"));
} }
sapi::v::Array<uint8_t> buffer2_(sz); sapi::v::Array<uint8_t> buffer2_(sz);
SAPI_ASSIGN_OR_RETURN( SAPI_ASSIGN_OR_RETURN(
new_sz, api.TIFFReadEncodedTile(&tif, kRawTileNumber, buffer2_.PtrBoth(), sz)); new_sz,
api.TIFFReadEncodedTile(&tif, kRawTileNumber, buffer2_.PtrBoth(), sz));
if (new_sz != 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(): ", new_sz,
new_sz, " instead of ", sz)); " instead of ", sz));
} }
pixel_status = true; pixel_status = true;

View File

@ -209,10 +209,11 @@ void TestWriting(const char* mode, int tiled, int height) {
for (int i = 0; i < (height + 15) / 16; ++i) { for (int i = 0; i < (height + 15) / 16; ++i) {
std::array<unsigned char, kTileBufferSize> tilebuffer; std::array<unsigned char, kTileBufferSize> tilebuffer;
tilebuffer.fill(i); tilebuffer.fill(i);
sapi::v::Array<unsigned char> tilebuffer_(tilebuffer.data(), kTileBufferSize); sapi::v::Array<unsigned char> tilebuffer_(tilebuffer.data(),
kTileBufferSize);
status_or_int = status_or_int = api.TIFFWriteEncodedTile(&tif, i, tilebuffer_.PtrBoth(),
api.TIFFWriteEncodedTile(&tif, i, tilebuffer_.PtrBoth(), kTileBufferSize); 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(kTileBufferSize)) EXPECT_THAT(status_or_int.value(), Eq(kTileBufferSize))
<< "line " << i << ": expected " << kTileBufferSize << ", got " << "line " << i << ": expected " << kTileBufferSize << ", got "
@ -249,9 +250,10 @@ void TestWriting(const char* mode, int tiled, int height) {
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(), kTileBufferSize); sapi::v::Array<unsigned char> tilebuffer_(tilebuffer.data(),
status_or_long = kTileBufferSize);
api.TIFFReadEncodedTile(&tif2, i, tilebuffer_.PtrBoth(), kTileBufferSize); status_or_long = 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(kTileBufferSize)) EXPECT_THAT(status_or_long.value(), Eq(kTileBufferSize))

View File

@ -74,7 +74,8 @@ 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, kSamplePerPixel); 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

@ -103,11 +103,12 @@ 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 "
<< "..=" << max_green << "), B=" << TIFFGetB(rgba) << " (expected " << min_green << "..=" << max_green << "), B=" << TIFFGetB(rgba)
<< min_blue << "..=" << max_blue << "), A=" << TIFFGetA(rgba) << " (expected " << min_blue << "..=" << max_blue
<< " (expected " << min_alpha << "..=" << max_alpha << ")"; << "), A=" << TIFFGetA(rgba) << " (expected " << min_alpha
<< "..=" << max_alpha << ")";
return comp; return comp;
} }

View File

@ -95,7 +95,8 @@ 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, kSamplePerPixel); 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";