blob: c7d7f7eefc1b26533c0ad7a9df6644064ea456b4 [file] [log] [blame]
Tao Bao92bdb5a2018-10-21 12:12:37 -07001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <stdint.h>
Tao Bao63b59dc2018-10-31 15:23:04 -070018#include <stdlib.h>
Tao Bao92bdb5a2018-10-21 12:12:37 -070019
Tao Baodd789822018-11-26 16:28:07 -080020#include <limits>
Tao Bao63b59dc2018-10-31 15:23:04 -070021#include <vector>
Tao Bao92bdb5a2018-10-21 12:12:37 -070022
23#include <gtest/gtest.h>
24
25#include "minui/minui.h"
26
27TEST(GRSurfaceTest, Create_aligned) {
Tao Baodd789822018-11-26 16:28:07 -080028 auto surface = GRSurface::Create(9, 11, 9, 1);
29 ASSERT_TRUE(surface);
30 ASSERT_EQ(0, reinterpret_cast<uintptr_t>(surface->data()) % GRSurface::kSurfaceDataAlignment);
31 // data_size will be rounded up to the next multiple of GRSurface::kSurfaceDataAlignment.
32 ASSERT_EQ(0, surface->data_size() % GRSurface::kSurfaceDataAlignment);
33 ASSERT_GE(surface->data_size(), 11 * 9);
34}
35
36TEST(GRSurfaceTest, Create_invalid_inputs) {
37 ASSERT_FALSE(GRSurface::Create(9, 11, 0, 1));
38 ASSERT_FALSE(GRSurface::Create(9, 0, 9, 1));
39 ASSERT_FALSE(GRSurface::Create(0, 11, 9, 1));
40 ASSERT_FALSE(GRSurface::Create(9, 11, 9, 0));
41 ASSERT_FALSE(GRSurface::Create(9, 101, std::numeric_limits<size_t>::max() / 100, 1));
Tao Bao92bdb5a2018-10-21 12:12:37 -070042}
Tao Bao63b59dc2018-10-31 15:23:04 -070043
44TEST(GRSurfaceTest, Clone) {
Tao Baodd789822018-11-26 16:28:07 -080045 auto image = GRSurface::Create(50, 10, 50, 1);
46 ASSERT_GE(image->data_size(), 10 * 50);
47 for (auto i = 0; i < image->data_size(); i++) {
Tao Bao63b59dc2018-10-31 15:23:04 -070048 image->data()[i] = rand() % 128;
49 }
50 auto image_copy = image->Clone();
Tao Baodd789822018-11-26 16:28:07 -080051 ASSERT_EQ(image->data_size(), image_copy->data_size());
52 ASSERT_EQ(std::vector(image->data(), image->data() + image->data_size()),
53 std::vector(image_copy->data(), image_copy->data() + image->data_size()));
Tao Bao63b59dc2018-10-31 15:23:04 -070054}