blob: c120555ec69a1ae0f216a53dc5f8f53035b61f6e [file] [log] [blame]
[email protected]3b63f8f42011-03-28 01:54:151// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]da2566e12010-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]da2566e12010-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]da2566e12010-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
21 // becomes zero, i.e. this function pointer is still valid if the DLL used
22 // 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.
25 FARPROC test_function;
26 {
[email protected]5257bcf2013-02-19 05:47:1027 FilePath path(GetNativeLibraryName(L"ddraw"));
28 ScopedNativeLibrary library(path);
[email protected]da2566e12010-03-10 06:23:3529 test_function = reinterpret_cast<FARPROC>(
30 library.GetFunctionPointer("DirectDrawCreate"));
31 EXPECT_EQ(0, IsBadCodePtr(test_function));
32 }
33 EXPECT_NE(0, IsBadCodePtr(test_function));
34#endif
35}
[email protected]5257bcf2013-02-19 05:47:1036
37} // namespace base