Skip to content

Commit

Permalink
* NEW Update the unit of codec/proto.
Browse files Browse the repository at this point in the history
Signed-off-by: wanghaemq <[email protected]>
  • Loading branch information
wanghaEMQ committed Jun 1, 2024
1 parent 1dfab5a commit 10cb540
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions test/codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,28 @@ test_codec_ack()
static int
test_codec_file()
{
int rv;
nftp * p;
size_t len;
uint8_t *v;

uint8_t demo1_file[] = {
0x03, 0x00, 0x00, 0x00, 0x13, // type & length
0x03, 0x00, 0x00, 0x00, 0x15, // type & length
0x7c, 0x6d, 0x8b, 0xab, // fileid
0x00, 0x02, 0x00, 0x06, // blockseq & length of content
0x00, 0x02, 0x00, 0x00, 0x00, 0x06, // blockseq & length of content
0x61, 0x62, 0x63, 0x64, 0x65, 0x66 // content
};

assert(0 == nftp_alloc(&p));

assert(0 == nftp_decode(p, demo1_file, sizeof(demo1_file)));
assert(0 == (rv = nftp_decode(p, demo1_file, sizeof(demo1_file))));

assert(NFTP_TYPE_FILE == p->type);
assert(sizeof(demo1_file) == p->len);
assert(((0x7c << 24) + (0x6d << 16) + (0x8b << 8) + (0xab)) == p->fileid);
assert(2 == p->blockseq);
assert(6 == p->ctlen);
assert(0 == strncmp((char *)(demo1_file + 13), (char *)p->content, 6));
assert(0 == strncmp((char *)(demo1_file + 15), (char *)p->content, 6));

assert(0 == nftp_encode(p, &v, &len));
assert(sizeof(demo1_file) == len);
Expand All @@ -147,9 +148,9 @@ test_codec_end()
uint8_t *v;

uint8_t demo1_end[] = {
0x04, 0x00, 0x00, 0x00, 0x13, // type & length
0x04, 0x00, 0x00, 0x00, 0x15, // type & length
0x7c, 0x6d, 0x8b, 0xab, // fileid
0x00, 0x02, 0x00, 0x06, // blockseq & length of content
0x00, 0x02, 0x00, 0x00, 0x00, 0x06, // blockseq & length of content
0x61, 0x62, 0x63, 0x64, 0x65, 0x66 // content
};

Expand All @@ -160,7 +161,7 @@ test_codec_end()
assert(NFTP_TYPE_END == p->type);
assert(sizeof(demo1_end) == p->len);
assert(((0x7c << 24) + (0x6d << 16) + (0x8b << 8) + (0xab)) == p->fileid);
assert(0 == strncmp((char *)(demo1_end + 13), (char *)p->content, 6));
assert(0 == strncmp((char *)(demo1_end + 15), (char *)p->content, 6));

assert(0 == nftp_encode(p, &v, &len));
assert(sizeof(demo1_end) == len);
Expand Down

0 comments on commit 10cb540

Please sign in to comment.