File: test.c

package info (click to toggle)
cfengine3 3.24.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,552 kB
  • sloc: ansic: 163,161; sh: 10,296; python: 2,950; makefile: 1,744; lex: 784; yacc: 633; perl: 211; pascal: 157; xml: 21; sed: 13
file content (65 lines) | stat: -rw-r--r-- 1,251 bytes parent folder | download | duplicates (10)
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 <test.h>

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <alloc.h>

char *file_read_string(FILE *in)
{
    fpos_t pos;
    long size;
    char *buffer;

    assert_int_equal(fgetpos(in, &pos), 0);

    assert_int_equal(fseek(in, 0, SEEK_END), 0);
    size = ftell(in);
    assert_true(size >= 0);

    assert_int_equal(fseek(in, 0, SEEK_SET), 0);

    buffer = xcalloc(size + 1L, sizeof(char));
    assert_int_equal(fread(buffer, 1, size, in), size);

    assert_int_equal(fsetpos(in, &pos), 0);

    return buffer;
}

void assert_file_equal(FILE *a, FILE *b)
{
    char *a_buffer = file_read_string(a);
    char *b_buffer = file_read_string(b);

    if (strcmp(a_buffer, b_buffer) != 0)
    {
        printf("\n=====\n%s != \n=====\n%s\n", a_buffer, b_buffer);
        fail();
    }

    free(a_buffer);
    free(b_buffer);
}

#define SMALL_DIFF 1e-14

void _assert_double_close(double left, double right, const char *const file, const int line)
{
    if (fabs(left - right) > SMALL_DIFF)
    {
        print_error("%f != %f (+- 1e-14)\n", left, right);
        _fail(file, line);
    }
}

void test_progress()
{
    putchar('.');
    fflush(stdout);
}
void test_progress_end()
{
    putchar('\n');
    fflush(stdout);
}