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
271cca8d
Commit
271cca8d
authored
Jan 04, 2012
by
Pieter Noordhuis
Browse files
Use macro in formatting tests
parent
b9e0d8a6
Changes
1
Show whitespace changes
Inline
Side-by-side
test/test-format.c
View file @
271cca8d
...
...
@@ -10,19 +10,21 @@
#include "../format.h"
#include "test-helper.h"
void
test_format_without_interpolation
(
void
)
{
char
*
cmd
;
#define SETUP() \
char *cmd;
\
int len;
TEST
(
format_without_interpolation
)
{
SETUP
();
len
=
redis_format_command
(
&
cmd
,
"SET foo bar"
);
assert
(
strncmp
(
cmd
,
"*3
\r\n
$3
\r\n
SET
\r\n
$3
\r\n
foo
\r\n
$3
\r\n
bar
\r\n
"
,
len
)
==
0
&&
len
==
4
+
4
+
(
3
+
2
)
+
4
+
(
3
+
2
)
+
4
+
(
3
+
2
));
free
(
cmd
);
}
void
test_format_with_string_interpolation
(
void
)
{
char
*
cmd
;
int
len
;
TEST
(
format_with_string_interpolation
)
{
SETUP
();
/* Regular */
len
=
redis_format_command
(
&
cmd
,
"SET %s %s"
,
"foo"
,
"bar"
);
...
...
@@ -43,9 +45,8 @@ void test_format_with_string_interpolation(void) {
free
(
cmd
);
}
void
test_format_with_binary_interpolation
(
void
)
{
char
*
cmd
;
int
len
;
TEST
(
format_with_binary_interpolation
)
{
SETUP
();
/* Regular */
len
=
redis_format_command
(
&
cmd
,
"SET %b %b"
,
"f
\0
o"
,
3
,
"b
\0
r"
,
3
);
...
...
@@ -66,9 +67,8 @@ void test_format_with_binary_interpolation(void) {
free
(
cmd
);
}
void
test_format_with_literal_percent
(
void
)
{
char
*
cmd
;
int
len
;
TEST
(
format_with_literal_percent
)
{
SETUP
();
len
=
redis_format_command
(
&
cmd
,
"SET %% %%"
);
assert
(
strncmp
(
cmd
,
"*3
\r\n
$3
\r\n
SET
\r\n
$1
\r\n
%
\r\n
$1
\r\n
%
\r\n
"
,
len
)
==
0
&&
...
...
@@ -76,9 +76,8 @@ void test_format_with_literal_percent(void) {
free
(
cmd
);
}
void
test_format_with_printf_format
(
void
)
{
char
*
cmd
;
int
len
;
TEST
(
format_with_printf_format
)
{
SETUP
();
/* Vararg width depends on the type. These tests make sure that the
* width is correctly determined using the format and subsequent varargs
...
...
@@ -111,20 +110,18 @@ void test_format_with_printf_format(void) {
INTEGER_WIDTH_TEST
(
"llu"
,
unsigned
long
long
);
FLOAT_WIDTH_TEST
(
float
);
FLOAT_WIDTH_TEST
(
double
);
}
void
test_format_with_invalid_printf_format
(
void
)
{
char
*
cmd
;
int
len
;
TEST
(
format_with_invalid_printf_format
)
{
SETUP
();
len
=
redis_format_command
(
&
cmd
,
"key:%08p %b"
,
1234
,
"foo"
,
3
);
assert
(
len
==
-
1
);
}
void
test_
format_argv
(
void
)
{
char
*
cmd
;
int
len
;
TEST
(
format_argv
)
{
SETUP
()
;
int
argc
=
3
;
const
char
*
argv
[
3
]
=
{
"SET"
,
"foo
\0
xxx"
,
"bar"
};
size_t
lens
[
3
]
=
{
3
,
7
,
3
};
...
...
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