96 lines
6.8 KiB
Lua
96 lines
6.8 KiB
Lua
-- Real Source terminal headers, native cleanup, and per-generation lifecycle.
|
|
local factory=assert(loadfile(assert(arg[1],"Source Glue adapter required")))();
|
|
local snapshot={generation=1,state=1,error=0,auth_result=0,discovery_result=0,
|
|
cancel=0,server_proof_verified=0,genuine_discovery=0,selected_index=-1,transport_prepared=0};
|
|
local reads,disconnects,loginAttempts=0,0,0;
|
|
local nativeState={auroraState=2,connectedToWoW=false};
|
|
local nativeError=function()return "BNET",1016 end;
|
|
C_Login={GetState=function()return nativeState end,GetLastError=nativeError,
|
|
DisconnectFromServer=function()disconnects=disconnects+1;nativeState.auroraState=0;end,
|
|
Login=function()loginAttempts=loginAttempts+1 end};
|
|
local shown,hidden={},{ };
|
|
StaticPopup_Show=function(kind,message,_,_,_,onHide)shown[#shown+1]={kind=kind,message=message,onHide=onHide};end;
|
|
StaticPopup_Hide=function(kind)hidden[#hidden+1]=kind end;
|
|
local source={Refresh=function()reads=reads+1 end,GetStatus=function()return false end,
|
|
GetLoginStatus=function()return snapshot end};
|
|
local disabled=factory(source,false);disabled.Refresh();
|
|
assert(reads==0 and disabled.GetFailureGeneration()==0 and not disabled.HandleFailure());
|
|
local adapter=factory(source,true);adapter.Refresh();
|
|
assert(not adapter.IsHolding() and adapter.GetFailureGeneration()==0 and not adapter.HandleFailure());
|
|
snapshot.state,snapshot.error,snapshot.auth_result=3,1,-2;adapter.Refresh();
|
|
assert(adapter.GetFailureGeneration()==1 and not adapter.IsPending() and not adapter.IsHolding());
|
|
assert(adapter.HandleFailure() and disconnects==1 and shown[1].kind=="OKAY" and hidden[1]=="CANCEL");
|
|
assert(not shown[1].message:find("password",1,true) and not shown[1].message:find("-2",1,true));
|
|
local acknowledgeFirst=shown[1].onHide;
|
|
for _=1,5 do adapter.Refresh();assert(adapter.HandleFailure());end;
|
|
assert(disconnects==1 and #shown==1 and C_Login.GetLastError==nativeError);
|
|
-- Retirement or a temporarily unavailable snapshot cannot erase the notice.
|
|
snapshot.state,snapshot.error,snapshot.auth_result=0,0,0;adapter.Refresh();
|
|
assert(adapter.GetFailureGeneration()==1 and adapter.HandleFailure());
|
|
acknowledgeFirst();adapter.Refresh();assert(not adapter.HandleFailure() and adapter.GetFailureGeneration()==0);
|
|
snapshot.state,snapshot.error,snapshot.auth_result=3,1,-2;adapter.Refresh();
|
|
assert(not adapter.HandleFailure() and #shown==1,"acknowledged retained failure must not reappear");
|
|
-- A new real generation resets the old notice; stale acknowledgements cannot
|
|
-- dismiss a later failure. No call to Login is made by this adapter.
|
|
snapshot.generation,snapshot.state,snapshot.error,snapshot.auth_result=2,1,0,0;adapter.Refresh();
|
|
assert(adapter.GetFailureGeneration()==0 and not adapter.HandleFailure());
|
|
snapshot.state,snapshot.error=3,4;adapter.Refresh();assert(adapter.HandleFailure());
|
|
assert(disconnects==2 and #shown==2);acknowledgeFirst();
|
|
assert(adapter.GetFailureGeneration()==2 and adapter.HandleFailure());shown[2].onHide();
|
|
assert(adapter.GetFailureGeneration()==0);
|
|
-- Explicit cancellation/closure and a zero or stale generation are not errors.
|
|
snapshot.generation,snapshot.state,snapshot.cancel=3,4,1;adapter.Refresh();assert(not adapter.HandleFailure());
|
|
snapshot.state,snapshot.error=3,1;adapter.Refresh();assert(not adapter.HandleFailure());
|
|
snapshot.generation,snapshot.cancel=0,0;adapter.Refresh();assert(not adapter.HandleFailure());
|
|
snapshot.generation=2;adapter.Refresh();assert(not adapter.HandleFailure());
|
|
assert(disconnects==2 and #shown==2 and loginAttempts==0 and C_Login.GetLastError==nativeError);
|
|
|
|
-- A new chosen generation can arrive without an intervening teardown poll.
|
|
-- Each generation receives its own bounded hold. Older delayed snapshots
|
|
-- cannot replace that state or extend its deadline; real connectivity wins.
|
|
local now=100;
|
|
GetTime=function() return now; end;
|
|
local current={generation=1,state=2,error=0,auth_result=0,discovery_result=0,
|
|
cancel=0,server_proof_verified=1,genuine_discovery=1,selected_index=0,transport_prepared=1};
|
|
local realmSource={Refresh=function() end,GetStatus=function() return true end,
|
|
GetLoginStatus=function() return current end};
|
|
nativeState.connectedToWoW=false;
|
|
local realm=factory(realmSource,true);
|
|
realm.Refresh(); assert(realm.IsHolding());
|
|
now=129;realm.Refresh();assert(realm.IsHolding());
|
|
current.generation=2;now=130;realm.Refresh();
|
|
assert(realm.IsHolding(),"chosen G2 must not inherit chosen G1's expired hold");
|
|
now=159;realm.Refresh();assert(realm.IsHolding(),"G2 receives its own 30 seconds");
|
|
current.generation=1;now=159.5;realm.Refresh();
|
|
assert(realm.IsHolding(),"delayed G1 must not discard G2's current hold");
|
|
nativeState.connectedToWoW=true;realm.Refresh();
|
|
assert(not realm.IsHolding(),"actual native connection releases the hold despite delayed status");
|
|
nativeState.connectedToWoW=false;current.generation=2;now=160;realm.Refresh();
|
|
assert(not realm.IsHolding(),"G2 expires at its own deadline");
|
|
current.generation=1;now=161;realm.Refresh();
|
|
assert(not realm.IsHolding(),"delayed chosen G1 cannot reopen the expired hold");
|
|
current.state,current.selected_index,current.transport_prepared=5,-1,0;realm.Refresh();
|
|
assert(not realm.IsPending() and not realm.IsHolding(),"delayed pending G1 cannot restore its realm view");
|
|
current.generation,current.state,current.selected_index,current.transport_prepared=2,2,0,1;
|
|
now=162;realm.Refresh();
|
|
assert(not realm.IsHolding(),"delayed status must not restart G2's timer");
|
|
current.generation=3;now=163;nativeState.connectedToWoW=true;realm.Refresh();
|
|
assert(not realm.IsHolding(),"a new generation cannot hide real native connectivity");
|
|
-- The Back button disconnects native WoW before Source retires its last chosen
|
|
-- snapshot. Within the original 30-second window, keep the login page available.
|
|
now=164;nativeState.connectedToWoW=false;realm.Refresh();
|
|
assert(not realm.IsHolding(),"Back must not reopen the realm screen for an already connected login");
|
|
-- A temporary gap in snapshots may hide the choice, but cannot start another
|
|
-- thirty-second window for the same login.
|
|
current.generation=4;now=170;realm.Refresh();assert(realm.IsHolding());
|
|
local chosenSnapshot=current;
|
|
current=nil;now=195;realm.Refresh();assert(not realm.IsHolding());
|
|
current=chosenSnapshot;now=202;realm.Refresh();
|
|
assert(not realm.IsHolding(),"a missing snapshot must not renew the generation's deadline");
|
|
-- A real new attempt still waits for its own connection, even to the same realm.
|
|
current.generation=5;now=203;realm.Refresh();assert(realm.IsHolding());
|
|
nativeState.connectedToWoW=true;now=204;realm.Refresh();assert(not realm.IsHolding());
|
|
print("PASS account Back and snapshot gap cannot reopen an old connection hold");
|
|
print("PASS genuine Source failure, native disconnect/OKAY, one notice per generation, acknowledgement and cancellation, no credential retry");
|
|
print("PASS generation-bound connection hold, delayed status rejection, native connected release");
|