From: Dan Sheppard Date: Tue, 22 Apr 2025 22:29:39 +0000 (+0100) Subject: Test desc truncation. X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~dans/git?a=commitdiff_plain;h=9c5b080c4421403fbc5c484a60b46707485c1f42;p=coquet.git Test desc truncation. --- diff --git a/src/coquet.h b/src/coquet.h index 304f1ad..4cd6547 100644 --- a/src/coquet.h +++ b/src/coquet.h @@ -29,11 +29,4 @@ int coquet_finish(coquet_t *cq); */ char * coquet_error_string(coquet_t *cq, int error); -#ifdef COQUET_TEST -void test_bail(coquet_t * cq, int error_code); -void test_unlink(char *path); -void test_file_compare(char *got, char *expected); -void test_assert(int is_true, char *msg); -#endif - #endif diff --git a/src/superblock.c b/src/superblock.c index 4f2b690..c92489d 100644 --- a/src/superblock.c +++ b/src/superblock.c @@ -243,6 +243,22 @@ char * cq_super_get_desc(struct cq_super *super) { #ifdef COQUET_TEST #include +#include "test.h" + +static void test_open(coquet_t *cq) { + int r; + + r = (cq->vfs_funcs.open)(cq->vfs_data, + COQUET_FILE_MAIN,COQUET_CMODE_EITHER); + test_bail(cq,r); +} + +static void test_close(coquet_t *cq) { + int r; + + r = (cq->vfs_funcs.close)(cq->vfs_data,COQUET_FILE_MAIN); + test_bail(cq,r); +} void test_superblock() { coquet_t cq; @@ -260,8 +276,7 @@ void test_superblock() { test_unlink("tmp/test.coquet"); - r = (cq.vfs_funcs.open)(cq.vfs_data,COQUET_FILE_MAIN,COQUET_CMODE_EITHER); - test_bail(&cq,r); + test_open(&cq); r = cq_super_load(&cq,&super,1); test_bail(&cq,r); @@ -274,14 +289,12 @@ void test_superblock() { cq_super_save(&cq,&super,1); test_bail(&cq,r); - r = (cq.vfs_funcs.close)(cq.vfs_data,COQUET_FILE_MAIN); - test_bail(&cq,r); + test_close(&cq); test_file_compare("tmp/test.coquet","testdata/sb1.coquet"); /* reopen to check the marshalling */ - r = (cq.vfs_funcs.open)(cq.vfs_data,COQUET_FILE_MAIN,COQUET_CMODE_EITHER); - test_bail(&cq,r); + test_open(&cq); r = cq_super_load(&cq,&super,1); test_bail(&cq,r); @@ -301,9 +314,50 @@ void test_superblock() { for(i=0;i #include "sha2.h" #include "superblock.h" +#include "test.h" void test_assert(int is_true, char *msg) { if(!is_true) { @@ -13,6 +14,22 @@ void test_assert(int is_true, char *msg) { } } +void test_eq_char(char got, char expect, char *msg) { + if(got!=expect) { + fprintf(stderr,"assertion '%s' failed got=%c expect=%c\n", + msg,got,expect); + exit(1); + } +} + +void test_eq_int(int got, int expect, char *msg) { + if(got!=expect) { + fprintf(stderr,"assertion '%s' failed got=%d expect=%d\n", + msg,got,expect); + exit(1); + } +} + void test_unlink(char *path) { int r; diff --git a/src/test.h b/src/test.h new file mode 100644 index 0000000..8454167 --- /dev/null +++ b/src/test.h @@ -0,0 +1,14 @@ +#ifndef COQUET_TEST_H +#define COQUET_TEST_H + +#ifdef COQUET_TEST +void test_bail(coquet_t * cq, int error_code); +void test_unlink(char *path); +void test_file_compare(char *got, char *expected); +void test_assert(int is_true, char *msg); + +void test_eq_int(int got, int expect, char *msg); +void test_eq_char(char got, char expect, char *msg); +#endif + +#endif \ No newline at end of file