Skip to content

Commit

Permalink
Address minor review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
maryla-uc committed Feb 11, 2025
1 parent 3ee07da commit 5771c38
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 73 deletions.
4 changes: 2 additions & 2 deletions tests/gtest/avif_fuzztest_enc_dec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ void EncodeDecodeValid(ImagePtr image, EncoderPtr encoder, DecoderPtr decoder) {
const avifResult encoder_result =
avifEncoderWrite(encoder.get(), image.get(), &encoded_data);
ASSERT_EQ(encoder_result, AVIF_RESULT_OK)
<< avifResultToString(encoder_result) << " " << encoder->diag.error;
<< avifResultToString(encoder_result) << ": " << encoder->diag.error;

const avifResult decoder_result = avifDecoderReadMemory(
decoder.get(), decoded_image.get(), encoded_data.data, encoded_data.size);
ASSERT_EQ(decoder_result, AVIF_RESULT_OK)
<< avifResultToString(decoder_result) << " " << decoder->diag.error;
<< avifResultToString(decoder_result) << ": " << decoder->diag.error;

EXPECT_EQ(decoded_image->width, image->width);
EXPECT_EQ(decoded_image->height, image->height);
Expand Down
10 changes: 5 additions & 5 deletions tests/gtest/avif_fuzztest_enc_dec_anim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ void EncodeDecodeAnimation(std::vector<ImagePtr> frames,
avifEncoderAddImage(encoder.get(), frames[i].get(),
frame_options[i].duration, frame_options[i].flags);
ASSERT_EQ(result, AVIF_RESULT_OK)
<< avifResultToString(result) << " " << encoder->diag.error;
<< avifResultToString(result) << ": " << encoder->diag.error;
}
AvifRwData encoded_data;
avifResult result = avifEncoderFinish(encoder.get(), &encoded_data);
ASSERT_EQ(result, AVIF_RESULT_OK)
<< avifResultToString(result) << " " << encoder->diag.error;
<< avifResultToString(result) << ": " << encoder->diag.error;

// Decode.
result = avifDecoderSetIOMemory(decoder.get(), encoded_data.data,
encoded_data.size);
ASSERT_EQ(result, AVIF_RESULT_OK)
<< avifResultToString(result) << " " << decoder->diag.error;
<< avifResultToString(result) << ": " << decoder->diag.error;

result = avifDecoderParse(decoder.get());
ASSERT_EQ(result, AVIF_RESULT_OK)
<< avifResultToString(result) << " " << decoder->diag.error;
<< avifResultToString(result) << ": " << decoder->diag.error;

if (decoder->requestedSource == AVIF_DECODER_SOURCE_PRIMARY_ITEM ||
num_frames == 1) {
Expand All @@ -76,7 +76,7 @@ void EncodeDecodeAnimation(std::vector<ImagePtr> frames,
}
result = avifDecoderNextImage(decoder.get());
ASSERT_EQ(result, AVIF_RESULT_NO_IMAGES_REMAINING)
<< avifResultToString(result) << " " << decoder->diag.error;
<< avifResultToString(result) << ": " << decoder->diag.error;
}
}

Expand Down
61 changes: 32 additions & 29 deletions tests/gtest/avif_fuzztest_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,24 +168,23 @@ inline auto ArbitraryAvifAnim() {
return fuzztest::OneOf(ArbitraryAvifAnim8b(), ArbitraryAvifAnim16b());
}

// Generates two signed fractions where the first one is smaller than the second
// one.
// Generates two signed fractions where the first one is smaller than or equal
// to the second one.
inline auto ArbitraryMinMaxSignedFraction() {
return fuzztest::FlatMap(
[](int32_t max_n, uint32_t max_d) {
return fuzztest::Map(
[max_n, max_d](int32_t min_n) {
// For simplicity, use the same denominator for both fractions.
// This does not cover all possible fractions but makes it easy
// to gurantee that the fraction is smaller.
// to guarantee that the first fraction is smaller.
return std::pair<avifSignedFraction, avifSignedFraction>(
{min_n, max_d}, {max_n, max_d});
},
fuzztest::InRange<int32_t>(std::numeric_limits<int32_t>::min(),
max_n));
},
fuzztest::Arbitrary<int32_t>(),
fuzztest::InRange<uint32_t>(1, std::numeric_limits<uint32_t>::max()));
fuzztest::Arbitrary<int32_t>(), fuzztest::NonZero<uint32_t>());
}

ImagePtr AddGainMapToImage(
Expand All @@ -207,30 +206,34 @@ ImagePtr AddGainMapToImage(

inline auto ArbitraryAvifImageWithGainMap() {
return fuzztest::Map(
AddGainMapToImage, ArbitraryAvifImage(), ArbitraryAvifImage(),
ArbitraryMinMaxSignedFraction(), ArbitraryMinMaxSignedFraction(),
ArbitraryMinMaxSignedFraction(),
fuzztest::InRange<uint32_t>(1, std::numeric_limits<uint32_t>::max()),
fuzztest::InRange<uint32_t>(1, std::numeric_limits<uint32_t>::max()),
fuzztest::InRange<uint32_t>(1, std::numeric_limits<uint32_t>::max()),
fuzztest::InRange<uint32_t>(1, std::numeric_limits<uint32_t>::max()),
fuzztest::InRange<uint32_t>(1, std::numeric_limits<uint32_t>::max()),
fuzztest::InRange<uint32_t>(1, std::numeric_limits<uint32_t>::max()),
fuzztest::Arbitrary<int32_t>(), fuzztest::Arbitrary<int32_t>(),
fuzztest::Arbitrary<int32_t>(),
fuzztest::InRange<uint32_t>(1, std::numeric_limits<uint32_t>::max()),
fuzztest::InRange<uint32_t>(1, std::numeric_limits<uint32_t>::max()),
fuzztest::InRange<uint32_t>(1, std::numeric_limits<uint32_t>::max()),
fuzztest::Arbitrary<int32_t>(), fuzztest::Arbitrary<int32_t>(),
fuzztest::Arbitrary<int32_t>(),
fuzztest::InRange<uint32_t>(1, std::numeric_limits<uint32_t>::max()),
fuzztest::InRange<uint32_t>(1, std::numeric_limits<uint32_t>::max()),
fuzztest::InRange<uint32_t>(1, std::numeric_limits<uint32_t>::max()),
fuzztest::Arbitrary<uint32_t>(),
fuzztest::InRange<uint32_t>(1, std::numeric_limits<uint32_t>::max()),
fuzztest::Arbitrary<uint32_t>(),
fuzztest::InRange<uint32_t>(1, std::numeric_limits<uint32_t>::max()),
fuzztest::Arbitrary<bool>());
AddGainMapToImage, ArbitraryAvifImage(),
/*gain_map=*/ArbitraryAvifImage(),
/*gain_map_min_max0=*/ArbitraryMinMaxSignedFraction(),
/*gain_map_min_max1=*/ArbitraryMinMaxSignedFraction(),
/*gain_map_min_max2=*/ArbitraryMinMaxSignedFraction(),
/*gain_map_gamma_n0=*/fuzztest::NonZero<uint32_t>(),
/*gain_map_gamma_n1=*/fuzztest::NonZero<uint32_t>(),
/*gain_map_gamma_n2=*/fuzztest::NonZero<uint32_t>(),
/*gain_map_gamma_d0=*/fuzztest::NonZero<uint32_t>(),
/*gain_map_gamma_d1=*/fuzztest::NonZero<uint32_t>(),
/*gain_map_gamma_d2=*/fuzztest::NonZero<uint32_t>(),
/*base_offset_n0=*/fuzztest::Arbitrary<int32_t>(),
/*base_offset_n1=*/fuzztest::Arbitrary<int32_t>(),
/*base_offset_n2=*/fuzztest::Arbitrary<int32_t>(),
/*base_offset_d0=*/fuzztest::NonZero<uint32_t>(),
/*base_offset_d1=*/fuzztest::NonZero<uint32_t>(),
/*base_offset_d2=*/fuzztest::NonZero<uint32_t>(),
/*alternate_offset_n0=*/fuzztest::Arbitrary<int32_t>(),
/*alternate_offset_n1=*/fuzztest::Arbitrary<int32_t>(),
/*alternate_offset_n2=*/fuzztest::Arbitrary<int32_t>(),
/*alternate_offset_d0=*/fuzztest::NonZero<uint32_t>(),
/*alternate_offset_d1=*/fuzztest::NonZero<uint32_t>(),
/*alternate_offset_d2=*/fuzztest::NonZero<uint32_t>(),
/*base_hdr_headroom_n=*/fuzztest::Arbitrary<uint32_t>(),
/*base_hdr_headroom_d=*/fuzztest::NonZero<uint32_t>(),
/*alternate_hdr_headroom_n=*/fuzztest::Arbitrary<uint32_t>(),
/*alternate_hdr_headroom_d=*/fuzztest::NonZero<uint32_t>(),
/*use_base_color_space=*/fuzztest::Arbitrary<bool>());
}

// Generator for an arbitrary EncoderPtr.
Expand Down
Loading

0 comments on commit 5771c38

Please sign in to comment.