filenator/pawnutils/testing/codec_tests.c
Gryb4s 7d66f821bc goosnight tests
FileInfo pawn codec test init.
2025-06-25 01:34:27 +03:00

51 lines
1.1 KiB
C

#include <assert.h>
#include <pawnutils/codec.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
void test_FileCfg_codec() {
srand((unsigned)time(0));
pawn_FileCfg s;
s.max_filename_len = rand();
s.max_keyword_len = rand();
struct_buf b;
s_buf_init(&b, sizeof(pawn_FileCfg));
size_t s_s = serialize_pawn_FileCfg(&b, &s);
assert(s_s != 0);
pawn_FileCfg a;
int d_s = deserialize_pawn_FileCfg(&b, &a);
assert(d_s == 1);
assert(a.max_filename_len == s.max_filename_len);
assert(a.max_keyword_len == s.max_keyword_len);
}
// todo: assert and rand data pawn_FileInfo.
void test_FileInfo_codec() {
srand((unsigned)time(0));
pawn_FileCfg s;
s.max_filename_len = rand();
s.max_filename_len = rand();
pawn_FileInfo i;
struct_buf b;
size_t buf_size = sizeof(pawn_FileInfo);
if (i.keywords != 0) {
buf_size += i.keyword_count * sizeof(uint8_t *);
for (uint64_t e = 0; e < i.keyword_count; e++) {
buf_size += strlen((const char *)i.keywords[e]) + 1;
}
}
if (i.filename != 0)
buf_size += strlen((const char *)i.filename) + 1;
s_buf_init(&b, buf_size);
}