blob: fea0f6520a4deed9865c9017fa682bf8731f69a7 [file] [edit]
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "formats/gif/assessor.h"
#include <string>
#include "absl/status/status_matchers.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "riegeli/bytes/string_reader.h"
namespace credentio {
namespace {
using ::absl_testing::IsOkAndHolds;
TEST(IsSupportedTest, FailureTooShort) {
std::string image = "test";
riegeli::StringReader<> input(image);
EXPECT_THAT(GifAssessor().IsSupported(input), IsOkAndHolds(false));
}
TEST(IsSupportedTest, FailureIncorrectHeader) {
std::string image = "this_is_not_a_gif";
riegeli::StringReader<> input(image);
EXPECT_THAT(GifAssessor().IsSupported(input), IsOkAndHolds(false));
}
TEST(IsSupportedTest, Succeeds) {
std::string image = "GIF89athis_is_a_gif";
riegeli::StringReader<> input(image);
EXPECT_THAT(GifAssessor().IsSupported(input), IsOkAndHolds(true));
}
TEST(IsSupportedTest, SucceedsAtOffset2) {
std::string image = "abGIF89athis_is_a_gif";
riegeli::StringReader<> input(image);
// Invalid at 0
EXPECT_THAT(GifAssessor().IsSupported(input), IsOkAndHolds(false));
EXPECT_EQ(input.pos(), 0);
// Valid at 2
ASSERT_TRUE(input.Seek(2));
EXPECT_THAT(GifAssessor().IsSupported(input), IsOkAndHolds(true));
EXPECT_EQ(input.pos(), 2);
}
} // namespace
} // namespace credentio