ShellLinkTests.cpp (1806B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #include "gtest/gtest.h" 7 8 #include "nsDirectoryServiceDefs.h" 9 #include "nsDirectoryServiceUtils.h" 10 #include "nsWindowsShellServiceInternal.h" 11 #include "nsXULAppAPI.h" 12 13 TEST(ShellLink, NarrowCharacterArguments) 14 { 15 nsCOMPtr<nsIFile> exe; 16 nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(exe)); 17 ASSERT_TRUE(NS_SUCCEEDED(rv)); 18 19 RefPtr<IShellLinkW> link; 20 rv = CreateShellLinkObject(exe, {u"test"_ns}, u"test"_ns, exe, 0, u"aumid"_ns, 21 getter_AddRefs(link)); 22 ASSERT_TRUE(NS_SUCCEEDED(rv)); 23 ASSERT_TRUE(link != nullptr); 24 25 std::wstring testArgs = L"\"test\" "; 26 27 wchar_t resultArgs[sizeof(testArgs)]; 28 HRESULT hr = link->GetArguments(resultArgs, sizeof(resultArgs)); 29 ASSERT_TRUE(SUCCEEDED(hr)); 30 31 ASSERT_TRUE(testArgs == resultArgs); 32 } 33 34 TEST(ShellLink, WideCharacterArguments) 35 { 36 nsCOMPtr<nsIFile> exe; 37 nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(exe)); 38 ASSERT_TRUE(NS_SUCCEEDED(rv)); 39 40 RefPtr<IShellLinkW> link; 41 rv = CreateShellLinkObject(exe, {u"Test\\テスト用アカウント\\Test"_ns}, 42 u"test"_ns, exe, 0, u"aumid"_ns, 43 getter_AddRefs(link)); 44 ASSERT_TRUE(NS_SUCCEEDED(rv)); 45 ASSERT_TRUE(link != nullptr); 46 47 std::wstring testArgs = L"\"Test\\テスト用アカウント\\Test\" "; 48 49 wchar_t resultArgs[sizeof(testArgs)]; 50 HRESULT hr = link->GetArguments(resultArgs, sizeof(resultArgs)); 51 ASSERT_TRUE(SUCCEEDED(hr)); 52 53 ASSERT_TRUE(testArgs == resultArgs); 54 }