blob: 035faa03f741119029ecafc278a979b30d6e53d3 [file] [log] [blame]
[email protected]3b63f8f2011-03-28 01:54:151// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]da2566e2010-03-10 06:23:352// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]e0785902011-05-19 23:34:175#include "base/scoped_native_library.h"
[email protected]864b1362010-08-19 03:49:386#if defined(OS_WIN)
[email protected]57999812013-02-24 05:40:527#include "base/files/file_path.h"
[email protected]864b1362010-08-19 03:49:388#endif
[email protected]da2566e2010-03-10 06:23:359
10#include "testing/gtest/include/gtest/gtest.h"
11
[email protected]5257bcf2013-02-19 05:47:1012namespace base {
13
[email protected]da2566e2010-03-10 06:23:3514// Tests whether or not a function pointer retrieved via ScopedNativeLibrary
15// is available only in a scope.
16TEST(ScopedNativeLibrary, Basic) {
17#if defined(OS_WIN)
18 // Get the pointer to DirectDrawCreate() from "ddraw.dll" and verify it
19 // is valid only in this scope.
20 // FreeLibrary() doesn't actually unload a DLL until its reference count
[email protected]cbd119a2013-10-31 20:28:4721 // becomes zero, i.e. function pointer is still valid if the DLL used
[email protected]da2566e2010-03-10 06:23:3522 // in this test is also used by another part of this executable.
23 // So, this test uses "ddraw.dll", which is not used by Chrome at all but
24 // installed on all versions of Windows.
[email protected]cbd119a2013-10-31 20:28:4725 const char kFunctionName[] = "DirectDrawCreate";
26 NativeLibrary native_library;
[email protected]da2566e2010-03-10 06:23:3527 {
[email protected]5257bcf2013-02-19 05:47:1028 FilePath path(GetNativeLibraryName(L"ddraw"));
[email protected]cbd119a2013-10-31 20:28:4729 native_library = LoadNativeLibrary(path, NULL);
30 ScopedNativeLibrary library(native_library);
31 FARPROC test_function =
32 reinterpret_cast<FARPROC>(library.GetFunctionPointer(kFunctionName));
[email protected]da2566e2010-03-10 06:23:3533 EXPECT_EQ(0, IsBadCodePtr(test_function));
[email protected]cbd119a2013-10-31 20:28:4734 EXPECT_EQ(
35 GetFunctionPointerFromNativeLibrary(native_library, kFunctionName),
36 test_function);
[email protected]da2566e2010-03-10 06:23:3537 }
[email protected]cbd119a2013-10-31 20:28:4738 EXPECT_EQ(NULL,
39 GetFunctionPointerFromNativeLibrary(native_library, kFunctionName));
[email protected]da2566e2010-03-10 06:23:3540#endif
41}
[email protected]5257bcf2013-02-19 05:47:1042
43} // namespace base