41 lines
2.0 KiB
Python
41 lines
2.0 KiB
Python
"""Round-trip tracker preferences through the actual classic config reader/writer."""
|
|
import pathlib, subprocess, tempfile, unittest, os
|
|
ROOT=pathlib.Path(__file__).resolve().parents[2]
|
|
class TrackConfigTest(unittest.TestCase):
|
|
def test_cold_restart_round_trip(self):
|
|
source=(ROOT/'src/port/UserInterface/PythonSystem.cpp').read_text()
|
|
header=(ROOT/'src/port/UserInterface/PythonSystem.h').read_text()
|
|
struct=header[header.index('typedef struct SConfig'):header.index('} TConfig;')+len('} TConfig;')]
|
|
def method(name):
|
|
a=source.index('bool CPythonSystem::'+name+'(');b=source.index('\n}',a)+2
|
|
return source[a:b]
|
|
code=r'''
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include <cassert>
|
|
#include <cmath>
|
|
using DWORD=unsigned;using BYTE=unsigned char;using FLOAT=float;
|
|
#define stricmp strcasecmp
|
|
#define DEFAULT_VALUE_ALWAYS_SHOW_NAME false
|
|
const int SM_CXFULLSCREEN=0,SM_CYFULLSCREEN=1;
|
|
unsigned GetSystemMetrics(int){return 4096;}
|
|
int g_iLoadingDelayTime=20;
|
|
class CPythonSystem {public:
|
|
'''+struct+r'''
|
|
TConfig m_Config={},m_OldConfig={};bool LoadConfig();bool SaveConfig();
|
|
};
|
|
'''+method('LoadConfig')+method('SaveConfig')+r'''
|
|
int main(){
|
|
CPythonSystem first;strcpy(first.m_Config.SaveID,"0");first.m_Config.width=1280;
|
|
first.m_Config.dungeonTrack=true;first.m_Config.bossTrack=true;assert(first.SaveConfig());
|
|
CPythonSystem cold;assert(cold.LoadConfig());assert(cold.m_Config.dungeonTrack && cold.m_Config.bossTrack);assert(cold.m_Config.width==1280);
|
|
cold.m_Config.dungeonTrack=false;assert(cold.SaveConfig());
|
|
CPythonSystem again;assert(again.LoadConfig());assert(!again.m_Config.dungeonTrack && again.m_Config.bossTrack);
|
|
}
|
|
'''
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
p=pathlib.Path(tmp);(p/'test.cpp').write_text(code)
|
|
subprocess.run([os.environ.get('CXX','c++'),'-std=c++17',str(p/'test.cpp'),'-o',str(p/'test')],check=True)
|
|
subprocess.run([str(p/'test')],cwd=tmp,check=True)
|