Skip to content

Commit b368bbd

Browse files
author
Pierre-Alexandre Meyer
committed
test: more decoding tests
They still fail at negative values though: Running TestSuite varint tests run: 7 assertions passed Test failure: expected -1 (?), got -4 (?) FAIL: test/smile_tests Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
1 parent a629e7b commit b368bbd

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
lines changed

c/src/smile_decode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ void smile_decode_value(u8** orig_data, struct content_handler* handler)
136136
if (length == 0) {
137137
// 32-bit
138138
handler->start_value();
139-
handler->number_value(varint_decode(orig_data));
139+
handler->number_value(zzvarint_decode(orig_data));
140140
(*orig_data)++;
141141
handler->end_value();
142142
} else if (length == 1) {
143143
// 64-bit
144144
handler->start_value();
145-
handler->number_value(varint_decode(orig_data));
145+
handler->number_value(zzvarint_decode(orig_data));
146146
(*orig_data)++;
147147
handler->end_value();
148148
} else if (length == 2) {

c/src/smile_utils.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,28 @@
1616

1717
#include "smile_utils.h"
1818

19-
long varint_decode(u8 **msg)
19+
long zzvarint_decode(u8 **msg)
2020
{
21-
// TODO - it doesn't work yet
22-
return 0L;
21+
return ZZ_DECODE(varint_decode(msg));
2322
}
2423

25-
long varint_decode_buffer(u8* input)
24+
long varint_decode(u8 **msg)
2625
{
27-
u8* msg = input;
2826
long x = 0;
29-
while(!(*msg & 0x80)) {
27+
while(!(**msg & 0x80)) {
3028
x <<= 7;
31-
x |= *msg;
32-
msg++;
29+
x |= **msg;
30+
(*msg)++;
3331
}
3432
// last byte only has 6 payload bits
3533
x <<= 6;
36-
x |= (*msg & 0x3F);
34+
x |= (**msg & 0x3F);
3735
return x;
3836
}
37+
38+
// For testing
39+
long varint_decode_buffer(u8* input)
40+
{
41+
u8* msg = input;
42+
varint_decode(&msg);
43+
}

c/src/smile_utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#define ZZ_DECODE(n) ((n >> 1) ^ (-(n & 1)))
77

8+
long zzvarint_decode(u8**);
89
long varint_decode(u8**);
910
long varint_decode_buffer(u8*);
1011

c/test/test_decode.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ inline void noop()
4949
{
5050
}
5151

52-
inline void number(long number)
52+
static long expected_long = 0;
53+
static char* expected_string = NULL;
54+
55+
inline void number(long actual)
5356
{
54-
// TODO
55-
//printf("%lu\n", number);
57+
ASSERT_EQUAL(expected_long, actual)
5658
}
5759

58-
static char* expected_string = NULL;
59-
6060
inline void string(const u8* ch, int start, int length)
6161
{
6262
//printf("%s (%s)\n", ch, expected_string);
@@ -91,7 +91,7 @@ void test_decode_smile()
9191

9292
expected_string = "eventDate";
9393
smile_decode_key((u8**) &ip, &handler);
94-
// TODO
94+
expected_long = 1311225160270;
9595
smile_decode_value((u8**) &ip, &handler);
9696

9797
expected_string = "eventGranularity";
@@ -101,7 +101,7 @@ void test_decode_smile()
101101

102102
expected_string = "int";
103103
smile_decode_key((u8**) &ip, &handler);
104-
// TODO
104+
expected_long = 1242;
105105
smile_decode_value((u8**) &ip, &handler);
106106

107107
expected_string = "string";
@@ -111,12 +111,12 @@ void test_decode_smile()
111111

112112
expected_string = "negative";
113113
smile_decode_key((u8**) &ip, &handler);
114-
// TODO
114+
expected_long = -1;
115115
smile_decode_value((u8**) &ip, &handler);
116116

117117
expected_string = "long";
118118
smile_decode_key((u8**) &ip, &handler);
119-
// TODO
119+
expected_long = 123456789;
120120
smile_decode_value((u8**) &ip, &handler);
121121
}
122122

0 commit comments

Comments
 (0)