mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
gstyle
This commit is contained in:
parent
358d919ea0
commit
6f3acfabb0
|
@ -35,9 +35,9 @@ static const std::vector<unsigned char> cluster_0 = {0, 0, 2, 0, 138, 139};
|
||||||
static const std::vector<unsigned char> cluster_64 = {0, 0, 9, 6, 134, 119};
|
static const std::vector<unsigned char> cluster_64 = {0, 0, 9, 6, 134, 119};
|
||||||
static const std::vector<unsigned char> cluster_128 = {44, 40, 63, 59, 230, 95};
|
static const std::vector<unsigned char> cluster_128 = {44, 40, 63, 59, 230, 95};
|
||||||
|
|
||||||
static int check_cluster(int cluster,
|
static int CheckCluster(int cluster,
|
||||||
const sapi::v::Array<unsigned char> &buffer,
|
const sapi::v::Array<unsigned char> &buffer,
|
||||||
const std::vector<unsigned char> &expected_cluster) {
|
const std::vector<unsigned char> &expected_cluster) {
|
||||||
unsigned char *target = buffer.GetData() + cluster * 6;
|
unsigned char *target = buffer.GetData() + cluster * 6;
|
||||||
|
|
||||||
if (!std::memcmp(target, expected_cluster.data(), 6)) {
|
if (!std::memcmp(target, expected_cluster.data(), 6)) {
|
||||||
|
@ -56,9 +56,9 @@ static int check_cluster(int cluster,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int check_rgb_pixel(int pixel, int min_red, int max_red, int min_green,
|
static int 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<unsigned char> &buffer) {
|
const sapi::v::Array<unsigned char> &buffer) {
|
||||||
unsigned char *rgb = buffer.GetData() + 3 * pixel;
|
unsigned char *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 &&
|
||||||
|
@ -74,10 +74,10 @@ static int check_rgb_pixel(int pixel, int min_red, int max_red, int min_green,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int check_rgba_pixel(int pixel, int min_red, int max_red, int min_green,
|
static int CheckRgbaPixel(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,
|
||||||
int min_alpha, int max_alpha,
|
int min_alpha, int max_alpha,
|
||||||
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;
|
||||||
uint32 rgba = buffer[adjusted_pixel];
|
uint32 rgba = buffer[adjusted_pixel];
|
||||||
|
@ -133,8 +133,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
std::string srcfile;
|
std::string srcfile;
|
||||||
// "test/images/quad-tile.jpg.tiff"
|
// "test/images/quad-tile.jpg.tiff"
|
||||||
std::string srcfilerel =
|
std::string srcfilerel = "quad-tile.jpg.tiff";
|
||||||
"quad-tile.jpg.tiff";
|
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
srcfile = GetFilePath(srcfilerel);
|
srcfile = GetFilePath(srcfilerel);
|
||||||
|
@ -200,9 +199,9 @@ int main(int argc, char **argv) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (check_cluster(0, buffer_, cluster_0) ||
|
if (CheckCluster(0, buffer_, cluster_0) ||
|
||||||
check_cluster(64, buffer_, cluster_64) ||
|
CheckCluster(64, buffer_, cluster_64) ||
|
||||||
check_cluster(128, buffer_, cluster_128)) {
|
CheckCluster(128, buffer_, cluster_128)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,9 +229,9 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned pixel_status = 0;
|
unsigned pixel_status = 0;
|
||||||
pixel_status |= check_rgb_pixel(0, 15, 18, 0, 0, 18, 41, buffer2_);
|
pixel_status |= CheckRgbPixel(0, 15, 18, 0, 0, 18, 41, buffer2_);
|
||||||
pixel_status |= check_rgb_pixel(64, 0, 0, 0, 0, 0, 2, buffer2_);
|
pixel_status |= CheckRgbPixel(64, 0, 0, 0, 0, 0, 2, buffer2_);
|
||||||
pixel_status |= check_rgb_pixel(512, 5, 6, 34, 36, 182, 196, buffer2_);
|
pixel_status |= CheckRgbPixel(512, 5, 6, 34, 36, 182, 196, buffer2_);
|
||||||
|
|
||||||
if (!api.TIFFClose(&tif).ok()) {
|
if (!api.TIFFClose(&tif).ok()) {
|
||||||
std::cerr << "TIFFClose error\n";
|
std::cerr << "TIFFClose error\n";
|
||||||
|
@ -260,11 +259,10 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pixel_status |=
|
pixel_status |=
|
||||||
check_rgba_pixel(0, 15, 18, 0, 0, 18, 41, 255, 255, rgba_buffer_);
|
CheckRgbaPixel(0, 15, 18, 0, 0, 18, 41, 255, 255, rgba_buffer_);
|
||||||
|
pixel_status |= CheckRgbaPixel(64, 0, 0, 0, 0, 0, 2, 255, 255, rgba_buffer_);
|
||||||
pixel_status |=
|
pixel_status |=
|
||||||
check_rgba_pixel(64, 0, 0, 0, 0, 0, 2, 255, 255, rgba_buffer_);
|
CheckRgbaPixel(512, 5, 6, 34, 36, 182, 196, 255, 255, rgba_buffer_);
|
||||||
pixel_status |=
|
|
||||||
check_rgba_pixel(512, 5, 6, 34, 36, 182, 196, 255, 255, rgba_buffer_);
|
|
||||||
|
|
||||||
if (!api.TIFFClose(&tif2).ok()) {
|
if (!api.TIFFClose(&tif2).ok()) {
|
||||||
std::cerr << "TIFFClose erro\n";
|
std::cerr << "TIFFClose erro\n";
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
#include <linux/futex.h>
|
#include <linux/futex.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "sandboxed_api/util/flag.h"
|
#include "sandboxed_api/util/flag.h"
|
||||||
|
@ -65,4 +66,4 @@ class TiffSapiSandbox : public TiffSandbox {
|
||||||
std::string dir_, file_;
|
std::string dir_, file_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -40,7 +40,7 @@ static const unsigned short kBps = 8;
|
||||||
static const unsigned short kRowsPerStrip = 1;
|
static const unsigned short kRowsPerStrip = 1;
|
||||||
static const unsigned short kSamplePerPixel = 1;
|
static const unsigned short kSamplePerPixel = 1;
|
||||||
|
|
||||||
void test_writing(const char* mode, int tiled, int height) {
|
void TestWriting(const char* mode, int tiled, int height) {
|
||||||
sapi::StatusOr<std::string> status_or_path =
|
sapi::StatusOr<std::string> status_or_path =
|
||||||
sandbox2::CreateNamedTempFileAndClose("defer_strile_writing.tif");
|
sandbox2::CreateNamedTempFileAndClose("defer_strile_writing.tif");
|
||||||
ASSERT_THAT(status_or_path, IsOk()) << "Could not create temp file";
|
ASSERT_THAT(status_or_path, IsOk()) << "Could not create temp file";
|
||||||
|
@ -314,9 +314,9 @@ void test_writing(const char* mode, int tiled, int height) {
|
||||||
|
|
||||||
TEST(SandboxTest, DeferStrileWriting) {
|
TEST(SandboxTest, DeferStrileWriting) {
|
||||||
for (int tiled = 0; tiled <= 1; ++tiled) {
|
for (int tiled = 0; tiled <= 1; ++tiled) {
|
||||||
test_writing("w", tiled, 1);
|
TestWriting("w", tiled, 1);
|
||||||
test_writing("w", tiled, 10);
|
TestWriting("w", tiled, 10);
|
||||||
test_writing("w8", tiled, 1);
|
TestWriting("w8", tiled, 1);
|
||||||
test_writing("wD", tiled, 1);
|
TestWriting("wD", tiled, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,13 +26,13 @@
|
||||||
* TIFFSetField
|
* TIFFSetField
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct long_tag {
|
struct LongTag {
|
||||||
ttag_t tag;
|
ttag_t tag;
|
||||||
short count;
|
short count;
|
||||||
unsigned value;
|
unsigned value;
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::vector<long_tag> long_tags = {
|
const std::vector<LongTag> long_tags = {
|
||||||
{TIFFTAG_SUBFILETYPE, 1,
|
{TIFFTAG_SUBFILETYPE, 1,
|
||||||
FILETYPE_REDUCEDIMAGE | FILETYPE_PAGE | FILETYPE_MASK}};
|
FILETYPE_REDUCEDIMAGE | FILETYPE_PAGE | FILETYPE_MASK}};
|
||||||
#define SPP 3 // kSamplePerPixel
|
#define SPP 3 // kSamplePerPixel
|
||||||
|
@ -132,4 +132,4 @@ TEST(SandboxTest, LongTag) {
|
||||||
|
|
||||||
ASSERT_THAT(api.TIFFClose(&tif2), IsOk()) << "TIFFClose fatal error";
|
ASSERT_THAT(api.TIFFClose(&tif2), IsOk()) << "TIFFClose fatal error";
|
||||||
unlink(srcfile.c_str());
|
unlink(srcfile.c_str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,9 +32,9 @@ static const std::vector<unsigned char> cluster_0 = {0, 0, 2, 0, 138, 139};
|
||||||
static const std::vector<unsigned char> cluster_64 = {0, 0, 9, 6, 134, 119};
|
static const std::vector<unsigned char> cluster_64 = {0, 0, 9, 6, 134, 119};
|
||||||
static const std::vector<unsigned char> cluster_128 = {44, 40, 63, 59, 230, 95};
|
static const std::vector<unsigned char> cluster_128 = {44, 40, 63, 59, 230, 95};
|
||||||
|
|
||||||
static int check_cluster(int cluster,
|
static int CheckCluster(int cluster,
|
||||||
const sapi::v::Array<unsigned char> &buffer,
|
const sapi::v::Array<unsigned char> &buffer,
|
||||||
const std::vector<unsigned char> &expected_cluster) {
|
const std::vector<unsigned char> &expected_cluster) {
|
||||||
unsigned char *target = buffer.GetData() + cluster * 6;
|
unsigned char *target = buffer.GetData() + cluster * 6;
|
||||||
|
|
||||||
bool comp = !(std::memcmp(target, expected_cluster.data(), 6) == 0);
|
bool comp = !(std::memcmp(target, expected_cluster.data(), 6) == 0);
|
||||||
|
@ -50,9 +50,9 @@ static int check_cluster(int cluster,
|
||||||
return comp;
|
return comp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int check_rgb_pixel(int pixel, int min_red, int max_red, int min_green,
|
static int 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<unsigned char> &buffer) {
|
const sapi::v::Array<unsigned char> &buffer) {
|
||||||
unsigned char *rgb = buffer.GetData() + 3 * pixel;
|
unsigned char *rgb = buffer.GetData() + 3 * pixel;
|
||||||
|
|
||||||
bool comp =
|
bool comp =
|
||||||
|
@ -68,10 +68,10 @@ static int check_rgb_pixel(int pixel, int min_red, int max_red, int min_green,
|
||||||
return comp;
|
return comp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int check_rgba_pixel(int pixel, int min_red, int max_red, int min_green,
|
static int CheckRgbaPixel(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,
|
||||||
int min_alpha, int max_alpha,
|
int min_alpha, int max_alpha,
|
||||||
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;
|
||||||
unsigned rgba = buffer[adjusted_pixel];
|
unsigned rgba = buffer[adjusted_pixel];
|
||||||
|
@ -140,9 +140,9 @@ TEST(SandboxTest, RawDecode) {
|
||||||
<< "Did not get expected result code from TIFFReadEncodedTile()("
|
<< "Did not get expected result code from TIFFReadEncodedTile()("
|
||||||
<< (int)status_or_long.value() << " instead of " << (int)sz << ")";
|
<< (int)status_or_long.value() << " instead of " << (int)sz << ")";
|
||||||
|
|
||||||
ASSERT_FALSE(check_cluster(0, buffer_, cluster_0) ||
|
ASSERT_FALSE(CheckCluster(0, buffer_, cluster_0) ||
|
||||||
check_cluster(64, buffer_, cluster_64) ||
|
CheckCluster(64, buffer_, cluster_64) ||
|
||||||
check_cluster(128, buffer_, cluster_128))
|
CheckCluster(128, buffer_, cluster_128))
|
||||||
<< "Clusters did not match expected results";
|
<< "Clusters did not match expected results";
|
||||||
|
|
||||||
status_or_int =
|
status_or_int =
|
||||||
|
@ -164,9 +164,9 @@ TEST(SandboxTest, RawDecode) {
|
||||||
<< "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;
|
||||||
|
|
||||||
pixel_status |= check_rgb_pixel(0, 15, 18, 0, 0, 18, 41, buffer2_);
|
pixel_status |= CheckRgbPixel(0, 15, 18, 0, 0, 18, 41, buffer2_);
|
||||||
pixel_status |= check_rgb_pixel(64, 0, 0, 0, 0, 0, 2, buffer2_);
|
pixel_status |= CheckRgbPixel(64, 0, 0, 0, 0, 0, 2, buffer2_);
|
||||||
pixel_status |= check_rgb_pixel(512, 5, 6, 34, 36, 182, 196, buffer2_);
|
pixel_status |= CheckRgbPixel(512, 5, 6, 34, 36, 182, 196, buffer2_);
|
||||||
|
|
||||||
ASSERT_THAT(api.TIFFClose(&tif), IsOk()) << "TIFFClose fatal error";
|
ASSERT_THAT(api.TIFFClose(&tif), IsOk()) << "TIFFClose fatal error";
|
||||||
|
|
||||||
|
@ -186,11 +186,10 @@ TEST(SandboxTest, RawDecode) {
|
||||||
<< "TIFFReadRGBATile() returned failure code";
|
<< "TIFFReadRGBATile() returned failure code";
|
||||||
|
|
||||||
pixel_status |=
|
pixel_status |=
|
||||||
check_rgba_pixel(0, 15, 18, 0, 0, 18, 41, 255, 255, rgba_buffer_);
|
CheckRgbaPixel(0, 15, 18, 0, 0, 18, 41, 255, 255, rgba_buffer_);
|
||||||
|
pixel_status |= CheckRgbaPixel(64, 0, 0, 0, 0, 0, 2, 255, 255, rgba_buffer_);
|
||||||
pixel_status |=
|
pixel_status |=
|
||||||
check_rgba_pixel(64, 0, 0, 0, 0, 0, 2, 255, 255, rgba_buffer_);
|
CheckRgbaPixel(512, 5, 6, 34, 36, 182, 196, 255, 255, rgba_buffer_);
|
||||||
pixel_status |=
|
|
||||||
check_rgba_pixel(512, 5, 6, 34, 36, 182, 196, 255, 255, rgba_buffer_);
|
|
||||||
|
|
||||||
EXPECT_THAT(api.TIFFClose(&tif2), IsOk()) << "TIFFClose fatal error";
|
EXPECT_THAT(api.TIFFClose(&tif2), IsOk()) << "TIFFClose fatal error";
|
||||||
|
|
||||||
|
|
|
@ -34,17 +34,17 @@ static const unsigned short kPhotometric = PHOTOMETRIC_RGB;
|
||||||
static const unsigned short kRowsPerStrip = 1;
|
static const unsigned short kRowsPerStrip = 1;
|
||||||
static const unsigned short kPlanarConfig = PLANARCONFIG_CONTIG;
|
static const unsigned short kPlanarConfig = PLANARCONFIG_CONTIG;
|
||||||
|
|
||||||
struct single_tag {
|
struct SingleTag {
|
||||||
const ttag_t tag;
|
const ttag_t tag;
|
||||||
const unsigned short value;
|
const unsigned short value;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct paired_tag {
|
struct PairedTag {
|
||||||
const ttag_t tag;
|
const ttag_t tag;
|
||||||
const std::array<unsigned short, 2> values;
|
const std::array<unsigned short, 2> values;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const std::vector<single_tag> short_single_tags = {
|
static const std::vector<SingleTag> short_single_tags = {
|
||||||
{TIFFTAG_COMPRESSION, COMPRESSION_NONE},
|
{TIFFTAG_COMPRESSION, COMPRESSION_NONE},
|
||||||
{TIFFTAG_FILLORDER, FILLORDER_MSB2LSB},
|
{TIFFTAG_FILLORDER, FILLORDER_MSB2LSB},
|
||||||
{TIFFTAG_ORIENTATION, ORIENTATION_BOTRIGHT},
|
{TIFFTAG_ORIENTATION, ORIENTATION_BOTRIGHT},
|
||||||
|
@ -55,7 +55,7 @@ static const std::vector<single_tag> short_single_tags = {
|
||||||
{TIFFTAG_NUMBEROFINKS, SPP},
|
{TIFFTAG_NUMBEROFINKS, SPP},
|
||||||
{TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT}};
|
{TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT}};
|
||||||
|
|
||||||
static const std::vector<paired_tag> short_paired_tags = {
|
static const std::vector<PairedTag> short_paired_tags = {
|
||||||
{TIFFTAG_PAGENUMBER, {1, 1}},
|
{TIFFTAG_PAGENUMBER, {1, 1}},
|
||||||
{TIFFTAG_HALFTONEHINTS, {0, 255}},
|
{TIFFTAG_HALFTONEHINTS, {0, 255}},
|
||||||
{TIFFTAG_DOTRANGE, {8, 16}},
|
{TIFFTAG_DOTRANGE, {8, 16}},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user