42 lines
2.0 KiB
C++
42 lines
2.0 KiB
C++
#include "../../src/host/ui_quality.h"
|
|
#include "../../src/host/hd_ui_archive.h"
|
|
#include <unistd.h>
|
|
#include <cstdio>
|
|
#include <vector>
|
|
|
|
int main() {
|
|
int failures=0;
|
|
auto check=[&](bool ok,const char* message) { if (!ok) { std::fprintf(stderr,"FAIL %s\n",message); ++failures; } };
|
|
using namespace mt_host;
|
|
check(font_raster_scale(1)==1 && font_raster_scale(2)==2 && font_raster_scale(2.01f)==3,
|
|
"fractional density uses enough glyph texels");
|
|
float x[]={0.25f,32.25f,0.25f,32.25f}, y[]={0.125f,0.125f,32.125f,32.125f};
|
|
check(align_ui_quad(x,y,2,2),"axis aligned icon snaps");
|
|
check(x[0]*2==std::round(x[0]*2) && y[0]*2==std::round(y[0]*2) && x[1]-x[0]==32,
|
|
"physical origin aligns without resizing");
|
|
x[2]+=1;
|
|
check(!align_ui_quad(x,y,2,2),"rotated quad remains unchanged");
|
|
check(ui_texels_match_pixels(64,64,64,64),"2x HD icon at 1:1 uses point sampling");
|
|
check(!ui_texels_match_pixels(64,64,32,32) && !ui_texels_match_pixels(48,48,64,64),
|
|
"upsized original art and downsized HD retain linear filtering");
|
|
|
|
char path[]="/tmp/metin2-hd-archive-XXXXXX";
|
|
const int fd=mkstemp(path);
|
|
check(fd>=0,"archive test fixture");
|
|
if (fd<0) return 1;
|
|
close(fd);
|
|
std::vector<unsigned char> data={'M','T','H','D',1,0,0,0,1,0,0,0,3,0,'f','o','o',25,0,0,0,4,0,0,0,1,2,3,4};
|
|
auto save=[&] { auto* f=std::fopen(path,"wb"); std::fwrite(data.data(),1,data.size(),f); std::fclose(f); };
|
|
save();
|
|
{ HdUiArchive archive; std::vector<std::uint8_t> out;
|
|
check(archive.open(path) && archive.size()==1 && archive.read("foo",out) && out==std::vector<std::uint8_t>({1,2,3,4}),
|
|
"valid resource archive payload");
|
|
check(!archive.read("missing",out),"uncovered asset falls back"); }
|
|
data[21]=200; save();
|
|
{ HdUiArchive archive; check(!archive.open(path) && archive.size()==0,"invalid payload range rejected"); }
|
|
data.resize(20); save();
|
|
{ HdUiArchive archive; check(!archive.open(path),"truncated index rejected"); }
|
|
unlink(path);
|
|
return failures ? 1 : 0;
|
|
}
|