9#include <gtest/gtest.h>
29class DungeonObjectRenderingTests :
public TestRomManager::BoundRomTest {
32 BoundRomTest::SetUp();
35 drawer_ = std::make_unique<zelda3::ObjectDrawer>(
rom());
38 bg1_ = std::make_unique<gfx::BackgroundBuffer>(512, 512);
39 bg2_ = std::make_unique<gfx::BackgroundBuffer>(512, 512);
49 BoundRomTest::TearDown();
57 for (
int i = 0; i < 16; i++) {
58 int intensity = i * 16;
73 std::unique_ptr<zelda3::ObjectDrawer>
drawer_;
74 std::unique_ptr<gfx::BackgroundBuffer>
bg1_;
75 std::unique_ptr<gfx::BackgroundBuffer>
bg2_;
80TEST_F(DungeonObjectRenderingTests, BasicObjectDrawing) {
81 std::vector<zelda3::RoomObject> objects;
82 objects.push_back(CreateTestObject(0x10, 5, 5, 0x12, 0));
83 objects.push_back(CreateTestObject(0x20, 10, 10, 0x22, 0));
88 auto status = drawer_->DrawObjectList(objects, *bg1_, *bg2_, palette_group_);
89 ASSERT_TRUE(status.ok()) <<
"Drawing failed: " << status.message();
92 auto& bg1_bitmap = bg1_->bitmap();
93 EXPECT_TRUE(bg1_bitmap.is_active());
94 EXPECT_GT(bg1_bitmap.width(), 0);
98TEST_F(DungeonObjectRenderingTests, MultiLayerRendering) {
99 std::vector<zelda3::RoomObject> objects;
100 objects.push_back(CreateTestObject(0x10, 5, 5, 0x12, 0));
101 objects.push_back(CreateTestObject(0x20, 10, 10, 0x22, 1));
102 objects.push_back(CreateTestObject(0x30, 15, 15, 0x12, 2));
107 auto status = drawer_->DrawObjectList(objects, *bg1_, *bg2_, palette_group_);
108 ASSERT_TRUE(status.ok());
111 EXPECT_TRUE(bg1_->bitmap().is_active());
112 EXPECT_TRUE(bg2_->bitmap().is_active());
116TEST_F(DungeonObjectRenderingTests, EmptyObjectList) {
117 std::vector<zelda3::RoomObject> objects;
122 auto status = drawer_->DrawObjectList(objects, *bg1_, *bg2_, palette_group_);
124 EXPECT_TRUE(status.ok());
128TEST_F(DungeonObjectRenderingTests, LargeObjectSet) {
129 std::vector<zelda3::RoomObject> objects;
132 for (
int i = 0; i < 100; i++) {
133 int x = (i % 10) * 5;
134 int y = (i / 10) * 5;
135 objects.push_back(CreateTestObject(0x10 + (i % 20), x, y, 0x12, i % 2));
141 auto start = std::chrono::high_resolution_clock::now();
142 auto status = drawer_->DrawObjectList(objects, *bg1_, *bg2_, palette_group_);
143 auto end = std::chrono::high_resolution_clock::now();
145 ASSERT_TRUE(status.ok());
147 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
149 EXPECT_LT(duration.count(), 1000) <<
"Rendered 100 objects in " << duration.count() <<
"ms";
153TEST_F(DungeonObjectRenderingTests, BoundaryObjects) {
154 std::vector<zelda3::RoomObject> objects;
157 objects.push_back(CreateTestObject(0x10, 0, 0, 0x12, 0));
158 objects.push_back(CreateTestObject(0x10, 63, 63, 0x12, 0));
159 objects.push_back(CreateTestObject(0x10, 32, 32, 0x12, 0));
164 auto status = drawer_->DrawObjectList(objects, *bg1_, *bg2_, palette_group_);
165 EXPECT_TRUE(status.ok());
169TEST_F(DungeonObjectRenderingTests, VariousObjectTypes) {
171 std::vector<int> object_types = {
172 0x00, 0x01, 0x02, 0x03,
179 for (
int obj_type : object_types) {
180 std::vector<zelda3::RoomObject> objects;
181 objects.push_back(CreateTestObject(obj_type, 10, 10, 0x12, 0));
186 auto status = drawer_->DrawObjectList(objects, *bg1_, *bg2_, palette_group_);
189 std::cout <<
"Object type 0x" << std::hex << obj_type << std::dec
190 <<
" not renderable: " << status.message() << std::endl;
196TEST_F(DungeonObjectRenderingTests, ErrorHandling) {
198 zelda3::ObjectDrawer null_drawer(
nullptr);
199 std::vector<zelda3::RoomObject> objects;
200 objects.push_back(CreateTestObject(0x10, 5, 5));
205 auto status = null_drawer.DrawObjectList(objects, *bg1_, *bg2_, palette_group_);
206 EXPECT_FALSE(status.ok());
207 EXPECT_EQ(status.code(), absl::StatusCode::kFailedPrecondition);
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
void AddColor(const SnesColor &color)
std::unique_ptr< gfx::BackgroundBuffer > bg1_
zelda3::RoomObject CreateTestObject(int id, int x, int y, int size=0x12, int layer=0)
gfx::PaletteGroup palette_group_
gfx::PaletteGroup CreateTestPaletteGroup()
std::unique_ptr< gfx::BackgroundBuffer > bg2_
std::unique_ptr< zelda3::ObjectDrawer > drawer_
TEST_F(DungeonObjectRenderingE2ETests, RunAllTests)
Main namespace for the application.
Represents a group of palettes.
void AddPalette(SnesPalette pal)