File: image_decoder_base_test.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (83 lines) | stat: -rw-r--r-- 3,044 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_IMAGE_DECODERS_IMAGE_DECODER_BASE_TEST_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_IMAGE_DECODERS_IMAGE_DECODER_BASE_TEST_H_

#include <stdint.h>

#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/platform/image-decoders/image_decoder.h"

namespace blink {

// Decodes a handful of image files and compares their MD5 sums to the stored
// sums on disk.  To recalculate the MD5 sums, uncomment the CALCULATE_MD5_SUMS
// #define in the .cc file.
//
// The image files and corresponding MD5 sums live in the directory
// webkit/data/*_decoder (where "*" is the format being tested).
//
// Note: The MD5 sums calculated in this test by little- and big-endian systems
// will differ, since no endianness correction is done.  If we start compiling
// for big endian machines this should be fixed.

class ImageDecoderBaseTest : public testing::Test {
 public:
  explicit ImageDecoderBaseTest(const String& format) : format_(format) {}
  ImageDecoderBaseTest(const ImageDecoderBaseTest&) = delete;
  ImageDecoderBaseTest& operator=(const ImageDecoderBaseTest&) = delete;

  enum class FileSelection {
    kAll,
    kSmaller,
    kBigger,
  };

 protected:
  void SetUp() override;

  // Returns the path the decoded data is saved at.
  base::FilePath GetMD5SumPath(const base::FilePath& path);

  // Returns the vector of image files for testing.
  Vector<base::FilePath> GetImageFiles() const;

  // Returns true if the image is bogus and should not be successfully decoded.
  bool ShouldImageFail(const base::FilePath& path) const;

  // Tests if decoder decodes image at image_path with underlying frame at
  // index desired_frame_index. The md5_sum_path is needed if the test is not
  // asked to generate one, i.e. if #define CALCULATE_MD5_SUMS is not set.
  void TestImageDecoder(const base::FilePath& image_path,
                        const base::FilePath& md5_sum_path,
                        int desired_frame_index) const;

  // Verifies each of the test image files is decoded correctly and matches the
  // expected state. |file_selection| and |threshold| can be used to select
  // files to test based on file size.
  // If just the MD5 sum is wanted, this skips chunking.
  void TestDecoding(FileSelection file_selection, const int64_t threshold);

  void TestDecoding() { TestDecoding(FileSelection::kAll, 0); }

  // Creates decoder.
  virtual std::unique_ptr<ImageDecoder> CreateImageDecoder() const = 0;

  // The format to be decoded, like "bmp" or "ico".
  String format_;

 protected:
  const base::FilePath& data_dir() const { return data_dir_; }

 private:
  // Path to the test files.
  base::FilePath data_dir_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_IMAGE_DECODERS_IMAGE_DECODER_BASE_TEST_H_