// --- start: Subscribe, then GetStatus and List at once -------------------
Check(!sync.Current().imsdPresent&&BannerText(sync.Current())=="imsd is not running","before imsd appears the banner says so");
sync.OnImsdAppeared();
Check(bus.subscribes.size()==1&&bus.statuses.empty()&&bus.lists.empty(),"Subscribe is called first, nothing else yet");
bus.AnswerSubscribe();
Check(sync.Current().subscribed&&bus.statuses.size()==1&&bus.lists.size()==1,"after Subscribe: GetStatus and List at once — a listed text keys itself");
Check(BannerText(sync.Current())=="Connecting to imsd\u2026"&&!CanSend(sync.Current()),"until GetStatus answers the banner says connecting");
bus.AnswerStatus(Online());
Check(sync.Current().enabled&&sync.Current().registered&&sync.Current().smsc=="+447785016005"&&sync.Current().ownNumber=="+31612345678"&&sync.Current().simOperator=="20408","GetStatus fills the status");
Check(sync.CountryCode()=="31","the country code comes from the subscriber's own number, not the foreign service centre's");
Check(sync.Plan()==SimPlan{"31","20408"},"the SIM's plan is that code and the status's operator");
Check(CanSend(sync.Current())&&BannerText(sync.Current()).empty(),"online: no banner, can send");
Check(store.Size()==2&&events.imported.size()==1&&events.imported[0].text=="new","List imports only the text the store lacks");
Check(bus.deletes.size()==2&&bus.deletes[0].first=="ims-sms-in-1-1"&&bus.deletes[1].first=="ims-sms-in-1-2","imsd's copies are deleted, the known one included");
Check(events.imported[0].conversation=="+31621308050"&&!events.imported[0].read,"the import is keyed and unread");
bus.AnswerDelete();
bus.AnswerDelete();
// --- a Received signal: imported once, imsd's copy deleted, a List follows -
Check(store.Size()==3&&events.imported.size()==2&&events.imported[1].conversation=="+31612345678","a signalled text is imported with the country code");
Check(bus.deletes.size()==1&&bus.deletes[0].first=="ims-sms-in-1-3","its copy is deleted");
Check(bus.lists.size()==1,"a List follows the signal");
Check(sync.Current().undeletable==1&&BannerText(sync.Current())=="imsd still holds 1 message this session may not delete","a refused delete is counted and shown");
Check(bus.deletes.size()==1&&bus.deletes[0].first=="ims-sms-in-1-4"&&sync.Current().undeletable==0,"a List admitted tries the refused delete again — one action gates both — and the count is off meanwhile");
Check(bus.deletes.size()==1&&bus.deletes[0].first=="ims-sms-in-1-6"&&store.Size()==6,"a timed-out delete is retried by the next list, without a second import");
bus.AnswerDelete();
// --- a conversation on screen is read at once ---------------------------------
Check(store.Get(ours)&&store.Get(ours)->state==MessageState::Pending&&store.Get(ours)->direction==Direction::Outgoing&&store.Get(ours)->read,"Send stores a pending outgoing message");
Check(bus.sends.size()==1&&bus.sends[0].number=="+31621308050"&&bus.sends[0].text=="hello"&&bus.sends[0].statusReport,"Send asks imsd with a status report");
bus.AnswerSend(std::string("ims-sms-1"));
Check(store.Get(ours)->imsdId=="ims-sms-1","the id is recorded");
Check(!events.changed.empty()&&events.changed.back().id==ours&&events.changed.back().state==MessageState::Delivered,"every step reached the listener");
sync.OnStateChanged("ims-sms-99","sent","");
Check(!events.logs.empty()&&events.logs.back().contains("not on record"),"a state for an unknown id is logged");
sync.OnStateChanged("ims-sms-1","teleported","");
Check(events.logs.back().contains("unknown state")&&store.Get(ours)->state==MessageState::Delivered,"an unknown state is logged and ignored");
// imsd gives the words in order (its §8.4): each applies as it comes, a
// text of several parts included (imsd holds a report on one part until
// the submission ends and posts it after sent).
conststd::uint64_tparts=sync.Send("+31621308050","+31621308050","a text long enough for two parts");
Check(store.Get(parts)->state==MessageState::DeliveryPending&&store.Get(parts)->stateReason=="TP-ST 0x30"&&events.changed.back().state==MessageState::DeliveryPending,"a report's word after sent applies, with its reason, and is announced");
Check(store.Get(parts)->state==MessageState::DeliveryFailed&&store.Get(parts)->stateReason=="TP-ST 0x40","and so does the centre's last word");
// imsd's own failed is the message's last word from imsd (it forgets the
// failed submission's parts): the retry goes under a new id.
conststd::uint64_thalf=sync.Send("+31621308050","+31621308050","two parts, the second refused");
bus.AnswerSend(std::string("ims-sms-45"));
sync.OnStateChanged("ims-sms-45","failed","segment 2/2 refused by the SC: RP cause 38");
Check(store.Get(half)->state==MessageState::Failed&&store.Get(half)->stateReason=="segment 2/2 refused by the SC: RP cause 38","imsd's failed applies with its reason");
sync.Retry(half);
Check(store.Get(half)->state==MessageState::Pending&&store.Get(half)->imsdId.empty()&&bus.sends.size()==1,"the retry submits it again, without the failed attempt's id");
bus.AnswerSend(std::string("ims-sms-46"));
sync.OnStateChanged("ims-sms-46","sent","");
sync.OnStateChanged("ims-sms-46","delivered","");
Check(store.Get(half)->state==MessageState::Delivered,"sent and delivered under the new id");
// A retry that never reaches imsd: the failed attempt's id leaves the
// row with the retry, so a word under it (none is due: imsd forgot the
// attempt) finds no row.
conststd::uint64_tagain=sync.Send("+31621308050","+31621308050","two parts, retried while unregistered");
bus.AnswerSend(std::string("ims-sms-47"));
sync.OnStateChanged("ims-sms-47","failed","segment 2/2 refused by the SC: RP cause 38");
sync.OnRegistrationChanged(false);
sync.Retry(again);
Check(store.Get(again)->state==MessageState::Failed&&store.Get(again)->imsdId.empty()&&bus.sends.empty(),"a retry while unregistered fails locally, without the old attempt's id");
Check(store.Get(again)->state==MessageState::Failed&&events.logs.back().contains("not on record"),"the old attempt's late report finds no row: the failed and its retry stay");
sync.OnRegistrationChanged(true);
bus.AnswerStatus(Online());
bus.AnswerStatus(Online());
sync.Retry(again);
Check(store.Get(again)->state==MessageState::Pending&&bus.sends.size()==1,"registered again, the retry goes to imsd");
bus.AnswerSend(std::string("ims-sms-48"));
sync.OnStateChanged("ims-sms-48","sent","");
Check(store.Get(again)->state==MessageState::Sent,"under its new id");
// --- the destination is the address as dialled; the key groups --------------------
conststd::uint64_tdialled=sync.Send("+31612345678","0612345678","to the number as typed");
Check(bus.sends.size()==1&&bus.sends[0].number=="0612345678"&&store.Get(dialled)->peer=="0612345678"&&store.Get(dialled)->conversation=="+31612345678","imsd is asked for the address as dialled; the key only groups");
bus.AnswerSend(std::string("ims-sms-5"));
sync.OnStateChanged("ims-sms-5","sent","");
Check(store.Get(dialled)->state==MessageState::Sent,"and the state lands under the key");
// --- a failed send and its retry ----------------------------------------------------
Check(store.Get(failed)->state==MessageState::Failed&&store.Get(failed)->stateReason=="no reply","a send error fails the message with the reason");
sync.Retry(failed);
Check(store.Get(failed)->state==MessageState::Pending&&bus.sends.size()==1&&bus.sends[0].text=="again","Retry submits the same message again");
bus.AnswerSend(std::string("ims-sms-2"));
sync.OnStateChanged("ims-sms-2","failed","RP-ERROR cause 38");
Check(store.Get(failed)->state==MessageState::Failed&&store.Get(failed)->stateReason=="RP-ERROR cause 38","imsd's failed state lands with its reason");
sync.Retry(ours);
Check(bus.sends.empty(),"a delivered message cannot be retried");
// --- registration and imsd vanishing ---------------------------------------------
sync.OnRegistrationChanged(false);
Check(!CanSend(sync.Current())&&BannerText(sync.Current())=="Not registered with the IMS network","unregistered: banner, no send");
Check(bus.statuses.size()==1,"an unregistration reads the status again too: an answer on its way may carry the state before the signal");
Check(store.Get(refused)->state==MessageState::Failed&&store.Get(refused)->stateReason=="Not registered with the IMS network"&&bus.sends.empty(),"a send while unregistered fails at once with the banner's reason");
Statusunregistered=Online();
unregistered.registered=false;
bus.AnswerStatus(unregistered);
Check(!sync.Current().registered,"the re-read keeps the unregistered state");
sync.OnRegistrationChanged(true);
Check(bus.statuses.size()==1,"a registration reads the status again");
Check(store.Get(inFlight)->state==MessageState::Failed&&store.Get(inFlight)->stateReason=="imsd stopped before confirming","imsd vanishing fails the message in flight");
Check(!sync.Current().imsdPresent&&BannerText(sync.Current())=="imsd is not running","vanished: the banner says so");
// --- imsd back: Subscribe again; a refused Subscribe is the degraded mode -----------
sync.OnImsdAppeared();
Check(bus.subscribes.size()==1,"Subscribe again when imsd reappears");
bus.AnswerSubscribe(Error(BusError::Kind::AccessDenied,"not the active session"));
Check(sync.Current().subscribeDenied&&!sync.Current().subscribed,"a refused Subscribe is remembered");
bus.AnswerStatus(Online());
Check(BannerText(sync.Current())=="No live updates: imsd refused this session (polkit)"&&!CanSend(sync.Current()),"the degraded banner wins over an online status");
Check(bus.lists.size()==1,"List is still tried");
bus.AnswerList(std::unexpected(Error(BusError::Kind::AccessDenied,"not the active session")));
Check(events.logs.back().contains("List failed"),"a refused List is logged");
// The session active again: Refresh (main's 30 s timer, RefreshWanted)
// subscribes again, and an admitted Subscribe ends the degraded mode.
Check(sync.RefreshWanted(),"a refusal wants a refresh");
sync.Refresh();
Check(bus.subscribes.size()==1,"Refresh subscribes again after a refused Subscribe");
sync.Refresh();
Check(bus.subscribes.size()==1,"and not again over that one unanswered: a rule that prompts is asked once");
bus.AnswerSubscribe();
Check(sync.Current().subscribed&&!sync.Current().subscribeDenied,"admitted: the degraded mode ends");
bus.AnswerStatus(Online());
Check(CanSend(sync.Current())&&BannerText(sync.Current()).empty()&&bus.lists.size()==1,"sending is on again and the list is read");
// A List refused while subscribed is the degraded mode too; the next
// List answered lifts it.
bus.AnswerList(std::unexpected(Error(BusError::Kind::AccessDenied,"not the active session")));
Check(sync.Current().subscribeDenied&&!CanSend(sync.Current())&&sync.RefreshWanted(),"a refused List turns sending off and wants a refresh");
sync.Refresh();
Check(bus.lists.size()==1,"Refresh lists again");
conststd::size_tannounced=events.statuses.size();
bus.AnswerList(std::unexpected(Error(BusError::Kind::AccessDenied,"not the active session")));
Check(events.statuses.size()==announced+1&&sync.RefreshWanted(),"refused again: announced again, and a refresh is still wanted");
sync.Refresh();
Check(bus.lists.size()==1,"and Refresh lists once more");
bus.AnswerList(std::vector<ReceivedMessage>{});
Check(!sync.Current().subscribeDenied&&CanSend(sync.Current()),"a List answered ends it");
// --- what failed is tried again: a Subscribe that timed out, a GetStatus that failed -------
Check(retrying.Current().subscribeFailed&&!retrying.Current().subscribed&&!retrying.Current().subscribeDenied,"a Subscribe that timed out is a failure, not the refusal");
Check(retrying.RefreshWanted()&&events5.statuses.size()==told+1&&!retrying.Current().subscribeDenied,"a List that timed out wants a refresh, and says so: the texts imsd holds are asked for again");
retrying.Refresh();
Check(bus5.lists.size()==1&&bus5.subscribes.empty()&&bus5.statuses.empty(),"Refresh lists again, and nothing else");
bus5.AnswerList(std::vector<ReceivedMessage>{Text("ims-sms-in-5-1","+31621308050","held by imsd",1200)});
Check(!retrying.RefreshWanted()&&events5.imported.size()==1,"answered: the held text is imported and no refresh is wanted");
bus5.AnswerDelete();
retrying.OnRegistrationChanged(true);
Check(bus5.statuses.size()==1&&bus5.subscribes.empty(),"a registration reads the status again");
StatuscentreOnly=Online();
centreOnly.ownNumber="";
bus5.AnswerStatus(centreOnly);
Check(retrying.CountryCode()=="44"&&retrying.Plan().code.empty(),"without an own number the service centre's code stands in for a key, and the plan has no code");
retrying.OnRegistrationChanged(true);
bus5.AnswerStatus(Online());
Check(retrying.CountryCode()=="31"&&retrying.Plan().code=="31","the own number, once read, gives the code, and it is the plan's");
retrying.OnRegistrationChanged(true);
bus5.AnswerStatus(centreOnly);
Check(retrying.CountryCode()=="44"&&retrying.Plan().code.empty(),"a read without it: the centre's stands in again and the plan has no code (imsd gives both from one snapshot, so a number it has is never missing)");
Check(retrying.RefreshWanted()&&retrying.Current().statusKnown,"a later GetStatus failure keeps what was known and wants a refresh");
retrying.Refresh();
Check(bus5.statuses.size()==1&&bus5.lists.size()==1,"Refresh reads the status and the list again");
bus5.AnswerStatus(Online());
bus5.AnswerList(std::vector<ReceivedMessage>{});
Check(!retrying.RefreshWanted(),"and nothing is wanted once both answered");
fs::remove_all(retryDir);
}
// --- a restart: a pending send of an earlier run is failed at start; a late word applies ---
Messagestale;
stale.conversation="+31621308050";
stale.direction=Direction::Outgoing;
stale.text="from an earlier run";
stale.state=MessageState::Pending;
stale.imsdId="ims-sms-8";
conststd::uint64_tstaleId=*store.Add(stale);
{
Fakebus2;
Recorderevents2;
Syncsync2(store,bus2,events2,"");
Check(sync2.CountryCode().empty(),"without imsd no country code is assumed: the store's correspondents do not say where the subscriber is, and a typed national number stays national");
Check(store.Get(staleId)->state==MessageState::Failed&&store.Get(staleId)->stateReason=="the app stopped before imsd confirmed it","a pending message from an earlier run is failed at start");
sync2.OnStateChanged("ims-sms-3","sent","late");
Check(store.Get(inFlight)->state==MessageState::Sent,"a state for an id found in the store is applied after a restart");
plan.OnStateChanged("ims-sms-plan-2","failed","RP-ERROR cause 38");
Check(planStore.Get(national)->plan==SimPlan{"31","20408"}&&planStore.Get(shortCode)->plan==SimPlan{"31","20408"},"a sent row records the SIM's plan: the code and the operator");
StatusstandIn=Online();
standIn.ownNumber="";
plan.OnRegistrationChanged(true);
bus9.AnswerStatus(standIn);
Check(plan.Plan()==SimPlan{"","20408"}&&plan.CountryCode()=="44","the same SIM with its own number unread: the centre's code stands in for a key, and the plan has none");
plan.Retry(shortCode);
Check(bus9.sends.size()==1&&bus9.sends[0].number=="1234","under the same operator the plan is the same, its code known or not: the retry goes");
bus9.AnswerSend(std::string("ims-sms-plan-3"));
plan.OnStateChanged("ims-sms-plan-3","failed","RP-ERROR cause 38");
StatusotherOperator=Online();
otherOperator.simOperator="20404";
plan.OnRegistrationChanged(true);
bus9.AnswerStatus(otherOperator);
plan.Retry(shortCode);
Check(planStore.Get(shortCode)->state==MessageState::Failed&&planStore.Get(shortCode)->stateReason=="the number was dialled under another SIM's plan: send it again"&&bus9.sends.empty(),"a short code is its operator's: under another operator of the same country a retry sends nothing and says why");
plan.Retry(national);
Check(bus9.sends.size()==1&&bus9.sends[0].number=="0612345678","a national number means the same under another operator of its country: the retry goes");
bus9.AnswerSend(std::string("ims-sms-plan-4"));
plan.OnStateChanged("ims-sms-plan-4","failed","RP-ERROR cause 38");
Statusabroad=Online();
abroad.ownNumber="+4915112345678";
abroad.simOperator="26201";
plan.OnRegistrationChanged(true);
bus9.AnswerStatus(abroad);
Check(plan.Plan()==SimPlan{"49","26201"},"another country's SIM: another code and another operator");
plan.Retry(national);
Check(planStore.Get(national)->state==MessageState::Failed&&planStore.Get(national)->stateReason=="the number was dialled under another SIM's plan: send it again"&&bus9.sends.empty(),"a retry of a national number under another SIM's plan sends nothing and says why");
fs::remove_all(planDir);
}
// --- a text keys itself by the number it arrived for: imported at once, before any status ----------
Check(events11.imported.size()==1&&events11.imported[0].conversation=="+49612345678"&&events11.imported[0].plan==SimPlan{"49","26201"}&&earlyStore.Size()==1,"a text signalled before the status's answer is imported at once, keyed and planned by the number it arrived for and the SIM it arrived under");
earlySync.OnReceived(Text("ims-sms-in-11-2","0612345678","no own number at receipt",1301));
Check(events11.imported.size()==2&&events11.imported[1].conversation=="+31612345678"&&events11.imported[1].plan==SimPlan{},"one that arrived under no own number: keyed by the centre that delivered it, and no code in its plan");
Check(silentStore.Size()==1&&events12.imported.size()==1&&events12.imported[0].text=="a text","a short message type 0 is neither stored nor announced");
Check(bus12.deletes.size()==2&&bus12.deletes[0].first=="ims-sms-in-12-1","and imsd's copy of it is deleted like any other");
bus12.AnswerDelete();
bus12.AnswerDelete();
silent.imsdId="ims-sms-in-12-3";
silentSync.OnReceived(silent);
Check(silentStore.Size()==1&&events12.imported.size()==1&&bus12.deletes.size()==1&&bus12.deletes[0].first=="ims-sms-in-12-3","one that comes as a signal: the same");
fs::remove_all(silentDir);
}
// --- a listener throwing out of a word is caught and told; no step of the sequence is lost ----------
{
structThrower:Recorder{
boolonStatus=false;
boolonLog=false;
voidOnStatus(constAppStatus&s)override{
Recorder::OnStatus(s);
if(std::exchange(onStatus,false))throwstd::runtime_error("a status handler's");
Check(bus13.subscribes.size()==1&&events13.logs.back()=="a listener threw: a status handler's","a throw out of OnStatus at the appearance is caught and told: Subscribe went out");
events13.onLog=true;
bus13.AnswerSubscribe(Error(BusError::Kind::AccessDenied,"not the active session"));
Check(bus13.statuses.size()==1&&bus13.lists.size()==1&&events13.logs.back()=="a listener threw: a log line's","a throw out of OnLog at a refused Subscribe: the status and the List are asked for all the same");
bus13.AnswerStatus(Online());
bus13.AnswerList(std::vector<ReceivedMessage>{});
events13.onStatus=true;
throwing.OnRegistrationChanged(true);
Check(bus13.statuses.size()==1&&events13.logs.back()=="a listener threw: a status handler's","a throw out of OnStatus at a registration change: the status is read again");
bus13.AnswerStatus(Online());
events13.onStatus=true;
events13.onLog=true;
throwing.OnImsdVanished();
Check(!throwing.Current().imsdPresent&&events13.logs.back()=="a listener threw: a status handler's","a word of the fault that throws too is dropped, and the vanish went through");
// A store that refused before a Sync was made on it: the
// constructor's status goes through the guard as every word does.
Check(late.Current().storeFailed&&events14.statuses.size()==1&&events14.logs.back()=="a listener threw: a status handler's","a throw out of OnStatus at the constructor, over a store that refuses: caught and told");
Check(seen==std::vector<MessageState>{MessageState::Pending,MessageState::Sent,MessageState::DeliveryPending}&&errandStore.Get(sent)->state==MessageState::DeliveryPending,"imsd's words reach the listener as the message's changes, as they come, and the store follows them");
// Unregistered: a send fails at once, a forced one goes to imsd.
Check(bus3.sends.size()==1&&bus3.sends[0].text=="forced","a forced send goes to imsd all the same");
bus3.AnswerSend(std::unexpected(Error(BusError::Kind::Other,"imsd is not registered")));
Check(errandStore.Get(forced)->state==MessageState::Failed&&errandStore.Get(forced)->stateReason=="imsd is not registered","and fails with imsd's reason");
Check(fullStore.Refused()&&full.Current().storeFailed&&full.RefreshWanted()&&announced>0&&events8.statuses.back().storeFailed&&events8.logs.back().contains("the store refused a write"),"the store's refusal reaches the status: the banner's flag, a Refresh wanted, the log");
conststd::stringlongText(4096,'y');// the room left after the filler holds no text of this size (a short one might still fit)
Check(full.Send("+31621308050","+31621308050",longText)==Sync::kNotStored&&bus8.sends.empty()&&events8.statuses.size()==announced,"a send the store refused answers kNotStored and asks imsd nothing");
full.OnImsdVanished();
full.OnImsdAppeared();
bus8.AnswerSubscribe();
bus8.AnswerStatus(Online());
bus8.AnswerList(std::vector<ReceivedMessage>{});
Check(full.Current().storeFailed&&full.RefreshWanted(),"imsd's restart does not forget the store's refusal: the flag is the store's");
full.Refresh();// what main's 30 s timer does while a Refresh is wanted
Check(bus8.deletes.empty()&&events8.imported.empty()&&events8.unstored.empty()&&full.Current().storeFailed&&full.RefreshWanted(),"an import the store refused leaves imsd's copy: nothing deleted, nothing announced — a listed text is not held —, the banner still up and a Refresh still wanted");
// A short text fits the room the store has (every string inline, a
// row slot free): it goes, the flag standing — nothing grew — and
Check(shortOne!=Sync::kNotStored&&bus8.sends.size()==1&&full.Current().storeFailed&&full.RefreshWanted(),"a short text's row fits: it goes to imsd, and the flag stands, nothing having grown");
Check(fullStore.Get(shortOne)->state==MessageState::Sent&&fullStore.Get(shortOne)->stateReason.empty(),"imsd's word lands: the id names the row, the state in place, its reason (needing room) not");
// A failed attempt's id goes at the retry, in place: imsd's words for
// the new attempt name the row, the old one's none.
full.OnStateChanged("ims-sms-8a1b2c3d-1793559285-2","failed","RP-ERROR cause 38");
Check(fullStore.Get(retried)->state==MessageState::Failed&&fullStore.Get(retried)->imsdId=="ims-sms-8a1b2c3d-1793559285-2","a short text's failed word lands on its row");
full.Retry(retried);
Check(bus8.sends.size()==1&&fullStore.Get(retried)->state==MessageState::Pending&&fullStore.Get(retried)->imsdId.empty(),"the retry goes to imsd, the failed attempt's id dropped in place");
Check(fullStore.Get(retried)->state==MessageState::Pending&&events8.logs.back().contains("not on record"),"the failed attempt's id went with the retry: its late word names no row");
Check(went!=Sync::kNotStored&&bus8.sends.size()==1&&!full.Current().storeFailed&&!full.RefreshWanted()&&!events8.statuses.back().storeFailed,"room again: the send's own write grows the file, clears the flag, and the text goes to imsd");
Check(fullStore.Get(shortOne)->imsdId=="ims-sms-8a1b2c3d-1793559285-1"&&fullStore.Get(retried)->imsdId=="ims-sms-8a1b2c3d-1793559285-3","the ids stand as recorded in place — the retry's, not the failed attempt's");
Check(bus8.lists.size()==1,"and the recovery lists at once: the held texts wait for no timer");
Check(events8.imported.size()==1&&bus8.deletes.size()==1&&bus8.deletes[0].first=="ims-sms-in-8-1","and the held text is imported and deleted at that List");
Check(sent&&sent->code==0&&sent->caption=="Sent"&&sent->reason=="2026-11-01T22:00:00+01:00"&&e.Done(),"sent: 0, imsd's caption and reason");
Check(!e.TimedOut("60 s").has_value()&&!e.NoFinalState("ended before a final state").has_value(),"a final state given first stands: the clock and the loop's end after it change nothing");
own.state=MessageState::Failed;
Check(!e.Changed(own).has_value(),"and over a later word");
Check(re&&re->code==1&&re->caption=="Failed"&&re->reason=="the store did not take the text"&&refused.Done(),"a store that refused the text: 1, ended");
Check(tw&&tw->code==2&&tw->caption=="no final state within 60 s"&&!waiting.TimedOut("60 s").has_value(),"the clock after the Send, before imsd's id: 2, no final state — once");
SendErrandtaken;
taken.SendDue(s);
taken.Sent(5);
Messaget;
t.id=5;
t.state=MessageState::Pending;
t.imsdId="ims-sms-5";
Check(!taken.Changed(t).has_value()&&!taken.TimedOut("60 s").has_value()&&!taken.Done(),"the clock once imsd has taken the text decides nothing: imsd bounds its submission itself");
Check(reStore.Refused(),"the store refused a write");
setrlimit(RLIMIT_FSIZE,&before);// room again: the errand's own write will grow the file and tell of the recovery, from inside Send
reSync.OnImsdAppeared();
bus10.AnswerSubscribe();
bus10.AnswerStatus(Online());
Check(events10.sends==1&&bus10.sends.size()==1&&!reStore.Refused()&&!events10.errand.Done(),"the status announced from inside the errand's Send makes no second Send: one text to imsd");
Check(events13.imported.empty()&&events13.unstored.size()==1&&events13.unstored[0].text==longText&&events13.unstored[0].imsdId=="ims-sms-in-13-1"&&!events13.unstored[0].read&&bus13.deletes.empty()&&holding.RefreshWanted(),"a signalled text the store refuses is told as unstored — unread, its conversation open — and held: nothing imported, nothing deleted, a Refresh wanted");
holding.SetOpenConversation(std::nullopt);
bus13.AnswerList(std::vector<ReceivedMessage>{});// the signal's List: imsd does not hold the text either
holding.Refresh();
bus13.AnswerList(std::vector<ReceivedMessage>{});
Check(events13.unstored.size()==1&&events13.imported.empty()&&!heldStore.FindByImsdId("ims-sms-in-13-1"),"tried again at a List's answer and at a Refresh while the store refuses: still held, told once");
setrlimit(RLIMIT_FSIZE,&before);
holding.Refresh();
Check(events13.imported.size()==1&&events13.imported[0].text==longText&&events13.imported[0].imsdId=="ims-sms-in-13-1"&&heldStore.FindByImsdId("ims-sms-in-13-1")&&!holding.Current().storeFailed,"room again: the held text is stored at the next Refresh, and the store's flag clears");
Check(bus13.deletes.size()==1&&bus13.deletes[0].first=="ims-sms-in-13-1","its delete goes to imsd as any import's");
bus13.AnswerDelete(Error(BusError::Kind::NotFound,"no stored message ims-sms-in-13-1"));// imsd never stored it
bus13.AnswerList(std::vector<ReceivedMessage>{});// the recovery's List
bus13.AnswerList(std::vector<ReceivedMessage>{});// the Refresh's own, asked while that one was in flight
Check(events13.imported.size()==1&&bus13.lists.empty()&&!holding.RefreshWanted(),"stored once, and no Refresh is wanted any more");
// A held text a List does carry is imsd's to keep after all: the
// copy held here goes, and the text comes in by the List.
Check(events13.imported.size()==1&&events13.unstored.size()==2&&bus13.deletes.empty(),"a List carried it while the store refused: imsd holds it, the copy held here is dropped, and a Refresh's retry imports nothing");
Check(events13.imported.size()==2&&events13.imported[1].imsdId=="ims-sms-in-13-2"&&bus13.deletes.size()==1&&bus13.deletes[0].first=="ims-sms-in-13-2","and the next List imports it and deletes imsd's copy");
// A text is held and the store gets room by another write: until
// the List the recovery sends is answered the text is still held,
bus13.AnswerList(std::vector<ReceivedMessage>{});// the signal's List
setrlimit(RLIMIT_FSIZE,&third);
conststd::uint64_tsent=holding.Send("+31621308050","+31621308050",longText);// grows the file: the store's recovery, told from inside the send
Check(sent!=Sync::kNotStored&&!holding.Current().storeFailed&&events13.imported.size()==2&&holding.RefreshWanted(),"the store writes again by a send's own row: the text is still held, and a Refresh is wanted for it alone");
bus13.AnswerList(std::vector<ReceivedMessage>{});// the recovery's List
Check(events13.imported.size()==3&&events13.imported[2].imsdId=="ims-sms-in-13-3"&&!holding.RefreshWanted(),"the recovery's List answered: the held text is stored, and no Refresh is wanted");