blob: d68e5e3a18089e35398c0ab16a3888d4e7c203b2 [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 Bao63b59dc2018-10-31 15:23:04 -070020#include <vector>
Tao Bao92bdb5a2018-10-21 12:12:37 -070021
22#include <gtest/gtest.h>
23
24#include "minui/minui.h"
25
26TEST(GRSurfaceTest, Create_aligned) {
27 static constexpr size_t kSurfaceDataAlignment = 8;
28 for (size_t data_size = 100; data_size < 128; data_size++) {
Tao Bao44820ac2018-10-30 23:34:50 -070029 auto surface = GRSurface::Create(10, 1, 10, 1, data_size);
Tao Bao92bdb5a2018-10-21 12:12:37 -070030 ASSERT_TRUE(surface);
31 ASSERT_EQ(0, reinterpret_cast<uintptr_t>(surface->data()) % kSurfaceDataAlignment);
32 }
33}
Tao Bao63b59dc2018-10-31 15:23:04 -070034
35TEST(GRSurfaceTest, Clone) {
36 static constexpr size_t kImageSize = 10 * 50;
37 auto image = GRSurface::Create(50, 10, 50, 1, kImageSize);
38 for (auto i = 0; i < kImageSize; i++) {
39 image->data()[i] = rand() % 128;
40 }
41 auto image_copy = image->Clone();
42 ASSERT_EQ(std::vector(image->data(), image->data() + kImageSize),
43 std::vector(image_copy->data(), image_copy->data() + kImageSize));
44}