883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
51 lines
4.7 KiB
C++
51 lines
4.7 KiB
C++
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
#include "social_translation.hpp"
|
|
#include <cassert>
|
|
#include <iostream>
|
|
using namespace gateway;
|
|
namespace {
|
|
template<class F> void bad(F&& f){bool failed=false;try{f();}catch(const Error&){failed=true;}assert(failed);}
|
|
Bytes friends(){Bytes b;le(b,2,1);le(b,42,8);le(b,2,1);le(b,12,4);le(b,60,4);le(b,1,4);le(b,77,8);le(b,0,1);return b;}
|
|
Bytes ignored(){Bytes b;le(b,2,1);le(b,42,8);le(b,88,8);return b;}
|
|
Bytes remove(Guid128 id,uint32_t realm){Bytes b;le(b,realm,4);append(b,pack_guid(id));return b;}
|
|
Bytes add(std::string name,bool ignore=false,std::string notes={}){
|
|
// Independent ByteBuffer MSB9-bit length oracle; the original reader is
|
|
// exercised additionally by social_original_writer_test.
|
|
Bytes b;size_t at=0;auto bits=[&](uint32_t value,unsigned n){while(n--){if(at%8==0)b.push_back(0);b.back()|=((value>>n)&1)<<(7-at%8);++at;}};
|
|
bits(uint32_t(name.size()),9);if(!ignore)bits(uint32_t(notes.size()),9);else append(b,pack_guid(Guid128{}));
|
|
b.insert(b.end(),name.begin(),name.end());b.insert(b.end(),notes.begin(),notes.end());return b;
|
|
}
|
|
}
|
|
int main(){
|
|
RosterRealm realm;NativeSocialTranslation state;Bytes flags;le(flags,7,4);
|
|
auto early=state.client(NativeContactListRequest,flags,realm);assert(early.held&&early.source.size()==1&&early.native.empty());
|
|
auto f=state.receive(0x67,friends(),realm);assert(f&&f->size()==1&&f->at(0).flags==1&&f->at(0).contacts.size()==2);
|
|
assert(f->at(0).contacts[0].source.guid==42&&f->at(0).contacts[0].source.cls==1);
|
|
auto i=state.receive(0x6b,ignored(),realm);assert(i&&i->at(0).flags==2&&i->at(0).contacts[0].flags==3);
|
|
auto parsed=social_projection_from_input(social_projection_input(i->at(0)));assert(parsed.contacts[0].source.status==2&&parsed.contacts[1].source.cls==0);
|
|
assert(state.contact_name_ids()==std::set<uint64_t>({42,77,88}));
|
|
auto del=state.client(NativeDelFriend,remove(forever_player_guid(42,realm.realm_id),realm.virtual_address),realm);
|
|
assert(del.source.size()==1&&del.source[0].opcode==0x6a);Reader dg(del.source[0].body);assert(dg.le(8)==42);dg.end();assert(state.contact_name_ids().contains(42));
|
|
assert(state.client(NativeDelFriend,remove(forever_player_guid(88,realm.realm_id),realm.virtual_address),realm).held);
|
|
assert(state.client(NativeDelIgnore,remove(forever_player_guid(42,realm.realm_id),realm.virtual_address+1),realm).held);
|
|
assert(state.client(NativeDelIgnore,remove(forever_player_guid(999,realm.realm_id),realm.virtual_address),realm).held);
|
|
auto af=state.client(NativeAddFriend,add("J\xc3\xbcrgen"),realm);assert(af.source.size()==1&&af.source[0].opcode==0x69&&state.contact_name_ids().size()==3);
|
|
assert(state.client(NativeAddFriend,add("Name#1234"),realm).held);
|
|
assert(state.client(NativeAddFriend,add("Name",false,"notes"),realm).held);
|
|
auto ai=state.client(NativeAddIgnore,add("Name",true),realm);assert(ai.source.size()==1&&ai.source[0].opcode==0x6c);
|
|
bad([&]{state.client(NativeAddFriend,add(std::string("a\0b",3)),realm);});
|
|
bad([&]{state.client(NativeAddFriend,add(std::string("\xc0\xaf",2)),realm);});
|
|
bad([&]{auto truncated=friends();truncated.pop_back();state.receive(0x67,truncated,realm);});assert(state.contact_name_ids().size()==3);
|
|
bad([&]{Bytes b;le(b,2,1);for(unsigned j=0;j<2;++j){le(b,99,8);le(b,0,1);}state.receive(0x67,b,realm);});assert(state.contact_name_ids().contains(77));
|
|
Bytes status;le(status,5,1);le(status,42,8);auto removed=state.receive(0x68,status,realm);assert(removed->at(0).contacts[0].source.guid==42&&state.contact_name_ids().contains(42));
|
|
assert(state.client(NativeDelFriend,remove(forever_player_guid(42,realm.realm_id),realm.virtual_address),realm).held);
|
|
assert(!state.client(NativeDelIgnore,remove(forever_player_guid(42,realm.realm_id),realm.virtual_address),realm).held);
|
|
status.clear();le(status,0x10,1);le(status,42,8);state.receive(0x68,status,realm);assert(!state.contact_name_ids().contains(42));
|
|
status.clear();le(status,0x1a,1);le(status,0,8);auto unknown=state.receive(0x68,status,realm);assert(native_friend_result(unknown->at(0).result)==0x1c);social_projection_input(unknown->at(0));
|
|
bad([&]{native_friend_result(0x12);});bad([&]{auto b=friends();b[9]=3;source_friend_list(b);});
|
|
flags.clear();le(flags,3,4);auto refresh=state.client(NativeContactListRequest,flags,realm);assert(!refresh.held&&refresh.source.size()==1&&refresh.native.size()==1&&refresh.native[0].flags==2);
|
|
assert(!state.receive(0x51,{},realm));state.reset();assert(state.contact_name_ids().empty());
|
|
assert(state.client(NativeDelFriend,remove(forever_player_guid(77,realm.realm_id),realm.virtual_address),realm).held);
|
|
std::cout<<"Social Source authority, role lifetimes, original framing bounds and held unsupported semantics PASS\n";
|
|
}
|