InstallationDirLayoutTest.cpp (2452B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 #include "gtest/gtest.h" 7 #include <windows.h> 8 #include "InstallationDirLayout.h" 9 #include <iostream> 10 #include "nsDirectoryServiceDefs.h" 11 #include "nsDirectoryServiceUtils.h" 12 13 class InstallationDirLayoutTest : public ::testing::Test { 14 protected: 15 nsCOMPtr<nsIFile> gre_dir; 16 17 void SetUp() override { 18 nsresult rv = NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(gre_dir)); 19 ASSERT_TRUE(NS_SUCCEEDED(rv)); 20 } 21 22 void TearDown() override { gre_dir = nullptr; } 23 }; 24 25 using FuncType = InstallationDirLayoutType (*)(); 26 27 TEST_F(InstallationDirLayoutTest, SingleLayoutTest) { 28 nsIFile* runtimelib_path; 29 nsresult res = gre_dir->Clone(&runtimelib_path); 30 ASSERT_TRUE(NS_SUCCEEDED(res)); 31 // Since this is the default, we don't need to access its by path. 32 runtimelib_path->Append(u"InstallationDirLayout.dll"_ns); 33 HINSTANCE hRuntimeLibrary = 34 LoadLibraryExW(runtimelib_path->NativePath().get(), nullptr, 0); 35 ASSERT_NE(hRuntimeLibrary, nullptr); 36 FuncType dirLayoutFunc = 37 (FuncType)GetProcAddress(hRuntimeLibrary, "GetInstallationDirLayoutType"); 38 ASSERT_NE(dirLayoutFunc, nullptr); 39 40 InstallationDirLayoutType layoutType = dirLayoutFunc(); 41 ASSERT_EQ(layoutType, InstallationDirLayoutType::Single); 42 bool freeResult = FreeLibrary(hRuntimeLibrary); 43 ASSERT_TRUE(freeResult); 44 } 45 46 TEST_F(InstallationDirLayoutTest, VersionedLayoutTest) { 47 nsIFile* runtimelib_path; 48 nsresult res = gre_dir->Clone(&runtimelib_path); 49 ASSERT_TRUE(NS_SUCCEEDED(res)); 50 runtimelib_path->Append(u"installation_dir_layout"_ns); 51 runtimelib_path->Append(u"versioned"_ns); 52 runtimelib_path->Append(u"InstallationDirLayout.dll"_ns); 53 HINSTANCE hRuntimeLibrary = 54 LoadLibraryExW(runtimelib_path->NativePath().get(), nullptr, 0); 55 56 ASSERT_NE(hRuntimeLibrary, nullptr); 57 FuncType dirLayoutFunc = 58 (FuncType)GetProcAddress(hRuntimeLibrary, "GetInstallationDirLayoutType"); 59 ASSERT_NE(dirLayoutFunc, nullptr); 60 61 InstallationDirLayoutType layoutType = dirLayoutFunc(); 62 ASSERT_EQ(layoutType, InstallationDirLayoutType::Versioned); 63 bool freeResult = FreeLibrary(hRuntimeLibrary); 64 ASSERT_TRUE(freeResult); 65 }