OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/scoped_native_library.h" | 5 #include "base/scoped_native_library.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 #if defined(OS_WIN) | 10 #if defined(OS_WIN) |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/strings/utf_string_conversions.h" | |
12 #endif | 13 #endif |
13 | 14 |
14 namespace base { | 15 namespace base { |
15 | 16 |
16 // Tests whether or not a function pointer retrieved via ScopedNativeLibrary | 17 // Tests whether or not a function pointer retrieved via ScopedNativeLibrary |
17 // is available only in a scope. | 18 // is available only in a scope. |
18 TEST(ScopedNativeLibrary, Basic) { | 19 TEST(ScopedNativeLibrary, Basic) { |
19 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
20 // Get the pointer to DirectDrawCreate() from "ddraw.dll" and verify it | 21 // Get the pointer to DirectDrawCreate() from "ddraw.dll" and verify it |
21 // is valid only in this scope. | 22 // is valid only in this scope. |
22 // FreeLibrary() doesn't actually unload a DLL until its reference count | 23 // FreeLibrary() doesn't actually unload a DLL until its reference count |
23 // becomes zero, i.e. function pointer is still valid if the DLL used | 24 // becomes zero, i.e. function pointer is still valid if the DLL used |
24 // in this test is also used by another part of this executable. | 25 // in this test is also used by another part of this executable. |
25 // So, this test uses "ddraw.dll", which is not used by Chrome at all but | 26 // So, this test uses "ddraw.dll", which is not used by Chrome at all but |
26 // installed on all versions of Windows. | 27 // installed on all versions of Windows. |
27 const char kFunctionName[] = "DirectDrawCreate"; | 28 const char kFunctionName[] = "DirectDrawCreate"; |
28 NativeLibrary native_library; | 29 NativeLibrary native_library; |
29 { | 30 { |
30 FilePath path(GetNativeLibraryName(L"ddraw")); | 31 FilePath path(base::ASCIIToUTF16(GetNativeLibraryName("ddraw"))); |
Mark Mentovai
2016/06/13 19:29:03
FilePath::FromUTF16Unsafe()?
Lei Zhang
2016/06/13 21:30:34
I might as well skip the ASCIIToUTF16() bit and us
| |
31 native_library = LoadNativeLibrary(path, NULL); | 32 native_library = LoadNativeLibrary(path, NULL); |
32 ScopedNativeLibrary library(native_library); | 33 ScopedNativeLibrary library(native_library); |
33 EXPECT_TRUE(library.is_valid()); | 34 EXPECT_TRUE(library.is_valid()); |
34 EXPECT_EQ(native_library, library.get()); | 35 EXPECT_EQ(native_library, library.get()); |
35 FARPROC test_function = | 36 FARPROC test_function = |
36 reinterpret_cast<FARPROC>(library.GetFunctionPointer(kFunctionName)); | 37 reinterpret_cast<FARPROC>(library.GetFunctionPointer(kFunctionName)); |
37 EXPECT_EQ(0, IsBadCodePtr(test_function)); | 38 EXPECT_EQ(0, IsBadCodePtr(test_function)); |
38 EXPECT_EQ( | 39 EXPECT_EQ( |
39 GetFunctionPointerFromNativeLibrary(native_library, kFunctionName), | 40 GetFunctionPointerFromNativeLibrary(native_library, kFunctionName), |
40 test_function); | 41 test_function); |
41 } | 42 } |
42 EXPECT_EQ(NULL, | 43 EXPECT_EQ(NULL, |
43 GetFunctionPointerFromNativeLibrary(native_library, kFunctionName)); | 44 GetFunctionPointerFromNativeLibrary(native_library, kFunctionName)); |
44 #endif | 45 #endif |
45 } | 46 } |
46 | 47 |
47 } // namespace base | 48 } // namespace base |
OLD | NEW |