static void run_test(int expected_ret, int manio_entries, int async_read_write_callback(struct async *as), void setup_asfds_callback(struct asfd *asfd, struct asfd *chfd, struct slist *slist)) { struct asfd *asfd; struct asfd *chfd; struct async *as; struct sdirs *sdirs; struct conf **confs; struct slist *slist=NULL; prng_init(0); base64_init(); hexmap_init(); setup(&as, &sdirs, &confs); asfd=asfd_mock_setup(&areads, &awrites); chfd=asfd_mock_setup(&creads, &cwrites); fail_unless((asfd->desc=strdup_w("a", __func__))!=NULL); fail_unless((chfd->desc=strdup_w("c", __func__))!=NULL); as->asfd_add(as, asfd); as->asfd_add(as, chfd); as->read_write=async_read_write_callback; if(manio_entries) slist=build_manifest(sdirs->phase1data, PROTO_2, manio_entries, 1 /*phase*/); setup_asfds_callback(asfd, chfd, slist); fail_unless(do_backup_phase2_server_protocol2( as, chfd, sdirs, 0, // resume confs )==expected_ret); if(!expected_ret) { // FIX THIS: Should check for the presence and correctness of // changed and unchanged manios. } asfd_free(&asfd); asfd_free(&chfd); asfd_mock_teardown(&areads, &awrites); asfd_mock_teardown(&creads, &cwrites); slist_free(&slist); tear_down(&as, &sdirs, &confs); }
END_TEST START_TEST(test_phase2_unset_sdirs_confs) { struct async *as; setup(&as, NULL, NULL); fail_unless(do_backup_phase2_server_protocol2( as, NULL, // chfd NULL, // sdirs 0, // resume NULL // confs )==-1); tear_down(&as, NULL, NULL); }
int backup_phase2_server_protocol2(struct async *as, struct sdirs *sdirs, int resume, struct conf **confs) { int ret=-1; struct asfd *chfd=NULL; if(!(chfd=champ_chooser_connect(as, sdirs, confs, resume))) { logp("problem connecting to champ chooser\n"); goto end; } ret=do_backup_phase2_server_protocol2(as, chfd, sdirs, resume, confs); end: if(chfd) as->asfd_remove(as, chfd); asfd_free(&chfd); return ret; }
END_TEST START_TEST(test_phase2_unset_asfd) { struct async *as; struct sdirs *sdirs; struct conf **confs; setup(&as, &sdirs, &confs); fail_unless(do_backup_phase2_server_protocol2( as, NULL, // chfd sdirs, 0, // resume confs )==-1); tear_down(&as, &sdirs, &confs); }
END_TEST START_TEST(test_phase2_unset_chfd) { struct asfd *asfd; struct async *as; struct sdirs *sdirs; struct conf **confs; setup(&as, &sdirs, &confs); asfd=asfd_mock_setup(&areads, &awrites); as->asfd_add(as, asfd); fail_unless(do_backup_phase2_server_protocol2( as, NULL, // chfd sdirs, 0, // resume confs )==-1); asfd_free(&asfd); asfd_mock_teardown(&areads, &awrites); tear_down(&as, &sdirs, &confs); }