Kumo
A hand-rolled game engine.
git clone https://git.sentomk.me/Kumo.git
golden_test.cpp (1401B) · raw
1 #include <cinttypes> 2 #include <cstdio> 3 4 #include "check.h" 5 #include "core/types.h" 6 #include "demo_scene.h" 7 #include "render/frame_buffer.h" 8 9 using kumo::FrameBuffer; 10 using kumo_test::draw_demo_scene; 11 using kumo_test::kDemoHeight; 12 using kumo_test::kDemoWidth; 13 14 // The hash of the demo picture. It must be the same on every platform, so a 15 // change here is only right if the picture was changed on purpose. Then run 16 // `kumoko test golden`, look at the picture in build/golden_demo.tga, and take 17 // the new value from the failure message. 18 constexpr uint64_t kExpectedHash = 0x635d63193c43fe8aull; 19 20 TEST(demo_scene_has_the_expected_hash) { 21 FrameBuffer frame(kDemoWidth, kDemoHeight); 22 draw_demo_scene(frame); 23 24 // Always saved, so that the picture can be looked at when the hash changes. 25 CHECK(kumo::write_tga(frame, "build/golden_demo.tga")); 26 27 const uint64_t hash = kumo::hash_pixels(frame); 28 if (hash != kExpectedHash) { 29 char message[96]; 30 std::snprintf(message, sizeof(message), 31 "hash is %016" PRIx64 ", expected %016" PRIx64, hash, 32 kExpectedHash); 33 kumo_test::fail(__FILE__, __LINE__, message); 34 } 35 } 36 37 TEST(drawing_the_scene_twice_gives_the_same_picture) { 38 FrameBuffer first(kDemoWidth, kDemoHeight); 39 FrameBuffer second(kDemoWidth, kDemoHeight); 40 draw_demo_scene(first); 41 draw_demo_scene(second); 42 CHECK(first.pixels == second.pixels); 43 }
