home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / MEMORIA / DVMAM.ZIP / DV_TEST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-24  |  4.5 KB  |  189 lines

  1. #include <dvmam.h>
  2. #include <conio.h>
  3. #include <dos.h>
  4.  
  5. unsigned long bytes_available(void);
  6. unsigned long bytes_total(void);
  7.  
  8. void main(void)
  9. {
  10.  int    b[10];
  11.  char   buf[14],buf2[14];
  12.  int    i;
  13.  int    result=0;
  14.  char * set[10]= {"1","2","3","4","5","6","7","8","9","0"};
  15.  int    x;
  16.  
  17.  clrscr();
  18.  memory_setup(5120);
  19.  
  20.  for (x=1; x<5; x++)
  21.  {
  22.   printf("\n");
  23.  
  24. /**************************************/
  25. /* print the memory type we are using */
  26. /**************************************/
  27.  
  28.   switch (x)
  29.   {
  30.    case 1: printf("Using conventional memory\n");
  31.            set_memory_usage(USE_CONV);
  32.            break;
  33.    case 2: printf("Using expanded memory\n");
  34.            set_memory_usage(USE_EMS);
  35.            break;
  36.    case 3: printf("Using extended memory\n");
  37.            set_memory_usage(USE_EXT);
  38.            break;
  39.    case 4: printf("All memory types in use.\n");
  40.            set_memory_usage(USE_CONV+USE_EMS+USE_EXT);
  41.            break;
  42.   }
  43.  
  44. /********************************************************/
  45. /* Show the amount of memory available and total memory */
  46. /********************************************************/
  47.  
  48.   printf("Memory available: %lu of %lu bytes\n",bytes_available(),bytes_total());
  49.  
  50.   printf("Allocating 10 5k blocks: ");
  51.  
  52. /*************************/
  53. /* Allocate 10 5k blocks */
  54. /*************************/
  55.  
  56.   result=0;
  57.   for (i=0; i<10; i++) if ((b[i]=alloc_mem(5120))==-1) result=1;
  58.  
  59.   if (result) printf("Failed!\n"); else printf("Ok\n");
  60.  
  61. /*****************/
  62. /* Setup strings */
  63. /*****************/
  64.  
  65.   i=0;
  66.   result=0;
  67.   do
  68.   {
  69.    i++;
  70.    strcpy(buf2,"String test ");
  71.    strcat(buf2,set[i-1]);
  72.    movedata(FP_SEG( (char far *) buf2),FP_OFF( (char far *) buf2),
  73.             FP_SEG(dvmam_dta),FP_OFF(dvmam_dta),13);
  74.    result=save_memory(b[i-1]);
  75.   }
  76.   while (i<10 && !result);
  77.  
  78.   if (!result && i==10) printf("Initial strings established\n"); else
  79.                         printf("Error saving initial strings\n");
  80.  
  81. /**********************/
  82. /* Do the string test */
  83. /**********************/
  84.  
  85.   i=0;
  86.   result=0;
  87.   do
  88.   {
  89.    i++;
  90.    strcpy(buf,"String test ");
  91.    strcat(buf,set[i-1]);
  92.    result=load_memory(b[i-1]);
  93.    movedata(FP_SEG(dvmam_dta),FP_OFF(dvmam_dta),
  94.             FP_SEG( (char far *) buf2),FP_OFF( (char far *) buf2),13);
  95.    if (result==0) result=strcmp(buf,buf2);
  96.   }
  97.   while (i<10 && !result);
  98.  
  99.   if (!result && i==10) printf("String test successful\n"); else
  100.                         printf("String test failed\n");
  101.  
  102. /*************************/
  103. /* Deallocate all memory */
  104. /*************************/
  105.  
  106.   printf("Deallocating memory: ");
  107.  
  108.   for (i=0; i<10; i++) if ((result=dealloc_mem(b[i]))==-1) i=10;
  109.  
  110.   if (result) printf("Failed\n"); else printf("Ok\n");
  111.  }
  112.  
  113.  printf("\nTesting across memory types: ");
  114.  
  115. /**************************************************/
  116. /* Set memory with all memory types going at once */
  117. /**************************************************/
  118.  
  119.  set_memory_usage(USE_CONV);
  120.  b[0]=alloc_mem(5120);
  121.  b[1]=alloc_mem(5120);
  122.  
  123.  set_memory_usage(USE_EXT);
  124.  b[2]=alloc_mem(5120);
  125.  b[3]=alloc_mem(5120);
  126.  
  127.  set_memory_usage(USE_EMS);
  128.  b[4]=alloc_mem(5120);
  129.  b[5]=alloc_mem(5120);
  130.  
  131.  result=0;
  132.  for (i=0; i<6; i++) if (b[i]==-1) result=1;
  133.  
  134.  if (result) printf("Failed\n"); else printf("Ok\n");
  135.  
  136. /*****************/
  137. /* Setup strings */
  138. /*****************/
  139.  
  140.  i=0;
  141.  result=0;
  142.  do
  143.  {
  144.   i++;
  145.    strcpy(buf2,"String test ");
  146.    strcat(buf2,set[i-1]);
  147.    movedata(FP_SEG( (char far *) buf2),FP_OFF( (char far *) buf2),
  148.             FP_SEG(dvmam_dta),FP_OFF(dvmam_dta),13);
  149.   result=save_memory(b[i-1]);
  150.  }
  151.  while (i<6 && !result);
  152.  
  153.  if (!result && i==6) printf("Initial strings established\n"); else
  154.                       printf("Error saving initial strings\n");
  155.  
  156. /**********************/
  157. /* Do the string test */
  158. /**********************/
  159.  
  160.  i=0;
  161.  result=0;
  162.  do
  163.  {
  164.   i++;
  165.   strcpy(buf,"String test ");
  166.   strcat(buf,set[i-1]);
  167.   result=load_memory(b[i-1]);
  168.   movedata(FP_SEG(dvmam_dta),FP_OFF(dvmam_dta),
  169.            FP_SEG( (char far *) buf2),FP_OFF( (char far *) buf2),13);
  170.   if (!result) result=strcmp(buf,buf2);
  171.  }
  172.  while (i<6 && !result);
  173.  
  174.  if (!result && i==6) printf("String test successful\n"); else
  175.                       printf("String test failed\n");
  176.  
  177.  result=0;
  178.  printf("Deallocating memory: ");
  179.  
  180. /*************************/
  181. /* Deallocate the memory */
  182. /*************************/
  183.  
  184.  for (i=0; i<6; i++) if ((result=dealloc_mem(b[i]))==-1) i=10;
  185.  if (result) printf("Failed\n"); else printf("Ok\n");
  186.  
  187.  memory_shutdown();
  188.  
  189. }