68 lines
4.1 KiB
C++
68 lines
4.1 KiB
C++
#include "gateway/character_creation.hpp"
|
|
#include "fixtures/character_creation_tauren_70334.hpp"
|
|
#include <algorithm>
|
|
#include <atomic>
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
#include <new>
|
|
|
|
static std::atomic_size_t allocations{0};
|
|
static bool count_allocations=false;
|
|
void* operator new(std::size_t size){
|
|
if(count_allocations)++allocations;
|
|
if(void* result=std::malloc(size?size:1))return result;
|
|
throw std::bad_alloc();
|
|
}
|
|
void operator delete(void* value)noexcept{std::free(value);}
|
|
void operator delete(void* value,std::size_t)noexcept{std::free(value);}
|
|
|
|
namespace c=gateway::character_creation;
|
|
static void check(bool value,const char* reason){if(!value)throw gateway::Error(reason);}
|
|
int main(){try{
|
|
for(const auto& fixture:CreationFixtures){
|
|
c::SourceAppearance source{6,fixture.sex,fixture.appearance};
|
|
auto result=c::project_source_appearances(std::span(&source,1));
|
|
check(result.size()==1&&result[0].resolved,"retained actual Tauren Source case held");
|
|
c::NativeCreate request;request.race=6;request.sex=fixture.sex;request.customizations=result[0].choices;
|
|
check(c::resolve_appearance(request)==fixture.appearance,"retained Tauren inverse differs");
|
|
}
|
|
// Existing-actor metadata must not apply NEW-character's canonicalization
|
|
// of Source Tauren male facial0/7. Both genuine aliases remain explicit holds.
|
|
const c::SourceAppearance aliases[]={{6,0,{0,0,0,0,0}},{6,0,{0,0,0,0,7}}};
|
|
for(const auto& result:c::project_source_appearances(aliases)){
|
|
check(!result.resolved&&result.held_reason.find("ambiguous")!=std::string::npos,"Tauren existing-actor alias incorrectly admitted");
|
|
}
|
|
const auto& fixture=CreationFixtures[0];
|
|
c::SourceAppearance source{6,fixture.sex,fixture.appearance};
|
|
auto projected=c::project_source_appearances(std::span(&source,1));
|
|
c::NativeCreate request;request.race=6;request.sex=fixture.sex;request.customizations=projected[0].choices;
|
|
c::AppearanceProfile copied=c::default_profile();
|
|
auto measure=[&](const c::AppearanceProfile& profile){
|
|
allocations=0;count_allocations=true;
|
|
auto resolved=c::resolve_appearance(request,profile);
|
|
auto output=c::project_source_appearances(std::span(&source,1),profile);
|
|
count_allocations=false;
|
|
check(resolved==fixture.appearance&&output[0].choices==projected[0].choices,"cached and local profile outputs differ");
|
|
return allocations.load();
|
|
};
|
|
const auto cached=measure(c::default_profile());
|
|
const auto uncached=measure(copied);
|
|
check(uncached>cached+c::default_profile().choices.size(),"default path rebuilds the immutable 10k-choice index");
|
|
std::vector<c::Choice> mutable_choices(copied.choices.begin(),copied.choices.end());
|
|
copied.choices=mutable_choices;
|
|
check(c::resolve_appearance(request,copied)==fixture.appearance,"custom initial relation failed");
|
|
const auto chosen=request.customizations.front();
|
|
auto choice=std::find_if(mutable_choices.begin(),mutable_choices.end(),[&](const auto& row){return row.id==chosen[1];});
|
|
check(choice!=mutable_choices.end(),"custom mutable choice missing");
|
|
choice->option=999999;
|
|
bool rejected=false;try{(void)c::resolve_appearance(request,copied);}catch(const c::Unsupported&){rejected=true;}
|
|
check(rejected,"custom profile cached after its backing choices changed");
|
|
const auto changed=c::project_source_appearances(std::span(&source,1),copied);
|
|
check(changed[0].resolved&&std::find(changed[0].choices.begin(),changed[0].choices.end(),std::array<uint32_t,2>{999999,chosen[1]})!=changed[0].choices.end(),"custom projector reused stale index");
|
|
choice->option=chosen[0];
|
|
check(c::resolve_appearance(request,copied)==fixture.appearance,"restored custom relation failed");
|
|
check(c::resolve_appearance(request)==fixture.appearance,"custom state leaked into immutable default");
|
|
std::cout<<"Actual3 Tauren Source vectors PASS; male facial0/7 remain held; default allocations="<<cached<<", uncached copy="<<uncached<<"; mutable custom profile remains uncached\n";
|
|
return 0;
|
|
}catch(const std::exception& error){count_allocations=false;std::cerr<<error.what()<<'\n';return 1;}}
|