Improve staticrootstest checks (tests)
authorIvan Maidanski <ivmai@mail.ru>
Fri, 19 Oct 2012 03:50:18 +0000 (07:50 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 19 Oct 2012 10:50:43 +0000 (14:50 +0400)
* tests/staticrootstest.c (libsrl_init): Report error (and exit) if
libsrl_init returns NULL; report the corresponding error if staticroot
content is not as expected.

tests/staticrootstest.c

index f0b45bb..5d5cb3e 100644 (file)
@@ -37,6 +37,10 @@ int main(void)
   /*GC_INIT();
   staticroot = GC_MALLOC(sizeof(struct treenode));*/
   staticroot = libsrl_init();
+  if (NULL == staticroot) {
+    fprintf(stderr, "GC_malloc returned NULL\n");
+    return 2;
+  }
   memset(staticroot, 0x42, sizeof(struct treenode));
   GC_gcollect();
   for (i = 0; i < 10; ++i) {
@@ -44,16 +48,20 @@ int main(void)
     GC_gcollect();
   }
   for (i = 0; i < (int)sizeof(struct treenode); ++i) {
-    if (staticroot[i] != 0x42)
+    if (staticroot[i] != 0x42) {
+      fprintf(stderr, "Memory check failed\n");
       return -1;
+    }
   }
   for (i = 0; i < 10; ++i) {
     root[i] = libsrl_mktree(12);
     GC_gcollect();
   }
   for (i = 0; i < (int)sizeof(struct treenode); ++i) {
-    if (staticroot[i] != 0x42)
+    if (staticroot[i] != 0x42) {
+      fprintf(stderr, "Memory check failed\n");
       return -1;
+    }
   }
   return 0;
 }