summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/testdata/battery_scale.pngbin0 -> 463 bytes
-rw-r--r--tests/unit/minui_test.cpp32
-rw-r--r--tests/unit/resources_test.cpp37
-rw-r--r--tests/unit/screen_ui_test.cpp6
4 files changed, 61 insertions, 14 deletions
diff --git a/tests/testdata/battery_scale.png b/tests/testdata/battery_scale.png
new file mode 100644
index 000000000..2ae8f0fd7
--- /dev/null
+++ b/tests/testdata/battery_scale.png
Binary files differ
diff --git a/tests/unit/minui_test.cpp b/tests/unit/minui_test.cpp
index d68e5e3a1..c7d7f7eef 100644
--- a/tests/unit/minui_test.cpp
+++ b/tests/unit/minui_test.cpp
@@ -17,6 +17,7 @@
#include <stdint.h>
#include <stdlib.h>
+#include <limits>
#include <vector>
#include <gtest/gtest.h>
@@ -24,21 +25,30 @@
#include "minui/minui.h"
TEST(GRSurfaceTest, Create_aligned) {
- static constexpr size_t kSurfaceDataAlignment = 8;
- for (size_t data_size = 100; data_size < 128; data_size++) {
- auto surface = GRSurface::Create(10, 1, 10, 1, data_size);
- ASSERT_TRUE(surface);
- ASSERT_EQ(0, reinterpret_cast<uintptr_t>(surface->data()) % kSurfaceDataAlignment);
- }
+ auto surface = GRSurface::Create(9, 11, 9, 1);
+ ASSERT_TRUE(surface);
+ ASSERT_EQ(0, reinterpret_cast<uintptr_t>(surface->data()) % GRSurface::kSurfaceDataAlignment);
+ // data_size will be rounded up to the next multiple of GRSurface::kSurfaceDataAlignment.
+ ASSERT_EQ(0, surface->data_size() % GRSurface::kSurfaceDataAlignment);
+ ASSERT_GE(surface->data_size(), 11 * 9);
+}
+
+TEST(GRSurfaceTest, Create_invalid_inputs) {
+ ASSERT_FALSE(GRSurface::Create(9, 11, 0, 1));
+ ASSERT_FALSE(GRSurface::Create(9, 0, 9, 1));
+ ASSERT_FALSE(GRSurface::Create(0, 11, 9, 1));
+ ASSERT_FALSE(GRSurface::Create(9, 11, 9, 0));
+ ASSERT_FALSE(GRSurface::Create(9, 101, std::numeric_limits<size_t>::max() / 100, 1));
}
TEST(GRSurfaceTest, Clone) {
- static constexpr size_t kImageSize = 10 * 50;
- auto image = GRSurface::Create(50, 10, 50, 1, kImageSize);
- for (auto i = 0; i < kImageSize; i++) {
+ auto image = GRSurface::Create(50, 10, 50, 1);
+ ASSERT_GE(image->data_size(), 10 * 50);
+ for (auto i = 0; i < image->data_size(); i++) {
image->data()[i] = rand() % 128;
}
auto image_copy = image->Clone();
- ASSERT_EQ(std::vector(image->data(), image->data() + kImageSize),
- std::vector(image_copy->data(), image_copy->data() + kImageSize));
+ ASSERT_EQ(image->data_size(), image_copy->data_size());
+ ASSERT_EQ(std::vector(image->data(), image->data() + image->data_size()),
+ std::vector(image_copy->data(), image_copy->data() + image->data_size()));
}
diff --git a/tests/unit/resources_test.cpp b/tests/unit/resources_test.cpp
new file mode 100644
index 000000000..c3f72718f
--- /dev/null
+++ b/tests/unit/resources_test.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string>
+
+#include <gtest/gtest.h>
+
+#include "common/test_constants.h"
+#include "minui/minui.h"
+
+TEST(ResourcesTest, res_create_multi_display_surface) {
+ GRSurface** frames;
+ int frame_count;
+ int fps;
+ ASSERT_EQ(0, res_create_multi_display_surface(from_testdata_base("battery_scale.png").c_str(),
+ &frame_count, &fps, &frames));
+ ASSERT_EQ(6, frame_count);
+ ASSERT_EQ(20, fps);
+
+ for (auto i = 0; i < frame_count; i++) {
+ free(frames[i]);
+ }
+ free(frames);
+}
diff --git a/tests/unit/screen_ui_test.cpp b/tests/unit/screen_ui_test.cpp
index 09c49977f..61a092551 100644
--- a/tests/unit/screen_ui_test.cpp
+++ b/tests/unit/screen_ui_test.cpp
@@ -231,7 +231,7 @@ TEST_F(ScreenUITest, WearMenuSelectItemsOverflow) {
}
TEST_F(ScreenUITest, GraphicMenuSelection) {
- auto image = GRSurface::Create(50, 50, 50, 1, 50 * 50);
+ auto image = GRSurface::Create(50, 50, 50, 1);
auto header = image->Clone();
std::vector<const GRSurface*> items = {
image.get(),
@@ -258,7 +258,7 @@ TEST_F(ScreenUITest, GraphicMenuSelection) {
}
TEST_F(ScreenUITest, GraphicMenuValidate) {
- auto image = GRSurface::Create(50, 50, 50, 1, 50 * 50);
+ auto image = GRSurface::Create(50, 50, 50, 1);
auto header = image->Clone();
std::vector<const GRSurface*> items = {
image.get(),
@@ -269,7 +269,7 @@ TEST_F(ScreenUITest, GraphicMenuValidate) {
ASSERT_TRUE(GraphicMenu::Validate(200, 200, header.get(), items));
// Menu exceeds the horizontal boundary.
- auto wide_surface = GRSurface::Create(300, 50, 300, 1, 300 * 50);
+ auto wide_surface = GRSurface::Create(300, 50, 300, 1);
ASSERT_FALSE(GraphicMenu::Validate(299, 200, wide_surface.get(), items));
// Menu exceeds the vertical boundary.