Debian Codegraph @

tests/API/probes/test_memusage.c

raw symbols SCIP
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2
3 #ifdef HAVE_CONFIG_H
4 #include <config.h>
5 #endif
6
7 #include <stdio.h>
8 #include "memusage.h"
9 #include "memusage.c"
10 #define OS_LINUX
11
12 static int test_basic()
13 {
14 size_t size;
15 char *strval = strdup("17 kB\n");
16 int ret = read_common_sizet(&size, strval);
17 free(strval);
18 return (size == 17 && ret == 0);
19 }
20
21 static int test_no_unit()
22 {
23 size_t size;
24 char *strval = strdup("42");
25 int ret = read_common_sizet(&size, strval);
26 free(strval);
27 return (ret == -1);
28 }
29
30 static int test_invalid_number()
31 {
32 size_t size;
33 char *strval = strdup("www kB\n");
34 int ret = read_common_sizet(&size, strval);
35 free(strval);
36 return (size == 0 && ret == 0);
37 }
38
39 static int test_errno()
40 {
41 size_t size;
42 char *strval = strdup("17 kB\n");
43
44 /* Test that setting errno outside of the read_common_sizet function
45 * doesn't influence the function and doesn't make the function fail.
46 */
47 errno = EINVAL;
48
49 int ret = read_common_sizet(&size, strval);
50 free(strval);
51 return (ret != -1);
52 }
53
54 int main(int argc, char *argv[])
55 {
56 if (!test_basic()) {
57 fprintf(stderr, "test_basic has failed\n");
58 return 1;
59 }
60 if (!test_no_unit()) {
61 fprintf(stderr, "test_no_unit has failed\n");
62 return 1;
63 }
64 if (!test_invalid_number()) {
65 fprintf(stderr, "test_invalid_number has failed\n");
66 return 1;
67 }
68 if (!test_errno()) {
69 fprintf(stderr, "test_errno has failed\n");
70 return 1;
71 }
72 return 0;
73 }