Skip to content

Commit

Permalink
Update some image tests to no longer expect exact encoded sequences
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 671068432
Change-Id: If927c1342512044a7a75f997a1a5e8d5a9de9df2
  • Loading branch information
laramiel authored and copybara-github committed Sep 4, 2024
1 parent ee6ec78 commit 62b6624
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 45 deletions.
1 change: 1 addition & 0 deletions tensorstore/driver/image/avif/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ tensorstore_cc_library(
"//tensorstore/driver/image:driver_impl",
"//tensorstore/internal:data_copy_concurrency_resource",
"//tensorstore/internal/cache:cache_pool_resource",
"//tensorstore/internal/image",
"//tensorstore/internal/image:avif",
"//tensorstore/internal/json_binding",
"//tensorstore/util:result",
Expand Down
2 changes: 2 additions & 0 deletions tensorstore/driver/image/avif/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <stddef.h>

#include <array>
#include <cstdint>

#include "absl/status/status.h"
#include "absl/strings/cord.h"
Expand All @@ -27,6 +28,7 @@
#include "tensorstore/index.h"
#include "tensorstore/internal/image/avif_reader.h"
#include "tensorstore/internal/image/avif_writer.h"
#include "tensorstore/internal/image/image_info.h"
#include "tensorstore/internal/json_binding/json_binding.h"
#include "tensorstore/util/result.h"
#include "tensorstore/util/span.h"
Expand Down
2 changes: 2 additions & 0 deletions tensorstore/internal/container/compressed_tuple_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ TEST(CompressedTupleTest, OneMoveOnRValueAccess) {
CopyableMovableInstance i2 = std::move(x).get<0>();
EXPECT_EQ(CopyableMovableInstance::num_copies, 0);
EXPECT_EQ(CopyableMovableInstance::num_moves, 1);
EXPECT_EQ(i2.value(), 1);
}

TEST(CompressedTupleTest, OneCopyOnLValueAccess) {
Expand All @@ -244,6 +245,7 @@ TEST(CompressedTupleTest, OneCopyOnLValueAccess) {
CopyableMovableInstance t = x.get<0>();
EXPECT_EQ(CopyableMovableInstance::num_copies, 1);
EXPECT_EQ(CopyableMovableInstance::num_moves, 1);
EXPECT_EQ(t.value(), 0);
}

TEST(CompressedTupleTest, ZeroCopyOnRefAccess) {
Expand Down
5 changes: 3 additions & 2 deletions tensorstore/internal/image/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ tensorstore_cc_test(
name = "jpeg_test",
srcs = ["jpeg_test.cc"],
deps = [
":image",
":jpeg",
"//tensorstore/util:result",
"//tensorstore/util:span",
"//tensorstore/util:status_testutil",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings:cord",
"@com_google_googletest//:gtest_main",
"@com_google_riegeli//riegeli/bytes:cord_reader",
Expand Down Expand Up @@ -215,12 +216,12 @@ tensorstore_cc_test(
deps = [
":image",
":tiff",
"//tensorstore:data_type",
"//tensorstore/internal:path",
"//tensorstore/util:span",
"//tensorstore/util:status_testutil",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings:cord",
"@com_google_googletest//:gtest_main",
"@com_google_riegeli//riegeli/bytes:cord_reader",
"@com_google_riegeli//riegeli/bytes:cord_writer",
Expand Down
43 changes: 13 additions & 30 deletions tensorstore/internal/image/avif_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include <stdint.h>

#include <string_view>
#include <vector>

#include <gmock/gmock.h>
#include <gtest/gtest.h>
Expand Down Expand Up @@ -87,35 +86,18 @@ TEST(AvifTest, Decode) {
}

TEST(AvifTest, EncodeDecode) {
static constexpr unsigned char raw[] = {
0x00, 0x00, 0x00, 0x1c, 0x66, 0x74, 0x79, 0x70, 0x61, 0x76, 0x69, 0x66,
0x00, 0x00, 0x00, 0x00, 0x61, 0x76, 0x69, 0x66, 0x6d, 0x69, 0x66, 0x31,
0x6d, 0x69, 0x61, 0x66, 0x00, 0x00, 0x00, 0xf0, 0x6d, 0x65, 0x74, 0x61,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x68, 0x64, 0x6c, 0x72,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x69, 0x63, 0x74,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x6c, 0x69, 0x62, 0x61, 0x76, 0x69, 0x66, 0x00, 0x00, 0x00, 0x00, 0x0e,
0x70, 0x69, 0x74, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x1e, 0x69, 0x6c, 0x6f, 0x63, 0x00, 0x00, 0x00, 0x00, 0x44, 0x00,
0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x14,
0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x28, 0x69, 0x69, 0x6e, 0x66,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1a, 0x69, 0x6e,
0x66, 0x65, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x61, 0x76,
0x30, 0x31, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x00, 0x00, 0x00, 0x68,
0x69, 0x70, 0x72, 0x70, 0x00, 0x00, 0x00, 0x49, 0x69, 0x70, 0x63, 0x6f,
0x00, 0x00, 0x00, 0x14, 0x69, 0x73, 0x70, 0x65, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0e,
0x70, 0x69, 0x78, 0x69, 0x00, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00,
0x00, 0x0c, 0x61, 0x76, 0x31, 0x43, 0x81, 0x00, 0x1c, 0x00, 0x00, 0x00,
0x00, 0x13, 0x63, 0x6f, 0x6c, 0x72, 0x6e, 0x63, 0x6c, 0x78, 0x00, 0x02,
0x00, 0x02, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x17, 0x69, 0x70, 0x6d,
0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x04,
0x01, 0x02, 0x83, 0x04, 0x00, 0x00, 0x00, 0x1d, 0x6d, 0x64, 0x61, 0x74,
0x12, 0x00, 0x0a, 0x07, 0x18, 0x00, 0x06, 0x18, 0x10, 0x10, 0x05, 0x32,
0x08, 0x10, 0x00, 0x00, 0x18, 0xe1, 0x42, 0x72, 0x10,
// https://aomediacodec.github.io/av1-avif/#baseline-profile
// The baseline profile for avif uses ftype=avif and
// compatible_brands avif,mif1,miaf.
// clang-format off
static constexpr const char prefix[] = {
0x0, 0x0, 0x0, 0x1c, 'f', 't', 'y', 'p', 'a', 'v', 'i', 'f',
0x0, 0x0, 0x0, 0x0, 'a', 'v', 'i', 'f', 'm', 'i', 'f', '1',
'm', 'i', 'a', 'f',
};
// clang-format on

uint8_t pixels[1] = {};
uint8_t pixels[1] = {42};

absl::Cord encoded;
{
Expand All @@ -128,8 +110,8 @@ TEST(AvifTest, EncodeDecode) {
ASSERT_THAT(encoder.Done(), ::tensorstore::IsOk());
}

EXPECT_THAT(encoded, ::testing::StrEq(std::string_view(
reinterpret_cast<const char*>(raw), sizeof(raw))));
EXPECT_THAT(encoded.Flatten(),
::testing::StartsWith(std::string_view(prefix, sizeof(prefix))));

{
AvifReader decoder;
Expand All @@ -141,6 +123,7 @@ TEST(AvifTest, EncodeDecode) {

uint8_t new_pixels[1] = {};
ASSERT_THAT(decoder.Decode(new_pixels), tensorstore::IsOk());
EXPECT_NEAR(new_pixels[0], pixels[0], 4);
}
}

Expand Down
5 changes: 3 additions & 2 deletions tensorstore/internal/image/jpeg_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@

#include <stddef.h>

#include <cmath>
#include <cstdint>
#include <vector>

#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "absl/status/status.h"
#include "absl/strings/cord.h"
#include "riegeli/bytes/cord_reader.h"
#include "riegeli/bytes/cord_writer.h"
#include "riegeli/bytes/string_reader.h"
#include "tensorstore/internal/image/image_info.h"
#include "tensorstore/internal/image/jpeg_reader.h"
#include "tensorstore/internal/image/jpeg_writer.h"
#include "tensorstore/util/result.h"
#include "tensorstore/util/span.h"
#include "tensorstore/util/status_testutil.h"

Expand Down
2 changes: 0 additions & 2 deletions tensorstore/internal/image/png_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

#include <stdint.h>

#include <string_view>

#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "absl/status/status.h"
Expand Down
2 changes: 1 addition & 1 deletion tensorstore/internal/image/tiff_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
#include <gtest/gtest.h>
#include "absl/flags/flag.h"
#include "absl/status/status.h"
#include "absl/strings/cord.h"
#include "riegeli/bytes/cord_reader.h"
#include "riegeli/bytes/cord_writer.h"
#include "riegeli/bytes/fd_reader.h"
#include "riegeli/bytes/read_all.h"
#include "riegeli/bytes/string_reader.h"
#include "tensorstore/data_type.h"
#include "tensorstore/internal/image/image_info.h"
#include "tensorstore/internal/image/tiff_reader.h"
#include "tensorstore/internal/image/tiff_writer.h"
Expand Down
13 changes: 5 additions & 8 deletions tensorstore/internal/image/webp_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include <stdint.h>

#include <string_view>
#include <vector>

#include <gmock/gmock.h>
#include <gtest/gtest.h>
Expand Down Expand Up @@ -64,11 +63,9 @@ TEST(WebPTest, Decode) {
}

TEST(WebPTest, EncodeDecode) {
static constexpr unsigned char raw[] = {
0x52, 0x49, 0x46, 0x46, 0x20, 0x00, 0x00, 0x00, 0x57, 0x45,
0x42, 0x50, 0x56, 0x50, 0x38, 0x4c, 0x14, 0x00, 0x00, 0x00,
0x2f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x50, 0x81, 0x54, 0x08,
0x20, 0x00, 0x0a, 0x9a, 0xfe, 0xc7, 0x88, 0x88, 0xfe, 0x07,
// https://developers.google.com/speed/webp/docs/riff_container
static constexpr const char prefix[] = {
'R', 'I', 'F', 'F', 0x20, 0x00, 0x00, 0x00, 'W', 'E', 'B', 'P',
};

uint8_t pixels[3] = {1, 2, 3};
Expand All @@ -84,8 +81,8 @@ TEST(WebPTest, EncodeDecode) {
ASSERT_THAT(encoder.Done(), ::tensorstore::IsOk());
}

EXPECT_THAT(encoded, ::testing::StrEq(std::string_view(
reinterpret_cast<const char*>(raw), sizeof(raw))));
EXPECT_THAT(encoded.Flatten(),
::testing::StartsWith(std::string_view(prefix, sizeof(prefix))));

{
WebPReader decoder;
Expand Down

0 comments on commit 62b6624

Please sign in to comment.