From 3c89841f31cd7fc6cb35c129a9135c5e974a7649 Mon Sep 17 00:00:00 2001 From: FreeArtMan <=> Date: Sat, 7 Nov 2015 18:18:59 +0000 Subject: example/test source --- test/test_multiple_write.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 test/test_multiple_write.c (limited to 'test/test_multiple_write.c') diff --git a/test/test_multiple_write.c b/test/test_multiple_write.c new file mode 100644 index 0000000..53d7cae --- /dev/null +++ b/test/test_multiple_write.c @@ -0,0 +1,96 @@ +#include +#include + +#include + +void pr_u8( nb_u8 *u8 ) +{ + if ( !u8 ) + { + printf("u8: NULL\n"); + return; + } else + { + printf("u8: t=0x%x v=0x%x\n", u8->type, u8->val ); + } +} + +void pr_u8arr( nb_u8arr *u8arr ) +{ + if (!u8arr) + { + printf("u8arr: NULL\n"); + return ; + } else + { + printf("u8arr: t=0x%x l=0x%x v=0x%x\n", + u8arr->type, u8arr->len, u8arr->val ); + } +} + +void pr_store( netbyte_store *nb ) +{ + int i; + + if (!nb) + { + printf("nb: NULL\n"); + return; + } + + printf("nb: s=0x%x c=0x%x\n", nb->size, nb->count ); + for (i=0;icount;i++) + { + printf("\t[%x] -> ",i ); + if ( nb->types[i].type == NBT_U8 ) + { + pr_u8( (nb_u8 *)nb->types[i].nb_val ); + } else if ( nb->types[i].type == NBT_U8ARRAY ) + { + pr_u8arr( (nb_u8arr *)nb->types[i].nb_val ); + } else + { + printf("Unknown\n"); + } + } +} + +int main() +{ + + int er; + const int len = 11; + char *str = "0123456789"; + uint8_t *res; + FILE *f; + + netbyte_store nb; + nb_u8arr u8arr; + + nb_init( &nb ); + + er = nb_u8arr_create( &u8arr, len, &str[0] ); + if (er) + printf("er create u8arr: %d\n",er); + + pr_u8arr( &u8arr ); + + er = nb_add_u8arr( &nb, &u8arr ); + if (er) + printf("er add u8arr: %d\n",er); + + pr_store( &nb ); + res = nb_create( &nb ); + pr_store( &nb ); + + f = fopen("test_many.nb","w+"); + fwrite( res, 1, nb.size , f ); + fwrite( res, 1, nb.size , f ); + fwrite( res, 1, nb.size , f ); + fwrite( res, 1, nb.size , f ); + fwrite( res, 1, nb.size , f ); + fclose( f ); + + printf("End test\n"); + return 0; +} \ No newline at end of file -- cgit v1.2.3