continuous-integration/drone/push Build is passing
Discover installed mod vehicles and save independent garage, traffic, patrol and convoy assignments. Retire the superseded RHS 1.9 overrides. Include native menu, crew/driving and publication evidence.
62 lines
5.8 KiB
Python
62 lines
5.8 KiB
Python
"""Exercise per-admin catalog navigation; discovery itself is checked natively."""
|
|
from policy_harness import ROOT, body, run
|
|
core=ROOT/'addons/core/Scripts/Game/ERR/00_Core'
|
|
s=body(core/'ERR_AdminSession.c','protected bool ItemCatalogCommand(')+'\n'+body(core/'ERR_AdminSession.c','protected bool VehicleCatalogCommand(')
|
|
for a,b in [('protected ',''),('array<string> replies','Array<string>& replies'),('array<string> parts','Array<string> parts'),('ERR_ServerItemCatalog catalog','Catalog* catalog'),('GetGame().ERR_ServerItems()','GetCatalog()'),('GetGame().ERR_ItemSelections().','preferences.'),('catalog.','catalog->'),('ERR_CommandArguments.Integer','Integer')]:s=s.replace(a,b)
|
|
s=s.replace('query.Length()', 'int(query.size())').replace('ERR_ServerVehicleCatalog catalog', 'Catalog* catalog').replace('GetGame().ERR_ServerVehicles()', 'GetCatalog()')
|
|
run(r'''
|
|
#include <cassert>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <sstream>
|
|
struct string;
|
|
template<class T>struct Array:std::vector<T>{using std::vector<T>::vector;bool IsEmpty(){return this->empty();}int Count(){return this->size();}void Insert(T x){this->push_back(x);}};
|
|
struct string:std::string{using std::string::string;string(std::string s):std::string(s){}bool IsEmpty(){return empty();}void Split(string,Array<string>& out,bool){std::istringstream in(*this);std::string word;while(in>>word)out.push_back(word);}};
|
|
struct Catalog{bool Contains(string a,string i){return a=="loaded-a"&&i=="known-item";}bool Capable(string i,int r){return i=="known-item"&&r!=4;}void Start(void* unused=nullptr){}bool Find(string s){return s=="loaded-a"||s=="loaded-b";}} catalog;
|
|
Catalog* GetCatalog(){return &catalog;}
|
|
bool Integer(string s,int& n){try{size_t p;n=std::stoi(s,&p);return p==s.size();}catch(...){return false;}}
|
|
struct Preferences{int edits=0;bool Preset(string action,string name){edits++;return action=="save"&&name=="test";}bool Set(string,string,bool){edits++;return true;}bool SetVehicleRole(string,string,int,bool){edits++;return true;}bool SetSwitch(string,string,bool){edits++;return true;}bool SetWeight(string,string,int){edits++;return true;}} preferences;
|
|
struct Session{void* m_Mode=nullptr;string m_ItemAddon;int m_ItemPage=0,m_ItemFilter=0;string m_ItemQuery,m_VehicleAddon,m_VehicleQuery;int m_VehiclePage=0,m_VehicleFilter=0,m_VehicleRole=0;
|
|
''' + s + r'''
|
|
};
|
|
int main(){Session a,b;Array<string> replies;
|
|
assert(!a.ItemCatalogCommand("status",replies));
|
|
assert(a.ItemCatalogCommand("items list loaded-a 2",replies)&&a.m_ItemAddon=="loaded-a"&&a.m_ItemPage==2);
|
|
assert(b.ItemCatalogCommand("items list loaded-b 1",replies)&&b.m_ItemAddon=="loaded-b"&&a.m_ItemAddon=="loaded-a"&&a.m_ItemPage==2);
|
|
for(string bad:{"items", "items list unknown 0", "items list loaded-a -1", "items list loaded-a 2731", "items list loaded-a 0junk", "items list loaded-a 0 extra", "items disable loaded-a 0"}){
|
|
assert(a.ItemCatalogCommand(bad,replies));assert(a.m_ItemAddon=="loaded-a"&&a.m_ItemPage==2);
|
|
}
|
|
assert(a.ItemCatalogCommand("items list loaded-a 0",replies)&&a.m_ItemPage==0);
|
|
for(string bad:{"items set unknown * 0","items set loaded-a unknown-item 0","items set loaded-a known-item 2","items set loaded-a * 0 extra"})a.ItemCatalogCommand(bad,replies);
|
|
assert(preferences.edits==0);
|
|
a.ItemCatalogCommand("items set loaded-a known-item 0",replies);assert(preferences.edits==1);
|
|
a.ItemCatalogCommand("items set loaded-a * 1",replies);assert(preferences.edits==2);
|
|
a.ItemCatalogCommand("items preset save test",replies);assert(preferences.edits==3);
|
|
for(string bad:{"items weight unknown * 100","items weight loaded-a unknown-item 100","items weight loaded-a * 101","items weight loaded-a * -1","items weight loaded-a * 100junk"})a.ItemCatalogCommand(bad,replies);
|
|
assert(preferences.edits==3);
|
|
a.ItemCatalogCommand("items weight loaded-a * 100",replies);assert(preferences.edits==4);
|
|
a.ItemCatalogCommand("items weight loaded-a known-item 0",replies);assert(preferences.edits==5);
|
|
assert(a.m_ItemAddon=="loaded-a"&&a.m_ItemPage==0);
|
|
a.ItemCatalogCommand("items browse loaded-a 2 2 first aid",replies);
|
|
assert(a.m_ItemPage==2&&a.m_ItemFilter==2&&a.m_ItemQuery=="first aid");
|
|
a.VehicleCatalogCommand("vehicles browse loaded-b 1 1 2 red",replies);
|
|
assert(a.m_VehicleAddon=="loaded-b"&&a.m_VehiclePage==1&&a.m_VehicleQuery=="red"&&a.m_ItemAddon=="loaded-a");
|
|
b.VehicleCatalogCommand("vehicles browse loaded-a 0 0 1",replies);assert(a.m_VehicleAddon=="loaded-b");
|
|
a.VehicleCatalogCommand("vehicles role unknown 0 * 0",replies);assert(preferences.edits==5);
|
|
a.VehicleCatalogCommand("vehicles role loaded-a 0 unknown-item 0",replies);assert(preferences.edits==5);
|
|
a.ItemCatalogCommand("items browse loaded-a 2 3",replies);assert(a.m_ItemFilter==2);
|
|
a.ItemCatalogCommand("items mod loaded-a 0",replies);assert(preferences.edits==6);
|
|
a.ItemCatalogCommand("items mod unknown 0",replies);assert(preferences.edits==6);
|
|
a.VehicleCatalogCommand("vehicles role loaded-a 2 known-item 0",replies);assert(preferences.edits==7);
|
|
for(string bad:{"vehicles role loaded-a 4 known-item 1","vehicles role loaded-a 5 known-item 1","vehicles role loaded-a -1 * 1","vehicles role loaded-a 2 known-item 2"})a.VehicleCatalogCommand(bad,replies);
|
|
assert(preferences.edits==7&&a.m_VehicleRole==2&&b.m_VehicleRole==1);
|
|
a.VehicleCatalogCommand("vehicles browse loaded-a 0 0 5",replies);assert(a.m_VehicleRole==2);
|
|
a.VehicleCatalogCommand("vehicles role loaded-a 3 * 0",replies);assert(preferences.edits==8);
|
|
}
|
|
''')
|
|
command=body(core/'ERR_AdminSession.c','void Command(')
|
|
assert command.index('if (!Authorize()) return;') < command.index('ItemCatalogCommand(arguments, replies)')
|
|
assert 'PAGE_SIZE = 12' in (core/'ERR_ServerItemCatalog.c').read_text()
|
|
assert 'GetLoadedAddons' in (core/'ERR_ServerItemCatalog.c').read_text()
|
|
print('PASS: catalog requests use authenticated sessions, independent admin page selections, loaded-mod allowlisting, bounded pages and allowlisted item mutations')
|