void Test_dictionary_unset(CuTest *tc) { int i, j; char sec_name[32]; char key_name[64]; dictionary *dic1; dictionary *dic2; char *dic1_dump; char *dic2_dump; /* try dummy unsets */ dictionary_unset(NULL, NULL); dictionary_unset(NULL, key_name); /* Generate two similar dictionaries */ dic1 = dictionary_new(DICTMINSZ); CuAssertPtrNotNull(tc, dic1); for (i = 1 ; i < 10; ++i) { sprintf(sec_name, "sec%d", i); dictionary_set(dic1, sec_name, ""); for (j = 1 ; j < 10; ++j) { sprintf(key_name, "%s:key%d", sec_name, j); dictionary_set(dic1, key_name, "dummy_value"); } } dic2 = dictionary_new(DICTMINSZ); CuAssertPtrNotNull(tc, dic2); for (i = 1 ; i < 10; ++i) { sprintf(sec_name, "sec%d", i); dictionary_set(dic2, sec_name, ""); for (j = 1 ; j < 10; ++j) { sprintf(key_name, "%s:key%d", sec_name, j); dictionary_set(dic2, key_name, "dummy_value"); } } /* Make sure the dictionaries are the same */ dic1_dump = get_dump(dic1); dic2_dump = get_dump(dic2); CuAssertStrEquals(tc, dic1_dump, dic2_dump); free(dic1_dump); free(dic2_dump); /* Those tests should not change the dictionary */ dictionary_unset(dic2, NULL); dictionary_unset(dic2, "bad_key"); /* dic1 and dic2 must still be the same */ dic1_dump = get_dump(dic1); dic2_dump = get_dump(dic2); CuAssertStrEquals(tc, dic1_dump, dic2_dump); free(dic1_dump); free(dic2_dump); }
void Test_dictionary_dump(CuTest *tc) { int i, j; char sec_name[32]; char key_name[64]; dictionary *dic; char *dump_buff; const char dump_real[] = "\ sec1\t[]\n\ sec1:key1\t[dummy_value]\n\ sec1:key2\t[dummy_value]\n\ sec1:key3\t[dummy_value]\n\ sec1:key4\t[dummy_value]\n\ sec2\t[]\n\ sec2:key1\t[dummy_value]\n\ sec2:key2\t[dummy_value]\n\ sec2:key3\t[dummy_value]\n\ sec2:key4\t[dummy_value]\n\ "; dic = dictionary_new(DICTMINSZ); CuAssertPtrNotNull(tc, dic); /* Try dummy values */ dictionary_dump(NULL, NULL); dictionary_dump(dic, NULL); /* Try with empty dictionary first */ dump_buff = get_dump(dic); CuAssertStrEquals(tc, "empty dictionary\n", dump_buff); free(dump_buff); /* Populate the dictionary */ for (i = 1 ; i < 3; ++i) { sprintf(sec_name, "sec%d", i); dictionary_set(dic, sec_name, ""); for (j = 1 ; j < 5; ++j) { sprintf(key_name, "%s:key%d", sec_name, j); dictionary_set(dic, key_name, "dummy_value"); } } /* Check the dump file */ dump_buff = get_dump(dic); CuAssertStrEquals(tc, dump_real, dump_buff); free(dump_buff); dictionary_del(dic); }
int get_args(int argc, char **argv, t_corewar *core) { if (is_error_in_args(argc, argv) == -1) return (usage()); get_dump(argc, argv, core); if ((save_args(argc, argv, core)) == -1) return (-1); if ((attribute_prog_number(core->champions, core->nb_champions)) == -1) return (-1); if ((attribute_address(core->champions, core->nb_champions)) == -1) return (-1); return (0); }
void wait_until(const chrono::time_point& timestamp) { while (true) { const auto& dump = get_dump(); if (dump->find("handystats.dump_timestamp") != dump->cend()) { dump_timestamp_visitor visitor; const auto& dump_timestamp_ms = boost::apply_visitor( visitor, boost::get<handystats::metrics::attribute>(dump->at("handystats.dump_timestamp")).value() ); chrono::time_point dump_timestamp(chrono::duration(dump_timestamp_ms, chrono::time_unit::MSEC), chrono::clock_type::SYSTEM); if (dump_timestamp >= timestamp) { return; } } std::this_thread::sleep_for(std::chrono::microseconds(1)); } }