File: SystemTest.c

package info (click to toggle)
monit 1%3A5.35.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,228 kB
  • sloc: ansic: 31,202; yacc: 4,634; sh: 4,071; lex: 1,190; pascal: 480; makefile: 285
file content (79 lines) | stat: -rw-r--r-- 2,083 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
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
#include "Config.h"

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>
#include <stdarg.h>

#include "Bootstrap.h"
#include "Str.h"
#include "system/System.h"
#include "system/Time.h"
#include "Thread.h"

/**
 * System.c unity tests.
 */


static void _handler(const char *s, va_list ap) {
        assert(s);
        char buf[STRLEN];
        va_list ap_copy;
        va_copy(ap_copy, ap);
        vsnprintf(buf, sizeof(buf), s, ap);
        va_end(ap_copy);
        printf("handler: %s", buf);
        assert(Str_isEqual(buf, "\tyellow submarine (5)(6)\n"));
}


int main(void) {

        Bootstrap(); // Need to initialize library

        printf("============> Start System Tests\n\n");

        printf("=> Test0: check error description\n");
        {
                const char *error = System_getError(EINVAL);
                assert(error != NULL);
                printf("\tEINVAL description: %s\n", error);
                errno = EINVAL;
                assert(Str_isEqual(System_lastError(), error));

        }
        printf("=> Test0: OK\n\n");

        printf("=> Test1: \n");
        {
                assert(System_descriptors(65) == 65);
                assert(System_descriptors(0) > 65);
                printf("\tMaximum file descriptors for process: %d\n", System_descriptors(0));
        }
        printf("=> Test1: OK\n\n");

        printf("=> Test2: check System_error\n");
        {
                System_error("\thello %s (%d)(%ld)\n", "world", 1, 2L);
                Bootstrap_setErrorHandler(_handler);
                System_error("\tyellow %s (%d)(%ld)\n", "submarine", 5, 6L);
        }
        printf("=> Test2: OK\n\n");

        printf("=> Test3: check System_error\n");
        {
                Bootstrap_setAbortHandler(_handler);
                System_abort("\tyellow %s (%d)(%ld)\n", "submarine", 5, 6L);
        }
        printf("=> Test3: OK\n\n");

        printf("============> System Tests: OK\n\n");

        return 0;
}