static void test_otrl_instag_find(void) { OtrlUserState us = otrl_userstate_create(); OtrlInsTag* p1 = (OtrlInsTag *)malloc(sizeof(OtrlInsTag)); OtrlInsTag* p2 = (OtrlInsTag *)malloc(sizeof(OtrlInsTag)); p1->accountname = strdup("account one"); p1->protocol = strdup("protocol one"); p1->instag = otrl_instag_get_new(); p1->next = us->instag_root; p1->tous = &(us->instag_root); us->instag_root = p1; p2->accountname = strdup("account two"); p2->protocol = strdup("protocol two"); p2->instag = otrl_instag_get_new(); p2->next = us->instag_root; p2->next->tous = &(p2->next); p2->tous = &(us->instag_root); us->instag_root = p2; ok(otrl_instag_find(us, "account two", "protocol two") == p2, "Found instag"); ok(otrl_instag_find(us, "account one", "protocol two") == NULL, "Instag not found"); ok(otrl_instag_find(us, "account three", "protocol three") == NULL, "Instag not found"); }
static void test_otrl_instag_forget_all(void) { OtrlUserState us = otrl_userstate_create(); OtrlInsTag* p = (OtrlInsTag *)malloc(sizeof(OtrlInsTag)); p->accountname = strdup("account name"); p->protocol = strdup("protocol name"); p->instag = otrl_instag_get_new(); /* otrl_instag_forget_all(NULL); ok(1, "Forget all on NULL didn't segfaulted"); */ otrl_instag_forget_all(us); ok(1, "Forget all on empty user state"); p->next = us->instag_root; p->tous = &(us->instag_root); us->instag_root = p; otrl_instag_forget_all(us); ok(1, "Forget all on a non-empty user state"); }
/* Generate a new instance tag for the given account and write to file * The FILE* must be open for writing. */ gcry_error_t otrl_instag_generate_FILEp(OtrlUserState us, FILE *instf, const char *accountname, const char *protocol) { OtrlInsTag *p; if (!accountname || !protocol) return gcry_error(GPG_ERR_NO_ERROR); p = (OtrlInsTag *)malloc(sizeof(OtrlInsTag)); p->accountname = strdup(accountname); p->protocol = strdup(protocol); p->instag = otrl_instag_get_new(); /* Add to our list in OtrlUserState */ p->next = us->instag_root; if (p->next) { p->next->tous = &(p->next); } p->tous = &(us->instag_root); us->instag_root = p; otrl_instag_write_FILEp(us, instf); return gcry_error(GPG_ERR_NO_ERROR); }
static void test_otrl_instag_get_new(void) { ok(otrl_instag_get_new() != 0, "New instag generated"); }