Tao Bao | 92bdb5a | 2018-10-21 12:12:37 -0700 | [diff] [blame] | 1 | /* |
| 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 Bao | 63b59dc | 2018-10-31 15:23:04 -0700 | [diff] [blame] | 18 | #include <stdlib.h> |
Tao Bao | 92bdb5a | 2018-10-21 12:12:37 -0700 | [diff] [blame] | 19 | |
Tao Bao | 63b59dc | 2018-10-31 15:23:04 -0700 | [diff] [blame] | 20 | #include <vector> |
Tao Bao | 92bdb5a | 2018-10-21 12:12:37 -0700 | [diff] [blame] | 21 | |
| 22 | #include <gtest/gtest.h> |
| 23 | |
| 24 | #include "minui/minui.h" |
| 25 | |
| 26 | TEST(GRSurfaceTest, Create_aligned) { |
| 27 | static constexpr size_t kSurfaceDataAlignment = 8; |
| 28 | for (size_t data_size = 100; data_size < 128; data_size++) { |
Tao Bao | 44820ac | 2018-10-30 23:34:50 -0700 | [diff] [blame] | 29 | auto surface = GRSurface::Create(10, 1, 10, 1, data_size); |
Tao Bao | 92bdb5a | 2018-10-21 12:12:37 -0700 | [diff] [blame] | 30 | ASSERT_TRUE(surface); |
| 31 | ASSERT_EQ(0, reinterpret_cast<uintptr_t>(surface->data()) % kSurfaceDataAlignment); |
| 32 | } |
| 33 | } |
Tao Bao | 63b59dc | 2018-10-31 15:23:04 -0700 | [diff] [blame] | 34 | |
| 35 | TEST(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 | } |