1/*
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
12static void test_bigwidth(skiatest::Reporter* reporter) {
13    SkBitmap bm;
14    int width = 1 << 29;    // *4 will be the high-bit of 32bit int
15
16    SkImageInfo info = SkImageInfo::MakeA8(width, 1);
17    REPORTER_ASSERT(reporter, bm.setInfo(info));
18    info.fColorType = kRGB_565_SkColorType;
19    REPORTER_ASSERT(reporter, bm.setInfo(info));
20
21    // 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
27    info.fColorType = kN32_SkColorType;
28    REPORTER_ASSERT(reporter, !bm.setInfo(info));
29}
30
31/**
32 *  This test contains basic sanity checks concerning bitmaps.
33 */
34DEF_TEST(Bitmap, reporter) {
35    // Zero-sized bitmaps are allowed
36    for (int width = 0; width < 2; ++width) {
37        for (int height = 0; height < 2; ++height) {
38            SkBitmap bm;
39            bool setConf = bm.setInfo(SkImageInfo::MakeN32Premul(width, height));
40            REPORTER_ASSERT(reporter, setConf);
41            if (setConf) {
42                REPORTER_ASSERT(reporter, bm.allocPixels(NULL));
43            }
44            REPORTER_ASSERT(reporter, SkToBool(width & height) != bm.empty());
45        }
46    }
47
48    test_bigwidth(reporter);
49}
50