1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Mozilla Public License Version
6
* 1.1 (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/MPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
23
* David Epstein <depstein@netscape.com>
24
* Ashish Bhatt <ashishbhatt@netscape.com>
26
* Alternatively, the contents of this file may be used under the terms of
27
* either the GNU General Public License Version 2 or later (the "GPL"), or
28
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29
* in which case the provisions of the GPL or the LGPL are applicable instead
30
* of those above. If you wish to allow use of your version of this file only
31
* under the terms of either the GPL or the LGPL, and not to allow others to
32
* use your version of this file under the terms of the MPL, indicate your
33
* decision by deleting the provisions above and replace them with the notice
34
* and other provisions required by the GPL or the LGPL. If you do not delete
35
* the provisions above, a recipient may use your version of this file under
36
* the terms of any one of the MPL, the GPL or the LGPL.
38
* ***** END LICENSE BLOCK ***** */
42
// These are utilities to help with QA tasks.
44
// Includes routine to post results to a QA log file.
47
#include "TestEmbed.h"
48
#include "BrowserView.h"
49
#include "BrowserImpl.h"
50
#include "BrowserFrm.h"
57
static char THIS_FILE[] = __FILE__;
60
storage getSupportObj;
62
void RvTestResultDlg(nsresult rv, CString pLine,BOOL bClearList)
64
static CShowTestResults dlgResult ;
66
dlgResult.Create(IDD_RUNTESTSDLG);
71
dlgResult.m_ListResults.DeleteAllItems();
72
dlgResult.ShowWindow(true);
76
dlgResult.AddItemToList(pLine,false);
78
dlgResult.AddItemToList(pLine,true);
82
void RvTestResult(nsresult rv, const char *pLine, int displayMethod)
84
// note: default displayMethod = 1 in .h file
86
CString strLine = pLine;
87
char theOutputLine[200];
90
strLine += " failed.";
92
strLine += " passed.";
94
strcpy(theOutputLine, strLine);
95
QAOutput(theOutputLine, displayMethod);
98
void WriteToOutputFile(const char *pLine)
102
CString strFileName = "c:\\temp\\TestOutput.txt";
104
if(! myFile.Open( strFileName, CStdioFile::modeCreate | CStdioFile::modeWrite
105
| CStdioFile::modeNoTruncate, &e ) )
107
CString failCause = "Unable to open file. Reason : ";
109
case CFileException::none:
110
failCause += "No error occurred.";
113
case CFileException::generic:
114
failCause += "An unspecified error occurred.";
117
case CFileException::fileNotFound:
118
failCause += "The file could not be located.";
121
case CFileException::badPath:
122
failCause += "All or part of the path is invalid.";
125
case CFileException::tooManyOpenFiles:
126
failCause += "The permitted number of open files was exceeded.";
129
case CFileException::accessDenied:
130
failCause += "The file could not be accessed.";
133
case CFileException::invalidFile:
134
failCause += "There was an attempt to use an invalid file handle.";
137
case CFileException::removeCurrentDir:
138
failCause += "The current working directory cannot be removed.";
141
case CFileException::directoryFull:
142
failCause += "There are no more directory entries.";
145
case CFileException::badSeek:
146
failCause += "There was an error trying to set the file pointer.";
149
case CFileException::hardIO:
150
failCause += "There was a hardware error.";
153
case CFileException::sharingViolation:
154
failCause += "SHARE.EXE was not loaded, or a shared region was locked.";
157
case CFileException::lockViolation:
158
failCause += "There was an attempt to lock a region that was already locked.";
161
case CFileException::diskFull:
162
failCause += "The disk is full.";
165
case CFileException::endOfFile:
166
failCause += "The end of file was reached.";
170
failCause += "Some reason not documented in <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_cfileexception.3a3a.m_cause.asp>.";
173
AfxMessageBox(failCause);
178
CString strLine = pLine;
181
myFile.WriteString(strLine);
187
void QAOutput(const char *pLine, int displayMethod)
189
// note: default displayMethod = 1 in .h file
190
// displayMethod 0 = mfc dialog; 1 = output log file; 2 = both
192
CString strLine = pLine;
194
if (displayMethod == 0)
195
AfxMessageBox(strLine);
196
else if (displayMethod == 1)
197
WriteToOutputFile(pLine);
200
WriteToOutputFile(pLine);
201
AfxMessageBox(strLine);
206
void FormatAndPrintOutput(const char *theInput, const char *theVar, int outputMode)
214
strMsg = outStr.get();
219
AfxMessageBox(strMsg);
222
WriteToOutputFile(outStr.get());
225
WriteToOutputFile(outStr.get());
226
AfxMessageBox(strMsg);
231
void FormatAndPrintOutput(const char *theInput, nsCAutoString theVar, int outputMode)
239
strMsg = outStr.get();
244
AfxMessageBox(strMsg);
247
WriteToOutputFile(outStr.get());
250
WriteToOutputFile(outStr.get());
251
AfxMessageBox(strMsg);
256
void FormatAndPrintOutput(const char *theInput, int theVar, int outputMode)
262
outStr.AppendInt(theVar);
264
strMsg = outStr.get();
269
AfxMessageBox(strMsg);
272
WriteToOutputFile(outStr.get());
275
WriteToOutputFile(outStr.get());
276
AfxMessageBox(strMsg);
281
void FormatAndPrintOutput(const char *theInput, double theVar, int outputMode)
287
outStr.AppendFloat(theVar);
289
strMsg = outStr.get();
294
AfxMessageBox(strMsg);
297
WriteToOutputFile(outStr.get());
300
WriteToOutputFile(outStr.get());
301
AfxMessageBox(strMsg);
306
void FormatAndPrintOutput(const char *theInput, PRUint32 theVar, int outputMode)
312
outStr.AppendFloat(theVar);
314
strMsg = outStr.get();
319
AfxMessageBox(strMsg);
322
WriteToOutputFile(outStr.get());
325
WriteToOutputFile(outStr.get());
326
AfxMessageBox(strMsg);
331
// stringMsg is returned in case embeddor wishes to use it in the calling method.
332
void RequestName(nsIRequest *request, nsCString &stringMsg, int displayMethod)
337
QAOutput("ERROR. nsIRequest object is Null. RequestName test fails.", displayMethod);
341
rv = request->GetName(stringMsg);
344
FormatAndPrintOutput("nsIRequest: The request name = ", stringMsg.get(), displayMethod);
346
QAOutput("nsIRequest: We didn't get the request name.", displayMethod);
349
void WebProgDOMWindowTest(nsIWebProgress *progress, const char *inString,
353
nsCString totalStr1, totalStr2;
354
nsCOMPtr<nsIDOMWindow> theDOMWindow;
356
totalStr1 = inString;
357
totalStr1 += ": Didn't get the DOMWindow. Test failed.";
359
totalStr2 = inString;
360
totalStr2 += ": nsIWebProgress:DOMWindow attribute test";
363
QAOutput("ERROR. nsIWebProgress object is Null. WebProgDOMWindowTest fails.", displayMethod);
367
rv = progress->GetDOMWindow(getter_AddRefs(theDOMWindow));
369
QAOutput(totalStr1.get(), displayMethod);
371
RvTestResult(rv, totalStr2.get(), displayMethod);
374
void WebProgIsDocLoadingTest(nsIWebProgress *progress, const char *inString,
382
totalStr += ": nsIWebProgress:IsDocumentLoading attribute test";
385
QAOutput("ERROR. nsIWebProgress object is Null. WebProgIsDocLoadingTest fails.", displayMethod);
389
rv = progress->GetIsLoadingDocument(&docLoading);
390
RvTestResult(rv, totalStr.get(), displayMethod);
391
FormatAndPrintOutput("nsIWebProgress: isDocumentLoading return value = ", docLoading, displayMethod);
394
nsIDOMWindow * GetTheDOMWindow(nsIWebBrowser *webBrowser)
396
nsCOMPtr<nsIDOMWindow> theDOMWindow;
398
webBrowser->GetContentDOMWindow(getter_AddRefs(theDOMWindow));
400
QAOutput("Didn't get a DOM Window.");
403
return (theDOMWindow);
406
nsCAutoString GetTheURI(nsIURI *theURI, int displayMethod)
409
nsCAutoString uriString;
412
QAOutput("nsIURI object is null. return failure.");
413
return uriString; //dep 3/30
415
rv = theURI->GetSpec(uriString);
416
RvTestResult(rv, "nsIURI::GetSpec() test", displayMethod);
417
FormatAndPrintOutput("the uri = ", uriString, displayMethod);
422
// used for web progress listener in BrowserImplWebPrgrsLstnr.cpp
423
void onStateChangeString(char *theStateType, char *theDocType,
424
nsCString stringMsg, PRUint32 status, int displayMode)
428
totalMsg = "OnStateChange(): ";
429
totalMsg += theStateType;
431
totalMsg += theDocType;
433
totalMsg += stringMsg;
434
totalMsg += ", status (hex) = ";
435
totalMsg.AppendInt(status, 16);
436
QAOutput(totalMsg.get(), displayMode);
439
void SaveObject(nsISupports *theSupports)
441
getSupportObj.sup = theSupports;
444
/////////////////////////////////////////////////////////////////////////////
445
// CShowTestResults dialog
448
CShowTestResults::CShowTestResults(CWnd* pParent /*=NULL*/)
449
: CDialog(CShowTestResults::IDD, pParent)
452
//{{AFX_DATA_INIT(CShowTestResults)
453
// NOTE: the ClassWizard will add member initialization here
459
void CShowTestResults::DoDataExchange(CDataExchange* pDX)
461
CDialog::DoDataExchange(pDX);
462
//{{AFX_DATA_MAP(CShowTestResults)
463
DDX_Control(pDX, IDC_LIST1, m_ListResults);
468
BEGIN_MESSAGE_MAP(CShowTestResults, CDialog)
469
//{{AFX_MSG_MAP(CShowTestResults)
473
/////////////////////////////////////////////////////////////////////////////
474
// CShowTestResults message handlers
476
BOOL CShowTestResults::OnInitDialog()
479
CDialog::OnInitDialog();
481
m_ListResults.InsertColumn(0,"Test Case",LVCFMT_LEFT,360);
482
m_ListResults.InsertColumn(1,"Result",LVCFMT_LEFT,100);
484
return TRUE; // return TRUE unless you set the focus to a control
485
// EXCEPTION: OCX Property Pages should return FALSE
489
void CShowTestResults::AddItemToList(LPCTSTR szTestCaseName, BOOL bResult)
493
lvitem.mask = LVIF_TEXT;
494
lvitem.iItem = m_ListResults.GetItemCount();
496
lvitem.pszText = (LPTSTR)szTestCaseName ;
497
//Insert the main item
498
m_ListResults.InsertItem(&lvitem);
501
m_ListResults.SetItemText(m_ListResults.GetItemCount()-1,1,"Passed");
503
m_ListResults.SetItemText(m_ListResults.GetItemCount()-1,1,"Failed");
505
//Insert the sub item
506
//m_ListResults.InsertItem(&lvitem);