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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
#include <stdio.h>
#include <string.h>
#include "lily-test.h"
#include "tests.h"
const char* test_mock_enqueue_dequeue_int() {
lily_queue_t *q = lily_queue_create();
/* enqueue A259482, for no particular reason */
lily_enqueue(q, int, 2);
lily_enqueue(q, int, 6);
lily_enqueue(q, int, 44);
int n = 2014;
lily_enqueue(q, int, n);
lily_dequeue(q, int, &n);
if (n != 2) return "dequeued incorrect first value";
lily_dequeue(q, int, &n);
/* queue next value after already popping */
lily_enqueue(q, long, 1651377);
if (n != 6) return "dequeued incorrect second value";
lily_dequeue(q, int, &n);
if (n != 44) return "dequeued incorrect third value";
lily_dequeue(q, int, &n);
if (n != 2014) return "dequeued incorrect fourth value";
long m;
lily_dequeue(q, long, &m);
if (m != 1651377) return "dequeued incorrect fifth value";
lily_queue_destroy(q);
return 0;
}
const char* test_mock_enqueue_dequeue_heterogenous()
{
lily_queue_t *q = lily_queue_create();
lily_enqueue(q, int, 2);
lily_enqueue(q, lily_queue_t *, q);
lily_enqueue(q, const char *, "hello, world!");
int n;
lily_dequeue(q, int, &n);
if (n != 2) return "dequeued incorrect int value";
lily_queue_t *p;
lily_dequeue(q, lily_queue_t *, &p);
if (p != q) return "dequeued incorrect pointer value";
const char *str;
lily_dequeue(q, const char *, &str);
if (strcmp(str, "hello, world!") != 0) return "dequeued incorrect string value";
lily_queue_destroy(q);
return 0;
}
const char* test_LILY_NARGS()
{
int n = 5;
const char *str = "hello, world!";
lily_queue_t *q;
struct lily_mock_arg_t args[] =
{ { sizeof(int), &n },
{ sizeof(const char *), &str },
{ sizeof(lily_queue_t *), &q },
};
if (LILY_NARGS(args) != 3) return "incorrect argument count!";
return 0;
}
const char* test_lily_mock_call()
{
lily_mock_t *m = lily_mock_create();
int n = 5;
const char *str = "hello, world!";
lily_queue_t *q;
struct lily_mock_arg_t args[] =
{ { sizeof(int), &n },
{ sizeof(const char *), &str },
{ sizeof(lily_queue_t *), &q },
};
lily_mock_call(m, args);
n = 16;
str = "hi there";
lily_mock_call(m, args);
if (m->n_calls != 2) return "incorrect number of calls registered";
int k; const char *s; lily_queue_t *p;
struct lily_mock_arg_t get_args[] =
{ { sizeof(int), &k },
{ sizeof(const char *), &s },
{ sizeof(lily_queue_t *), &p },
};
lily_get_call(m, get_args, 0);
if (k != 5) return "incorrect int argument 0 registered";
if (strcmp(s, "hello, world!") != 0) return "incorrect string argument 0 registered";
if (p != q) return "incorrect pointer argument 0 registered";
lily_get_call(m, get_args, 1);
if (k != 16) return "incorrect int argument 1 registered";
if (strcmp(s, "hi there") != 0) return "incorrect string argument 1 registered";
if (p != q) return "incorrect pointer argument 1 registered";
lily_mock_destroy(m);
return 0;
}
|