Skip to content

Commit 561ba5b

Browse files
add context test
1 parent e5b2196 commit 561ba5b

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

tests/test_context.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,36 @@ static int test_controller_send_null_params(void)
509509
return 0;
510510
}
511511

512+
/* Fake write function that simulates I2C failure */
513+
static int fake_write_fails(void *user_ctx, uint8_t addr, const uint8_t *data, size_t len)
514+
{
515+
(void)user_ctx;
516+
(void)addr;
517+
(void)data;
518+
(void)len;
519+
return -99; /* Simulate I2C write failure */
520+
}
521+
522+
static int test_controller_send_write_fails(void)
523+
{
524+
crumbs_context_t ctx = {0};
525+
crumbs_init(&ctx, CRUMBS_ROLE_CONTROLLER, 0);
526+
527+
crumbs_message_t msg = {0};
528+
msg.type_id = 0x01;
529+
msg.opcode = 0x02;
530+
531+
int rc = crumbs_controller_send(&ctx, 0x20, &msg, fake_write_fails, NULL);
532+
if (rc != -99)
533+
{
534+
fprintf(stderr, "controller_send_write_fails: expected -99, got %d\n", rc);
535+
return 1;
536+
}
537+
538+
printf(" controller_send write_fn failure: PASS\n");
539+
return 0;
540+
}
541+
512542
/* ---- Main ------------------------------------------------------------- */
513543

514544
int main(void)
@@ -550,6 +580,7 @@ int main(void)
550580

551581
failures += test_controller_send_wrong_role();
552582
failures += test_controller_send_null_params();
583+
failures += test_controller_send_write_fails();
553584

554585
if (failures == 0)
555586
{

0 commit comments

Comments
 (0)