Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
hiredis
Commits
112019a0
Commit
112019a0
authored
Jul 05, 2011
by
Pieter Noordhuis
Browse files
Print values on assertion failure
parent
03a86088
Changes
1
Hide whitespace changes
Inline
Side-by-side
test/parser.c
View file @
112019a0
...
@@ -4,6 +4,16 @@
...
@@ -4,6 +4,16 @@
#include <assert.h>
#include <assert.h>
#include "parser.h"
#include "parser.h"
#define assert_equal_size_t(a,b) do { \
__typeof__ (a) a_ = (a); \
__typeof__ (b) b_ = (b); \
if (a_ != b_) { \
fprintf(stderr, "%s:%d: %lu != %lu\n", \
__FILE__, __LINE__, a_, b_); \
assert(0); \
} \
} while(0)
typedef
struct
log_entry_s
log_entry_t
;
typedef
struct
log_entry_s
log_entry_t
;
struct
log_entry_s
{
struct
log_entry_s
{
...
@@ -101,11 +111,11 @@ void test_char_by_char(redis_protocol_t *ref, const char *buf, size_t len) {
...
@@ -101,11 +111,11 @@ void test_char_by_char(redis_protocol_t *ref, const char *buf, size_t len) {
redis_parser_init
(
p
,
&
callbacks
);
redis_parser_init
(
p
,
&
callbacks
);
/* Slice 1 */
/* Slice 1 */
assert
(
i
==
redis_parser_execute
(
p
,
&
res
,
buf
,
i
));
assert
_equal_size_t
(
redis_parser_execute
(
p
,
&
res
,
buf
,
i
)
,
i
);
assert
(
NULL
==
res
);
/* no result */
assert
(
NULL
==
res
);
/* no result */
/* Slice 2 */
/* Slice 2 */
assert
(
len
-
i
==
redis_parser_execute
(
p
,
&
res
,
buf
+
i
,
len
-
i
));
assert
_equal_size_t
(
redis_parser_execute
(
p
,
&
res
,
buf
+
i
,
len
-
i
)
,
len
-
i
);
assert
(
NULL
!=
res
);
assert
(
NULL
!=
res
);
/* Compare result with reference */
/* Compare result with reference */
...
@@ -124,7 +134,7 @@ void test_string(void) {
...
@@ -124,7 +134,7 @@ void test_string(void) {
/* Parse and check resulting protocol_t */
/* Parse and check resulting protocol_t */
reset_cb_log
();
reset_cb_log
();
assert
(
redis_parser_execute
(
p
,
&
res
,
buf
,
len
)
==
len
);
assert
_equal_size_t
(
redis_parser_execute
(
p
,
&
res
,
buf
,
len
)
,
len
);
assert
(
res
!=
NULL
);
assert
(
res
!=
NULL
);
assert
(
res
->
type
==
REDIS_STRING_T
);
assert
(
res
->
type
==
REDIS_STRING_T
);
assert
(
res
->
poff
==
0
);
assert
(
res
->
poff
==
0
);
...
@@ -155,7 +165,7 @@ void test_array(void) {
...
@@ -155,7 +165,7 @@ void test_array(void) {
/* Parse and check resulting protocol_t */
/* Parse and check resulting protocol_t */
reset_cb_log
();
reset_cb_log
();
assert
(
redis_parser_execute
(
p
,
&
res
,
buf
,
len
)
==
len
);
assert
_equal_size_t
(
redis_parser_execute
(
p
,
&
res
,
buf
,
len
)
,
len
);
assert
(
res
!=
NULL
);
assert
(
res
!=
NULL
);
assert
(
res
->
type
==
REDIS_ARRAY_T
);
assert
(
res
->
type
==
REDIS_ARRAY_T
);
assert
(
res
->
poff
==
0
);
assert
(
res
->
poff
==
0
);
...
@@ -199,7 +209,7 @@ void test_integer(void) {
...
@@ -199,7 +209,7 @@ void test_integer(void) {
/* Parse and check resulting protocol_t */
/* Parse and check resulting protocol_t */
reset_cb_log
();
reset_cb_log
();
assert
(
redis_parser_execute
(
p
,
&
res
,
buf
,
len
)
==
len
);
assert
_equal_size_t
(
redis_parser_execute
(
p
,
&
res
,
buf
,
len
)
,
len
);
assert
(
res
!=
NULL
);
assert
(
res
!=
NULL
);
assert
(
res
->
type
==
REDIS_INTEGER_T
);
assert
(
res
->
type
==
REDIS_INTEGER_T
);
assert
(
res
->
poff
==
0
);
assert
(
res
->
poff
==
0
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment