Skip to content

Commit a52dc9c

Browse files
committed
Added macros to denote OK and KO + more tests implemented
1 parent 8948933 commit a52dc9c

File tree

5 files changed

+105
-22
lines changed

5 files changed

+105
-22
lines changed

carbon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern "C" {
3030
#include "include/carbon_log.h"
3131
#include "include/carbon_junit.h"
3232
#include "include/carbon_should.h"
33+
#include "include/carbon_defines.h"
3334
#include "include/carbon_test_manager.h"
3435

3536
#ifdef __cplusplus

include/carbon_defines.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* BSD Carbon --- A simple C/C++ unit testing framework
3+
* Copyright (C) 2024 Wasym A. Alonso
4+
*
5+
* This file is part of Carbon.
6+
*
7+
* Carbon is free software: you can redistribute it and/or modify
8+
* it under the terms of the BSD 3-Clause "New" or "Revised" License
9+
* as published by The Regents of the University of California.
10+
*
11+
* Carbon is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* BSD 3-Clause "New" or "Revised" License for more details.
15+
*
16+
* You should have received a copy of the BSD 3-Clause "New" or
17+
* "Revised" License along with Carbon.
18+
* If not, see <https://opensource.org/license/BSD-3-Clause>.
19+
*/
20+
21+
22+
#pragma once
23+
24+
#define CARBON_OK 1
25+
#define CARBON_KO 0

include/carbon_should.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
__LINE__, \
3232
(int) (actual), \
3333
(int) (expected)); \
34-
return 0; \
34+
return CARBON_KO; \
3535
} \
3636
}
3737

@@ -43,7 +43,7 @@
4343
__LINE__, \
4444
(int) (actual), \
4545
(int) (expected)); \
46-
return 0; \
46+
return CARBON_KO; \
4747
} \
4848
}
4949

@@ -57,7 +57,7 @@
5757
(int) (expected), \
5858
(int) (actual), \
5959
(int) (expected)); \
60-
return 0; \
60+
return CARBON_KO; \
6161
} \
6262
}
6363

@@ -71,21 +71,21 @@
7171
(int) (expected), \
7272
(int) (actual), \
7373
(int) (expected)); \
74-
return 0; \
74+
return CARBON_KO; \
7575
} \
7676
}
7777

7878
#define carbon_should_be_gt(expected, actual) \
7979
{ \
80-
if ((int) (expected) >= (int) (actual)) { \
80+
if ((int) (expected) >= (int) (actual)) { \
8181
CARBON_ERROR("%s:%d :: FAILED -> got '%d <= %d', expected '%d > %d'\n", \
8282
__FILE__, \
8383
__LINE__, \
8484
(int) (actual), \
8585
(int) (expected), \
8686
(int) (actual), \
8787
(int) (expected)); \
88-
return 0; \
88+
return CARBON_KO; \
8989
} \
9090
}
9191

@@ -99,31 +99,31 @@
9999
(int) (expected), \
100100
(int) (actual), \
101101
(int) (expected)); \
102-
return 0; \
102+
return CARBON_KO; \
103103
} \
104104
}
105105

106106
#define carbon_should_be_p(expected, actual) \
107107
{ \
108-
if ((void *) (expected) != (void *) (actual)) { \
108+
if ((void *) (expected) != (void *) (actual)) { \
109109
CARBON_ERROR("%s:%d :: FAILED -> got '%p', expected '%p'\n", \
110110
__FILE__, \
111111
__LINE__, \
112112
(void *) (actual), \
113113
(void *) (expected)); \
114-
return 0; \
114+
return CARBON_KO; \
115115
} \
116116
}
117117

118118
#define carbon_should_not_be_p(expected, actual) \
119119
{ \
120-
if ((void *) (expected) == (void *) (actual)) { \
120+
if ((void *) (expected) == (void *) (actual)) { \
121121
CARBON_ERROR("%s:%d :: FAILED -> got '%p == %p', expected not to\n", \
122122
__FILE__, \
123123
__LINE__, \
124124
(void *) (actual), \
125125
(void *) (expected)); \
126-
return 0; \
126+
return CARBON_KO; \
127127
} \
128128
}
129129

@@ -135,7 +135,7 @@
135135
__LINE__, \
136136
(actual), \
137137
(expected)); \
138-
return 0; \
138+
return CARBON_KO; \
139139
} \
140140
}
141141

@@ -147,7 +147,7 @@
147147
__LINE__, \
148148
(actual), \
149149
(expected)); \
150-
return 0; \
150+
return CARBON_KO; \
151151
} \
152152
}
153153

@@ -157,7 +157,7 @@
157157
CARBON_ERROR("%s:%d :: FAILED -> got 'false', expected 'true'\n", \
158158
__FILE__, \
159159
__LINE__); \
160-
return 0; \
160+
return CARBON_KO; \
161161
} \
162162
}
163163

@@ -167,6 +167,6 @@
167167
CARBON_ERROR("%s:%d :: FAILED -> got 'true', expected 'false'\n", \
168168
__FILE__, \
169169
__LINE__); \
170-
return 0; \
170+
return CARBON_KO; \
171171
} \
172172
}

test/src/carbon_should_test.c

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,84 @@
2424

2525
static unsigned char carbon_should_test_should_be(void) {
2626
carbon_should_be(1, 1);
27-
return 1;
27+
return CARBON_OK;
2828
}
2929

3030
static unsigned char carbon_should_test_should_not_be(void) {
3131
carbon_should_not_be(2, 1);
32-
return 1;
32+
return CARBON_OK;
33+
}
34+
35+
static unsigned char carbon_should_test_should_be_lt(void) {
36+
carbon_should_be_lt(2, 1);
37+
return CARBON_OK;
38+
}
39+
40+
static unsigned char carbon_should_test_should_be_le(void) {
41+
carbon_should_be_le(1, 1);
42+
carbon_should_be_le(2, 1);
43+
return CARBON_OK;
44+
}
45+
46+
static unsigned char carbon_should_test_should_be_gt(void) {
47+
carbon_should_be_gt(1, 2);
48+
return CARBON_OK;
49+
}
50+
51+
static unsigned char carbon_should_test_should_be_ge(void) {
52+
carbon_should_be_ge(1, 1);
53+
carbon_should_be_ge(1, 2);
54+
return CARBON_OK;
55+
}
56+
57+
static unsigned char carbon_should_test_should_be_p(void) {
58+
int i = 7;
59+
int *i_addr = &i;
60+
carbon_should_be_p(i_addr, &i);
61+
return CARBON_OK;
62+
}
63+
64+
static unsigned char carbon_should_test_should_not_be_p(void) {
65+
int i = 7, j = 9;
66+
carbon_should_not_be_p(0, &i);
67+
carbon_should_not_be_p(0, &j);
68+
carbon_should_not_be_p(&i, &j);
69+
return CARBON_OK;
70+
}
71+
72+
static unsigned char carbon_should_test_should_be_s(void) {
73+
const char *s = "Hello, World!";
74+
carbon_should_be_s("Hello, World!", s);
75+
return CARBON_OK;
76+
}
77+
78+
static unsigned char carbon_should_test_should_not_be_s(void) {
79+
const char *s = "Hello, World!";
80+
carbon_should_not_be_s("Hello, Seaman!", s);
81+
return CARBON_OK;
3382
}
3483

3584
static unsigned char carbon_should_test_should_be_true(void) {
3685
carbon_should_be_true(1 == 1);
37-
return 1;
86+
return CARBON_OK;
3887
}
3988

4089
static unsigned char carbon_should_test_should_be_false(void) {
4190
carbon_should_be_false(2 == 1);
42-
return 1;
91+
return CARBON_OK;
4392
}
4493

4594
void carbon_should_test_register(void) {
4695
CARBON_REGISTER_TEST(carbon_should_test_should_be);
4796
CARBON_REGISTER_TEST(carbon_should_test_should_not_be);
97+
CARBON_REGISTER_TEST(carbon_should_test_should_be_lt);
98+
CARBON_REGISTER_TEST(carbon_should_test_should_be_le);
99+
CARBON_REGISTER_TEST(carbon_should_test_should_be_gt);
100+
CARBON_REGISTER_TEST(carbon_should_test_should_be_ge);
101+
CARBON_REGISTER_TEST(carbon_should_test_should_be_p);
102+
CARBON_REGISTER_TEST(carbon_should_test_should_not_be_p);
103+
CARBON_REGISTER_TEST(carbon_should_test_should_be_s);
104+
CARBON_REGISTER_TEST(carbon_should_test_should_not_be_s);
48105
CARBON_REGISTER_TEST(carbon_should_test_should_be_true);
49106
CARBON_REGISTER_TEST(carbon_should_test_should_be_false);
50107
}

test/src/carbon_test_manager_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424

2525
static unsigned char test_dummy(void) {
2626
carbon_should_be_true(1 == 1);
27-
return 1;
27+
return CARBON_OK;
2828
}
2929

3030
static unsigned char carbon_test_manager_test_suite_creation(void) {
3131
Suite s = carbon_test_manager_spawn();
3232
carbon_should_be_p(0, s.tests);
3333
carbon_should_be(0, s.n);
34-
return 1;
34+
return CARBON_OK;
3535
}
3636

3737
static unsigned char carbon_test_manager_test_registration(void) {
@@ -47,7 +47,7 @@ static unsigned char carbon_test_manager_test_registration(void) {
4747
carbon_test_manager_cleanup_s(&s);
4848
carbon_should_be_p(0, s.tests);
4949
carbon_should_be(0, s.n);
50-
return 1;
50+
return CARBON_OK;
5151
}
5252

5353
void carbon_test_manager_test_register(void) {

0 commit comments

Comments
 (0)