diff --git a/tests/gtest/avif_fuzztest_properties.cc b/tests/gtest/avif_fuzztest_properties.cc index 1a98d7acc3..ff5d45ace0 100644 --- a/tests/gtest/avif_fuzztest_properties.cc +++ b/tests/gtest/avif_fuzztest_properties.cc @@ -25,24 +25,35 @@ struct TestProp { }; void EncodeDecode(ImagePtr image, EncoderPtr encoder, DecoderPtr decoder, - const std::vector& testProps) { + const std::vector& test_props) { ImagePtr decoded_image(avifImageCreateEmpty()); ASSERT_NE(image.get(), nullptr); ASSERT_NE(encoder.get(), nullptr); ASSERT_NE(decoder.get(), nullptr); ASSERT_NE(decoded_image.get(), nullptr); - for (const TestProp& testProp : testProps) { + std::vector valid_test_properties; + for (const TestProp& testProp : test_props) { if (testProp.fourcc == std::array{'u', 'u', 'i', 'd'}) { - ASSERT_EQ( + const avifResult result = avifImageAddUUIDProperty(image.get(), testProp.uuid.data(), - testProp.body.data(), testProp.body.size()), - AVIF_RESULT_OK); + testProp.body.data(), testProp.body.size()); + if (avifIsValidUUID(testProp.uuid.data())) { + valid_test_properties.push_back(testProp); + ASSERT_EQ(result, AVIF_RESULT_OK); + } else { + ASSERT_EQ(result, AVIF_RESULT_INVALID_ARGUMENT); + } } else { - ASSERT_EQ(avifImageAddOpaqueProperty(image.get(), testProp.fourcc.data(), - testProp.body.data(), - testProp.body.size()), - AVIF_RESULT_OK); + const avifResult result = avifImageAddOpaqueProperty( + image.get(), testProp.fourcc.data(), testProp.body.data(), + testProp.body.size()); + if (avifIsKnownPropertyType(testProp.fourcc.data())) { + ASSERT_EQ(result, AVIF_RESULT_INVALID_ARGUMENT); + } else { + valid_test_properties.push_back(testProp); + ASSERT_EQ(result, AVIF_RESULT_OK); + } } } @@ -57,9 +68,9 @@ void EncodeDecode(ImagePtr image, EncoderPtr encoder, DecoderPtr decoder, ASSERT_EQ(decoder_result, AVIF_RESULT_OK) << avifResultToString(decoder_result); - ASSERT_EQ(decoder->image->numProperties, testProps.size()); - for (size_t i = 0; i < testProps.size(); i++) { - const TestProp& testProp = testProps[i]; + ASSERT_EQ(decoder->image->numProperties, valid_test_properties.size()); + for (size_t i = 0; i < valid_test_properties.size(); i++) { + const TestProp& testProp = valid_test_properties[i]; const avifImageItemProperty& decodeProp = decoder->image->properties[i]; EXPECT_EQ(std::string(decodeProp.boxtype, decodeProp.boxtype + 4), std::string(testProp.fourcc.data(), testProp.fourcc.data() + 4)); @@ -74,22 +85,14 @@ inline auto ArbitraryProp() { auto fourcc = fuzztest::Arbitrary>(); auto uuid = fuzztest::Arbitrary>(); // ignored auto body = fuzztest::Arbitrary>(); - // Don't return known properties. - return fuzztest::Filter( - [](const TestProp& prop) { - return !avifIsKnownPropertyType(prop.fourcc.data()); - }, - fuzztest::StructOf(fourcc, uuid, body)); + return fuzztest::StructOf(fourcc, uuid, body); } inline auto ArbitraryUUIDProp() { auto fourcc = fuzztest::Just(std::array{'u', 'u', 'i', 'd'}); auto uuid = fuzztest::Arbitrary>(); auto body = fuzztest::Arbitrary>(); - // Don't use invalid UUIDs. - return fuzztest::Filter( - [](const TestProp& prop) { return avifIsValidUUID(prop.uuid.data()); }, - fuzztest::StructOf(fourcc, uuid, body)); + return fuzztest::StructOf(fourcc, uuid, body); } inline auto ArbitraryProps() {