blob: ef637f4738b74324447cfdfc6a38dfea746da42a [file] [log] [blame]
halcanary@google.com44287342013-12-13 18:29:51 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "SkBitmap.h"
9
10#include "Test.h"
11#include "TestClassDef.h"
12
reed@google.com48569642013-12-30 19:21:22 +000013static void test_bigwidth(skiatest::Reporter* reporter) {
14 SkBitmap bm;
15 int width = 1 << 29; // *4 will be the high-bit of 32bit int
16
17 REPORTER_ASSERT(reporter, bm.setConfig(SkBitmap::kA8_Config, width, 1));
18 REPORTER_ASSERT(reporter, bm.setConfig(SkBitmap::kRGB_565_Config, width, 1));
skia.committer@gmail.comf5e1f632013-12-31 07:01:36 +000019
reed@google.com48569642013-12-30 19:21:22 +000020 // for a 4-byte config, this width will compute a rowbytes of 0x80000000,
21 // which does not fit in a int32_t. setConfig should detect this, and fail.
22
23 // TODO: perhaps skia can relax this, and only require that rowBytes fit
24 // in a uint32_t (or larger), but for now this is the constraint.
25
26 REPORTER_ASSERT(reporter, !bm.setConfig(SkBitmap::kARGB_8888_Config, width, 1));
27}
28
halcanary@google.com44287342013-12-13 18:29:51 +000029/**
30 * This test contains basic sanity checks concerning bitmaps.
31 */
32DEF_TEST(Bitmap, reporter) {
33 const SkBitmap::Config conf = SkBitmap::kARGB_8888_Config;
34 // Zero-sized bitmaps are allowed
35 for (int width = 0; width < 2; ++width) {
36 for (int height = 0; height < 2; ++height) {
37 SkBitmap bm;
38 bool setConf = bm.setConfig(conf, width, height);
39 REPORTER_ASSERT(reporter, setConf);
40 if (setConf) {
41 REPORTER_ASSERT(reporter, bm.allocPixels(NULL));
42 }
halcanary@google.com2af6c122013-12-13 19:25:21 +000043 REPORTER_ASSERT(reporter, SkToBool(width & height) != bm.empty());
halcanary@google.com44287342013-12-13 18:29:51 +000044 }
45 }
skia.committer@gmail.comf5e1f632013-12-31 07:01:36 +000046
reed@google.com48569642013-12-30 19:21:22 +000047 test_bigwidth(reporter);
halcanary@google.com44287342013-12-13 18:29:51 +000048}