blob: ef560aa6d63290385f58ca2fab9730899d574c9f [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"
halcanary@google.com44287342013-12-13 18:29:51 +000011
reed@google.com48569642013-12-30 19:21:22 +000012static void test_bigwidth(skiatest::Reporter* reporter) {
13 SkBitmap bm;
14 int width = 1 << 29; // *4 will be the high-bit of 32bit int
15
commit-bot@chromium.orga3264e52014-05-30 13:26:10 +000016 SkImageInfo info = SkImageInfo::MakeA8(width, 1);
17 REPORTER_ASSERT(reporter, bm.setInfo(info));
commit-bot@chromium.orgfa9e5fa2014-02-13 22:00:04 +000018 info.fColorType = kRGB_565_SkColorType;
commit-bot@chromium.orga3264e52014-05-30 13:26:10 +000019 REPORTER_ASSERT(reporter, bm.setInfo(info));
skia.committer@gmail.comf5e1f632013-12-31 07:01:36 +000020
reed@google.com48569642013-12-30 19:21:22 +000021 // for a 4-byte config, this width will compute a rowbytes of 0x80000000,
22 // which does not fit in a int32_t. setConfig should detect this, and fail.
23
24 // TODO: perhaps skia can relax this, and only require that rowBytes fit
25 // in a uint32_t (or larger), but for now this is the constraint.
26
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +000027 info.fColorType = kN32_SkColorType;
commit-bot@chromium.orga3264e52014-05-30 13:26:10 +000028 REPORTER_ASSERT(reporter, !bm.setInfo(info));
reed@google.com48569642013-12-30 19:21:22 +000029}
30
halcanary@google.com44287342013-12-13 18:29:51 +000031/**
32 * This test contains basic sanity checks concerning bitmaps.
33 */
34DEF_TEST(Bitmap, reporter) {
halcanary@google.com44287342013-12-13 18:29:51 +000035 // Zero-sized bitmaps are allowed
36 for (int width = 0; width < 2; ++width) {
37 for (int height = 0; height < 2; ++height) {
38 SkBitmap bm;
commit-bot@chromium.orga3264e52014-05-30 13:26:10 +000039 bool setConf = bm.setInfo(SkImageInfo::MakeN32Premul(width, height));
halcanary@google.com44287342013-12-13 18:29:51 +000040 REPORTER_ASSERT(reporter, setConf);
41 if (setConf) {
42 REPORTER_ASSERT(reporter, bm.allocPixels(NULL));
43 }
halcanary@google.com2af6c122013-12-13 19:25:21 +000044 REPORTER_ASSERT(reporter, SkToBool(width & height) != bm.empty());
halcanary@google.com44287342013-12-13 18:29:51 +000045 }
46 }
skia.committer@gmail.comf5e1f632013-12-31 07:01:36 +000047
reed@google.com48569642013-12-30 19:21:22 +000048 test_bigwidth(reporter);
halcanary@google.com44287342013-12-13 18:29:51 +000049}