main, utilities: bench helpers and a fake imsd
--prefill types into the opened conversation's field (App::Prefill, the bench's typing, comes with it), --send-draft taps Send 1.5 s after start and --screenshot-after chooses the moment of the capture, so a machine can exercise the compose path and look at the result; --prefill and --send-draft are window flags as --screenshot is — refused beside --send and --quit, and beside a running instance (--screenshot-after acts through --screenshot, refused there, its seconds checked as --quit-after's are) — and a --prefill text that is not UTF-8 is refused as --send's is. utilities/fake-imsd.py owns net.catcrafts.IMS1 on the session bus with the answers chosen on its command line: a registered daemon (its GetStatus answers name the subscriber's number, --ppi; the Messaging one and every text the SIM's operator, --operator) that accepts sends and reports them sent (the stamp in imsd's ISO 8601 form, at the host's offset) and delivered, a store to list and delete, texts injected at start or delivered as unicast Received while the app runs, the refusals (AccessDenied, NotSupported, failed sends) and a Subscribe answered late (--subscribe-delay: the app before imsd's status is in). It runs on the host (python3-gi), the app in the sandbox, both on the same session bus.
This commit is contained in:
parent
efd8dd92d3
commit
8a03a4ed49
4 changed files with 164 additions and 5 deletions
|
|
@ -46,7 +46,10 @@ struct Options {
|
|||
std::optional<std::string> uri;
|
||||
std::optional<fs::path> dataDir;
|
||||
std::optional<fs::path> screenshot;
|
||||
double screenshotAfter = 2.5; // seconds after start
|
||||
std::optional<double> quitAfter; // seconds
|
||||
std::optional<std::string> prefill; // typed into the opened conversation's field
|
||||
bool sendDraft = false; // and sent, as if the button were tapped
|
||||
std::string country;
|
||||
std::string error;
|
||||
};
|
||||
|
|
@ -56,7 +59,7 @@ struct Options {
|
|||
// a running instance, whose window is not this one. What configures a
|
||||
// process (its store, its country code) is not among them: beside a
|
||||
// running instance that instance's own stands.
|
||||
bool WindowFlags(const Options& o) { return o.screenshot.has_value(); }
|
||||
bool WindowFlags(const Options& o) { return o.screenshot || o.prefill || o.sendDraft; }
|
||||
|
||||
// A bench clock's seconds, which its timer takes as a guint of
|
||||
// milliseconds: what is not such a number is the error.
|
||||
|
|
@ -83,7 +86,10 @@ Options Parse(std::span<const char* const> args) {
|
|||
i += 2;
|
||||
} else if (a == "--data-dir" && i + 1 < args.size()) o.dataDir = fs::path(args[++i]);
|
||||
else if (a == "--screenshot" && i + 1 < args.size()) o.screenshot = fs::path(args[++i]);
|
||||
else if (a == "--screenshot-after" && i + 1 < args.size()) o.screenshotAfter = Seconds(a, args[++i], o.error);
|
||||
else if (a == "--quit-after" && i + 1 < args.size()) o.quitAfter = Seconds(a, args[++i], o.error);
|
||||
else if (a == "--prefill" && i + 1 < args.size()) o.prefill = args[++i];
|
||||
else if (a == "--send-draft") o.sendDraft = true;
|
||||
else if (a == "--country" && i + 1 < args.size()) o.country = args[++i];
|
||||
else if (IsSmsUri(a)) o.uri = std::string(a);
|
||||
else o.error = std::format("unknown argument: {}", a);
|
||||
|
|
@ -95,6 +101,7 @@ Options Parse(std::span<const char* const> args) {
|
|||
const auto utf8 = [](const std::string& s) { return g_utf8_validate(s.data(), static_cast<gssize>(s.size()), nullptr) != FALSE; };
|
||||
if (o.send && !(utf8(o.send->first) && utf8(o.send->second))) o.error = "--send: NUMBER and TEXT have to be UTF-8";
|
||||
if (o.uri && !utf8(*o.uri)) o.error = "the sms: link has to be UTF-8";
|
||||
if (o.prefill && !utf8(*o.prefill)) o.error = "--prefill: the text has to be UTF-8";
|
||||
// A country code as the ITU's length rule reads one (none begins with 0,
|
||||
// and CountryCodeOf gives it back from a number that begins with it): a
|
||||
// completed key is made of it as it is, and read by that rule.
|
||||
|
|
@ -264,7 +271,7 @@ int main(int argc, char** argv) {
|
|||
return 0;
|
||||
}
|
||||
if (o.help) {
|
||||
std::println("imsd-messages [--daemon|--headless] [--send NUMBER TEXT] [--quit] [--session] [--data-dir DIR] [--country CC] [--screenshot FILE.png] [--quit-after SECONDS] [sms:NUMBER] [--version]");
|
||||
std::println("imsd-messages [--daemon|--headless] [--send NUMBER TEXT] [--quit] [--session] [--data-dir DIR] [--country CC] [--screenshot FILE.png] [--screenshot-after SECONDS] [--quit-after SECONDS] [--prefill TEXT] [--send-draft] [sms:NUMBER] [--version]");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -381,6 +388,7 @@ int main(int argc, char** argv) {
|
|||
const std::string recipient = SmsUriRecipient(*o.uri);
|
||||
const std::string key = ConversationKey(recipient, sync.CountryCode());
|
||||
if (!key.empty()) app->Open(key, DialledNumber(recipient));
|
||||
if (o.prefill) app->Prefill(*o.prefill);
|
||||
} else if (!o.daemon) {
|
||||
app->Show();
|
||||
}
|
||||
|
|
@ -394,8 +402,14 @@ int main(int argc, char** argv) {
|
|||
g_main_loop_unref(loop);
|
||||
return 1;
|
||||
}
|
||||
// The screenshot renders and saves without the compositor, 2.5 s after
|
||||
// start (600 ms later where the window has to be made first).
|
||||
// The bench's tap on Send, 1.5 s after start.
|
||||
if (o.sendDraft) g_timeout_add(1500, [](gpointer data) -> gboolean {
|
||||
static_cast<Ui::App*>(data)->SendDraft();
|
||||
return G_SOURCE_REMOVE;
|
||||
}, &*app);
|
||||
// The screenshot renders and saves without the compositor,
|
||||
// --screenshot-after seconds after start (600 ms later where the
|
||||
// window has to be made first).
|
||||
struct ScreenshotJob {
|
||||
Ui::App* app;
|
||||
fs::path path;
|
||||
|
|
@ -403,7 +417,7 @@ int main(int argc, char** argv) {
|
|||
std::optional<ScreenshotJob> screenshotJob;
|
||||
if (o.screenshot) {
|
||||
screenshotJob.emplace(&*app, *o.screenshot);
|
||||
g_timeout_add(2500, [](gpointer data) -> gboolean {
|
||||
g_timeout_add(static_cast<guint>(o.screenshotAfter * 1000), [](gpointer data) -> gboolean {
|
||||
ScreenshotJob& job = *static_cast<ScreenshotJob*>(data);
|
||||
job.app->ScreenshotThenQuit(job.path);
|
||||
return G_SOURCE_REMOVE;
|
||||
|
|
|
|||
Loading…
Reference in a new issue