[email protected] | da2566e1 | 2010-03-10 06:23:35 | [diff] [blame^] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/scoped_native_library.h" |
| 6 | |
| 7 | #include "testing/gtest/include/gtest/gtest.h" |
| 8 | |
| 9 | // Tests whether or not a function pointer retrieved via ScopedNativeLibrary |
| 10 | // is available only in a scope. |
| 11 | TEST(ScopedNativeLibrary, Basic) { |
| 12 | #if defined(OS_WIN) |
| 13 | // Get the pointer to DirectDrawCreate() from "ddraw.dll" and verify it |
| 14 | // is valid only in this scope. |
| 15 | // FreeLibrary() doesn't actually unload a DLL until its reference count |
| 16 | // becomes zero, i.e. this function pointer is still valid if the DLL used |
| 17 | // in this test is also used by another part of this executable. |
| 18 | // So, this test uses "ddraw.dll", which is not used by Chrome at all but |
| 19 | // installed on all versions of Windows. |
| 20 | FARPROC test_function; |
| 21 | { |
| 22 | FilePath path(base::GetNativeLibraryName(L"ddraw")); |
| 23 | base::ScopedNativeLibrary library(path); |
| 24 | test_function = reinterpret_cast<FARPROC>( |
| 25 | library.GetFunctionPointer("DirectDrawCreate")); |
| 26 | EXPECT_EQ(0, IsBadCodePtr(test_function)); |
| 27 | } |
| 28 | EXPECT_NE(0, IsBadCodePtr(test_function)); |
| 29 | #endif |
| 30 | } |