File: test.c

package info (click to toggle)
criterion 2.3.3git1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,832 kB
  • sloc: ansic: 17,852; cpp: 795; python: 72; sh: 27; makefile: 23
file content (82 lines) | stat: -rw-r--r-- 1,247 bytes parent folder | download | duplicates (2)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <criterion/criterion.h>
#include <stdlib.h>

#include "foo.h"

Test(strlen, empty)
{
    cr_assert_eq(foo_strlen(""), 0);
}

Test(strlen, simple)
{
    cr_assert_eq(foo_strlen("foo"), 3);
}

Test(strlen, longer)
{
    cr_assert_eq(foo_strlen("foo\0bar"), 3);
}

Test(strcpy, empty)
{
    char dst[] = "a";

    foo_strcpy(dst, "");
    cr_assert_str_empty(dst);
}

Test(strcpy, return)
{
    char dst[4];
    char *ret = foo_strcpy(dst, "foo");

    cr_assert_eq(ret, dst);
}

Test(strcpy, larger_dest)
{
    char dst[] = "foo baz";

    foo_strcpy(dst, "bar");

    cr_assert_str_eq(dst, "bar");
    cr_assert_str_eq(&dst[4], "baz");
}

Test(strdup, null)
{
    char *out = foo_strdup(NULL);

    /* NULL should be propagated */
    cr_assert_null(out);
}

Test(strdup, duplicate)
{
    char *out = foo_strdup("foo");

    /* out should contain the source string */
    cr_assert_str_eq(out, "foo");
    free(out);
}

/* These two tests expect a crash on failure */

Test(strdup, dynamic)
{
    char *out = foo_strdup("foo");

    /* out should be returned by malloc */
    free(out);
}

Test(strdup, writeable)
{
    char *out = foo_strdup("foo");

    /* out should be writeable memory */
    foo_strcpy(out, "bar");

    free(out);
}