From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- xpcom/tests/windows/TestWinFileAttribs.cpp | 173 +++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 xpcom/tests/windows/TestWinFileAttribs.cpp (limited to 'xpcom/tests/windows/TestWinFileAttribs.cpp') diff --git a/xpcom/tests/windows/TestWinFileAttribs.cpp b/xpcom/tests/windows/TestWinFileAttribs.cpp new file mode 100644 index 000000000..56fbcbdea --- /dev/null +++ b/xpcom/tests/windows/TestWinFileAttribs.cpp @@ -0,0 +1,173 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Test: + */ + +#include "../TestHarness.h" +#include "nsEmbedString.h" +#include "nsILocalFileWin.h" +#include + +#define BUFFSIZE 512 + +nsresult TestWinAttribs() +{ + + nsresult rv; + + // File variables + HANDLE hIndexed; + nsCOMPtr localFile; + WCHAR filePath[MAX_PATH]; + + // Create and open temporary file + hIndexed = CreateFileW(L".\\indexbit.txt", + GENERIC_READ | GENERIC_WRITE, + 0, + nullptr, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, //FILE_ATTRIBUTE_NOT_CONTENT_INDEXED, not supported by cf + nullptr); + + if(hIndexed == INVALID_HANDLE_VALUE) + { + fail("Test Win Attribs: Creating Test File"); + return NS_ERROR_FAILURE; + } + + CloseHandle(hIndexed); + + GetFullPathNameW((LPCWSTR)L".\\indexbit.txt", + MAX_PATH, filePath, nullptr); + + //wprintf(filePath); + //wprintf(L"\n"); + + rv = NS_NewLocalFile(nsEmbedString(filePath), false, + getter_AddRefs(localFile)); + if (NS_FAILED(rv)) + { + fail("Test Win Attribs: Opening Test File"); + DeleteFileW(filePath); + return rv; + } + + nsCOMPtr localFileWin(do_QueryInterface(localFile)); + + DWORD dwAttrs = GetFileAttributesW(filePath); + if (dwAttrs == INVALID_FILE_ATTRIBUTES) + { + fail("Test Win Attribs: GetFileAttributesW - couldn't find our temp file."); + DeleteFileW(filePath); + return NS_ERROR_FAILURE; + } + + dwAttrs |= FILE_ATTRIBUTE_NOT_CONTENT_INDEXED; + SetFileAttributesW(filePath, dwAttrs); + + uint32_t attribs = 0; + rv = localFileWin->GetFileAttributesWin(&attribs); + + if (NS_FAILED(rv)) + { + fail("Test Win Attribs: GetFileAttributesWin failed to GET attributes. (1)"); + DeleteFileW(filePath); + return NS_ERROR_FAILURE; + } + + if (attribs & nsILocalFileWin::WFA_SEARCH_INDEXED) + { + fail("Test Win Attribs: GetFileAttributesWin attributed did not match. (2)"); + DeleteFileW(filePath); + return NS_ERROR_FAILURE; + } + + dwAttrs &= ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED; + SetFileAttributesW(filePath, dwAttrs); + + rv = localFileWin->GetFileAttributesWin(&attribs); + + if (NS_FAILED(rv)) + { + fail("Test Win Attribs: GetFileAttributesWin failed to GET attributes. (3)"); + DeleteFileW(filePath); + return NS_ERROR_FAILURE; + } + + if (!(attribs & nsILocalFileWin::WFA_SEARCH_INDEXED)) + { + fail("Test Win Attribs: GetFileAttributesWin attributed did not match. (4)"); + DeleteFileW(filePath); + return NS_ERROR_FAILURE; + } + + dwAttrs &= ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED; + SetFileAttributesW(filePath, dwAttrs); + + attribs = nsILocalFileWin::WFA_SEARCH_INDEXED; + rv = localFileWin->SetFileAttributesWin(attribs); + + dwAttrs = GetFileAttributesW(filePath); + + if (NS_FAILED(rv)) + { + fail("Test Win Attribs: GetFileAttributesWin failed to SET attributes. (5)"); + DeleteFileW(filePath); + return NS_ERROR_FAILURE; + } + + if (dwAttrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) + { + fail("Test Win Attribs: SetFileAttributesWin attributed did not match. (6)"); + DeleteFileW(filePath); + return NS_ERROR_FAILURE; + } + + dwAttrs |= FILE_ATTRIBUTE_NOT_CONTENT_INDEXED; + SetFileAttributesW(filePath, dwAttrs); + + attribs = 0; + rv = localFileWin->SetFileAttributesWin(attribs); + + dwAttrs = GetFileAttributesW(filePath); + + if (NS_FAILED(rv)) + { + fail("Test Win Attribs: GetFileAttributesWin failed to SET attributes. (7)"); + DeleteFileW(filePath); + return NS_ERROR_FAILURE; + } + + if (!(dwAttrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED)) + { + fail("Test Win Attribs: SetFileAttributesWin attributed did not match. (8)"); + DeleteFileW(filePath); + return NS_ERROR_FAILURE; + } + + DeleteFileW(filePath); + + passed("Test Win Attribs: passed tests."); + + return NS_OK; +} + +int main(int argc, char** argv) +{ + ScopedXPCOM xpcom("WinFileAttributes"); + if (xpcom.failed()) + return 1; + + int rv = 0; + + if(NS_FAILED(TestWinAttribs())) + rv = 1; + + return rv; + +} + -- cgit v1.2.3