예제 #1
0
파일: main.c 프로젝트: fdotli/libu
static int test_full_advance (int opts)
{
    int i;
    char c, prev, star = '*';
    enum { SZ = 3 };
    u_rb_t *rb = NULL;

    con_err_if (u_rb_create(SZ, opts, &rb));

    /* fill the rb */
    for (i = 0; i < SZ; i++)
        con_err_if (writec(rb, star));

    for (c = 32; c < 126; c++)
    {
        if (c < (SZ + 32))
            con_err_if (readc(rb, &star));
        else
        {
            prev = c - SZ; 
            con_err_if (readc(rb, &prev));
        }

        con_err_if (writec(rb, c));
    }

    return 0;
err:
    return 1;
}
예제 #2
0
파일: json.c 프로젝트: fdotli/libu
int test_suite_json_register (u_test_t *t)
{
    u_test_suite_t *ts = NULL;

    con_err_if (u_test_suite_new("JSON", &ts));

    con_err_if (u_test_case_register("Encode-Decode", test_codec, ts));
    con_err_if (u_test_case_register("Builder (simple object)", 
                test_build_simple_object, ts));
    con_err_if (u_test_case_register("Builder (simple array)", 
                test_build_simple_array, ts));
    con_err_if (u_test_case_register("Builder (nested object)", 
                test_build_nested_object, ts));
    con_err_if (u_test_case_register("Iterators", test_iterators, ts));
    con_err_if (u_test_case_register("Nesting", test_max_nesting, ts));

    /* JSON depends on the lexer and hmap modules. */
    con_err_if (u_test_suite_dep_register("Lexer", ts));
    con_err_if (u_test_suite_dep_register("Hash Map", ts));

    return u_test_suite_add(ts, t);
err:
    u_test_suite_free(ts);
    return ~0;
}
예제 #3
0
파일: main.c 프로젝트: fdotli/libu
static int test_empty (int opts)
{
    enum { SZ = 3 };
    u_rb_t *rb = NULL;

    con_err_if (u_rb_create(SZ, opts, &rb));
    con_err_if (readc(rb, NULL) == 0);   /* underflow, readc() must fail */

    return 0;
err:
    return 1;
}
예제 #4
0
파일: string.c 프로젝트: childhood/libu
int test_suite_string_register (u_test_t *t)
{
    u_test_suite_t *ts = NULL;

    con_err_if (u_test_suite_new("Strings", &ts));

    con_err_if (u_test_case_register("Various functions", test_u_str, ts));

    return u_test_suite_add(ts, t);
err:
    u_test_suite_free(ts);
    return ~0;
}
예제 #5
0
파일: main.c 프로젝트: fdotli/libu
int main (void)
{
    int opts = U_RB_OPT_IMPL_MALLOC | U_RB_OPT_USE_CONTIGUOUS_MEM;

    con_err_if (test_full(opts));
    con_err_if (test_empty(opts));
    con_err_if (test_advance(opts));
    con_err_if (test_full_advance(opts));

    return 0;
err:
    return 1;
}
예제 #6
0
파일: bst.c 프로젝트: fdotli/libu
int test_suite_bst_register (u_test_t *t)
{
    u_test_suite_t *ts = NULL;

    con_err_if (u_test_suite_new("Binary Search Tree", &ts));

    con_err_if (u_test_case_register("Sort", test_sort, ts));
    con_err_if (u_test_case_register("Search", test_search, ts));

    return u_test_suite_add(ts, t);
err:
    u_test_suite_free(ts);
    return ~0;
}
예제 #7
0
파일: main.c 프로젝트: fdotli/libu
static int test_full (int opts)
{
    enum { SZ = 2 };
    u_rb_t *rb = NULL;

    con_err_if (u_rb_create(SZ, opts, &rb));
    con_err_if (write1(rb));
    con_err_if (write2(rb));
    con_err_if (write3(rb) == 0);   /* overflow, write3 must fail */

    return 0;
err:
    return 1;
}
예제 #8
0
파일: lexer.c 프로젝트: fdotli/libu
int test_suite_lexer_register (u_test_t *t)
{
    u_test_suite_t *ts = NULL;

    con_err_if (u_test_suite_new("Lexer", &ts));

    con_err_if (u_test_case_register("scan (no skip ws)", test_scan0, ts));
    con_err_if (u_test_case_register("scan (skip ws)", test_scan1, ts));
    con_err_if (u_test_case_register("match", test_match, ts));

    return u_test_suite_add(ts, t);
err:
    u_test_suite_free(ts);
    return ~0;
}
예제 #9
0
파일: pqueue.c 프로젝트: fdotli/libu
int test_suite_pqueue_register (u_test_t *t)
{
    u_test_suite_t *ts = NULL;

    con_err_if (u_test_suite_new("Priority Queues", &ts));

    con_err_if (u_test_case_register("Top 10 (reverse) in 10 million", 
                test_top10, ts));
    con_err_if (u_test_case_register("Heap sort 1 million random entries", 
                test_heapsort, ts));

    return u_test_suite_add(ts, t);
err:
    u_test_suite_free(ts);
    return ~0;
}
예제 #10
0
파일: main.c 프로젝트: fdotli/libu
static int test_advance (int opts)
{
    char c;
    enum { SZ = 3 };
    u_rb_t *rb = NULL;

    con_err_if (u_rb_create(SZ, opts, &rb));

    for (c = 0; c < 127; c++)
    {
        if (!isprint(c))
            continue;
        con_err_if (writec(rb, c));
        con_err_if (readc(rb, &c));
    }

    return 0;
err:
    return 1;
}
예제 #11
0
파일: rb.c 프로젝트: fdotli/libu
int test_suite_rb_register (u_test_t *t)
{
    u_test_suite_t *ts = NULL;

    con_err_if (u_test_suite_new("Ring Buffer", &ts));

#ifdef U_RB_CAN_MMAP
    con_err_if (u_test_case_register("Read-write (mmap)", test_rw, ts));
    con_err_if (u_test_case_register("Read-write fast (mmap)", 
                test_rw_fast, ts));
#endif  /* U_RB_CAN_MMAP */
    con_err_if (u_test_case_register("Read-write (malloc)", 
                test_rw_malloc, ts));
    con_err_if (u_test_case_register("Read-write fast (malloc)", 
                test_rw_fast_malloc, ts));

    return u_test_suite_add(ts, t);
err:
    u_test_suite_free(ts);
    return ~0;
}
예제 #12
0
파일: main.c 프로젝트: fdotli/libu
int main (int argc, char *argv[])
{
    char c;
    int i, rc, in_memory = 0;
    u_pwd_t *pwd = NULL;
    char prompt[128];

    while ((c = getopt(argc, argv, "m")) != -1)
    {
        switch (c)
        {
            case 'm':
                ++in_memory;
                break;
            default:
                con_err("usage: pwd [-m] user ...");
        }
    }
    
    argc -= optind;
    argv += optind;

    con_err_if (u_pwd_init_file("./passwd", NULL, 0, in_memory, &pwd));

    for (i = 0; i < argc; i++)
    {
        u_snprintf(prompt, sizeof prompt, "%s: ", argv[i]);
        rc = u_pwd_auth_user(pwd, argv[i], getpass(prompt));
        u_con("auth %s", rc ? "failed" : "ok");
    }

    u_pwd_term(pwd);

    return EXIT_SUCCESS;
err:
    return EXIT_FAILURE;
}
예제 #13
0
파일: main.c 프로젝트: fdotli/libu
int main (void)
{
    u_array_t *a = NULL;
    size_t idx;
    long double _Complex c0, c1;

    con_err_if (u_array_create(U_ARRAY_TYPE_LONG_DOUBLE_COMPLEX, 0, &a));

    for (idx = 0; idx < 10; idx++)
    {
        c0 = idx + idx * _Complex_I;
        con_err_if (u_array_set_long_double_complex(a, idx, c0, NULL));
        con_err_if (u_array_get_long_double_complex(a, idx, &c1));
        con_err_if (creal(c0) != creal(c1) || cimag(c0) != cimag(c1));
    }

    for (idx = 0; idx < 10; idx++)
    {
        long double _Complex c2;

        c0 = (idx + 10) + (idx + 10) * _Complex_I;
        con_err_if (u_array_set_long_double_complex(a, idx, c0, &c2));
        u_con("overwrite %lf + %lfi at %zu with %lf + %lfi", 
                creal(c2), cimag(c2), idx, creal(c0), cimag(c0)); 
        con_err_if (u_array_get_long_double_complex(a, idx, &c1));
        con_err_if (creal(c0) != creal(c1) || cimag(c0) != cimag(c1));
    }

    /* index too high */
    con_if (u_array_set_long_double_complex(a, 134217727, c0, NULL));

    u_array_free(a);

    return 0;
err:
    return 1;
}