53 lines
2.2 KiB
Python
53 lines
2.2 KiB
Python
"""Exercise production area inheritance and access rules in compiled C++."""
|
|
from pathlib import Path
|
|
import subprocess
|
|
import tempfile
|
|
|
|
root = Path(__file__).resolve().parents[2]
|
|
harness = r'''
|
|
#include "AdventureAreaPolicy.h"
|
|
#include <cassert>
|
|
#include <iostream>
|
|
using namespace AdventureAreaPolicy;
|
|
int main()
|
|
{
|
|
std::unordered_map<unsigned,Area> areas;
|
|
areas[1]={0,0,2,1,10,-1,-1}; // Horde starter region
|
|
areas[2]={0,1,3,-1,-1,-1,-1}; // neutral subarea cannot override parent
|
|
auto child=Resolve(areas,2);
|
|
assert(!child.Allows(1,85,true));
|
|
assert(child.Allows(2,1,true));
|
|
areas[3]={0,0,0}; // Vashjir
|
|
areas[4]={0,3,3,80,82};
|
|
assert(!Resolve(areas,4).Allows(1,85,true));
|
|
assert(!Resolve(areas,4).Allows(2,85,true));
|
|
areas[5]={571,0,-1,68,72,5,1};
|
|
auto north=Resolve(areas,5);
|
|
assert(!north.Allows(1,62,true));
|
|
assert(north.Allows(1,63,true));
|
|
assert(north.Allows(2,85,true)); // max band is not an upper access cap
|
|
assert(north.PreferFlight);
|
|
areas[6]={571,5,-1,1,10,-1,0}; // cannot weaken parent level minimum
|
|
assert(!Resolve(areas,6).Allows(1,20,true));
|
|
assert(!Resolve(areas,6).PreferFlight);
|
|
areas[7]={0,0}; // unknown outdoor band is conservative
|
|
assert(!Resolve(areas,7).Allows(1,20,true));
|
|
assert(Resolve(areas,7).Allows(1,85,true));
|
|
assert(Resolve(areas,7).Allows(1,20,false)); // native instance access is separate
|
|
assert(!Resolve(areas,999).Valid);
|
|
areas[8]={0,9};assert(!Resolve(areas,8).Valid); // orphan
|
|
areas[9]={0,8};assert(!Resolve(areas,8).Valid); // cycle
|
|
// A reloaded parent restriction changes the exact same child without edits.
|
|
areas[1].Factions=0;
|
|
assert(!Resolve(areas,2).Allows(2,85,true));
|
|
std::cout << "Area inheritance, faction intersection, level limits, flight overrides and invalid data passed.\n";
|
|
}
|
|
'''
|
|
with tempfile.TemporaryDirectory(prefix='vcore-area-policy-') as folder:
|
|
cpp = Path(folder) / 'test.cpp'
|
|
binary = Path(folder) / 'test'
|
|
cpp.write_text(harness)
|
|
subprocess.run(['c++', '-std=c++17', '-I', str(root / 'src/server/game/World'),
|
|
str(cpp), '-o', str(binary)], check=True)
|
|
subprocess.run([str(binary)], check=True)
|