File size: 3,344 Bytes
3ce1a40 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | #include "test_main.h"
#include "runtime/engine.h"
#include <lua.h>
using namespace unify;
TEST(snapkitty_menu_repository_and_architect) {
HeadlessBackend backend;
EngineConfig cfg; cfg.asset_root=UNIFY_GAME_ASSETS; cfg.boot_scene="snapkitty";
Engine engine(backend,cfg);
std::string error;
CHECK(engine.boot(error));
auto frame=[&]() {backend.advance_clock(16666667);engine.frame();};
auto tap=[&](uint16_t code) {engine.inject(code,true);frame();engine.inject(code,false);frame();};
frame();
CHECK(engine.assets().find("textures/snapkitty/kitten").bits != 0);
tap(key::I);
CHECK(engine.lua().run("assert(scene.state().info == true)", "test"));
tap(key::R);
CHECK(engine.active_scene()->name == "repositories");
frame();
CHECK(engine.assets().find("textures/snapkitty/snap-os").bits != 0);
tap(key::Escape);
CHECK(engine.active_scene()->name == "snapkitty");
tap(key::Enter);
CHECK(engine.active_scene()->name == "snapkitty_level");
CHECK(engine.lua().run("local s=scene.state(); local x,y=s.architect:position(); s.player:set_position(x,y,true)", "test"));
tap(key::E);
CHECK(engine.lua().run("assert(scene.state().msg == 'SEAL THE EVENTS. REACH THE TERMINAL.')", "test"));
for (const auto& line:engine.log_lines()) CHECK(line.rfind("ERROR",0) != 0);
}
TEST(snapkitty_disk_save_survives_engine_restart) {
HeadlessBackend first;
EngineConfig cfg; cfg.asset_root=UNIFY_GAME_ASSETS; cfg.boot_scene="snapkitty";
std::string error;
{
Engine engine(first,cfg);
CHECK(engine.boot(error));
auto frame=[&]() {first.advance_clock(16666667);engine.frame();};
auto tap=[&](uint16_t code) {engine.inject(code,true);frame();engine.inject(code,false);frame();};
frame(); tap(key::Enter);
CHECK(engine.lua().run("scene.state().score = 7300", "test"));
tap(key::F5);
}
HeadlessBackend second;
Engine engine(second,cfg);
CHECK(engine.boot(error));
auto frame=[&]() {second.advance_clock(16666667);engine.frame();};
frame(); engine.inject(key::F9,true); frame();engine.inject(key::F9,false);frame();
CHECK(engine.active_scene()->name == "snapkitty_level");
CHECK(engine.lua().run("assert(scene.state().score == 7300)", "test"));
CHECK(engine.lua().run("scene.state().score = 0", "test"));
engine.inject(key::F9,true);frame();engine.inject(key::F9,false);frame();
CHECK(engine.lua().run("assert(scene.state().score == 7300)", "test"));
}
TEST(snapkitty_finish_returns_to_menu) {
HeadlessBackend backend;
EngineConfig cfg; cfg.asset_root=UNIFY_GAME_ASSETS; cfg.boot_scene="snapkitty_level";
Engine engine(backend,cfg);std::string error;CHECK(engine.boot(error));
CHECK(engine.lua().run(R"lua(
local m=map.load("maps/level1")
for r=1,m.height do
local x=m.rows[r]:find("F",1,true)
if x then scene.state().player:set_position(x-.5,m.height-r+1,true); break end
end
)lua", "test"));
for(int i=0;i<5;i++){backend.advance_clock(16666667);engine.frame();}
CHECK(engine.lua().run("assert(scene.state().won and scene.state().score >= 1000)", "test"));
for(int i=0;i<250;i++){backend.advance_clock(16666667);engine.frame();}
CHECK(engine.active_scene()->name == "snapkitty");
}
|