summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-05 22:18:09 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-05 22:18:09 +0000
commit108c2a1d2780d49121e16b18a29580ef4d28c790 (patch)
treeeca587b489c7c22924814f4475c4a56ec5bc5b8e /base
parent9e241cc8a7320c0a818da0ddac1bc3910fc1b60a (diff)
downloadchromium_src-108c2a1d2780d49121e16b18a29580ef4d28c790.zip
chromium_src-108c2a1d2780d49121e16b18a29580ef4d28c790.tar.gz
chromium_src-108c2a1d2780d49121e16b18a29580ef4d28c790.tar.bz2
Porting the browser tests to Unix.
The browser tests are an alternative to UI tests. They provide a way to exercise the browser from within the test (without having the test and the browser running in different processes). In order to ensure atexit hanlders are run after each tests and static initializers start fresh for each test, each test is run in a new process (on Linux and Mac). On Windows, a DLL containing the test is loaded/unloaded for each tests. BUG=None TEST=Run the browser tests. Review URL: http://codereview.chromium.org/115896 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17781 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/command_line.cc1
-rw-r--r--base/native_library.h33
-rw-r--r--base/native_library_linux.cc8
-rw-r--r--base/native_library_mac.mm41
-rw-r--r--base/native_library_win.cc8
5 files changed, 79 insertions, 12 deletions
diff --git a/base/command_line.cc b/base/command_line.cc
index 8fb2dcc..a1f919a 100644
--- a/base/command_line.cc
+++ b/base/command_line.cc
@@ -169,7 +169,6 @@ bool CommandLine::IsSwitch(const StringType& parameter_string,
// static
void CommandLine::Init(int argc, const char* const* argv) {
- DCHECK(current_process_commandline_ == NULL);
#if defined(OS_WIN)
current_process_commandline_ = new CommandLine;
current_process_commandline_->ParseFromString(::GetCommandLineW());
diff --git a/base/native_library.h b/base/native_library.h
index ce85c23..6c835f2 100644
--- a/base/native_library.h
+++ b/base/native_library.h
@@ -16,19 +16,36 @@
#import <Carbon/Carbon.h>
#endif // OS_*
+#include "base/string16.h"
+
+// Macro usefull for writing cross-platform function pointers.
+#if defined(OS_WIN) && !defined(CDECL)
+#define CDECL __cdecl
+#else
+#define CDECL
+#endif
+
class FilePath;
namespace base {
#if defined(OS_WIN)
typedef HMODULE NativeLibrary;
-typedef char* NativeLibraryFunctionNameType;
#elif defined(OS_MACOSX)
-typedef CFBundleRef NativeLibrary;
-typedef CFStringRef NativeLibraryFunctionNameType;
+enum NativeLibraryType {
+ BUNDLE,
+ DYNAMIC_LIB
+};
+struct NativeLibraryStruct {
+ NativeLibraryType type;
+ union {
+ CFBundleRef bundle;
+ void* dylib;
+ };
+};
+typedef NativeLibraryStruct* NativeLibrary;
#elif defined(OS_LINUX)
typedef void* NativeLibrary;
-typedef const char* NativeLibraryFunctionNameType;
#endif // OS_*
// Loads a native library from disk. Release it with UnloadNativeLibrary when
@@ -40,7 +57,13 @@ void UnloadNativeLibrary(NativeLibrary library);
// Gets a function pointer from a native library.
void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
- NativeLibraryFunctionNameType name);
+ const char* name);
+
+// Returns the full platform specific name for a native library.
+// For example:
+// "mylib" returns "mylib.dll" on Windows, "libmylib.so" on Linux,
+// "mylib.dylib" on Mac.
+string16 GetNativeLibraryName(const string16& name);
} // namespace base
diff --git a/base/native_library_linux.cc b/base/native_library_linux.cc
index f103bba..39221c1 100644
--- a/base/native_library_linux.cc
+++ b/base/native_library_linux.cc
@@ -8,6 +8,7 @@
#include "base/file_path.h"
#include "base/logging.h"
+#include "base/string_util.h"
namespace base {
@@ -29,8 +30,13 @@ void UnloadNativeLibrary(NativeLibrary library) {
// static
void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
- NativeLibraryFunctionNameType name) {
+ const char* name) {
return dlsym(library, name);
}
+// static
+string16 GetNativeLibraryName(const string16& name) {
+ return ASCIIToUTF16("lib") + name + ASCIIToUTF16(".so");
+}
+
} // namespace base
diff --git a/base/native_library_mac.mm b/base/native_library_mac.mm
index f817a01..577f5ac 100644
--- a/base/native_library_mac.mm
+++ b/base/native_library_mac.mm
@@ -4,15 +4,28 @@
#include "base/native_library.h"
+#include <dlfcn.h>
#import <Carbon/Carbon.h>
#include "base/file_path.h"
+#include "base/file_util.h"
#include "base/scoped_cftyperef.h"
+#include "base/string_util.h"
namespace base {
// static
NativeLibrary LoadNativeLibrary(const FilePath& library_path) {
+ if (library_path.Extension() == "dylib" ||
+ !file_util::DirectoryExists(library_path)) {
+ void* dylib = dlopen(library_path.value().c_str(), RTLD_LAZY);
+ if (!dylib)
+ return NULL;
+ NativeLibrary native_lib = new NativeLibraryStruct();
+ native_lib->type = DYNAMIC_LIB;
+ native_lib->dylib = dylib;
+ return native_lib;
+ }
scoped_cftyperef<CFURLRef> url(CFURLCreateFromFileSystemRepresentation(
kCFAllocatorDefault,
(const UInt8*)library_path.value().c_str(),
@@ -20,19 +33,39 @@ NativeLibrary LoadNativeLibrary(const FilePath& library_path) {
true));
if (!url)
return NULL;
+ CFBundleRef bundle = CFBundleCreate(kCFAllocatorDefault, url.get());
+ if (!bundle)
+ return NULL;
- return CFBundleCreate(kCFAllocatorDefault, url.get());
+ NativeLibrary native_lib = new NativeLibraryStruct();
+ native_lib->type = BUNDLE;
+ native_lib->bundle = bundle;
+ return native_lib;
}
// static
void UnloadNativeLibrary(NativeLibrary library) {
- CFRelease(library);
+ if (library->type == BUNDLE)
+ CFRelease(library->bundle);
+ else
+ dlclose(library->dylib);
+ delete library;
}
// static
void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
- NativeLibraryFunctionNameType name) {
- return CFBundleGetFunctionPointerForName(library, name);
+ const char* name) {
+ if (library->type == BUNDLE)
+ return CFBundleGetFunctionPointerForName(library->bundle,
+ CFStringCreateWithCString(kCFAllocatorDefault, name,
+ kCFStringEncodingUTF8));
+
+ return dlsym(library->dylib, name);
+}
+
+// static
+string16 GetNativeLibraryName(const string16& name) {
+ return name + ASCIIToUTF16(".dylib");
}
} // namespace base
diff --git a/base/native_library_win.cc b/base/native_library_win.cc
index cf477fe..459e2ff 100644
--- a/base/native_library_win.cc
+++ b/base/native_library_win.cc
@@ -8,6 +8,7 @@
#include "base/file_path.h"
#include "base/path_service.h"
+#include "base/string_util.h"
namespace base {
@@ -39,8 +40,13 @@ void UnloadNativeLibrary(NativeLibrary library) {
// static
void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
- NativeLibraryFunctionNameType name) {
+ const char* name) {
return GetProcAddress(library, name);
}
+// static
+string16 GetNativeLibraryName(const string16& name) {
+ return name + ASCIIToUTF16(".dll");
+}
+
} // namespace base