Beispiel #1
0
static void test_group_readwrite(CuTest * tc)
{
    faction * f;
    group *g;
    ally *al;
    storage store;
    FILE *F;
    stream strm;

    F = fopen("test.dat", "wb");
    fstream_init(&strm, F);
    binstore_init(&store, &strm);
    test_cleanup();
    test_create_world();
    f = test_create_faction(0);
    g = new_group(f, "test", 42);
    al = ally_add(&g->allies, f);
    al->status = HELP_GIVE;
    write_groups(&store, f);
    binstore_done(&store);
    fstream_done(&strm);

    F = fopen("test.dat", "rb");
    fstream_init(&strm, F);
    binstore_init(&store, &strm);
    f->groups = 0;
    free_group(g);
    read_groups(&store, f);
    binstore_done(&store);
    fstream_done(&strm);

    CuAssertPtrNotNull(tc, f->groups);
    CuAssertPtrNotNull(tc, f->groups->allies);
    CuAssertPtrEquals(tc, 0, f->groups->allies->next);
    CuAssertPtrEquals(tc, f, f->groups->allies->faction);
    CuAssertIntEquals(tc, HELP_GIVE, f->groups->allies->status);
    remove("test.dat");
    test_cleanup();
}
Beispiel #2
0
static void reports(void)
{
    FILE * F;
    ql_iter fli;

    _mkdir("reports");

    for (fli = qli_init(&factions); qli_more(fli);) {
        faction * f = (faction *)qli_next(&fli);
        cJSON * json;
        char buf[256];
        stream strm;

        sprintf(buf, "reports/%d-%d.json", turn, f->no);
        fstream_init(&strm, fopen(buf, "w"));
        json = json_report(f);
        json_write(json, &strm);
        cJSON_Delete(json);
        fstream_done(&strm);

        report(f);
    }
    F = fopen("send", "w");
    puts("Writing send file...");

    for (fli = qli_init(&factions); qli_more(fli);) {
        faction * f = (faction *)qli_next(&fli);
        const char * addr = faction_getaddr(f);
        if (addr) {
            fprintf(F, "mail %d-%d.r\n", turn, f->no);
            fprintf(F, "in%%\"%s\"\n", addr);
            fprintf(F, "Atlantis Report for %s\n", gamedate());
        }
    }

    fclose(F);

    F = fopen("maillist", "w");
    puts("Writing maillist file...");

    for (fli = qli_init(&factions); qli_more(fli);) {
        faction * f = (faction *)qli_next(&fli);
        const char * addr = faction_getaddr(f);
        if (addr) {
            fprintf(F, "%s\n", addr);
        }
    }

    fclose(F);
}