File: RandomTest.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 (65 lines) | stat: -rw-r--r-- 1,710 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
#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/Random.h"
#include "system/Time.h"

/**
 * Ranom.c unity tests.
 */


int main(void) {

        Bootstrap(); // Need to initialize library

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

        printf("=> Test0: Random data generator\n");
        {
                //
                printf("\tnumber:   %llu\n", Random_number());
                //
                printf("\t1  byte:  ");
                char buf0[1];
                assert(Random_bytes(buf0, sizeof(buf0)));
                for (size_t i = 0; i < sizeof(buf0); i++) {
                        printf("%x", buf0[i]);
                }
                printf("\n");
                //
                printf("\t4  bytes: ");
                char buf1[4];
                assert(Random_bytes(buf1, sizeof(buf1)));
                for (size_t i = 0; i < sizeof(buf1); i++) {
                        printf("%x", buf1[i]);
                }
                printf("\n");
                //
                printf("\t16 bytes: ");
                char buf2[16];
                assert(Random_bytes(buf2, sizeof(buf2)));
                for (size_t i = 0; i < sizeof(buf2); i++) {
                        printf("%x", buf2[i]);
                }
                printf("\n");
                //
                assert(Random_number() != Random_number());
        }
        printf("=> Test0: OK\n\n");

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

        return 0;
}