File: core_api.c

package info (click to toggle)
cgreen 1.6.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,588 kB
  • sloc: ansic: 12,276; sh: 558; makefile: 474; cpp: 403; python: 181; xml: 33; sed: 13
file content (53 lines) | stat: -rw-r--r-- 1,535 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
#include <cgreen/cgreen.h>
#include <cgreen/mocks.h>

/*
  These tests are only an attempt to exercise the whole public API of
  Cgreen to ensure that it compiles.  Attempting to run them will
  surely result in crashes, plagues and pestilence.  For unit tests
  see other tests.  */

#ifdef __cplusplus
using namespace cgreen;
#endif

// ASSERT
Ensure(assert_that_compiles) {
    assert_that(1 == 1);
    assert_that(1 == 1, is_true);
    assert_that_double(1, is_equal_to(1));
    significant_figures_for_assert_double_are(3);
}

// CONSTRAINTS
Ensure(constraints_compiles) {
    char array[5];
    char *string = (char *)"some string";

    assert_that(1, is_equal_to(1));
    assert_that(1, is_not_equal_to(1));
    assert_that(1, is_greater_than(1));
    assert_that(1, is_less_than(1));

    assert_that(array, is_equal_to_contents_of(array, 5));
    assert_that(array, is_not_equal_to_contents_of(array, 3));

    assert_that(string, is_equal_to_string(string));
    assert_that(string, is_not_equal_to_string(string));
    assert_that(string, contains_string(string));
    assert_that(string, does_not_contain_string(string));
    assert_that(string, begins_with_string(string));
}

static int int_stub(int parameter) {
    return mock(parameter);
}

// Mocks
Ensure(mocks_compiles) {
    always_expect(int_stub, will_return(1));
    always_expect(int_stub, will_set_contents_of_output_parameter(parameter, 1, sizeof(int)));
    never_expect(int_stub);
    expect(int_stub, when(parameter, is_equal_to(1)));
    int_stub(1);
}