1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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
19 * Portions created by the Initial Developer are Copyright (C) 2009
20 * the Initial Developer. All Rights Reserved.
23 * Jim Mathies <jmathies@mozilla.com>.
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
43 #include "../TestHarness.h"
44 #include "nsEmbedString.h"
45 #include "nsILocalFileWin.h"
54 ZeroMemory(&osvi
, sizeof(OSVERSIONINFO
));
55 osvi
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
59 return ( (osvi
.dwMajorVersion
> 5) ||
60 ( (osvi
.dwMajorVersion
== 5) && (osvi
.dwMinorVersion
>= 1) ));
63 nsresult
TestWinAttribs()
68 printf("Is XP or greater, running tests...\n");
74 nsCOMPtr
<nsILocalFile
> localFile
;
75 WCHAR filePath
[MAX_PATH
];
77 // Create and open temporary file
78 hIndexed
= CreateFileW(L
".\\indexbit.txt",
79 GENERIC_READ
| GENERIC_WRITE
,
83 FILE_ATTRIBUTE_NORMAL
, //FILE_ATTRIBUTE_NOT_CONTENT_INDEXED, not supported by cf
86 if(hIndexed
== INVALID_HANDLE_VALUE
)
88 fail("Test Win Attribs: Creating Test File");
89 return NS_ERROR_FAILURE
;
92 CloseHandle(hIndexed
);
94 GetFullPathNameW((LPCWSTR
)L
".\\indexbit.txt",
95 MAX_PATH
, filePath
, NULL
);
100 rv
= NS_NewLocalFile(nsEmbedString(filePath
), PR_FALSE
,
101 getter_AddRefs(localFile
));
104 fail("Test Win Attribs: Opening Test File");
105 DeleteFileW(filePath
);
109 nsCOMPtr
<nsILocalFileWin
> localFileWin(do_QueryInterface(localFile
));
111 DWORD dwAttrs
= GetFileAttributesW(filePath
);
112 if (dwAttrs
== INVALID_FILE_ATTRIBUTES
)
114 fail("Test Win Attribs: GetFileAttributesW - couldn't find our temp file.");
115 DeleteFileW(filePath
);
116 return NS_ERROR_FAILURE
;
119 dwAttrs
|= FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
;
120 SetFileAttributesW(filePath
, dwAttrs
);
122 PRUint32 attribs
= 0;
123 rv
= localFileWin
->GetFileAttributesWin(&attribs
);
127 fail("Test Win Attribs: GetFileAttributesWin failed to GET attributes. (1)");
128 DeleteFileW(filePath
);
129 return NS_ERROR_FAILURE
;
132 if (attribs
& nsILocalFileWin::WFA_SEARCH_INDEXED
)
134 fail("Test Win Attribs: GetFileAttributesWin attributed did not match. (2)");
135 DeleteFileW(filePath
);
136 return NS_ERROR_FAILURE
;
139 dwAttrs
&= ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
;
140 SetFileAttributesW(filePath
, dwAttrs
);
142 rv
= localFileWin
->GetFileAttributesWin(&attribs
);
146 fail("Test Win Attribs: GetFileAttributesWin failed to GET attributes. (3)");
147 DeleteFileW(filePath
);
148 return NS_ERROR_FAILURE
;
151 if (!(attribs
& nsILocalFileWin::WFA_SEARCH_INDEXED
))
153 fail("Test Win Attribs: GetFileAttributesWin attributed did not match. (4)");
154 DeleteFileW(filePath
);
155 return NS_ERROR_FAILURE
;
158 dwAttrs
&= ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
;
159 SetFileAttributesW(filePath
, dwAttrs
);
161 attribs
= nsILocalFileWin::WFA_SEARCH_INDEXED
;
162 rv
= localFileWin
->SetFileAttributesWin(attribs
);
164 dwAttrs
= GetFileAttributesW(filePath
);
168 fail("Test Win Attribs: GetFileAttributesWin failed to SET attributes. (5)");
169 DeleteFileW(filePath
);
170 return NS_ERROR_FAILURE
;
173 if (dwAttrs
& FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
)
175 fail("Test Win Attribs: SetFileAttributesWin attributed did not match. (6)");
176 DeleteFileW(filePath
);
177 return NS_ERROR_FAILURE
;
180 dwAttrs
|= FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
;
181 SetFileAttributesW(filePath
, dwAttrs
);
184 rv
= localFileWin
->SetFileAttributesWin(attribs
);
186 dwAttrs
= GetFileAttributesW(filePath
);
190 fail("Test Win Attribs: GetFileAttributesWin failed to SET attributes. (7)");
191 DeleteFileW(filePath
);
192 return NS_ERROR_FAILURE
;
195 if (!(dwAttrs
& FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
))
197 fail("Test Win Attribs: SetFileAttributesWin attributed did not match. (8)");
198 DeleteFileW(filePath
);
199 return NS_ERROR_FAILURE
;
202 DeleteFileW(filePath
);
204 passed("Test Win Attribs: passed tests.");
209 int main(int argc
, char** argv
)
211 ScopedXPCOM
xpcom("WinFileAttributes");
217 if(NS_FAILED(TestWinAttribs()))