Skip to content

Commit

Permalink
Update printf-formatting tests to fail
Browse files Browse the repository at this point in the history
  • Loading branch information
pietern committed Jul 9, 2011
1 parent 5def864 commit 4ac55be
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,18 @@ static void test_format_commands(void) {
len == 4+4+(3+2)+4+(1+2)+4+(1+2));
free(cmd);

/* sizeof(long long) is 8 bytes regardless of architecture */
test("Format command with printf-delegation (long long): ");
len = redisFormatCommand(&cmd,"key:%08lld",1234ll);
test_cond(strncmp(cmd,"*1\r\n$12\r\nkey:00001234\r\n",len) == 0 &&
len == 4+5+(12+2));
len = redisFormatCommand(&cmd,"key:%08lld str:%s",1234ll, "hello");
test_cond(strncmp(cmd,"*2\r\n$12\r\nkey:00001234\r\n$9\r\nstr:hello\r\n",len) == 0 &&
len == 4+5+(12+2)+4+(9+2));
free(cmd);

/* sizeof(float) is 4 bytes regardless of architecture */
test("Format command with printf-delegation (float): ");
len = redisFormatCommand(&cmd,"v:%06.1f",12.34f);
test_cond(strncmp(cmd,"*1\r\n$8\r\nv:0012.3\r\n",len) == 0 &&
len == 4+4+(8+2));
len = redisFormatCommand(&cmd,"v:%06.1f str:%s",12.34f,"hello");
test_cond(strncmp(cmd,"*2\r\n$8\r\nv:0012.3\r\n$9\r\nstr:hello\r\n",len) == 0 &&
len == 4+4+(8+2)+4+(9+2));
free(cmd);

test("Format command with printf-delegation and extra interpolation: ");
Expand Down

0 comments on commit 4ac55be

Please sign in to comment.