c-template
random_test.c
Go to the documentation of this file.
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <time.h>
4
#include <stdarg.h>
5
#include <stddef.h>
6
#include <setjmp.h>
7
#include <cmocka.h>
8
#include <assert.h>
9
#include "../../include/utils/random.h"
10
#include "../../include/utils/array_len.h"
11
#include "../../include/utils/returns.h"
12
13
#pragma GCC diagnostic ignored "-Wunused-parameter"
14
#pragma GCC diagnostic ignored "-Wunused-variable"
15
void
test_get_random_string_length
(
void
**state) {
16
cg_return
*ret_val =
get_random_string
(10);
17
assert(ret_val->
err
== NULL);
18
char
*word = (
char
*)ret_val->
value
;
19
assert(
sizeof
(word) == 8);
20
assert(strlen(word) == 10);
21
free(word);
22
free_cg_return
(ret_val);
23
}
24
25
#pragma GCC diagnostic ignored "-Wunused-parameter"
26
#pragma GCC diagnostic ignored "-Wunused-variable"
27
void
test_get_random_number_range
(
void
**state) {
28
int
number =
get_random_number
(0, 25);
29
assert(number >= 0 && number <= 25);
30
}
31
32
int
main
(
void
) {
33
// seed random number generate using time
34
srand(time(0));
35
const
struct
CMUnitTest tests[] = {
36
cmocka_unit_test(
test_get_random_string_length
),
37
cmocka_unit_test(
test_get_random_number_range
),
38
};
39
return
cmocka_run_group_tests(tests, NULL, NULL);
40
}
test_get_random_number_range
void test_get_random_number_range(void **state)
Definition:
random_test.c:27
cg_return::value
void * value
Definition:
returns.h:16
cg_return::err
cg_error * err
Definition:
returns.h:19
main
int main(void)
Definition:
random_test.c:32
get_random_number
int get_random_number(int lower, int upper)
Definition:
random.c:22
cg_return
allows returning both a value and error message from a function call useful as it makes it easier to ...
Definition:
returns.h:14
free_cg_return
void free_cg_return(cg_return *ret)
frees up resources associated with an instance of cg_return
Definition:
returns.c:24
get_random_string
cg_return * get_random_string(int stringLength)
Definition:
random.c:7
test_get_random_string_length
void test_get_random_string_length(void **state)
Definition:
random_test.c:15
src
utils
random_test.c
Generated by
1.8.17