diff options
| author | Ezra Peisach <epeisach@mit.edu> | 2001-04-25 17:33:13 +0000 |
|---|---|---|
| committer | Ezra Peisach <epeisach@mit.edu> | 2001-04-25 17:33:13 +0000 |
| commit | a3cf7c0f87f060b62f82fc397b92eec6e54ac0ef (patch) | |
| tree | 3781e80a7d591eadca2a61d91d0cab5f31746ecb /src/util/dyn/test.c | |
| parent | 87f3ef154866dfad28853bf0da08c28bf5b688bf (diff) | |
* Makefile.in: Add lclint support
* dyn.h: Lclint annotate functions.
* dyn_create.c (DynCreate): Do not assume that malloc(0) is valid
and returns a valid pointer. Fix memory leak if malloc fails.
* dyn_realloc.c (_DynResize): Turn off warning of shifting a
signed variable.
* test.c: Check the return values of all library calls.
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@13191 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/util/dyn/test.c')
| -rw-r--r-- | src/util/dyn/test.c | 65 |
1 files changed, 52 insertions, 13 deletions
diff --git a/src/util/dyn/test.c b/src/util/dyn/test.c index 9ac1d0157..8282c6079 100644 --- a/src/util/dyn/test.c +++ b/src/util/dyn/test.c @@ -30,9 +30,10 @@ static char insert3[] = " This follows the random string."; int main(argc, argv) - int argc; - char **argv; +/*@unused@*/int argc; +/*@unused@*/char **argv; { + /*@-exitarg@*/ DynObject obj; int i, s; char d, *data; @@ -50,16 +51,25 @@ main(argc, argv) o_size = malloc_inuse(&hist1); #endif + /*@+matchanyintegral@*/ obj = DynCreate(sizeof(char), -8); if (! obj) { fprintf(stderr, "test: create failed.\n"); exit(1); } - DynDebug(obj, 1); - DynParanoid(obj, 1); + if(DynDebug(obj, 1) != DYN_OK) { + fprintf(stderr, "test: setting paranoid failed.\n"); + exit(1); + } + if(DynParanoid(obj, 1) != DYN_OK) { + fprintf(stderr, "test: setting paranoid failed.\n"); + exit(1); + } + - if (DynGet(obj, -5) || DynGet(obj, 0) || DynGet(obj, 1000)) { + if ((DynGet(obj, -5) != NULL) || + (DynGet(obj, 0) != NULL) || (DynGet(obj, 1000) != NULL)) { fprintf(stderr, "test: Get did not fail when it should have.\n"); exit(1); } @@ -96,19 +106,27 @@ main(argc, argv) exit(1); } - d = 200; + d = '\200'; if (DynAdd(obj, &d) != DYN_OK) { fprintf(stderr, "test: Adding %d failed.\n", i); exit(1); } data = (char *) DynGet(obj, 0); + if(data == NULL) { + fprintf(stderr, "test: getting object 0 failed.\n"); + exit(1); + } s = DynSize(obj); for (i=0; i < s; i++) - printf("Element %d is %d.\n", i, (unsigned char) data[i]); + printf("Element %d is %d.\n", i, (int) data[i]); data = (char *) DynGet(obj, 13); - printf("Element 13 is %d.\n", (unsigned char) *data); + if(data == NULL) { + fprintf(stderr, "test: getting element 13 failed.\n"); + exit(1); + } + printf("Element 13 is %d.\n", (int) *data); data = (char *) DynGet(obj, DynSize(obj)); if (data) { @@ -116,7 +134,12 @@ main(argc, argv) exit(1); } - printf("This should be the random string: \"%s\"\n", DynGet(obj, 14)); + data = DynGet(obj, 14); + if(data == NULL) { + fprintf(stderr, "test: getting element 13 failed.\n"); + exit(1); + } + printf("This should be the random string: \"%s\"\n", data); if (DynInsert(obj, -1, "foo", 4) != DYN_BADINDEX || DynInsert(obj, DynSize(obj) + 1, "foo", 4) != DYN_BADINDEX || @@ -141,11 +164,26 @@ main(argc, argv) exit(1); } - printf("A new random string: \"%s\"\n", DynGet(obj, 14 + - strlen(insert1) + 1)); - printf("This was put at the beginning: \"%s\"\n", DynGet(obj, 0)); + data = DynGet(obj, 14 + strlen(insert1) + 1); + if (data == NULL) { + fprintf(stderr, "DynGet of 14+strelen(insert1) failed.\n"); + exit(1); + + } + printf("A new random string: \"%s\"\n", data); + + data = DynGet(obj, 0); + if (data == NULL) { + fprintf(stderr, "DynGet of 0 failed.\n"); + exit(1); + + } + printf("This was put at the beginning: \"%s\"\n", data); - DynDestroy(obj); + if(DynDestroy(obj) != DYN_OK) { + fprintf(stderr, "test: destroy failed.\n"); + exit(1); + } #ifdef _DEBUG_MALLOC_INC c_size = malloc_inuse(&hist2); @@ -156,6 +194,7 @@ main(argc, argv) } #endif + printf("All tests pass\n"); return 0; } |
