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:
@@ -13,6 +13,8 @@ struct Ibusfix
|
|||||||
{
|
{
|
||||||
Channel *oldreply;
|
Channel *oldreply;
|
||||||
Pump pump;
|
Pump pump;
|
||||||
|
/* A fake connection is nothing but an address to tell two apart. */
|
||||||
|
char fake[2];
|
||||||
DBusConnection *c1;
|
DBusConnection *c1;
|
||||||
DBusConnection *c2;
|
DBusConnection *c2;
|
||||||
};
|
};
|
||||||
@@ -81,8 +83,8 @@ cleanup:
|
|||||||
CT_CHECK(t, rmdir(root) == 0);
|
CT_CHECK(t, rmdir(root) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static void
|
||||||
ibusbegin(struct ct *t, Ibusfix *f)
|
ibusbegin(Ibusfix *f)
|
||||||
{
|
{
|
||||||
Drawcmd dc;
|
Drawcmd dc;
|
||||||
|
|
||||||
@@ -97,9 +99,8 @@ ibusbegin(struct ct *t, Ibusfix *f)
|
|||||||
f->oldreply = replyc;
|
f->oldreply = replyc;
|
||||||
replyc = chancreate(sizeof(Keyres), 0);
|
replyc = chancreate(sizeof(Keyres), 0);
|
||||||
pumpstart(&f->pump, Maxcontexts);
|
pumpstart(&f->pump, Maxcontexts);
|
||||||
f->c1 = malloc(1);
|
f->c1 = (DBusConnection*)&f->fake[0];
|
||||||
f->c2 = malloc(1);
|
f->c2 = (DBusConnection*)&f->fake[1];
|
||||||
return CT_CHECK(t, f->c1 != nil && f->c2 != nil);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -119,8 +120,6 @@ ibusend(Ibusfix *f)
|
|||||||
testengineinit(LangEN);
|
testengineinit(LangEN);
|
||||||
while(channbrecv(drawc, &dc) > 0)
|
while(channbrecv(drawc, &dc) > 0)
|
||||||
;
|
;
|
||||||
free(f->c1);
|
|
||||||
free(f->c2);
|
|
||||||
chanfree(replyc);
|
chanfree(replyc);
|
||||||
replyc = f->oldreply;
|
replyc = f->oldreply;
|
||||||
}
|
}
|
||||||
@@ -168,8 +167,7 @@ ibus_capability_policy(struct ct *t)
|
|||||||
Ictx *a, *b;
|
Ictx *a, *b;
|
||||||
Keyres res;
|
Keyres res;
|
||||||
|
|
||||||
if(!ibusbegin(t, &f))
|
ibusbegin(&f);
|
||||||
goto cleanup;
|
|
||||||
a = newcontext(f.c1, "/context/cap-a");
|
a = newcontext(f.c1, "/context/cap-a");
|
||||||
b = newcontext(f.c2, "/context/cap-b");
|
b = newcontext(f.c2, "/context/cap-b");
|
||||||
if(!CT_CHECK(t, a != nil && b != nil))
|
if(!CT_CHECK(t, a != nil && b != nil))
|
||||||
@@ -223,8 +221,7 @@ ibus_private_input_policy(struct ct *t)
|
|||||||
char text[Maxutf];
|
char text[Maxutf];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if(!ibusbegin(t, &f))
|
ibusbegin(&f);
|
||||||
goto cleanup;
|
|
||||||
ctx = newcontext(f.c1, "/context/private");
|
ctx = newcontext(f.c1, "/context/private");
|
||||||
if(!CT_CHECK(t, ctx != nil))
|
if(!CT_CHECK(t, ctx != nil))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@@ -274,8 +271,7 @@ ibus_context_lifecycle(struct ct *t)
|
|||||||
Caret at;
|
Caret at;
|
||||||
char text[Maxutf];
|
char text[Maxutf];
|
||||||
|
|
||||||
if(!ibusbegin(t, &f))
|
ibusbegin(&f);
|
||||||
goto cleanup;
|
|
||||||
a = newcontext(f.c1, "/context/one");
|
a = newcontext(f.c1, "/context/one");
|
||||||
b = newcontext(f.c2, "/context/one");
|
b = newcontext(f.c2, "/context/one");
|
||||||
if(!CT_CHECK(t, a != nil && b != nil && a != b))
|
if(!CT_CHECK(t, a != nil && b != nil && a != b))
|
||||||
@@ -387,8 +383,7 @@ ibus_active_release_lifecycle(struct ct *t)
|
|||||||
Ictx *ctx, *reused;
|
Ictx *ctx, *reused;
|
||||||
Keyres res;
|
Keyres res;
|
||||||
|
|
||||||
if(!ibusbegin(t, &f))
|
ibusbegin(&f);
|
||||||
goto cleanup;
|
|
||||||
ctx = newcontext(f.c1, "/context/reset");
|
ctx = newcontext(f.c1, "/context/reset");
|
||||||
if(!CT_CHECK(t, ctx != nil))
|
if(!CT_CHECK(t, ctx != nil))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|||||||
@@ -398,8 +398,8 @@ struct Freejob
|
|||||||
Channel *done;
|
Channel *done;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
static void
|
||||||
ximbegin(struct ct *t, Ximfix *f, int lang)
|
ximbegin(Ximfix *f, int lang)
|
||||||
{
|
{
|
||||||
Drawcmd dc;
|
Drawcmd dc;
|
||||||
|
|
||||||
@@ -410,8 +410,6 @@ ximbegin(struct ct *t, Ximfix *f, int lang)
|
|||||||
f->oldreply = replyc;
|
f->oldreply = replyc;
|
||||||
replyc = chancreate(sizeof(Keyres), 0);
|
replyc = chancreate(sizeof(Keyres), 0);
|
||||||
pumpstart(&f->pump, 16);
|
pumpstart(&f->pump, 16);
|
||||||
USED(t);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -466,8 +464,7 @@ xim_adapter_key_contract(struct ct *t)
|
|||||||
u32int allmod;
|
u32int allmod;
|
||||||
|
|
||||||
memset(&state, 0, sizeof state);
|
memset(&state, 0, sizeof state);
|
||||||
if(!ximbegin(t, &f, LangJP))
|
ximbegin(&f, LangJP);
|
||||||
goto cleanup;
|
|
||||||
allmod = ~0;
|
allmod = ~0;
|
||||||
keypress(&state, 'x', allmod, &res);
|
keypress(&state, 'x', allmod, &res);
|
||||||
req = nexttrace(t, &f, Keypress, &state);
|
req = nexttrace(t, &f, Keypress, &state);
|
||||||
@@ -487,7 +484,6 @@ xim_adapter_key_contract(struct ct *t)
|
|||||||
CT_CHECK(t, !res.eaten);
|
CT_CHECK(t, !res.eaten);
|
||||||
checkstr(t, "preedit", "か", &res.commit);
|
checkstr(t, "preedit", "か", &res.commit);
|
||||||
checkstr(t, "preedit", "", &res.preedit);
|
checkstr(t, "preedit", "", &res.preedit);
|
||||||
cleanup:
|
|
||||||
ximend(&f);
|
ximend(&f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -502,8 +498,7 @@ xim_adapter_release_lifecycle(struct ct *t)
|
|||||||
memset(&a, 0, sizeof a);
|
memset(&a, 0, sizeof a);
|
||||||
memset(&b, 0, sizeof b);
|
memset(&b, 0, sizeof b);
|
||||||
dead = nil;
|
dead = nil;
|
||||||
if(!ximbegin(t, &f, LangJP))
|
ximbegin(&f, LangJP);
|
||||||
goto cleanup;
|
|
||||||
keypress(&a, 'k', 0, &res);
|
keypress(&a, 'k', 0, &res);
|
||||||
nexttrace(t, &f, Keypress, &a);
|
nexttrace(t, &f, Keypress, &a);
|
||||||
keypress(&a, 'a', 0, &res);
|
keypress(&a, 'a', 0, &res);
|
||||||
@@ -580,8 +575,7 @@ xim_adapter_free_waits_for_release(struct ct *t)
|
|||||||
state = nil;
|
state = nil;
|
||||||
freed = nil;
|
freed = nil;
|
||||||
workeractive = 0;
|
workeractive = 0;
|
||||||
if(!ximbegin(t, &f, LangJP))
|
ximbegin(&f, LangJP);
|
||||||
goto cleanup;
|
|
||||||
state = calloc(1, sizeof *state);
|
state = calloc(1, sizeof *state);
|
||||||
freed = chancreate(sizeof(uchar), 0);
|
freed = chancreate(sizeof(uchar), 0);
|
||||||
if(!CT_CHECK(t, state != nil && freed != nil))
|
if(!CT_CHECK(t, state != nil && freed != nil))
|
||||||
@@ -736,8 +730,7 @@ xim_adapter_placement_updates(struct ct *t)
|
|||||||
ic = (xcb_im_input_context_t*)(uintptr)71;
|
ic = (xcb_im_input_context_t*)(uintptr)71;
|
||||||
memset(&state, 0, sizeof state);
|
memset(&state, 0, sizeof state);
|
||||||
oldstate = kstate;
|
oldstate = kstate;
|
||||||
if(!ximbegin(t, &f, LangJP))
|
ximbegin(&f, LangJP);
|
||||||
goto cleanup;
|
|
||||||
kstate = testkeystate("us");
|
kstate = testkeystate("us");
|
||||||
if(!CT_CHECK(t, kstate != nil))
|
if(!CT_CHECK(t, kstate != nil))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@@ -891,8 +884,7 @@ xim_adapter_callback_cleanup(struct ct *t)
|
|||||||
|
|
||||||
ic = (xcb_im_input_context_t*)(uintptr)29;
|
ic = (xcb_im_input_context_t*)(uintptr)29;
|
||||||
memset(&state, 0, sizeof state);
|
memset(&state, 0, sizeof state);
|
||||||
if(!ximbegin(t, &f, LangJP))
|
ximbegin(&f, LangJP);
|
||||||
return;
|
|
||||||
wireclear();
|
wireclear();
|
||||||
wirebind(0, ic, &state);
|
wirebind(0, ic, &state);
|
||||||
state.xic = ic;
|
state.xic = ic;
|
||||||
@@ -980,8 +972,7 @@ xim_adapter_callback_transfer(struct ct *t)
|
|||||||
aic = (xcb_im_input_context_t*)(uintptr)50;
|
aic = (xcb_im_input_context_t*)(uintptr)50;
|
||||||
memset(&a, 0, sizeof a);
|
memset(&a, 0, sizeof a);
|
||||||
memset(&b, 0, sizeof b);
|
memset(&b, 0, sizeof b);
|
||||||
if(!ximbegin(t, &f, LangJP))
|
ximbegin(&f, LangJP);
|
||||||
goto cleanup;
|
|
||||||
wireclear();
|
wireclear();
|
||||||
a.xic = aic;
|
a.xic = aic;
|
||||||
a.clientpre = 1;
|
a.clientpre = 1;
|
||||||
@@ -996,7 +987,6 @@ xim_adapter_callback_transfer(struct ct *t)
|
|||||||
CT_EQ_PTR(t, nil, preowner);
|
CT_EQ_PTR(t, nil, preowner);
|
||||||
release(&b);
|
release(&b);
|
||||||
nexttrace(t, &f, Keyrelease, &b);
|
nexttrace(t, &f, Keyrelease, &b);
|
||||||
cleanup:
|
|
||||||
preowner = nil;
|
preowner = nil;
|
||||||
ximend(&f);
|
ximend(&f);
|
||||||
}
|
}
|
||||||
@@ -1016,8 +1006,7 @@ xim_adapter_callback_owner_loss(struct ct *t)
|
|||||||
ic = (xcb_im_input_context_t*)(uintptr)51;
|
ic = (xcb_im_input_context_t*)(uintptr)51;
|
||||||
memset(&state, 0, sizeof state);
|
memset(&state, 0, sizeof state);
|
||||||
foreign = 0;
|
foreign = 0;
|
||||||
if(!ximbegin(t, &f, LangJP))
|
ximbegin(&f, LangJP);
|
||||||
goto cleanup;
|
|
||||||
wireclear();
|
wireclear();
|
||||||
wirebind(0, ic, &state);
|
wirebind(0, ic, &state);
|
||||||
state.xic = ic;
|
state.xic = ic;
|
||||||
@@ -1086,7 +1075,6 @@ xim_adapter_callback_owner_loss(struct ct *t)
|
|||||||
CT_CHECK(t, channbrecv(f.pump.trace, &trace) > 0);
|
CT_CHECK(t, channbrecv(f.pump.trace, &trace) > 0);
|
||||||
CT_EQ_INT(t, Keyrelease, trace.op);
|
CT_EQ_INT(t, Keyrelease, trace.op);
|
||||||
CT_EQ_PTR(t, &foreign, trace.owner);
|
CT_EQ_PTR(t, &foreign, trace.owner);
|
||||||
cleanup:
|
|
||||||
preowner = nil;
|
preowner = nil;
|
||||||
ximend(&f);
|
ximend(&f);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user