Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/VideoConfigTests.cpp

Source at documentation-generation time. See Test catalog for fixture associations.

1#include "../Config/config.h"
2#include <filesystem>
3#include <fstream>
4#include <iostream>
5#include <stdexcept>
6
7namespace fs=std::filesystem;
8unsigned checks=0;
9void Check(bool ok,const char* text){++checks;if(!ok)throw std::runtime_error(text);}
10int main()
11{
12 // Exercise the real loader/writer in a fresh fixture directory, never the
13 // player's saved credentials or bindings. Keep fixtures for diagnostics.
14 const auto original=fs::current_path();
15 try
16 {
17 const auto fixture=original/"outputs"/"video-settings"/("config-"+std::to_string(GetCurrentProcessId()));
18 Check(fs::create_directories(fixture),"fixture must be a new directory");
19 fs::current_path(fixture);
20 std::ofstream("patchdate.txt")<<"test\n";
21 Config settings;
22 Check(settings.videoSamples==4 && settings.videoVSync,"new configuration keeps 4x / VSync defaults");
23 settings.scale=1.25f;
25 settings.soundConfigComputer.volume=.75f;
26 for(const unsigned char samples:std::initializer_list<unsigned char>{1,2,4,8})for(bool vsync:{false,true})
27 {
28 settings.videoSamples=samples;settings.videoVSync=vsync;settings.Save();
29 Config loaded;
30 Check(loaded.videoSamples==samples && loaded.videoVSync==vsync,"MSAA and VSync survive reload");
31 Check(loaded.configver==38 && loaded.scale==1.25f && loaded.soundConfigComputer.volume==.75f,
32 "video save preserves existing layout and preferences");
33 Check(loaded.keyBindings.size()==1 && loaded.keyBindings[0].function==BindingEnum::AUTOFLYTE_CYCLE &&
34 loaded.keyBindings[0].scancode==DIK_F10 && loaded.keyBindings[0].shift,"video save preserves custom bindings");
35 }
36 for(const unsigned char value:std::initializer_list<unsigned char>{0,3,255})
37 {
38 std::fstream file("Save/client.cfg",std::ios::in|std::ios::out|std::ios::binary);
39 file.seekp(47);file.put(static_cast<char>(value));file.put(static_cast<char>(value));file.close();
40 Config loaded;
41 Check(loaded.videoSamples==4 && loaded.videoVSync,"old or invalid reserved bytes keep defaults");
42 Check(loaded.keyBindings.size()==1 && loaded.keyBindings[0].shift,"legacy load preserves bindings");
43 }
44 fs::current_path(original);
45 std::cout<<"PASS: "<<checks<<" video config checks\n";return 0;
46 }
47 catch(const std::exception& error){fs::current_path(original);std::cerr<<"FAIL: "<<error.what()<<'\n';return 1;}
48}
@ AUTOFLYTE_CYCLE
Definition binding.h:33
unsigned char configver
Definition config.h:20
SoundConfig soundConfigComputer
Definition config.h:49
bool videoVSync
Definition config.h:28
std::vector< KeyBinding > keyBindings
Definition config.h:54
unsigned char videoSamples
Definition config.h:27
void Save()
Definition config.cpp:648
float scale
Definition config.h:29
KeyBinding(BindingEnum prmFunction, short prmScancode, bool prmShift)
Definition binding.h:226