home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / qaoutput.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.6 KB  |  129 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. // qaoutput.cpp
  19. // Test prototype for API testing
  20. //
  21.  
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <iostream.h>
  25. #include <string.h>
  26. #include "stdafx.h"
  27. #include "qaoutput.h"
  28.  
  29. // declarations
  30. enum outcome GetMessage();
  31.  
  32. // defines
  33. #define space "    "
  34.  
  35. // global variables
  36. enum outcome { pass = 0, fail, none };
  37. char *TestcaseOutputFilename;
  38. FILE *stream2;
  39.  
  40. // currently can handle only a single testcase. Doing a second
  41. // testcase requires changing the FileJustOpened variable.
  42. int QAOpenOutputFile()
  43. {
  44.     static int FileJustOpened = 0;
  45.  
  46.     if (FileJustOpened == 0)
  47.     {
  48.         FileJustOpened = 1;
  49.         if (!TestcaseOutputFilename)
  50.         {
  51.             AfxMessageBox("Output Filename is not defined");
  52.             return 1;
  53.         }
  54.  
  55.         /* Open for write */
  56.         if( (stream2 = fopen(TestcaseOutputFilename, "w+")) == NULL )
  57.         {
  58.             // cout << "The file qaoutput was not opened\n";
  59.             return 1;
  60.         }
  61.         else
  62.         {
  63.             // cout << "The file qaoutput was opened\n";
  64.             fputs( "Whitebox Testing Trace Log\n", stream2);
  65.         }
  66.     }
  67.     else
  68.     {    
  69.         // Open for append
  70.         if( (stream2 = fopen(TestcaseOutputFilename, "a+")) == NULL )
  71.         {
  72.         // cout << "The file qaoutput was not opened\n";
  73.         return 1;
  74.         }
  75.     }
  76.  
  77.     return 0;
  78. }
  79.  
  80. int QACloseOutputFile()
  81. {
  82.     /* Close stream */
  83.     if( fclose( stream2 ) )
  84.     {
  85.         // cout << "The file 'data' was not closed\n";
  86.         return 1;
  87.     }
  88.  
  89.     return 0;
  90. }
  91.  
  92. int QAAddToOutputFile(char* s)
  93. {
  94.     if (!s)
  95.         return 1;
  96.     else
  97.     {
  98.         fputs(s, stream2);
  99.         fputs("\n",stream2);
  100.     }
  101.  
  102.     return 0;
  103. }
  104.  
  105. int AssignFilename(const char* newfilename)
  106. {
  107.     int length = strlen(newfilename);
  108.     TestcaseOutputFilename = new char[length+1];
  109.     if (!TestcaseOutputFilename)
  110.         return 1;
  111.  
  112.     strcpy(TestcaseOutputFilename,newfilename);
  113.     return 0;
  114. }
  115.  
  116. int DeleteFilename()
  117. {
  118.     if (TestcaseOutputFilename)
  119.     {
  120.         delete[] TestcaseOutputFilename;
  121.         return 0;
  122.     }
  123.     else
  124.         return 1;
  125. }
  126.  
  127.  
  128.  
  129.