File: check_str_array.c

package info (click to toggle)
libr3 1.3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, stretch
  • size: 1,084 kB
  • ctags: 1,086
  • sloc: ansic: 13,117; cpp: 175; makefile: 112; sh: 64; ruby: 52
file content (53 lines) | stat: -rw-r--r-- 1,276 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * check_str_array.c
 * Copyright (C) 2014 c9s <yoanlin93@gmail.com>
 *
 * Distributed under terms of the MIT license.
 */
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <check.h>
#include "r3.h"
#include "r3_str.h"
#include "zmalloc.h"

START_TEST (test_str_array)
{
    str_array * l = str_array_create(3);
    ck_assert(l);

    ck_assert(str_array_append(l, zstrdup("abc")));
    ck_assert( l->len == 1 );

    ck_assert(str_array_append(l, zstrdup("foo") ));
    ck_assert( l->len == 2 );

    ck_assert( str_array_append(l, zstrdup("bar") ) );
    ck_assert( l->len == 3 );

    ck_assert( str_array_append(l, zstrdup("zoo") ) );
    ck_assert( l->len == 4 );

    ck_assert( str_array_resize(l, l->cap * 2) );
    str_array_free(l);
}
END_TEST

Suite* r3_suite (void) {
    Suite *suite = suite_create("str_array test");
    TCase *tcase = tcase_create("testcase");
    tcase_add_test(tcase, test_str_array);
    suite_add_tcase(suite, tcase);
    return suite;
}

int main (int argc, char *argv[]) {
    int number_failed;
    Suite *suite = r3_suite();
    SRunner *runner = srunner_create(suite);
    srunner_run_all(runner, CK_NORMAL);
    number_failed = srunner_ntests_failed(runner);
    srunner_free(runner);
    return number_failed;
}