summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorevanm@google.com <evanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-15 01:04:11 +0000
committerevanm@google.com <evanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-15 01:04:11 +0000
commit4c0040c49331c5cb5b88960ecec04ce8a5f0756a (patch)
treeeb20f932e07a7c3fcb5bf144cba675d48ca791af /base
parent1b3deed79fc638d3755ba5159108712238d8beb7 (diff)
downloadchromium_src-4c0040c49331c5cb5b88960ecec04ce8a5f0756a.zip
chromium_src-4c0040c49331c5cb5b88960ecec04ce8a5f0756a.tar.gz
chromium_src-4c0040c49331c5cb5b88960ecec04ce8a5f0756a.tar.bz2
To pass string_util_unittest, we need the ICU data file. To get the ICU data file, we need some of PathService, which brings along with it a bunch of other needed functions. So here are a bunch of stubs, along with another file's worth of passing tests. (Based on a patch from Dean.)
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@921 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/SConscript11
-rw-r--r--base/base_paths.h2
-rw-r--r--base/base_paths_linux.cc57
-rw-r--r--base/base_paths_linux.h52
-rw-r--r--base/file_util.cc1
-rw-r--r--base/file_util_linux.cc30
-rw-r--r--base/file_util_mac.mm2
-rw-r--r--base/file_util_win.cc2
-rw-r--r--base/icu_util.cc22
-rw-r--r--base/logging.cc4
-rw-r--r--base/path_service.cc21
-rw-r--r--base/string_util_unittest.cc13
12 files changed, 197 insertions, 20 deletions
diff --git a/base/SConscript b/base/SConscript
index de6748f..4bc8d4b 100644
--- a/base/SConscript
+++ b/base/SConscript
@@ -55,6 +55,7 @@ if env['PLATFORM'] == 'win32':
# cross-platform live below.
input_files = [
'at_exit.cc',
+ 'base_paths.cc',
'base_switches.cc',
'bzip2_error_handler.cc',
'command_line.cc',
@@ -93,7 +94,6 @@ if env['PLATFORM'] == 'win32':
# TODO: move all these files to either the cross-platform block above or
# a platform-specific block below.
input_files.extend([
- 'base_paths.cc',
'clipboard_util.cc',
'debug_on_start.cc',
'event_recorder.cc',
@@ -160,6 +160,7 @@ if env['PLATFORM'] == 'darwin':
if env['PLATFORM'] == 'posix':
input_files.extend([
'atomicops_internals_x86_gcc.cc',
+ 'base_paths_linux.cc',
'file_util_linux.cc',
'sys_string_conversions_linux.cc',
])
@@ -246,6 +247,7 @@ test_files = [
'string_escape_unittest.cc',
'string_piece_unittest.cc',
'string_tokenizer_unittest.cc',
+ 'string_util_unittest.cc',
'time_unittest.cc',
'values_unittest.cc',
'waitable_event_unittest.cc',
@@ -274,7 +276,6 @@ if env['PLATFORM'] == 'win32':
'shared_event_unittest.cc',
'shared_memory_unittest.cc',
'stats_table_unittest.cc',
- 'string_util_unittest.cc',
'thread_local_storage_unittest.cc',
'thread_unittest.cc',
'timer_unittest.cc',
@@ -310,7 +311,11 @@ SConscript(sconscript_dirs, exports=['env'])
# Setup alias for all base related targets.
-env.Alias('base', ['.', installed_base_unittests, '../icudt38.dll'])
+if env['PLATFORM'] == 'win32':
+ icudata = '../icudt38.dll'
+else:
+ icudata = '../icudt38l.dat'
+env.Alias('base', ['.', installed_base_unittests, icudata])
# These aren't ported to other platforms yet.
diff --git a/base/base_paths.h b/base/base_paths.h
index 507398b..31344a2 100644
--- a/base/base_paths.h
+++ b/base/base_paths.h
@@ -38,6 +38,8 @@
#include "base/base_paths_win.h"
#elif defined(OS_MACOSX)
#include "base/base_paths_mac.h"
+#elif defined(OS_LINUX)
+#include "base/base_paths_linux.h"
#endif
namespace base {
diff --git a/base/base_paths_linux.cc b/base/base_paths_linux.cc
new file mode 100644
index 0000000..69c9078
--- /dev/null
+++ b/base/base_paths_linux.cc
@@ -0,0 +1,57 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "base/base_paths_linux.h"
+
+#include <unistd.h>
+
+#include "base/logging.h"
+#include "base/sys_string_conversions.h"
+
+namespace base {
+
+bool PathProviderLinux(int key, std::wstring* result) {
+ switch (key) {
+ case base::FILE_EXE:
+ case base::FILE_MODULE: { // TODO(evanm): is this correct?
+ char bin_dir[PATH_MAX + 1];
+ int bin_dir_size = readlink("/proc/self/exe", bin_dir, PATH_MAX);
+ if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) {
+ NOTREACHED() << "Unable to resolve /proc/self/exe.";
+ return false;
+ }
+ bin_dir[bin_dir_size] = 0;
+ *result = base::SysNativeMBToWide(bin_dir);
+ return true;
+ }
+ }
+ return false;
+}
+
+} // namespace base
diff --git a/base/base_paths_linux.h b/base/base_paths_linux.h
new file mode 100644
index 0000000..b0f3d48
--- /dev/null
+++ b/base/base_paths_linux.h
@@ -0,0 +1,52 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef BASE_BASE_PATHS_LINUX_H_
+#define BASE_BASE_PATHS_LINUX_H_
+
+// This file declares Linux-specific path keys for the base module.
+// These can be used with the PathService to access various special
+// directories and files.
+
+namespace base {
+
+enum {
+ PATH_LINUX_START = 200,
+
+ FILE_EXE, // Path and filename of the current executable.
+ FILE_MODULE, // Path and filename of the module containing the code for the
+ // PathService (which could differ from FILE_EXE if the
+ // PathService were compiled into a shared object, for example).
+
+ PATH_LINUX_END
+};
+
+} // namespace base
+
+#endif // BASE_BASE_PATHS_LINUX_H_
diff --git a/base/file_util.cc b/base/file_util.cc
index 8ba361e..234c466 100644
--- a/base/file_util.cc
+++ b/base/file_util.cc
@@ -38,7 +38,6 @@
namespace file_util {
-const wchar_t kPathSeparator = L'\\';
const wchar_t kExtensionSeparator = L'.';
bool EndsWithSeparator(std::wstring* path) {
diff --git a/base/file_util_linux.cc b/base/file_util_linux.cc
index 1d1a628..0795460 100644
--- a/base/file_util_linux.cc
+++ b/base/file_util_linux.cc
@@ -32,9 +32,17 @@
#include <string>
#include "base/logging.h"
+#include "base/notimplemented.h"
#include "base/string_util.h"
namespace file_util {
+
+const wchar_t kPathSeparator = L'/';
+
+bool AbsolutePath(std::wstring* path) {
+ NOTIMPLEMENTED();
+ return false;
+}
bool GetTempDir(std::wstring* path) {
const char* tmp = getenv("TMPDIR");
@@ -47,7 +55,27 @@ bool GetTempDir(std::wstring* path) {
bool CopyFile(const std::wstring& from_path, const std::wstring& to_path) {
// TODO(erikkay): implement
- DCHECK(false);
+ NOTIMPLEMENTED();
+ return false;
+}
+
+bool PathExists(const std::wstring& path) {
+ NOTIMPLEMENTED();
+ return false;
+}
+
+bool GetCurrentDirectory(std::wstring* path) {
+ NOTIMPLEMENTED();
+ return false;
+}
+
+bool CreateDirectory(const std::wstring& full_path) {
+ NOTIMPLEMENTED();
+ return false;
+}
+
+bool SetCurrentDirectory(const std::wstring& current_directory) {
+ NOTIMPLEMENTED();
return false;
}
diff --git a/base/file_util_mac.mm b/base/file_util_mac.mm
index bcabf4c..91a569d 100644
--- a/base/file_util_mac.mm
+++ b/base/file_util_mac.mm
@@ -37,6 +37,8 @@
namespace file_util {
+const wchar_t kPathSeparator = L'/';
+
bool GetTempDir(std::wstring* path) {
NSString* tmp = NSTemporaryDirectory();
if (tmp == nil)
diff --git a/base/file_util_win.cc b/base/file_util_win.cc
index f415016..80ae52f 100644
--- a/base/file_util_win.cc
+++ b/base/file_util_win.cc
@@ -42,6 +42,8 @@
namespace file_util {
+const wchar_t kPathSeparator = L'\\';
+
std::wstring GetDirectoryFromPath(const std::wstring& path) {
wchar_t path_buffer[MAX_PATH];
wchar_t* file_ptr = NULL;
diff --git a/base/icu_util.cc b/base/icu_util.cc
index fdb2003..b0f999d 100644
--- a/base/icu_util.cc
+++ b/base/icu_util.cc
@@ -29,7 +29,7 @@
#include "build/build_config.h"
-#ifdef OS_WIN
+#if defined(OS_WIN)
#include <windows.h>
#endif
@@ -40,12 +40,14 @@
#include "base/logging.h"
#include "base/file_util.h"
#include "base/path_service.h"
+#include "base/sys_string_conversions.h"
+#include "unicode/putil.h"
#include "unicode/udata.h"
namespace icu_util {
bool Initialize() {
-#ifdef OS_WIN
+#if defined(OS_WIN)
// Assert that we are not called more than once. Even though calling this
// function isn't harmful (ICU can handle it), being called twice probably
// indicates a programming error.
@@ -71,11 +73,19 @@ bool Initialize() {
UErrorCode err = U_ZERO_ERROR;
udata_setCommonData(reinterpret_cast<void*>(addr), &err);
return err == U_ZERO_ERROR;
-#else
- // Windows ships ICU's data separate, so it needs to link the code to data
- // here. Other platforms don't need this.
+#elif defined(OS_MACOSX)
+ // Mac bundles the ICU data in.
return true;
-#endif // OS_WIN
+#elif defined(OS_LINUX)
+ // For now, expect the data file to be alongside the executable.
+ // This is sufficient while we work on unit tests, but will eventually
+ // likely live in a data directory.
+ std::wstring data_path;
+ bool path_ok = PathService::Get(base::DIR_EXE, &data_path);
+ DCHECK(path_ok);
+ u_setDataDirectory(base::SysWideToNativeMB(data_path).c_str());
+ return true;
+#endif
}
} // namespace icu_util
diff --git a/base/logging.cc b/base/logging.cc
index 1e20dd0..87ac934 100644
--- a/base/logging.cc
+++ b/base/logging.cc
@@ -74,7 +74,11 @@ const char* const log_severity_names[LOG_NUM_SEVERITIES] = {
int min_log_level = 0;
LogLockingState lock_log_file = LOCK_LOG_FILE;
+#if defined(OS_WIN)
LoggingDestination logging_destination = LOG_ONLY_TO_FILE;
+#elif defined(OS_POSIX)
+LoggingDestination logging_destination = LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG;
+#endif
const int kMaxFilteredLogLevel = LOG_WARNING;
std::string* log_filter_prefix;
diff --git a/base/path_service.cc b/base/path_service.cc
index e8d92a5..f66069a 100644
--- a/base/path_service.cc
+++ b/base/path_service.cc
@@ -46,8 +46,10 @@ namespace base {
bool PathProvider(int key, std::wstring* result);
#if defined(OS_WIN)
bool PathProviderWin(int key, std::wstring* result);
-#elif defined (OS_MACOSX)
+#elif defined(OS_MACOSX)
bool PathProviderMac(int key, std::wstring* result);
+#elif defined(OS_LINUX)
+ bool PathProviderLinux(int key, std::wstring* result);
#endif
}
@@ -97,8 +99,19 @@ static Provider base_provider_win = {
#endif
};
#endif
-
-
+
+#if defined(OS_LINUX)
+static Provider base_provider_linux = {
+ base::PathProviderLinux,
+ &base_provider,
+#ifndef NDEBUG
+ base::PATH_LINUX_START,
+ base::PATH_LINUX_END
+#endif
+ };
+#endif
+
+
struct PathData {
Lock lock;
PathMap cache; // Track mappings from path key to path value.
@@ -111,7 +124,7 @@ struct PathData {
#elif defined(OS_MACOSX)
providers = &base_provider_mac;
#elif defined(OS_LINUX)
- providers = &base_provider;
+ providers = &base_provider_linux;
#endif
}
};
diff --git a/base/string_util_unittest.cc b/base/string_util_unittest.cc
index 05ba0a1..01fac05 100644
--- a/base/string_util_unittest.cc
+++ b/base/string_util_unittest.cc
@@ -607,11 +607,11 @@ TEST(StringUtilTest, FormatBytes) {
TEST(StringUtilTest, ReplaceSubstringsAfterOffset) {
static const struct {
- wchar_t* str;
+ const wchar_t* str;
std::wstring::size_type start_offset;
- wchar_t* find_this;
- wchar_t* replace_with;
- wchar_t* expected;
+ const wchar_t* find_this;
+ const wchar_t* replace_with;
+ const wchar_t* expected;
} cases[] = {
{L"aaa", 0, L"a", L"b", L"bbb"},
{L"abb", 0, L"ab", L"a", L"ab"},
@@ -1053,7 +1053,7 @@ TEST(StringUtilTest, Grow) {
src[i] = 'A';
src[1025] = 0;
- char* fmt = "%sB%sB%sB%sB%sB%sB%s";
+ const char* fmt = "%sB%sB%sB%sB%sB%sB%s";
std::string out;
SStringPrintf(&out, fmt, src, src, src, src, src, src, src);
@@ -1087,6 +1087,8 @@ TEST(StringUtilTest, GrowBoundary) {
EXPECT_STREQ(src, out.c_str());
}
+// TODO(evanm): what's the proper cross-platform test here?
+#if defined(OS_WIN)
// sprintf in Visual Studio fails when given U+FFFF. This tests that the
// failure case is gracefuly handled.
TEST(StringUtilTest, Invalid) {
@@ -1098,6 +1100,7 @@ TEST(StringUtilTest, Invalid) {
SStringPrintf(&out, L"%ls", invalid);
EXPECT_STREQ(L"", out.c_str());
}
+#endif
// Test for SplitString
TEST(StringUtilTest, SplitString) {