File: BMPImageDecoderTest.cpp

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (89 lines) | stat: -rw-r--r-- 3,135 bytes parent folder | download
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
84
85
86
87
88
89
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "platform/image-decoders/bmp/BMPImageDecoder.h"

#include "platform/SharedBuffer.h"
#include "platform/image-decoders/ImageDecoderTestHelpers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "wtf/PtrUtil.h"
#include <memory>

namespace blink {

namespace {

std::unique_ptr<ImageDecoder> createDecoder() {
  return WTF::wrapUnique(
      new BMPImageDecoder(ImageDecoder::AlphaNotPremultiplied,
                          ColorBehavior::transformToTargetForTesting(),
                          ImageDecoder::noDecodedImageByteLimit));
}

}  // anonymous namespace

TEST(BMPImageDecoderTest, isSizeAvailable) {
  const char* bmpFile = "/LayoutTests/images/resources/lenna.bmp";  // 256x256
  RefPtr<SharedBuffer> data = readFile(bmpFile);
  ASSERT_TRUE(data.get());

  std::unique_ptr<ImageDecoder> decoder = createDecoder();
  decoder->setData(data.get(), true);
  EXPECT_TRUE(decoder->isSizeAvailable());
  EXPECT_EQ(256, decoder->size().width());
  EXPECT_EQ(256, decoder->size().height());
}

TEST(BMPImageDecoderTest, parseAndDecode) {
  const char* bmpFile = "/LayoutTests/images/resources/lenna.bmp";  // 256x256
  RefPtr<SharedBuffer> data = readFile(bmpFile);
  ASSERT_TRUE(data.get());

  std::unique_ptr<ImageDecoder> decoder = createDecoder();
  decoder->setData(data.get(), true);

  ImageFrame* frame = decoder->frameBufferAtIndex(0);
  ASSERT_TRUE(frame);
  EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus());
  EXPECT_EQ(256, frame->bitmap().width());
  EXPECT_EQ(256, frame->bitmap().height());
  EXPECT_FALSE(decoder->failed());
}

// Test if a BMP decoder returns a proper error while decoding an empty image.
TEST(BMPImageDecoderTest, emptyImage) {
  const char* bmpFile = "/LayoutTests/images/resources/0x0.bmp";  // 0x0
  RefPtr<SharedBuffer> data = readFile(bmpFile);
  ASSERT_TRUE(data.get());

  std::unique_ptr<ImageDecoder> decoder = createDecoder();
  decoder->setData(data.get(), true);

  ImageFrame* frame = decoder->frameBufferAtIndex(0);
  ASSERT_TRUE(frame);
  EXPECT_EQ(ImageFrame::FrameEmpty, frame->getStatus());
  EXPECT_TRUE(decoder->failed());
}

TEST(BMPImageDecoderTest, int32MinHeight) {
  const char* bmpFile =
      "/LayoutTests/images/resources/1xint32_min.bmp";  // 0xINT32_MIN
  RefPtr<SharedBuffer> data = readFile(bmpFile);
  std::unique_ptr<ImageDecoder> decoder = createDecoder();
  // Test when not all data is received.
  decoder->setData(data.get(), false);
  EXPECT_FALSE(decoder->isSizeAvailable());
  EXPECT_TRUE(decoder->failed());
}

// This test verifies that calling SharedBuffer::mergeSegmentsIntoBuffer() does
// not break BMP decoding at a critical point: in between a call to decode the
// size (when BMPImageDecoder stops while it may still have input data to
// read) and a call to do a full decode.
TEST(BMPImageDecoderTest, mergeBuffer) {
  const char* bmpFile = "/LayoutTests/images/resources/lenna.bmp";
  testMergeBuffer(&createDecoder, bmpFile);
}

}  // namespace blink