home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / RiscOS / APP / DEVS / FORTH / BEETLE / BEETLE.ZIP / Beetle / loadobjt.c < prev    next >
C/C++ Source or Header  |  1997-04-22  |  2KB  |  76 lines

  1. /* LOADOBJT.C
  2.  
  3.     Vrsn  Date   Comment
  4.     ----|-------|---------------------------------------------------------------
  5.     0.00 24jan95
  6.     0.01 17feb95 Modified to work with new version of storage.c, and use
  7.                  btests.h rather than bintern.h. Also added directives and code
  8.                  to make proper debug/nodebug mode.
  9.     0.02 26feb95 An error in a printf format removed.
  10.     0.03 25mar95 btests.h not #included any more.
  11.  
  12.     Reuben Thomas
  13.  
  14.  
  15.     Test load_object().
  16.  
  17. */
  18.  
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include "beetle.h"     /* main header */
  23.  
  24.  
  25. int correct[] = { -2, -2, -1, -3, 0, 0 };
  26.  
  27.  
  28. int try(char *file, CELL *address)
  29. {
  30.     FILE *fp = fopen(file, "r");
  31.     int ret = load_object(fp, address);
  32.  
  33. #ifdef B_DEBUG
  34.     printf("load_object(\"%s\", 0) returns %d", file, ret);
  35. #endif
  36.     fclose(fp);
  37.  
  38.     return ret;
  39. }
  40.  
  41.  
  42. int main(void)
  43. {
  44.     char *files[] = { "badobj1", "badobj2", "badobj3", "badobj4", "testobj1",
  45.         "testobj2" };
  46.     int i, res;
  47.  
  48.     init_beetle((BYTE *)malloc(1024), 256, 16);
  49.  
  50.     for (i = 0; i < 4; i++) {
  51.         res = try(files[i], (CELL *)M0);
  52. #ifdef B_DEBUG
  53.         printf(" should be %d\n", correct[i]);
  54. #endif
  55.         if (res != correct[i]) {
  56.             printf("Error in LoadObjT: file %s\n", files[i]);
  57.             exit(1);
  58.         }
  59.     }
  60.  
  61.     for (; i < 6; i++) {
  62.         res = try(files[i], (CELL *)M0);
  63. #ifdef B_DEBUG
  64.         printf(" should be %d\n", correct[i]);
  65.         printf("Word 0 of memory is %lx; should be 1020304\n", *(CELL*)M0);
  66. #endif
  67.         if (res != correct[i]) {
  68.             printf("Error in LoadObjT: file %s\n", files[i]);
  69.             exit(1);
  70.         }
  71.     }
  72.  
  73.     printf("LoadObjT ran OK\n");
  74.     return 0;
  75. }
  76.