/*****************************************************************************
*
*                            IBM Confidential
*
*  TEST CASE NAME   :   PRT_A51
*
*  DESCRIPTIVE NAME :   AUTOMATED TEST
*
*  DESCRIPTION AND PURPOSE :
*
*  PRT_A51 sends all of the printable characters to the printer using the
*  DOSWRITE function call.  The characters that are sent are 32 through 126
*  ASCII and 160 through 254 ASCII.  All the characters are sent while the
*  printer is in default mode.
*
*  HARDWARE AND SOFTWARE REQUIREMENTS :
*
*     PC's with printers.
*
*  EXECUTION INSTRUCTIONS :
*
*     The testcase is written in accordance with the Microsoft test case
*  standard.  To execute this testcase simply type the test case name followed
*  by the logging level, the logfile name and the -a option if applicable.
*  An optional parameter can be used to specify the port this testcase will
*  test.  If a -p# parameter is used, where # is a number from 1 to 3, the
*  testcase will test to that port.  A menu will come up if this parameter is
*  not used.
*
*  TEST CASE WRITER :  BRYAN WRIGHT
*
*  TEST CASE OWNER  :  JANET DMITROVICH
*
************************ END OF SPECIFICATIONS ******************************/


#include <writes.h>
#include <stdio.h>
#include <doscalls.h>
#include <print_dd.h>
#include <mstlogn.h>
#include <error.h>
#include <error2.h>

main(argc, argv)

  int argc;
  char *argv[];

{
  int count;
  int times;
  char crlf[] = {0x0a, 0x0d, '\0'};  /* carrige return = 0x0a, line feed = 0x0d */
  char charr[10];
  charr[1] = '\0';
  times = 0;



  initialize_test (argc, argv, 2, "PRT_A51", "Character data test A51\n");

/****************************************************************************
*         SENDING ALL PRINTABLE CHARACTERS TO PORT - NORMAL MODE -
*                            (BEGIN VARIATION #1)
*****************************************************************************/

VARLOG (1);

  time (&starttime);

  CWRITELOG (L_TRACE, (l_log, "Sending ascii chars 32-126 & 160-254 to %s.\n",port));

  rc = DOSWRITE (handle, "Printing ascii chars 32-126 & 160-254.\n\n", 40, (unsigned far *)&num_bytes);

  if (rc || (40 != num_bytes)) {
    CWRITELOG (L_FAIL, (l_log, "Error on DOSWRITE 1, rc is %#x.\n",rc));
    pass_fail = 'F';
  }

  rc = DOSWRITE (handle, (char far *)crlf, 3, (unsigned far *)&num_bytes);

  if (rc || (3 != num_bytes)) {
    CWRITELOG (L_FAIL, (l_log, "Error on DOSWRITE 2, rc is %#x.\n",rc));
    pass_fail = 'F';
  }

  for (count = 32;count < 255;count++) {
    if (!(count >=127 && count <= 159)) {
      times++;
      charr[0] = count;
      rc = DOSWRITE (handle, "Character = ", 12, (unsigned far *)&num_bytes);
      if (rc || (12 != num_bytes)) {
        CWRITELOG (L_FAIL, (l_log, "Error on DOSWRITE 3, rc is %#x.\n",rc));
        pass_fail = 'F';
      }
      rc = DOSWRITE (handle, (char far *)charr, 1, (unsigned far *)&num_bytes);
      if (rc || (1 != num_bytes)) {
        CWRITELOG (L_FAIL, (l_log, "Error on DOSWRITE 4, rc is %#x.\n",rc));
        pass_fail = 'F';
      }
      rc = DOSWRITE (handle, "   ", 3, (unsigned far *)&num_bytes);
      if (rc || (3 != num_bytes)) {
        CWRITELOG (L_FAIL, (l_log, "Error on DOSWRITE 5, rc is %#x.\n",rc));
        pass_fail = 'F';
      }
      if (times == 5) {
        times = 0;
        rc = DOSWRITE (handle, (char far *)crlf, 3, (unsigned far *)&num_bytes);
        if (rc || (3 != num_bytes)) {
          CWRITELOG (L_FAIL, (l_log, "Error on DOSWRITE 6, rc is %#x.\n",rc));
          pass_fail = 'F';
        }
      }
    }
  }

  rc = DOSWRITE (handle, "", 1, (unsigned far *)&num_bytes);

  if (rc || (1 != num_bytes)) {
    CWRITELOG (L_FAIL, (l_log, "Error on DOSWRITE 7, rc is %#x.\n",rc));
    pass_fail = 'F';
  }



/****************************************************************************
*    MAKE SURE PORT IS IN DEFAULT STATE AT TERMINATION OF THIS TESTCASE
*****************************************************************************/


  rc = DOSCLOSE (handle);

  if (rc) {
    CWRITELOG (L_ABORT, (l_log, "%s was not closed, rc is %#x.\n",port,rc));
    pass_fail = 'F';
    ABORTLOG ();
  }
  else {
    CWRITELOG (L_TRACE, (l_log, "%s was closed, rc is %#x.\n",port,rc));
  }

  if (pass_fail == 'P') {
    CLOSELOG ("PASSED",(l_log,"IF ALL CHARACTERS WERE PRINTED\n"));
  }
  else {
    CLOSELOG ("FAIL,",(l_log,"CHECK THAT ALL CHARACTERS WERE PRINTED\n"));
  }
}
