Check(convs.size()==2&&convs[1].unread==0&&convs[1].lastDirection==Direction::Outgoing,"our own message never counts as unread");
Check(GroupConversations({}).empty(),"no messages, no conversations");
AppStatuss;
CheckEqual(BannerText(s),"imsd is not running","banner: imsd absent");
s.imsdPresent=true;
CheckEqual(BannerText(s),"Connecting to imsd\u2026","banner: imsd present, GetStatus not answered yet");
Check(!CanSend(s),"cannot send before GetStatus answered");
s.statusKnown=true;
CheckEqual(BannerText(s),"SMS over IMS is off in imsd (SMS_OVER_IMS=0)","banner: off");
s.enabled=true;
s.subscribeDenied=true;
CheckEqual(BannerText(s),"No live updates: imsd refused this session (polkit)","banner: subscribe denied");
s.subscribeDenied=false;
s.subscribeFailed=true;
CheckEqual(BannerText(s),"Not registered with the IMS network","banner: unregistered outranks a failed subscription, being what blocks sending");
AppStatusregisteredToo=s;
registeredToo.registered=true;
Check(CanSend(registeredToo),"a failed subscription leaves sending on: imsd answers a Send to its caller");
CheckEqual(BannerText(registeredToo),"No live updates: imsd did not answer the subscription","banner: subscribe failed, once registered");
s.subscribeFailed=false;
CheckEqual(BannerText(s),"Not registered with the IMS network","banner: unregistered");
s.registered=true;
s.undeletable=1;
CheckEqual(BannerText(s),"imsd still holds 1 message this session may not delete","banner: one undeletable");
s.undeletable=3;
CheckEqual(BannerText(s),"imsd still holds 3 messages this session may not delete","banner: undeletable plural");
s.undeletable=0;
CheckEqual(BannerText(s),"","banner: nothing to say");
s.storeFailed=true;
CheckEqual(BannerText(s),"Cannot save messages (storage full?): texts wait until there is room","banner: the store refused a write");
Check(CanSend(s),"and sending stays on: the send is tried");
s.registered=false;
CheckEqual(BannerText(s),"Not registered with the IMS network","banner: what blocks sending outranks the store's refusal, the line being a refused send's reason");
s.registered=true;
s.subscribeFailed=true;
CheckEqual(BannerText(s),"Cannot save messages (storage full?): texts wait until there is room","banner: the store's refusal outranks a failed subscription: texts wait");
s.subscribeFailed=false;
s.storeFailed=false;
Check(CanSend(s),"can send when present, on, registered");
// The address a text goes to: the typed or linked one, else the latest
// message's, never the key.
Messagein;
in.conversation="+31612345678";
in.peer="+31612345678";
constSimPlankpn{"31","20408"};
constSimPlanvodafoneNl{"31","20404"};
constSimPlantelekomDe{"49","26201"};
in.plan=kpn;
Messageout;
out.conversation="+31612345678";
out.peer="0612345678";
out.plan=kpn;
out.direction=Direction::Outgoing;
conststd::vector<Message>thread={in,out};
CheckEqual(SendAddress("06 12",kpn,thread,kpn),"06 12","the typed or linked address wins");
CheckEqual(SendAddress("",{},thread,kpn),"0612345678","else the latest message's address, as dialled or as the network gave it");
CheckEqual(SendAddress("",{},thread,{}),"0612345678","with no plan known now, as stored");
CheckEqual(SendAddress("",{},thread,telekomDe),"","a national-form peer under another SIM's plan than its row's: no address, Send off");
CheckEqual(SendAddress("",{},thread,vodafoneNl),"0612345678","under another operator of its country it means the same: as stored");
CheckEqual(SendAddress("0612345678",kpn,thread,telekomDe),"","a typed or linked national-form address under another SIM's plan than it was typed under: none either — the view keeps it across the change");
CheckEqual(SendAddress("0612345678",kpn,{},kpn),"0612345678","typed under the plan known now: dialled");
Messageabroad=out;
abroad.plan=telekomDe;
CheckEqual(SendAddress("0612345678",kpn,std::vector<Message>{abroad},kpn),"0612345678","a typed or linked address is judged by its own plan, whatever plan the latest row was written under");
CheckEqual(SendAddress("+31612345678",kpn,thread,telekomDe),"+31612345678","an international address names its own plan: dialled under any SIM");
Messageunplanned;
unplanned.conversation="0612345678";
unplanned.peer="0612345678";
unplanned.direction=Direction::Outgoing;
CheckEqual(SendAddress("",{},std::vector<Message>{unplanned},telekomDe),"0612345678","a row written under no known plan names none: as stored");
Messageclosed;
closed.conversation="+393477123456";
closed.peer="3477123456";
closed.plan={"39","22210"};
CheckEqual(SendAddress("",{},std::vector<Message>{closed},{"1","310260"}),"","a national number of a plan without a trunk prefix under another SIM's plan: none — the row's plan tells");
CheckEqual(SendAddress("",{},std::vector<Message>{closed},{"39","22210"}),"3477123456","and under its own: as stored");
CheckEqual(SendAddress("1234",kpn,{},telekomDe),"","a short code typed under another SIM's plan: none");
CheckEqual(SendAddress("1234",kpn,{},vodafoneNl),"","nor under another operator of the same country: a short code is its operator's");
CheckEqual(SendAddress("1234",{"","20408"},{},kpn),"1234","under the same operator it is dialled, the own number not read when it was typed");
CheckEqual(SendAddress("1234",kpn,{},kpn),"1234","and read when it was typed");
CheckEqual(SendAddress("0612345678",{"","20408"},{},{"44","23410"}),"","a national number typed before the own number was read, under another operator: none — the centre's country is not known to be the SIM's");
CheckEqual(SendAddress("",{},{},kpn),"","an emptied conversation has no address: never its key");