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 // Test cases for the nsIClipBoardCommand Interface
61 void CNsIFile::OnStartTests(UINT nMenuID
)
63 // Calls all or indivdual test cases on the basis of the
64 // option selected from menu.
66 nsCOMPtr
<nsILocalFile
> theTestFile(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID
));
67 nsCOMPtr
<nsILocalFile
> theFileOpDir(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID
));
71 QAOutput("File object doesn't exist. No File tests performed.", 2);
77 QAOutput("File object doesn't exist. No File tests performed.", 2);
83 case ID_INTERFACES_NSIFILE_RUNALLTESTS
:
84 QAOutput("Begin nsIFile tests.", 1);
85 RunAllTests(theTestFile
,theFileOpDir
);
86 QAOutput("End nsIFile tests.", 1);
89 case ID_INTERFACES_NSIFILE_INITWITHPATH
:
90 InitWithPathTest(theTestFile
, 2);
93 case ID_INTERFACES_NSIFILE_APPENDRELATICEPATH
:
94 AppendRelativePathTest(theTestFile
, 2);
97 case ID_INTERFACES_NSIFILE_EXISTS
:
98 FileCreateTest(theTestFile
, 2);
101 case ID_INTERFACES_NSIFILE_CREATE
:
102 FileExistsTest(theTestFile
, 2);
105 case ID_INTERFACES_NSIFILE_COPYTO
:
106 FileCopyTest(theTestFile
, theFileOpDir
, 2);
109 case ID_INTERFACES_NSIFILE_MOVETO
:
110 FileMoveTest(theTestFile
, theFileOpDir
, 2);
116 // ***********************************************************************
117 // ************************** Interface Tests ****************************
118 // ***********************************************************************
122 void CNsIFile::RunAllTests(nsILocalFile
*theTestFile
, nsILocalFile
*theFileOpDir
)
124 InitWithPathTest(theTestFile
, 1);
125 AppendRelativePathTest(theTestFile
, 1);
126 FileCreateTest(theTestFile
, 1);
127 FileExistsTest(theTestFile
, 1);
128 FileCopyTest(theTestFile
, theFileOpDir
, 1);
129 FileMoveTest(theTestFile
, theFileOpDir
, 1);
132 // ***********************************************************************
134 // Individual nsIFile tests
138 void CNsIFile::InitWithPathTest(nsILocalFile
*theTestFile
, PRInt16 displayMode
)
140 rv
= theTestFile
->InitWithNativePath(NS_LITERAL_CSTRING("c:\\temp\\"));
141 RvTestResult(rv
, "InitWithNativePath() test (initializing file path)", displayMode
);
142 RvTestResultDlg(rv
, "InitWithNativePath() test (initializing file path)", true);
145 void CNsIFile::AppendRelativePathTest(nsILocalFile
*theTestFile
, PRInt16 displayMode
)
147 rv
= theTestFile
->AppendRelativeNativePath(NS_LITERAL_CSTRING("myFile.txt"));
148 RvTestResult(rv
, "AppendRelativeNativePath() test (append file to the path)", displayMode
);
149 RvTestResultDlg(rv
, "AppendRelativeNativePath() test (append file to the path)");
152 void CNsIFile::FileCreateTest(nsILocalFile
*theTestFile
, PRInt16 displayMode
)
154 PRBool exists
= PR_TRUE
;
156 rv
= theTestFile
->InitWithNativePath(NS_LITERAL_CSTRING("c:\\temp\\"));
157 rv
= theTestFile
->AppendRelativeNativePath(NS_LITERAL_CSTRING("myFile.txt"));
159 rv
= theTestFile
->Exists(&exists
);
162 QAOutput("File doesn't exist. We'll try creating it.", displayMode
);
163 rv
= theTestFile
->Create(nsIFile::NORMAL_FILE_TYPE
, 0777);
164 RvTestResult(rv
, "File Create() test ('myFile.txt')", displayMode
);
165 RvTestResultDlg(rv
, "File Create() test ('myFile.txt')");
168 QAOutput("File already exists (myFile.txt). We won't create it.", displayMode
);
171 void CNsIFile::FileExistsTest(nsILocalFile
*theTestFile
, PRInt16 displayMode
)
173 PRBool exists
= PR_TRUE
;
175 rv
= theTestFile
->InitWithNativePath(NS_LITERAL_CSTRING("c:\\temp\\"));
176 rv
= theTestFile
->AppendRelativeNativePath(NS_LITERAL_CSTRING("myFile.txt"));
178 rv
= theTestFile
->Exists(&exists
);
179 RvTestResult(rv
, "File Exists() test ('myFile.txt')", displayMode
);
180 RvTestResultDlg(rv
, "File Exists() test ('myFile.txt')");
182 QAOutput("Exists() test Failed. File (myFile.txt) doesn't exist.", displayMode
);
184 QAOutput("Exists() test Passed. File (myFile.txt) exists.", displayMode
);
187 void CNsIFile::FileCopyTest(nsILocalFile
*theTestFile
, nsILocalFile
*theFileOpDir
,
190 PRBool exists
= PR_TRUE
;
192 QAOutput("Start File Copy test.", displayMode
);
193 rv
= theFileOpDir
->InitWithNativePath(NS_LITERAL_CSTRING("c:\\temp\\"));
196 QAOutput("The target dir wasn't found.", displayMode
);
198 QAOutput("The target dir was found.", displayMode
);
200 rv
= theTestFile
->InitWithNativePath(NS_LITERAL_CSTRING("c:\\temp\\myFile.txt"));
202 QAOutput("The path wasn't found.", displayMode
);
204 QAOutput("The path was found.", displayMode
);
206 rv
= theTestFile
->CopyToNative(theFileOpDir
, NS_LITERAL_CSTRING("myFile2.txt"));
207 RvTestResult(rv
, "rv CopyToNative() test", displayMode
);
208 RvTestResultDlg(rv
, "File CopyToNative() test ('myFile.txt')");
210 rv
= theTestFile
->InitWithNativePath(NS_LITERAL_CSTRING("c:\\temp\\myFile2.txt"));
212 rv
= theTestFile
->Exists(&exists
);
214 QAOutput("File didn't copy. CopyToNative() test Failed.", displayMode
);
216 QAOutput("File copied. CopyToNative() test Passed.", displayMode
);
219 void CNsIFile::FileMoveTest(nsILocalFile
*theTestFile
, nsILocalFile
*theFileOpDir
,
222 PRBool exists
= PR_TRUE
;
224 QAOutput("Start File Move test.", displayMode
);
226 rv
= theFileOpDir
->InitWithNativePath(NS_LITERAL_CSTRING("c:\\Program Files\\"));
228 QAOutput("The target dir wasn't found.", displayMode
);
230 rv
= theTestFile
->InitWithNativePath(NS_LITERAL_CSTRING("c:\\temp\\myFile2.txt"));
232 QAOutput("The path wasn't found.", displayMode
);
234 rv
= theTestFile
->MoveToNative(theFileOpDir
, NS_LITERAL_CSTRING("myFile2.txt"));
235 RvTestResult(rv
, "MoveToNative() test", displayMode
);
236 RvTestResultDlg(rv
, "File MoveToNative() test ('myFile.txt')");
238 rv
= theTestFile
->InitWithNativePath(NS_LITERAL_CSTRING("c:\\Program Files\\myFile2.txt"));
240 rv
= theTestFile
->Exists(&exists
);
242 QAOutput("File wasn't moved. MoveToNative() test Failed.", displayMode
);
244 QAOutput("File was moved. MoveToNative() test Passed.", displayMode
);