Added nsiFile.cpp and .h, Testcases for nsILocalFile

git-svn-id: svn://10.0.0.236/trunk@118489 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
ashishbhatt%netscape.com 2002-04-08 22:19:03 +00:00
parent 74d361a0fd
commit 95e4c7abb0
8 changed files with 340 additions and 134 deletions

View File

@ -61,6 +61,7 @@
#include "nsProfile.h"
#include "nsIClipboardCmd.h"
#include "nsIObserServ.h"
#include "nsIFile.h"
#include "QaUtils.h"
#include <stdio.h>
@ -84,15 +85,14 @@ BEGIN_MESSAGE_MAP(CTests, CWnd)
ON_COMMAND(ID_TESTS_CREATEPROFILE, OnTestsCreateprofile)
ON_COMMAND(ID_TESTS_ADDWEBPROGLISTENER, OnTestsAddWebProgListener)
ON_COMMAND(ID_TESTS_ADDHISTORYLISTENER, OnTestsAddHistoryListener)
ON_COMMAND(ID_INTERFACES_NSIFILE, OnInterfacesNsifile)
ON_COMMAND(ID_TOOLS_REMOVEGHPAGE, OnToolsRemoveGHPage)
ON_COMMAND(ID_TOOLS_REMOVEALLGH, OnToolsRemoveAllGH)
ON_COMMAND(ID_TOOLS_TESTYOURMETHOD, OnToolsTestYourMethod)
ON_COMMAND(ID_TOOLS_TESTYOURMETHOD2, OnToolsTestYourMethod2)
ON_COMMAND(ID_VERIFYBUGS_70228, OnVerifybugs70228)
ON_COMMAND(ID_INTERFACES_NSIREQUEST_CANCEL, OnInterfacesNsirequest)
ON_COMMAND(ID_INTERFACES_NSIREQUEST_CANCEL, OnInterfacesNsirequest)
ON_COMMAND(ID_INTERFACES_NSIDOMWINDOW_RUNALLTESTS, OnInterfacesNsidomwindow)
ON_COMMAND(ID_INTERFACES_NSIDIRECTORYSERVICE_INIT, OnInterfacesNsidirectoryservice)
ON_COMMAND(ID_INTERFACES_NSIDIRECTORYSERVICE_INIT, OnInterfacesNsidirectoryservice)
ON_COMMAND(ID_INTERFACES_NSISELECTION_RUNALLTESTS, OnInterfacesNsiselection)
ON_COMMAND(ID_VERIFYBUGS_90195, OnVerifybugs90195)
ON_COMMAND(ID_INTERFACES_NSIPROFILE_RUNALLTESTS, OnInterfacesNsiprofile)
@ -100,6 +100,7 @@ BEGIN_MESSAGE_MAP(CTests, CWnd)
ON_COMMAND(ID_TESTS_REMOVEHISTORYLISTENER, OnTestsRemovehistorylistener)
ON_COMMAND(ID_INTERFACES_NSIWEBNAV_GETCANGOBACK, OnInterfacesNsiwebnav)
ON_COMMAND(ID_INTERFACES_NSICLIPBOARDCOMMANDS_CANCOPYSELECTION, OnInterfacesNsiclipboardcommands)
ON_COMMAND(ID_INTERFACES_NSIOBSERVERSERVICE_ADDOBSERVERS, OnInterfacesNsiobserverservice)
ON_COMMAND(ID_INTERFACES_NSIDIRECTORYSERVICE_REGISTERPROVIDER, OnInterfacesNsidirectoryservice)
ON_COMMAND(ID_INTERFACES_NSIDIRECTORYSERVICE_RUNALLTESTS, OnInterfacesNsidirectoryservice)
ON_COMMAND(ID_INTERFACES_NSIDIRECTORYSERVICE_UNREGISTERPROVIDER, OnInterfacesNsidirectoryservice)
@ -188,11 +189,17 @@ BEGIN_MESSAGE_MAP(CTests, CWnd)
ON_COMMAND(ID_INTERFACES_NSICLIPBOARDCOMMANDS_PASTE, OnInterfacesNsiclipboardcommands)
ON_COMMAND(ID_INTERFACES_NSICLIPBOARDCOMMANDS_SELECTALL, OnInterfacesNsiclipboardcommands)
ON_COMMAND(ID_INTERFACES_NSICLIPBOARDCOMMANDS_SELECTNONE, OnInterfacesNsiclipboardcommands)
ON_COMMAND(ID_INTERFACES_NSIOBSERVERSERVICE_ADDOBSERVERS, OnInterfacesNsiobserverservice)
ON_COMMAND(ID_INTERFACES_NSIOBSERVERSERVICE_ENUMERATEOBSERVERS, OnInterfacesNsiobserverservice)
ON_COMMAND(ID_INTERFACES_NSIOBSERVERSERVICE_NOTIFYOBSERVERS, OnInterfacesNsiobserverservice)
ON_COMMAND(ID_INTERFACES_NSIOBSERVERSERVICE_REMOVEOBSERVERS, OnInterfacesNsiobserverservice)
ON_COMMAND(ID_INTERFACES_NSIOBSERVERSERVICE_RUNALLTESTS, OnInterfacesNsiobserverservice)
ON_COMMAND(ID_INTERFACES_NSIFILE_APPENDRELATICEPATH, OnInterfacesNsifile)
ON_COMMAND(ID_INTERFACES_NSIFILE_COPYTO, OnInterfacesNsifile)
ON_COMMAND(ID_INTERFACES_NSIFILE_CREATE, OnInterfacesNsifile)
ON_COMMAND(ID_INTERFACES_NSIFILE_EXISTS, OnInterfacesNsifile)
ON_COMMAND(ID_INTERFACES_NSIFILE_INITWITHPATH, OnInterfacesNsifile)
ON_COMMAND(ID_INTERFACES_NSIFILE_MOVETO, OnInterfacesNsifile)
ON_COMMAND(ID_INTERFACES_NSIFILE_RUNALLTESTS, OnInterfacesNsifile)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
@ -515,134 +522,6 @@ void CTests::OnToolsTestYourMethod2()
// place your test code here
}
// ***********************************************************************
// ************************** Interface Tests ****************************
// ***********************************************************************
// nsIFile:
void CTests::OnInterfacesNsifile()
{
nsCOMPtr<nsILocalFile> theTestFile(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
nsCOMPtr<nsILocalFile> theFileOpDir(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
if (!theTestFile)
{
QAOutput("File object doesn't exist. No File tests performed.", 2);
return;
}
if (!theFileOpDir)
{
QAOutput("File object doesn't exist. No File tests performed.", 2);
return;
}
QAOutput("Begin nsIFile tests.", 2);
InitWithPathTest(theTestFile);
AppendRelativePathTest(theTestFile);
FileCreateTest(theTestFile);
FileExistsTest(theTestFile);
// FILE COPY test
FileCopyTest(theTestFile, theFileOpDir);
// FILE MOVE test
FileMoveTest(theTestFile, theFileOpDir);
QAOutput("End nsIFile tests.", 2);
}
// ***********************************************************************
// Individual nsIFile tests
void CTests::InitWithPathTest(nsILocalFile *theTestFile)
{
rv = theTestFile->InitWithPath("c:\\temp\\");
RvTestResult(rv, "InitWithPath() test (initializing file path)", 2);
}
void CTests::AppendRelativePathTest(nsILocalFile *theTestFile)
{
rv = theTestFile->AppendRelativePath("myFile.txt");
RvTestResult(rv, "AppendRelativePath() test (append file to the path)", 2);
}
void CTests::FileCreateTest(nsILocalFile *theTestFile)
{
rv = theTestFile->Exists(&exists);
if (!exists)
{
QAOutput("File doesn't exist. We'll try creating it.", 2);
rv = theTestFile->Create(nsIFile::NORMAL_FILE_TYPE, 0777);
RvTestResult(rv, " File Create() test ('myFile.txt')", 2);
}
else
QAOutput("File already exists (myFile.txt). We won't create it.", 2);
}
void CTests::FileExistsTest(nsILocalFile *theTestFile)
{
rv = theTestFile->Exists(&exists);
if (!exists)
QAOutput("Exists() test Failed. File (myFile.txt) doesn't exist.", 2);
else
QAOutput("Exists() test Passed. File (myFile.txt) exists.", 2);
}
void CTests::FileCopyTest(nsILocalFile *theTestFile, nsILocalFile *theFileOpDir)
{
QAOutput("Start File Copy test.", 2);
rv = theFileOpDir->InitWithPath("c:\\temp\\");
if (NS_FAILED(rv))
QAOutput("The target dir wasn't found.", 2);
else
QAOutput("The target dir was found.", 2);
rv = theTestFile->InitWithPath("c:\\temp\\myFile.txt");
if (NS_FAILED(rv))
QAOutput("The path wasn't found.", 2);
else
QAOutput("The path was found.", 2);
rv = theTestFile->CopyTo(theFileOpDir, "myFile2.txt");
RvTestResult(rv, "rv CopyTo() test", 2);
rv = theTestFile->InitWithPath("c:\\temp\\myFile2.txt");
rv = theTestFile->Exists(&exists);
if (!exists)
QAOutput("File didn't copy. CopyTo() test Failed.", 2);
else
QAOutput("File copied. CopyTo() test Passed.", 2);
}
void CTests::FileMoveTest(nsILocalFile *theTestFile, nsILocalFile *theFileOpDir)
{
QAOutput("Start File Move test.", 2);
rv = theFileOpDir->InitWithPath("c:\\Program Files\\");
if (NS_FAILED(rv))
QAOutput("The target dir wasn't found.", 2);
rv = theTestFile->InitWithPath("c:\\temp\\myFile2.txt");
if (NS_FAILED(rv))
QAOutput("The path wasn't found.", 2);
rv = theTestFile->MoveTo(theFileOpDir, "myFile2.txt");
RvTestResult(rv, "MoveTo() test", 2);
rv = theTestFile->InitWithPath("c:\\Program Files\\myFile2.txt");
rv = theTestFile->Exists(&exists);
if (!exists)
QAOutput("File wasn't moved. MoveTo() test Failed.", 2);
else
QAOutput("File was moved. MoveTo() test Passed.", 2);
}
// ***********************************************************************
// ***************** Bug Verifications ******************
// ***********************************************************************
@ -743,3 +622,9 @@ void CTests::OnInterfacesNsiobserverservice()
oObserv.OnStartTests(nCommandID);
}
void CTests::OnInterfacesNsifile()
{
CNsIFile oFile ;
oFile.OnStartTests(nCommandID);
}

View File

@ -85,6 +85,7 @@ OBJS = \
.\$(OBJDIR)\nsProfile.obj \
.\$(OBJDIR)\nsIClipBoardCmd.obj \
.\$(OBJDIR)\nsIObserServ.obj \
.\$(OBJDIR)\nsIFile.obj \
$(NULL)
LLIBS= \

View File

@ -0,0 +1,226 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ashish Bhatt <ashishbhatt@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// File Overview....
//
// Test cases for the nsIClipBoardCommand Interface
#include "stdafx.h"
#include "QaUtils.h"
#include <stdio.h>
#include "nsIFile.h"
CNsIFile::CNsIFile()
{
}
CNsIFile::~CNsIFile()
{
}
void CNsIFile::OnStartTests(UINT nMenuID)
{
// Calls all or indivdual test cases on the basis of the
// option selected from menu.
nsCOMPtr<nsILocalFile> theTestFile(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
nsCOMPtr<nsILocalFile> theFileOpDir(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
if (!theTestFile)
{
QAOutput("File object doesn't exist. No File tests performed.", 2);
return;
}
if (!theFileOpDir)
{
QAOutput("File object doesn't exist. No File tests performed.", 2);
return;
}
QAOutput("Begin nsIFile tests.", 2);
switch(nMenuID)
{
case ID_INTERFACES_NSIFILE_RUNALLTESTS :
RunAllTests(theTestFile,theFileOpDir);
break ;
case ID_INTERFACES_NSIFILE_INITWITHPATH :
InitWithPathTest(theTestFile);
break ;
case ID_INTERFACES_NSIFILE_APPENDRELATICEPATH :
AppendRelativePathTest(theTestFile);
break ;
case ID_INTERFACES_NSIFILE_EXISTS :
FileCreateTest(theTestFile);
break ;
case ID_INTERFACES_NSIFILE_CREATE :
FileExistsTest(theTestFile);
break ;
case ID_INTERFACES_NSIFILE_COPYTO :
FileCopyTest(theTestFile, theFileOpDir);
break ;
case ID_INTERFACES_NSIFILE_MOVETO :
FileMoveTest(theTestFile, theFileOpDir);
break ;
}
}
// ***********************************************************************
// ************************** Interface Tests ****************************
// ***********************************************************************
// nsIFile:
void CNsIFile::RunAllTests(nsILocalFile *theTestFile, nsILocalFile *theFileOpDir)
{
InitWithPathTest(theTestFile);
AppendRelativePathTest(theTestFile);
FileCreateTest(theTestFile);
FileExistsTest(theTestFile);
FileCopyTest(theTestFile, theFileOpDir);
FileMoveTest(theTestFile, theFileOpDir);
}
// ***********************************************************************
// Individual nsIFile tests
void CNsIFile::InitWithPathTest(nsILocalFile *theTestFile)
{
rv = theTestFile->InitWithPath("c:\\temp\\");
RvTestResult(rv, "InitWithPath() test (initializing file path)", 2);
}
void CNsIFile::AppendRelativePathTest(nsILocalFile *theTestFile)
{
rv = theTestFile->AppendRelativePath("myFile.txt");
RvTestResult(rv, "AppendRelativePath() test (append file to the path)", 2);
}
void CNsIFile::FileCreateTest(nsILocalFile *theTestFile)
{
PRBool exists = PR_TRUE;
rv = theTestFile->InitWithPath("c:\\temp\\");
rv = theTestFile->AppendRelativePath("myFile.txt");
rv = theTestFile->Exists(&exists);
if (!exists)
{
QAOutput("File doesn't exist. We'll try creating it.", 2);
rv = theTestFile->Create(nsIFile::NORMAL_FILE_TYPE, 0777);
RvTestResult(rv, " File Create() test ('myFile.txt')", 2);
}
else
QAOutput("File already exists (myFile.txt). We won't create it.", 2);
}
void CNsIFile::FileExistsTest(nsILocalFile *theTestFile)
{
PRBool exists = PR_TRUE;
rv = theTestFile->InitWithPath("c:\\temp\\");
rv = theTestFile->AppendRelativePath("myFile.txt");
rv = theTestFile->Exists(&exists);
if (!exists)
QAOutput("Exists() test Failed. File (myFile.txt) doesn't exist.", 2);
else
QAOutput("Exists() test Passed. File (myFile.txt) exists.", 2);
}
void CNsIFile::FileCopyTest(nsILocalFile *theTestFile, nsILocalFile *theFileOpDir)
{
PRBool exists = PR_TRUE;
QAOutput("Start File Copy test.", 2);
rv = theFileOpDir->InitWithPath("c:\\temp\\");
if (NS_FAILED(rv))
QAOutput("The target dir wasn't found.", 2);
else
QAOutput("The target dir was found.", 2);
rv = theTestFile->InitWithPath("c:\\temp\\myFile.txt");
if (NS_FAILED(rv))
QAOutput("The path wasn't found.", 2);
else
QAOutput("The path was found.", 2);
rv = theTestFile->CopyTo(theFileOpDir, "myFile2.txt");
RvTestResult(rv, "rv CopyTo() test", 2);
rv = theTestFile->InitWithPath("c:\\temp\\myFile2.txt");
rv = theTestFile->Exists(&exists);
if (!exists)
QAOutput("File didn't copy. CopyTo() test Failed.", 2);
else
QAOutput("File copied. CopyTo() test Passed.", 2);
}
void CNsIFile::FileMoveTest(nsILocalFile *theTestFile, nsILocalFile *theFileOpDir)
{
PRBool exists = PR_TRUE;
QAOutput("Start File Move test.", 2);
rv = theFileOpDir->InitWithPath("c:\\Program Files\\");
if (NS_FAILED(rv))
QAOutput("The target dir wasn't found.", 2);
rv = theTestFile->InitWithPath("c:\\temp\\myFile2.txt");
if (NS_FAILED(rv))
QAOutput("The path wasn't found.", 2);
rv = theTestFile->MoveTo(theFileOpDir, "myFile2.txt");
RvTestResult(rv, "MoveTo() test", 2);
rv = theTestFile->InitWithPath("c:\\Program Files\\myFile2.txt");
rv = theTestFile->Exists(&exists);
if (!exists)
QAOutput("File wasn't moved. MoveTo() test Failed.", 2);
else
QAOutput("File was moved. MoveTo() test Passed.", 2);
}

View File

@ -0,0 +1,66 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ashish Bhatt <ashishbhatt@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// File Overview....
//
// Header file for nsIClipBoardCommand interface test cases
class CNsIFile
{
public:
CNsIFile();
public:
~CNsIFile();
public:
void OnStartTests(UINT nMenuID);
void RunAllTests(nsILocalFile*, nsILocalFile *);
void InitWithPathTest(nsILocalFile*);
void AppendRelativePathTest(nsILocalFile*);
void FileCreateTest(nsILocalFile*);
void FileExistsTest(nsILocalFile*);
void FileCopyTest(nsILocalFile*, nsILocalFile *);
void FileMoveTest(nsILocalFile*, nsILocalFile *);
protected:
};

View File

@ -190,6 +190,13 @@
#define ID_INTERFACES_NSIOBSERVERSERVICE_ENUMERATEOBSERVERS 32924
#define ID_INTERFACES_NSIOBSERVERSERVICE_NOTIFYOBSERVERS 32925
#define ID_INTERFACES_NSIOBSERVERSERVICE_REMOVEOBSERVERS 32926
#define ID_INTERFACES_NSIFILE_INITWITHPATH 32927
#define ID_INTERFACES_NSIFILE_APPENDRELATICEPATH 32928
#define ID_INTERFACES_NSIFILE_EXISTS 32929
#define ID_INTERFACES_NSIFILE_CREATE 32930
#define ID_INTERFACES_NSIFILE_COPYTO 32931
#define ID_INTERFACES_NSIFILE_MOVETO 32932
#define ID_INTERFACES_NSIFILE_RUNALLTESTS 32933
#define ID_CLIPBOARDCMD_PASTE 42789
#define ID_CLIPBOARDCMD_COPYSELECTION 42790
#define ID_CLIPBOARDCMD_SELECTALL 42791
@ -206,7 +213,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_3D_CONTROLS 1
#define _APS_NEXT_RESOURCE_VALUE 146
#define _APS_NEXT_COMMAND_VALUE 32927
#define _APS_NEXT_COMMAND_VALUE 32934
#define _APS_NEXT_CONTROL_VALUE 1025
#define _APS_NEXT_SYMED_VALUE 101
#endif

View File

@ -246,6 +246,10 @@ SOURCE=.\nsiDirServ.h
# End Source File
# Begin Source File
SOURCE=.\nsIFile.h
# End Source File
# Begin Source File
SOURCE=.\nsiHistory.h
# End Source File
# Begin Source File

View File

@ -159,7 +159,24 @@ BEGIN
END
POPUP "&Interfaces"
BEGIN
MENUITEM "nsI&File", ID_INTERFACES_NSIFILE
POPUP "nsI&File"
BEGIN
MENUITEM "Run All Tests", ID_INTERFACES_NSIFILE_RUNALLTESTS
MENUITEM SEPARATOR
MENUITEM "InitWithPath", ID_INTERFACES_NSIFILE_INITWITHPATH
MENUITEM "AppendRelaticePath", ID_INTERFACES_NSIFILE_APPENDRELATICEPATH
MENUITEM "Exists", ID_INTERFACES_NSIFILE_EXISTS
MENUITEM "Create", ID_INTERFACES_NSIFILE_CREATE
MENUITEM "CopyTo", ID_INTERFACES_NSIFILE_COPYTO
MENUITEM "MoveTo", ID_INTERFACES_NSIFILE_MOVETO
END
POPUP "nsI&SHistory"
BEGIN
MENUITEM "Run All Tests", ID_INTERFACES_NSISHISTORY_RUNALLTESTS