52 lines
3.4 KiB
Python
52 lines
3.4 KiB
Python
"""Exercise the production name resolver with native metadata boundaries doubled."""
|
|
from policy_harness import ROOT, body, run
|
|
p = ROOT / 'addons/core/Scripts/Game/ERR/00_Core/ERR_TelemetryServerName.c'
|
|
method = body(p, 'static string Resolve(')
|
|
for a, b in [('BackendApi backend = GetGame().GetBackendApi()', 'BackendApi* backend = backendAvailable ? &backendApi : nullptr'), ('SCR_DSConfig dedicated = new SCR_DSConfig()', 'SCR_DSConfig dedicated'), ('backend.GetRunningDSConfig', 'backend->GetRunningDSConfig'), ('dedicated.game.name', 'dedicated.game->name'), ('ServerConfig config', 'ServerConfig* config'), ('ServerInfo info', 'ServerInfo* info'),
|
|
('GetGame().GetServerInfo()', 'ServerLobbyApi::GetServerInfo()'), ('ServerLobbyApi.', 'ServerLobbyApi::'), ('config.GetName()', 'config->GetName()'), ('info.GetName()', 'info->GetName()')]:
|
|
method = method.replace(a, b)
|
|
run(r'''
|
|
#include <cassert>
|
|
#include <string>
|
|
struct string:std::string {
|
|
using std::string::string;using std::string::operator=;
|
|
string(std::string v):std::string(v){}
|
|
bool IsEmpty(){return empty();}int Length(){return size();}
|
|
string Substring(int start,int count){return substr(start,count);}
|
|
void TrimInPlace(){auto a=find_first_not_of(" \t\r\n");if(a==npos){clear();return;}*this=substr(a,find_last_not_of(" \t\r\n")-a+1);}
|
|
};
|
|
struct ServerConfig {string name=" Community Escape ";string GetName(){return name;}};
|
|
struct ServerInfo {string name="Listed server";string GetName(){return name;}};
|
|
namespace ServerLobbyApi {ServerConfig cfg;ServerInfo info;bool configPresent=true,infoPresent=true;
|
|
ServerConfig* GetServerConfig(){return configPresent?&cfg:nullptr;}ServerInfo* GetServerInfo(){return infoPresent?&info:nullptr;}}
|
|
struct DSGameConfig {string name=" Dedicated game name ";};
|
|
struct SCR_DSConfig {DSGameConfig* game=nullptr;};
|
|
struct BackendApi {bool running=true,hasGame=true;DSGameConfig game;
|
|
bool GetRunningDSConfig(SCR_DSConfig& config){config.game=hasGame?&game:nullptr;return running;}} backendApi;
|
|
bool backendAvailable=true;
|
|
struct Names {
|
|
''' + method + r'''
|
|
};
|
|
int main(){
|
|
assert(Names::Resolve("")=="Dedicated game name");
|
|
assert(Names::Resolve(" Manual label ")=="Manual label");
|
|
backendApi.game.name="Renamed dedicated server";assert(Names::Resolve("")=="Renamed dedicated server");
|
|
backendApi.hasGame=false;assert(Names::Resolve("")=="Community Escape");
|
|
backendApi.hasGame=true;backendApi.game.name=" ";assert(Names::Resolve("")=="Community Escape");
|
|
backendApi.running=false;assert(Names::Resolve("")=="Community Escape");
|
|
backendAvailable=false;
|
|
assert(Names::Resolve("")=="Community Escape");
|
|
assert(Names::Resolve(" Manual label ")=="Manual label");
|
|
assert(Names::Resolve(" ")=="Community Escape");
|
|
ServerLobbyApi::configPresent=false;assert(Names::Resolve("")=="Listed server");
|
|
ServerLobbyApi::infoPresent=false;assert(Names::Resolve("")=="");
|
|
ServerLobbyApi::configPresent=true;ServerLobbyApi::cfg.name="Changed name";
|
|
assert(Names::Resolve("")=="Changed name");
|
|
assert(Names::Resolve(string(160,'x')).Length()==120);
|
|
ServerLobbyApi::cfg.name=" ";ServerLobbyApi::infoPresent=true;assert(Names::Resolve("")=="Listed server");
|
|
}
|
|
''')
|
|
telemetry = p.with_name('ERR_Telemetry.c')
|
|
assert 'ERR_TelemetryServerName.Resolve(m_Config.ServerName)' in body(telemetry, 'protected void Event(')
|
|
print('PASS: running dedicated configuration, automatic server config/lobby name, explicit override, startup absence, rename and payload bound')
|