Files
metin2-client/tests/host/ui_sampler_capture_test.cpp

25 lines
1.3 KiB
C++

#include "../../src/host/draw_capture.h"
#include <unistd.h>
#include <cassert>
#include <cstdio>
#include <iterator>
int main() {
char path[]="/tmp/metin2-ui-address-XXXXXX";
int fd=mkstemp(path);assert(fd>=0);close(fd);
UIRenderCommand cmd{UIRenderCommand::Image,0,0,320,470,0xffffffff};
cmd.quad=true;cmd.eu=2.5f;cmd.ev=3.5f;cmd.address_u=1;cmd.address_v=2;
native_draw_capture::write(path,{}, {},320,470,{cmd});
auto current=native_draw_capture::read_capture(path);
assert(current.version==11 && current.ui_commands.size()==1);
assert(current.ui_commands[0].address_u==1 && current.ui_commands[0].address_v==2);
assert(current.ui_commands[0].eu==2.5f && current.ui_commands[0].ev==3.5f);
// Version 10 ends the UI record before the two address fields. Old captures must still load.
std::ifstream input(path,std::ios::binary);
std::vector<char> bytes((std::istreambuf_iterator<char>(input)),{});input.close();
bytes[4]=10;bytes.resize(bytes.size()-8);
std::ofstream output(path,std::ios::binary|std::ios::trunc);output.write(bytes.data(),bytes.size());output.close();
auto legacy=native_draw_capture::read_capture(path);
assert(legacy.version==10 && legacy.ui_commands[0].address_u==3 && legacy.ui_commands[0].address_v==3);
unlink(path);
}