DtsodV24 deserialization almost completed
This commit is contained in:
47
DtsodC/tests/main.c
Normal file
47
DtsodC/tests/main.c
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "../src/base/base.h"
|
||||
#include "tests.h"
|
||||
|
||||
|
||||
void printuni(Unitype v){
|
||||
switch (v.type) {
|
||||
case Null: printf("{%s}",typename(v.type));break;
|
||||
case Double: printf("{%s:%lf}",typename(v.type),v.Double);break;
|
||||
case Float: printf("{%s:%f}",typename(v.type),v.Float);break;
|
||||
case Char: printf("{%s:%c}",typename(v.type),v.Int8);break;
|
||||
case UInt8:
|
||||
case UInt16: printf("{%s:%u}",typename(v.type),v.UInt16);break;
|
||||
case UInt32:
|
||||
case UInt64: printf("{%s:%lu}",typename(v.type),v.UInt64);break;
|
||||
case Bool:
|
||||
case Int8:
|
||||
case Int16: printf("{%s:%d}",typename(v.type),v.Int16);break;
|
||||
case Int32:
|
||||
case Int64: printf("{%s:%ld}",typename(v.type),v.Int64);break;
|
||||
case Int8Ptr:
|
||||
case UInt8Ptr:
|
||||
case Int16Ptr:
|
||||
case UInt16Ptr:
|
||||
case Int32Ptr:
|
||||
case UInt32Ptr:
|
||||
case Int64Ptr:
|
||||
case UInt64Ptr: printf("{%s:%p}",typename(v.type),v.VoidPtr);break;
|
||||
default: throw(ERR_WRONGTYPE);break;
|
||||
}
|
||||
}
|
||||
|
||||
void test_all(){
|
||||
test_searchtree();
|
||||
test_autoarr2();
|
||||
test_hashtable();
|
||||
test_string();
|
||||
test_dtsod();
|
||||
printf("\e[96m---------------------------------------\e[0m\n");
|
||||
}
|
||||
|
||||
int main(){
|
||||
setlocale(LC_ALL, "en-US.Unicode");
|
||||
printf("\e[92mdtsod parser in c language!\e[97m\n");
|
||||
optime("test_all",1,{test_all();});
|
||||
printf("\e[0m\n");
|
||||
return 0;
|
||||
}
|
||||
52
DtsodC/tests/test_autoarr2.c
Normal file
52
DtsodC/tests/test_autoarr2.c
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "tests.h"
|
||||
#include "../src/Autoarr/Autoarr2.h"
|
||||
|
||||
static void printautoarr(Autoarr2(uint16)* ar){
|
||||
printf("\e[94mAutoarr2(uint16): %lu\n"
|
||||
" max_blocks_count: %u\n"
|
||||
" blocks_count: %u\n"
|
||||
" max_block_length: %u\n"
|
||||
" block_length: %u\n"
|
||||
" max_length: %u\n"
|
||||
" length: %u\n",
|
||||
sizeof(Autoarr2(uint16)),
|
||||
ar->max_blocks_count,
|
||||
ar->blocks_count,
|
||||
ar->max_block_length,
|
||||
ar->block_length,
|
||||
Autoarr2_max_length(ar),
|
||||
Autoarr2_length(ar));
|
||||
}
|
||||
|
||||
static void fillar(Autoarr2(uint16)* ar){
|
||||
for (uint16 i=0;i<Autoarr2_max_length(ar);i++)
|
||||
Autoarr2_add(ar,i);
|
||||
}
|
||||
static void resetar(Autoarr2(uint16)* ar){
|
||||
for (uint16 i=0;i<Autoarr2_max_length(ar);i++)
|
||||
Autoarr2_set(ar,i,Autoarr2_max_length(ar)-i-1);
|
||||
}
|
||||
|
||||
static void printallval(Autoarr2(uint16)* ar){
|
||||
printf("\e[90m");
|
||||
for (uint16 i=0;i<Autoarr2_length(ar);i++)
|
||||
printf("%u ",Autoarr2_get(ar,i));
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void test_autoarr2(){
|
||||
optime("test_autoarr2",1,({
|
||||
printf("\e[96m------------[test_autoarr2]------------\n");
|
||||
Autoarr2(uint16) ar=Autoarr2_create(uint16,10,16);
|
||||
printf("\e[92mautoarr created\n");
|
||||
fillar(&ar);
|
||||
printf("\e[92mautoarr filled up\n");
|
||||
printautoarr(&ar);
|
||||
printallval(&ar);
|
||||
resetar(&ar);
|
||||
printf("\e[92mautoarr values reset\n");
|
||||
printallval(&ar);
|
||||
Autoarr2_clear(((&ar)));
|
||||
printf("\e[92mautoarr cleared\n");
|
||||
}));
|
||||
}
|
||||
19
DtsodC/tests/test_dtsod.c
Normal file
19
DtsodC/tests/test_dtsod.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "tests.h"
|
||||
#include "../src/DtsodParser/DtsodV24.h"
|
||||
|
||||
void test_dtsod(){
|
||||
optime(__func__,1,({
|
||||
printf("\e[96m-------------[test_dtsod]-------------\n");
|
||||
char text[]=
|
||||
"message:\n"
|
||||
"{\n"
|
||||
" type: \"sent\";\n"
|
||||
" time: \"15.12.2021 20:51:24 +03:00\";\n"
|
||||
" author_id: 293798876950036480ul;\n"
|
||||
" channel_id: 913088838761603212ul;\n"
|
||||
" message_id: 920734809096077353ul;\n"
|
||||
" text: \"_$\\\"\\\\'''\n\ta ыыы000;2;=:%d;```\";\n"
|
||||
"};\n";
|
||||
Hashtable* dtsod=DtsodV24_deserialize(text);
|
||||
}));
|
||||
}
|
||||
77
DtsodC/tests/test_hashtable.c
Normal file
77
DtsodC/tests/test_hashtable.c
Normal file
@@ -0,0 +1,77 @@
|
||||
#include "tests.h"
|
||||
#include "../src/Hashtable/Hashtable.h"
|
||||
|
||||
void printkvp(KeyValuePair p){
|
||||
printf("{\"%s\", ",p.key);
|
||||
printuni(p.value);
|
||||
printf("}");
|
||||
}
|
||||
|
||||
void print_hashtable(Hashtable* ht){
|
||||
printf("\e[94mHashtable:%lu\n"
|
||||
" hein: %u\n"
|
||||
" height: %u\n"
|
||||
" rows: %p\n",
|
||||
sizeof(Hashtable),
|
||||
ht->hein,
|
||||
Hashtable_height(ht),
|
||||
ht->rows);
|
||||
}
|
||||
|
||||
void printrowgraph(Hashtable* ht){
|
||||
printf("\e[94mrow length graph:\n");
|
||||
uint16 lgs_l=1000;
|
||||
uint32 lgs[lgs_l];
|
||||
for(uint32 i=0; i<lgs_l; i++)
|
||||
lgs[i]=0;
|
||||
for(uint16 h=0;h<Hashtable_height(ht);h++){
|
||||
Autoarr2(KeyValuePair)* ar=ht->rows+h;
|
||||
uint32 l=Autoarr2_length(ar);
|
||||
lgs[l]++;
|
||||
}
|
||||
for(uint32 i=0; i<lgs_l; i++)
|
||||
if(lgs[i]>0) {
|
||||
char* str0=char_multiply(' ',i>=100?0:(i>=10?1:2));
|
||||
char* str1=char_multiply(' ',lgs[i]>=100?0:(lgs[i]>=10?1:2));
|
||||
char* str2=char_multiply('#',lgs[i]/100);
|
||||
printf("\e[94m length: \e[96m%u %s \e[94mfrequency: \e[96m%u %s \e[90m%s\n",i,str0,lgs[i],str1,str2);
|
||||
free(str0);
|
||||
free(str1);
|
||||
free(str2);
|
||||
}
|
||||
}
|
||||
|
||||
void fill(Hashtable* ht){
|
||||
for(uint32 i=0;i<100000;i++){
|
||||
char* key=malloc(12);
|
||||
sprintf(key,"key__%u",i);
|
||||
Hashtable_add(ht,key,Uni(UInt32,i));
|
||||
}
|
||||
}
|
||||
|
||||
Unitype gett(Hashtable* ht){
|
||||
char* key=malloc(12);
|
||||
Unitype u;
|
||||
for(uint32 i=0;i<100000;i++){
|
||||
sprintf(key,"key__%u",i);
|
||||
u=Hashtable_get(ht,key);
|
||||
}
|
||||
free(key);
|
||||
return u;
|
||||
}
|
||||
|
||||
|
||||
void test_hashtable(){
|
||||
optime("test_hashtable",1,({
|
||||
printf("\e[96m-----------[test_hashtable]------------\n");
|
||||
Hashtable* ht=Hashtable_create();
|
||||
printf("\e[92mhashtable created\n");
|
||||
print_hashtable(ht);
|
||||
optime("fill",1,fill(ht));
|
||||
optime("get",1,gett(ht));
|
||||
printrowgraph(ht);
|
||||
print_hashtable(ht);
|
||||
Hashtable_free(ht);
|
||||
printf("\e[92mhashtable freed\n");
|
||||
}));
|
||||
}
|
||||
71
DtsodC/tests/test_searchtree.c
Normal file
71
DtsodC/tests/test_searchtree.c
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "tests.h"
|
||||
#include "../src/SearchTree/SearchTree.h"
|
||||
|
||||
void printstnode(STNode* node){
|
||||
printf("\e[94mSTNode: %lu\n address: %p\n value: ",sizeof(STNode),node);
|
||||
printuni(node->value);
|
||||
// prints pointers to all existing branches
|
||||
printf("\n branches: %p\n", node->branches);
|
||||
if(node->branches) for(uint8 i=0;i<8;i++){
|
||||
printf(" \e[90m[%u]=%p\n",i,node->branches[i]);
|
||||
if(node->branches[i])
|
||||
for (uint8 ii = 0; ii < 8; ii++){
|
||||
printf(" \e[90m[%u]=%p\n",ii,node->branches[i][ii]);
|
||||
if(node->branches[i][ii])
|
||||
for (uint8 iii = 0; iii < 4; iii++)
|
||||
printf(" \e[90m[%u]=%p\n",iii,node->branches[i][ii][iii]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void test_searchtree(){
|
||||
optime("test_searchtree",1,({
|
||||
printf("\e[96m-----------[test_searchtree]-----------\n");
|
||||
STNode* node=STNode_create();
|
||||
printf("\e[92mnode created\n");
|
||||
printf("push:\e[94m\n ");
|
||||
Unitype u={.type=Int16,.Int16=-3};
|
||||
printuni(u);
|
||||
ST_push(node,"type", u);
|
||||
printf(" -> type\n ");
|
||||
u=(Unitype){.type=Int16,.Int16=25};
|
||||
printuni(u);
|
||||
ST_push(node,"time", u);
|
||||
printf(" -> time\n ");
|
||||
u=(Unitype){.type=Double,.Double=-542.00600};
|
||||
printuni(u);
|
||||
ST_push(node,"author_id", u);
|
||||
printf(" -> author_id\n ");
|
||||
u=(Unitype){.type=Int64,.Int64=-31255};
|
||||
printuni(u);
|
||||
ST_push(node,"channel_id", u);
|
||||
printf(" -> channel_id\n ");
|
||||
u=(Unitype){.type=Float,.Float=32.2004};
|
||||
printuni(u);
|
||||
ST_push(node,"message_id", u);
|
||||
printf(" -> message_id\n ");
|
||||
u=(Unitype){.type=Int8Ptr,.VoidPtr=malloc(1)};
|
||||
printuni(u);
|
||||
ST_push(node,"text", u);
|
||||
printf(" -> text\n");
|
||||
printf("\e[92mpull:\e[94m");
|
||||
printf("\n type -> ");
|
||||
printuni(ST_pull(node,"type"));
|
||||
printf("\n time -> ");
|
||||
printuni(ST_pull(node,"time"));
|
||||
printf("\n author_id -> ");
|
||||
printuni(ST_pull(node,"author_id"));
|
||||
printf("\n channel_id -> ");
|
||||
printuni(ST_pull(node,"channel_id"));
|
||||
printf("\n message_id -> ");
|
||||
printuni(ST_pull(node,"message_id"));
|
||||
printf("\n text -> ");
|
||||
printuni(ST_pull(node,"text"));
|
||||
printf("\n");
|
||||
printf("\e[92mfirst node: ");
|
||||
printstnode(node);
|
||||
STNode_free(node);
|
||||
printf("\e[92mnode deleted\n");
|
||||
}));
|
||||
}
|
||||
16
DtsodC/tests/test_string.c
Normal file
16
DtsodC/tests/test_string.c
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "tests.h"
|
||||
#include "../src/base/mystr.h"
|
||||
|
||||
void test_string(){
|
||||
optime(__func__,1,({
|
||||
printf("\e[96m-------------[test_string]-------------\n");
|
||||
char c[]="0123456789abcdef";
|
||||
string s=string_cpFromCharPtr(c);
|
||||
printf("\e[92m\"%s\" -> string_cpFromCharPtr()\n",c);
|
||||
if(s.length!=16) throw("string created with incorrect length");
|
||||
char* p=string_cpToCharPtr(s);
|
||||
printf("\e[92mstring_cpToCharPtr() -> \"%s\"\n",p);
|
||||
free(p);
|
||||
free(s.ptr);
|
||||
}));
|
||||
}
|
||||
11
DtsodC/tests/tests.h
Normal file
11
DtsodC/tests/tests.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "../src/base/base.h"
|
||||
|
||||
void printuni(Unitype v);
|
||||
|
||||
void test_searchtree();
|
||||
void test_autoarr2();
|
||||
void test_hashtable();
|
||||
void test_string();
|
||||
void test_dtsod();
|
||||
Reference in New Issue
Block a user