Skip to content
This repository was archived by the owner on Oct 13, 2020. It is now read-only.

Commit 102a584

Browse files
author
Christian Hergert
committed
tests: make bson_eq_bson a macro to squash inline warnings.
1 parent bfa5ec9 commit 102a584

File tree

1 file changed

+38
-47
lines changed

1 file changed

+38
-47
lines changed

tests/bson-tests.h

Lines changed: 38 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -58,53 +58,44 @@ BSON_BEGIN_DECLS
5858
#endif
5959

6060

61-
static BSON_INLINE void
62-
bson_eq_bson (bson_t *bson,
63-
bson_t *expected)
64-
{
65-
char *bson_json, *expected_json;
66-
const uint8_t *bson_data = bson_get_data (bson);
67-
const uint8_t *expected_data = bson_get_data (expected);
68-
int unequal;
69-
unsigned o;
70-
int off = -1;
71-
72-
unequal = (expected->len != bson->len)
73-
|| memcmp (bson_get_data (expected), bson_get_data (
74-
bson), expected->len);
75-
76-
if (unequal) {
77-
bson_json = bson_as_json (bson, NULL);
78-
expected_json = bson_as_json (expected, NULL);
79-
80-
for (o = 0; o < bson->len && o < expected->len; o++) {
81-
if (bson_data [o] != expected_data [o]) {
82-
off = o;
83-
break;
84-
}
85-
}
86-
87-
if (off == -1) {
88-
off = MAX (expected->len, bson->len) - 1;
89-
}
90-
91-
fprintf (stderr, "bson objects unequal (byte %u):\n(%s)\n(%s)\n",
92-
off, bson_json, expected_json);
93-
94-
{
95-
int fd1 = bson_open ("failure.bad.bson", O_RDWR | O_CREAT, 0640);
96-
int fd2 = bson_open ("failure.expected.bson", O_RDWR | O_CREAT, 0640);
97-
assert (fd1 != -1);
98-
assert (fd2 != -1);
99-
assert (bson->len == write (fd1, bson_data, bson->len));
100-
assert (expected->len == write (fd2, expected_data, expected->len));
101-
close (fd1);
102-
close (fd2);
103-
}
104-
105-
assert (0);
106-
}
107-
}
61+
#define bson_eq_bson(bson,expected) \
62+
do { \
63+
char *bson_json, *expected_json; \
64+
const uint8_t *bson_data = bson_get_data ((bson)); \
65+
const uint8_t *expected_data = bson_get_data ((expected)); \
66+
int unequal; \
67+
unsigned o; \
68+
int off = -1; \
69+
unequal = ((expected)->len != (bson)->len) \
70+
|| memcmp (bson_get_data ((expected)), bson_get_data ( \
71+
(bson)), (expected)->len); \
72+
if (unequal) { \
73+
bson_json = bson_as_json (bson, NULL); \
74+
expected_json = bson_as_json ((expected), NULL); \
75+
for (o = 0; o < (bson)->len && o < (expected)->len; o++) { \
76+
if (bson_data [o] != expected_data [o]) { \
77+
off = o; \
78+
break; \
79+
} \
80+
} \
81+
if (off == -1) { \
82+
off = MAX ((expected)->len, (bson)->len) - 1; \
83+
} \
84+
fprintf (stderr, "bson objects unequal (byte %u):\n(%s)\n(%s)\n", \
85+
off, bson_json, expected_json); \
86+
{ \
87+
int fd1 = bson_open ("failure.bad.bson", O_RDWR | O_CREAT, 0640); \
88+
int fd2 = bson_open ("failure.expected.bson", O_RDWR | O_CREAT, 0640); \
89+
assert (fd1 != -1); \
90+
assert (fd2 != -1); \
91+
assert ((bson)->len == write (fd1, bson_data, (bson)->len)); \
92+
assert ((expected)->len == write (fd2, expected_data, (expected)->len)); \
93+
close (fd1); \
94+
close (fd2); \
95+
} \
96+
assert (0); \
97+
} \
98+
} while (0)
10899

109100

110101
static BSON_INLINE void

0 commit comments

Comments
 (0)