END_TEST START_TEST (test_bad_file_1) { char fileName[] = "./conf-filesls/conf_file_1"; conf_file_t cf; int res; char *validVarNames[] = { "size", NULL}; print_start("Testing basic"); if(debug) msx_set_debug(MAP_DEBUG); cf = cf_new(validVarNames); fail_unless(cf != NULL, "Faild to build conf file object"); res = cf_parseFile(cf, fileName); fail_unless(res == 0, "Failed to parse a valid conf file\n"); cf_free(cf); print_end(); msx_set_debug(0); }
// We should not override the options specified in the command line int parseInfodConfFile(infod_cmdline_t *opts) { conf_file_t cf; if(!(cf = cf_new(validVarNames))) { fprintf(stderr, "Error generating conf file object\n"); return 0; } printf("Parsing configuration file [%s]\n", opts->opt_confFile); if(access(opts->opt_confFile, R_OK) != 0) { fprintf(stderr, "Error: configuration files [%s] does not exists or is not readable\n", opts->opt_confFile); return 0; } if(!cf_parseFile(cf, opts->opt_confFile)) { fprintf(stderr, "Error parsing configuration file\n"); return 0; } conf_var_t ent; int intVal; if(cf_getVar(cf, "provider", &ent)) set_provider(ent.varValue); if(cf_getVar(cf, "myip", &ent)) set_my_ip(ent.varValue); if(cf_getVar(cf, "port", &ent)) { if(!getInt(ent.varValue, &intVal)) { fprintf(stderr, "Error: parameter port is not an integer\n"); return 0; } set_port(&intVal); } if(cf_getVar(cf, "maptype", &ent)) set_map_type(ent.varValue); if(cf_getVar(cf, "mapfile", &ent)) set_map_file(ent.varValue); if(cf_getVar(cf, "mapcmd", &ent)) set_map_cmd(ent.varValue); if(cf_getVar(cf, "timestep", &ent)) { if(!getInt(ent.varValue, &intVal)) { fprintf(stderr, "Error: parameter timestep is not an integer\n"); return 0; } set_time_step(&intVal); } if(cf_getVar(cf, "gossip-algo", &ent)) set_gossip_algo(ent.varValue); if(cf_getVar(cf, "wintype", &ent)) set_win_type(ent.varValue); if(cf_getVar(cf, "winparam", &ent)) set_win_param(ent.varValue); if(cf_getVar(cf, "avgage", &ent)) { if(!getInt(ent.varValue, &intVal)) { fprintf(stderr, "Error: parameter avgage is not an integer\n"); return 0; } set_avgage(&intVal); } if(cf_getVar(cf, "avgmax", &ent)) { if(!getInt(ent.varValue, &intVal)) { fprintf(stderr, "Error: parameter avgmax is not an integer\n"); return 0; } set_avgmax(&intVal); } if(cf_getVar(cf, "upto-entries", &ent)) { if(!getInt(ent.varValue, &intVal)) { fprintf(stderr, "Error: parameter upto-entries is not an integer\n"); return 0; } set_uptoentries(&intVal); } if(cf_getVar(cf, "watch-fs", &ent)) set_watch_fs(ent.varValue); if(cf_getVar(cf, "watch-net", &ent)) set_watch_net(ent.varValue); if(cf_getVar(cf, "info-file", &ent)) set_info_file(ent.varValue); if(cf_getVar(cf, "eco-file", &ent)) set_eco_file(ent.varValue); if(cf_getVar(cf, "proc-file", &ent)) set_proc_file(ent.varValue); if(cf_getVar(cf, "jmig-file", &ent)) set_jmig_file(ent.varValue); cf_free(cf); return 1; }
/** * \brief Testing the continued fractions generator. * * */ void test_cf(void) { bigfraction_t x = {NULL, NULL}; cf_t* f; size_t i; bigfraction_t *it; BIGNUM* expected; f = cf_new(); x.h = BN_new(); x.k = BN_new(); expected = BN_new(); /* * Testing aᵢ * * 1 * √2 = 1 + ⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽ * 1 * 2 + ⎽⎽⎽⎽⎽⎽ * 2 + … * */ BN_dec2bn(&x.h, "14142135623730951"); BN_dec2bn(&x.k, "10000000000000000"); BN_dec2bn(&expected, "2"); cf_init(f, x.h, x.k); it = cf_next(f); assert(BN_is_one(f->a)); for (i=0; i!=5 && it; i++) { it = cf_next(f); assert(!BN_cmp(f->a, expected)); } assert(i==5); /* * Testing hᵢ/kᵢ * * 1 * φ = (1+√5)/2 = 1 + ⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽ * 1 * 1 + ⎽⎽⎽⎽⎽ * 1 + … */ const char* fib[] = {"1", "1", "2", "3", "5", "8", "13"}; BN_dec2bn(&x.h, "323606797749979"); BN_dec2bn(&x.k, "200000000000000"); cf_init(f, x.h, x.k); it = cf_next(f); for (i=1; i!=7; i++) { BN_dec2bn(&expected, fib[i]); assert(!BN_cmp(it->h, expected)); BN_dec2bn(&expected, fib[i-1]); assert(!BN_cmp(it->k, expected)); it=cf_next(f); } BN_dec2bn(&x.h, "60728973"); BN_dec2bn(&x.k, "160523347"); cf_init(f, x.h, x.k); /* 0 */ it = cf_next(f); /* 1 / 2 */ it = cf_next(f); BN_dec2bn(&expected, "2"); assert(BN_is_one(it->h) && !BN_cmp(it->k, expected)); /* 1 / 3 */ it = cf_next(f); BN_dec2bn(&expected, "3"); assert(BN_is_one(it->h) && !BN_cmp(it->k, expected)); /* 2 / 5 */ it = cf_next(f); BN_dec2bn(&expected, "2"); assert(!BN_cmp(expected, it->h)); BN_dec2bn(&expected, "5"); assert(!BN_cmp(expected, it->k)); /* 3 / 8 */ it = cf_next(f); BN_dec2bn(&expected, "3"); assert(!BN_cmp(expected, it->h)); BN_dec2bn(&expected, "8"); assert(!BN_cmp(expected, it->k)); /* 14/ 37 */ it = cf_next(f); BN_dec2bn(&expected, "14"); assert(!BN_cmp(expected, it->h)); BN_dec2bn(&expected, "37"); assert(!BN_cmp(expected, it->k)); }