test: a fixture that cannot fail needs no guard

ximbegin took a struct ct* only to USED() it and always returned 1, so
its seven `if(!ximbegin(...)) goto cleanup;` call sites tested nothing
and three of the cleanup labels they jumped to were unreachable.
ibusbegin malloc'd one byte twice so that its two fake DBusConnections
would differ by address, then CT_CHECKed the mallocs; two bytes in the
fixture are two addresses, and nothing has to be freed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-18 16:16:02 +09:00
parent bdf05e3c4a
commit 591029237e
2 changed files with 19 additions and 36 deletions

View File

@@ -13,6 +13,8 @@ struct Ibusfix
{
Channel *oldreply;
Pump pump;
/* A fake connection is nothing but an address to tell two apart. */
char fake[2];
DBusConnection *c1;
DBusConnection *c2;
};
@@ -81,8 +83,8 @@ cleanup:
CT_CHECK(t, rmdir(root) == 0);
}
static int
ibusbegin(struct ct *t, Ibusfix *f)
static void
ibusbegin(Ibusfix *f)
{
Drawcmd dc;
@@ -97,9 +99,8 @@ ibusbegin(struct ct *t, Ibusfix *f)
f->oldreply = replyc;
replyc = chancreate(sizeof(Keyres), 0);
pumpstart(&f->pump, Maxcontexts);
f->c1 = malloc(1);
f->c2 = malloc(1);
return CT_CHECK(t, f->c1 != nil && f->c2 != nil);
f->c1 = (DBusConnection*)&f->fake[0];
f->c2 = (DBusConnection*)&f->fake[1];
}
static void
@@ -119,8 +120,6 @@ ibusend(Ibusfix *f)
testengineinit(LangEN);
while(channbrecv(drawc, &dc) > 0)
;
free(f->c1);
free(f->c2);
chanfree(replyc);
replyc = f->oldreply;
}
@@ -168,8 +167,7 @@ ibus_capability_policy(struct ct *t)
Ictx *a, *b;
Keyres res;
if(!ibusbegin(t, &f))
goto cleanup;
ibusbegin(&f);
a = newcontext(f.c1, "/context/cap-a");
b = newcontext(f.c2, "/context/cap-b");
if(!CT_CHECK(t, a != nil && b != nil))
@@ -223,8 +221,7 @@ ibus_private_input_policy(struct ct *t)
char text[Maxutf];
int i;
if(!ibusbegin(t, &f))
goto cleanup;
ibusbegin(&f);
ctx = newcontext(f.c1, "/context/private");
if(!CT_CHECK(t, ctx != nil))
goto cleanup;
@@ -274,8 +271,7 @@ ibus_context_lifecycle(struct ct *t)
Caret at;
char text[Maxutf];
if(!ibusbegin(t, &f))
goto cleanup;
ibusbegin(&f);
a = newcontext(f.c1, "/context/one");
b = newcontext(f.c2, "/context/one");
if(!CT_CHECK(t, a != nil && b != nil && a != b))
@@ -387,8 +383,7 @@ ibus_active_release_lifecycle(struct ct *t)
Ictx *ctx, *reused;
Keyres res;
if(!ibusbegin(t, &f))
goto cleanup;
ibusbegin(&f);
ctx = newcontext(f.c1, "/context/reset");
if(!CT_CHECK(t, ctx != nil))
goto cleanup;