michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * Test: michael@0: */ michael@0: michael@0: #include "../TestHarness.h" michael@0: #include "nsEmbedString.h" michael@0: #include "nsILocalFileWin.h" michael@0: #include michael@0: michael@0: #define BUFFSIZE 512 michael@0: michael@0: nsresult TestWinAttribs() michael@0: { michael@0: michael@0: nsresult rv; michael@0: michael@0: // File variables michael@0: HANDLE hIndexed; michael@0: nsCOMPtr localFile; michael@0: WCHAR filePath[MAX_PATH]; michael@0: michael@0: // Create and open temporary file michael@0: hIndexed = CreateFileW(L".\\indexbit.txt", michael@0: GENERIC_READ | GENERIC_WRITE, michael@0: 0, michael@0: nullptr, michael@0: CREATE_ALWAYS, michael@0: FILE_ATTRIBUTE_NORMAL, //FILE_ATTRIBUTE_NOT_CONTENT_INDEXED, not supported by cf michael@0: nullptr); michael@0: michael@0: if(hIndexed == INVALID_HANDLE_VALUE) michael@0: { michael@0: fail("Test Win Attribs: Creating Test File"); michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: CloseHandle(hIndexed); michael@0: michael@0: GetFullPathNameW((LPCWSTR)L".\\indexbit.txt", michael@0: MAX_PATH, filePath, nullptr); michael@0: michael@0: //wprintf(filePath); michael@0: //wprintf(L"\n"); michael@0: michael@0: rv = NS_NewLocalFile(nsEmbedString(filePath), false, michael@0: getter_AddRefs(localFile)); michael@0: if (NS_FAILED(rv)) michael@0: { michael@0: fail("Test Win Attribs: Opening Test File"); michael@0: DeleteFileW(filePath); michael@0: return rv; michael@0: } michael@0: michael@0: nsCOMPtr localFileWin(do_QueryInterface(localFile)); michael@0: michael@0: DWORD dwAttrs = GetFileAttributesW(filePath); michael@0: if (dwAttrs == INVALID_FILE_ATTRIBUTES) michael@0: { michael@0: fail("Test Win Attribs: GetFileAttributesW - couldn't find our temp file."); michael@0: DeleteFileW(filePath); michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: dwAttrs |= FILE_ATTRIBUTE_NOT_CONTENT_INDEXED; michael@0: SetFileAttributesW(filePath, dwAttrs); michael@0: michael@0: uint32_t attribs = 0; michael@0: rv = localFileWin->GetFileAttributesWin(&attribs); michael@0: michael@0: if (NS_FAILED(rv)) michael@0: { michael@0: fail("Test Win Attribs: GetFileAttributesWin failed to GET attributes. (1)"); michael@0: DeleteFileW(filePath); michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: if (attribs & nsILocalFileWin::WFA_SEARCH_INDEXED) michael@0: { michael@0: fail("Test Win Attribs: GetFileAttributesWin attributed did not match. (2)"); michael@0: DeleteFileW(filePath); michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: dwAttrs &= ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED; michael@0: SetFileAttributesW(filePath, dwAttrs); michael@0: michael@0: rv = localFileWin->GetFileAttributesWin(&attribs); michael@0: michael@0: if (NS_FAILED(rv)) michael@0: { michael@0: fail("Test Win Attribs: GetFileAttributesWin failed to GET attributes. (3)"); michael@0: DeleteFileW(filePath); michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: if (!(attribs & nsILocalFileWin::WFA_SEARCH_INDEXED)) michael@0: { michael@0: fail("Test Win Attribs: GetFileAttributesWin attributed did not match. (4)"); michael@0: DeleteFileW(filePath); michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: dwAttrs &= ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED; michael@0: SetFileAttributesW(filePath, dwAttrs); michael@0: michael@0: attribs = nsILocalFileWin::WFA_SEARCH_INDEXED; michael@0: rv = localFileWin->SetFileAttributesWin(attribs); michael@0: michael@0: dwAttrs = GetFileAttributesW(filePath); michael@0: michael@0: if (NS_FAILED(rv)) michael@0: { michael@0: fail("Test Win Attribs: GetFileAttributesWin failed to SET attributes. (5)"); michael@0: DeleteFileW(filePath); michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: if (dwAttrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) michael@0: { michael@0: fail("Test Win Attribs: SetFileAttributesWin attributed did not match. (6)"); michael@0: DeleteFileW(filePath); michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: dwAttrs |= FILE_ATTRIBUTE_NOT_CONTENT_INDEXED; michael@0: SetFileAttributesW(filePath, dwAttrs); michael@0: michael@0: attribs = 0; michael@0: rv = localFileWin->SetFileAttributesWin(attribs); michael@0: michael@0: dwAttrs = GetFileAttributesW(filePath); michael@0: michael@0: if (NS_FAILED(rv)) michael@0: { michael@0: fail("Test Win Attribs: GetFileAttributesWin failed to SET attributes. (7)"); michael@0: DeleteFileW(filePath); michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: if (!(dwAttrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED)) michael@0: { michael@0: fail("Test Win Attribs: SetFileAttributesWin attributed did not match. (8)"); michael@0: DeleteFileW(filePath); michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: DeleteFileW(filePath); michael@0: michael@0: passed("Test Win Attribs: passed tests."); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: int main(int argc, char** argv) michael@0: { michael@0: ScopedXPCOM xpcom("WinFileAttributes"); michael@0: if (xpcom.failed()) michael@0: return 1; michael@0: michael@0: int rv = 0; michael@0: michael@0: if(NS_FAILED(TestWinAttribs())) michael@0: rv = 1; michael@0: michael@0: return rv; michael@0: michael@0: } michael@0: