feat: add typed data and views with scoped device power
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package cn.ucvl.zhaodisplay;
|
||||
|
||||
/** Pure Java checks: no transport, credentials, Android runtime or physical power operations. */
|
||||
public class PhonePowerModelTest {
|
||||
static int assertions;
|
||||
static void check(boolean condition,String description){assertions++;if(!condition)throw new AssertionError(description);}
|
||||
static PhonePowerModel power(int run,int op,String state,long at,boolean start,boolean shutdown,boolean managed){return new PhonePowerModel(run,op,state,at,start,shutdown,managed);}
|
||||
public static void main(String[] args){
|
||||
PhonePowerModel online=power(1,0,"online",1000,false,true,true);
|
||||
check(online.run(1045)==1,"fresh online RUN remains observed at TTL boundary");
|
||||
check(online.may(2,1045,false),"fresh explicitly allowed shutdown");
|
||||
check(!online.may(1,1000,false),"online cannot be started even when caller chooses OP1");
|
||||
check(online.run(1046)==-1,"stale RUN must become unknown");
|
||||
check(!online.may(2,1046,false),"stale permission cannot enable shutdown");
|
||||
PhonePowerModel offline=power(0,0,"offline",1000,true,false,true);
|
||||
check(offline.run(1000)==0&&offline.may(1,1000,false),"fresh offline asset allows granted start");
|
||||
check(!offline.may(2,1000,false),"offline cannot be shut down");
|
||||
check(!power(0,0,"offline",1000,false,false,true).may(1,1000,false),"view grant is not control grant");
|
||||
check(!power(1,0,"online",1000,true,true,false).may(2,1000,false),"unmanaged assets cannot receive power commands");
|
||||
check(!online.may(2,1000,true),"in flight request blocks repeated taps");
|
||||
for(int op:new int[]{1,2}){
|
||||
PhonePowerModel pending=power(1,op,"online",1000,true,true,true);
|
||||
check(pending.run(1000)==1,"OP must not infer RUN");
|
||||
check(!pending.may(1,1000,false)&&!pending.may(2,1000,false),"server pending OP blocks further commands");
|
||||
}
|
||||
for(PhonePowerModel invalid:new PhonePowerModel[]{power(-1,0,"unknown",1000,true,true,true),power(0,0,"online",1000,true,true,true),power(1,0,"offline",1000,true,true,true),power(1,0,"online",0,true,true,true),power(1,0,"online",1100,true,true,true),power(1,7,"online",1000,true,true,true)}){
|
||||
check(invalid.run(1000)==-1,"unknown, inconsistent or invalid server state fails closed");
|
||||
check(!invalid.may(1,1000,false)&&!invalid.may(2,1000,false),"invalid state disables both actions");
|
||||
}
|
||||
check(!online.may(0,1000,false)&&!online.may(3,1000,false),"only OP1 and OP2 are executable");
|
||||
|
||||
PhoneHomeSession session=new PhoneHomeSession();
|
||||
session.bind("paired-a",true,1);PhoneHomeSession.Ticket first=session.begin();
|
||||
check(session.accepts(first,"paired-a"),"current paired foreground request accepted");
|
||||
check(!session.accepts(first,"paired-b"),"token supplier change rejects callback before next render");
|
||||
session.bind("paired-a",true,1);check(session.accepts(first,"paired-a"),"same context refresh retains request");
|
||||
PhoneHomeSession.Ticket newer=session.begin();check(!session.accepts(first,"paired-a")&&session.accepts(newer,"paired-a"),"newer request supersedes old response");
|
||||
session.bind("paired-a",true,2);check(!session.accepts(newer,"paired-a"),"tab switch invalidates callbacks");
|
||||
PhoneHomeSession.Ticket tab=session.begin();session.bind("paired-a",false,2);check(!session.accepts(tab,"paired-a"),"pause invalidates callbacks");
|
||||
session.bind("paired-a",true,2);check(!session.accepts(tab,"paired-a"),"resume cannot revive pre-pause response");
|
||||
PhoneHomeSession.Ticket rebound=session.begin();session.bind("paired-b",true,2);check(!session.accepts(rebound,"paired-a")&&!session.accepts(rebound,"paired-b"),"re-pair invalidates old identity");
|
||||
session.bind("",true,2);try{session.begin();throw new AssertionError("unpaired request allowed");}catch(IllegalStateException expected){assertions++;}
|
||||
session.bind("paired-b",false,2);try{session.begin();throw new AssertionError("background request allowed");}catch(IllegalStateException expected){assertions++;}
|
||||
System.out.println("Phone power/session: "+assertions+" assertions passed");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user