home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / ALIB12.ZIP / EX02.EXE / WYSE.C < prev    next >
Text File  |  1992-02-16  |  7KB  |  241 lines

  1. /* wyse.c */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <alloc.h>
  6. #include <string.h>
  7. #include <time.h>
  8. #include <dir.h>
  9.  
  10. /* AutoLibrary by Avid Software */
  11. #include "al.h"
  12.  
  13. #include "wyse.h"
  14.  
  15. #ifndef TRUE
  16. #define TRUE 1
  17. #endif
  18.  
  19. #ifndef FALSE
  20. #define FALSE 0
  21. #endif
  22.  
  23. /*******************/
  24. void clear_wyse_screen(com)
  25. int com;
  26. /*******************/
  27. {
  28. char temp_buf[85];
  29. int err, info;
  30.  
  31.     sprintf(temp_buf, "%s*", ESC_CODE);
  32.     if ((err = AvidSend(AVID, com, temp_buf, &info, "")) != ERR_SNF)
  33.     AvidLogInfo(AVID, com, "Problem clearing screen", err, &info, "*ETL");
  34. }
  35.  
  36. /*******************/
  37. void initialize_testing(com)
  38. int com;
  39. /*******************/
  40. {
  41. char temp_buf[85];
  42. int err, info;
  43.  
  44.     /* Before even trying the tests make sure things are cabled
  45.        correctly and we are connected to a Wyse 50 or Wyse 30 terminal.
  46.        Use the command     ESC space
  47.        Where:
  48.        space is a blank space.
  49.        The Wyse terminal will return 50\r, 30\r or 60\r
  50.     */
  51.  
  52.     sprintf(temp_buf, ".s'%s ' 1w'50' 2w'30' 3w'60' .d'1'", ESC_CODE);
  53.     if ((err = AvidSendSearch(AVID, com, (long)10, (long)30, &info, temp_buf)) <= ERR_SNF)
  54.     AvidLogInfo(AVID, com, "Failed to connect", err, &info, "*ETL");
  55.  
  56.     /* Clear the screen. */
  57.     clear_wyse_screen(com);
  58. }
  59.  
  60. /*******************/
  61. char new_char()
  62. /*******************/
  63. {
  64. static char *abc = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  65.  
  66.     return (abc[random(62)]);
  67. }
  68.  
  69. /*******************/
  70. void test_protected_mode(com)
  71. int com;
  72. /*******************/
  73. {
  74. int info;
  75.  
  76.     com = com; /* for compiler */
  77.     AvidLogInfo(AVID, com, "Executing protected mode tests", 0, &info, "*T");
  78.     AvidLogInfo(AVID, com, "Finished", 0, &info, "*T");
  79. }
  80.  
  81. /*******************/
  82. void test_scr_attribs(com)
  83. int com;
  84. /*******************/
  85. {
  86. int info;
  87.  
  88.     com = com; /* for compiler */
  89.     AvidLogInfo(AVID, com, "Executing screen attributes tests", 0, &info, "*T");
  90.     AvidLogInfo(AVID, com, "Finished", 0, &info, "*T");
  91. }
  92.  
  93. /*******************/
  94. void test_scr_loc(com, num_row, num_col)
  95. int com;
  96. int num_row;  /* The number of rows to test. */
  97. int num_col;  /* The number of columns to test. */
  98. /*******************/
  99. {
  100. int i, j, row, col;
  101. char temp_buf[100];
  102. long actual;
  103. char capture[85];
  104. int err, info;
  105.  
  106.     /*
  107.     This will test the following commands...
  108.     ESC a rr R ccc C    which moves the cursor to a specified
  109.                 row and column for an 80 or 132 column
  110.                 screen.  ESCa1R1C  will position cursor
  111.                 at home position, for example.
  112.  
  113.     ESC b   which transmits the cursor address to the host
  114.         computer for the active text segment in the format
  115.         rr R ccc C
  116.  
  117.     Where:
  118.     rr  =  the ASCII encoded decimal value of the row
  119.     R   =  ASCII R
  120.     ccc =  the ASCII encoded decimal value of the column
  121.     C   =  ASCII C
  122.  
  123.  
  124.     Test Description:
  125.  
  126.     Within a nested for loop the ESC a rr R ccc C  command is used
  127.     to position the cursor.  The ESC b  command is then used to
  128.     verify that the cursor was moved.
  129.     */
  130.     /* Clear the screen. */
  131.     clear_wyse_screen(com);
  132.  
  133.     AvidLogInfo(AVID, com, "Executing screen location test", 0, &info, "*T");
  134.  
  135.     /* Shorten the test if requested. */
  136.     if ( !long_version)
  137.     num_col = 10;
  138.  
  139.     /* Test each screen location. */
  140.     for (j=1; j<=num_col; j++) {
  141.     for (i=1; i<=num_row; i++) {
  142.  
  143.         /* Move cursor to known location with    ESC a rr R ccc C */
  144.         sprintf(temp_buf, "%sa%dR%dC", ESC_CODE, i, j);
  145.         if ((err = AvidSend(AVID, com, temp_buf, &info, "")) != ERR_SNF)
  146.         AvidLogInfo(AVID, com, "Problem sending string", err, &info, "*ETL");
  147.  
  148.         /* Make sure the cursor is where we placed it with  ESC b */
  149.         sprintf(temp_buf, ".s'%sb' 1w'C' -c'6'", ESC_CODE);
  150.         if ((err = AvidSendSearch(AVID, com, (long)10, (long)30, &info, temp_buf, (long *)&actual, capture)) <= ERR_SNF)
  151.         AvidLogInfo(AVID, com, "Cursor not placed correctly", err, &info, "*ETL");
  152.  
  153.         /* Get the cursor positions out of the capture string. */
  154.         sscanf(capture, "%dR%d", &row, &col);
  155.         if (row != i)
  156.         AvidLogInfo(AVID, com, "Cursor not placed correctly", row, &info, "*ETL");
  157.         if (col != j)
  158.         AvidLogInfo(AVID, com, "Cursor not placed correctly", col, &info, "*ETL");
  159.     }
  160.     }
  161.  
  162.     AvidLogInfo(AVID, com, "Finished", 0, &info, "*T");
  163. }
  164.  
  165. /*******************/
  166. void test_scr_print(com, num_row, num_col)
  167. int com;
  168. int num_row;
  169. int num_col;
  170. /*******************/
  171. {
  172. int i, j, row, col;
  173. char temp_buf[100];
  174. long actual;
  175. char capture[85];
  176. int err, info;
  177. char r;
  178.  
  179.     /*
  180.     This will test the following commands...
  181.     ESC M    which causes the terminal to send the character at
  182.          the cursor position to the host computer.
  183.  
  184.     Test Description:
  185.  
  186.     Within a nested for loop the ESC a rr R ccc C  command is used
  187.     to position the cursor.  Then a random character is written to
  188.     the screen.  Printing a character will advance the cursor, therefore
  189.     the command ESC a rr R ccc C   is executed to position the cursor
  190.     over the character just written.  The ESC M command is then used
  191.     to verify the character was written correctly.
  192.     */
  193.  
  194.     AvidLogInfo(AVID, com, "Executing screen print test", 0, &info, "*T");
  195.  
  196.     /* Clear the screen. */
  197.     clear_wyse_screen(com);
  198.  
  199.     /* Shorten the test if requested. */
  200.     if ( !long_version)
  201.     num_col = 10;
  202.  
  203.     /* Test each screen location. */
  204.     for (j=1; j<=num_col; j++) {
  205.     for (i=1; i<=num_row; i++) {
  206.  
  207.         /* Move cursor to known location with    ESC a rr R ccc C */
  208.         sprintf(temp_buf, "%sa%dR%dC", ESC_CODE, i, j);
  209.         if ((err = AvidSend(AVID, com, temp_buf, &info, "")) != ERR_SNF)
  210.         AvidLogInfo(AVID, com, "Problem sending string", err, &info, "");
  211.  
  212.         /* Print a character. */
  213.         r = new_char();
  214.         sprintf(temp_buf, "%c", r);
  215.         if ((err = AvidSend(AVID, com, temp_buf, &info, "")) != ERR_SNF)
  216.         AvidLogInfo(AVID, com, "Problem sending string", err, &info, "*ETL");
  217.  
  218.         /* Put the cursor back to the know location. */
  219.         sprintf(temp_buf, "%sa%dR%dC", ESC_CODE, i, j);
  220.         if ((err = AvidSend(AVID, com, temp_buf, &info, "")) != ERR_SNF)
  221.         AvidLogInfo(AVID, com, "Problem sending string", err, &info, "*ETL");
  222.  
  223.         /* Get the character just placed. */
  224.         sprintf(temp_buf, ".s'%sM' +c'1'", ESC_CODE);
  225.         if ((err = AvidSendSearch(AVID, com, (long)10, (long)30, &info, temp_buf, (long *)&actual, capture)) != ERR_SNF)
  226.         AvidLogInfo(AVID, com, "Cursor not placed correctly", err, &info, "*ETL");
  227.  
  228.         /* Fake errors for the demo. */
  229.         if ((j == 2) && (i == 10)) r = ' ';
  230.         if ((j == 4) && (i == 19)) r = ' ';
  231.         if ((j == 60) && (i == 12)) r = ' ';
  232.  
  233.         /* Make sure the character we placed is there. */
  234.         if (capture[0] != r)
  235.         AvidLogInfo(AVID, com, "Incorrect character", capture[0], &info, "*ETL");
  236.     }
  237.     }
  238.  
  239.     AvidLogInfo(AVID, com, "Finished", 0, &info, "*T");
  240. }
  241.