// test_golden.cpp - §13.4 golden screens
#include "../tttest.hpp"
#include "../ttgui.hpp"
using namespace ttgui;
static VirtualTerminal renderWindowVT(const std::string& wc,const std::string& title){
Config cfg=Config::defaults(); VirtualTerminal vt(36,9);
Window w(title,wc); w.cfg=&cfg; w.bounds={1,1,30,6}; w.focused=true; w.draw(vt.canvas);
CellStyle s; s.fg=cfg.windowColor(wc).fg; s.bg=cfg.windowColor(wc).bg;
vt.canvas.drawText(3,3,"Body "+wc, s);
return vt;
}
TEST_CASE("golden: one window of each semantic colour", "[golden]"){
for(auto wc: {"brown","purple","grey","green","lightblue","lightred","blue","red","white"}){
// Full-cell golden (glyph+fg+bg+attrs): a colour-only regression fails.
auto vt=renderWindowVT(wc, wc);
CHECK_GOLDEN_CELLS(std::string("window-")+wc+".cells.txt", vt);
// Negative control: recolouring the same glyphs changes the serialization.
auto vt2=renderWindowVT(std::string(wc)=="red"?"blue":"red", wc);
CHECK_NE(tttest::fullCellText(vt2.canvas), tttest::fullCellText(vt.canvas));
}
}
TEST_CASE("golden: panel + desktop boot screen at 80x24 and 120x40 (text)", "[golden]"){
for(auto sz: {std::pair{80,24},{120,40}}){
Config cfg=Config::defaults(); VirtualTerminal vt(sz.first,sz.second);
Desktop d; d.cfg=&cfg; d.bounds={0,0,sz.first,sz.second}; d.icons={{"H","Home"},{"T","Terminal"}}; d.draw(vt.canvas);
Panel p; p.cfg=&cfg; p.windowClass="green"; p.bounds={0,0,sz.first,1}; p.draw(vt.canvas);
{ CellStyle s; auto wc2=cfg.windowColor("green"); s.fg=wc2.fg; s.bg=wc2.bg; vt.canvas.drawText(0,0," Menu Term Files", s); }
std::string nm="boot-"+std::to_string(sz.first)+"x"+std::to_string(sz.second)+".cells.txt";
CHECK_GOLDEN_CELLS(nm, vt);
}
}
TEST_CASE("golden: gallery buttons tab and graphs tab (screen assertions)", "[golden]"){
// Buttons tab screen
VirtualTerminal vt(40,8); Config cfg=Config::defaults();
PushButton b("Push"); b.cfg=&cfg; b.bounds={1,1,12,1}; b.draw(vt.canvas);
CheckBox c("Check",true); c.cfg=&cfg; c.bounds={1,2,16,1}; c.draw(vt.canvas);
Slider s(50,0,100); s.cfg=&cfg; s.bounds={1,3,20,1}; s.draw(vt.canvas);
CHECK_GOLDEN_CELLS("gallery-buttons.cells.txt", vt);
VirtualTerminal vt2(30,7); Graph g; g.series={{1,4,2,5,3}}; g.legend={"Profit"}; g.cfg=&cfg; g.bounds={0,0,28,6}; g.draw(vt2.canvas);
CHECK_GOLDEN_CELLS("gallery-graph.cells.txt", vt2);
}
TEST_CASE("golden: bevel/inset cells via CHECK_CELLS", "[golden][unit]"){
VirtualTerminal vt(12,5); CellStyle s; s.bg=Color::rgb(170,170,170); s.fg=Color::rgb(0,0,0);
vt.canvas.drawBox({0,0,12,5},s,false);
CHECK_CELLS(vt,0,0,12,1,"┌──────────┐");
CHECK_CELLS(vt,0,4,12,1,"└──────────┘");
// Full-cell: glyphs plus the exact bevel style on every cell in the row.
CHECK_CELLS_FULL(vt.canvas,0,0,12,1,tttest::fullCellRect(vt.canvas,0,0,12,1));
VirtualTerminal other(12,5); CellStyle alt; alt.bg=Color::rgb(1,2,3); other.canvas.drawBox({0,0,12,5},alt,false);
CHECK_NE(tttest::fullCellRect(other.canvas,0,0,12,1), tttest::fullCellRect(vt.canvas,0,0,12,1));
}