1 // Copyright 2013 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.
5 #include "build/build_config.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/icu/source/common/unicode/putil.h"
15 #include "third_party/icu/source/common/unicode/udata.h"
17 #define ICU_UTIL_DATA_SHARED 1
18 #define ICU_UTIL_DATA_STATIC 2
20 #ifndef ICU_UTIL_DATA_IMPL
23 #define ICU_UTIL_DATA_IMPL ICU_UTIL_DATA_SHARED
24 #elif defined(OS_MACOSX)
25 #define ICU_UTIL_DATA_IMPL ICU_UTIL_DATA_STATIC
26 #elif defined(OS_LINUX)
27 #define ICU_UTIL_DATA_IMPL ICU_UTIL_DATA_FILE
30 #endif // ICU_UTIL_DATA_IMPL
33 #define ICU_UTIL_DATA_SYMBOL "icudt" U_ICU_VERSION_SHORT "_dat"
34 #define ICU_UTIL_DATA_SHARED_MODULE_NAME "icudt" U_ICU_VERSION_SHORT ".dll"
37 bool InitializeICU() {
38 #if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED)
39 // We expect to find the ICU data module alongside the current module.
40 // Because the module name is ASCII-only, "A" API should be safe.
41 // Chrome's copy of ICU dropped a version number XX from icudt dll,
42 // but 3rd-party embedders may need it. So, we try both.
43 HMODULE module
= LoadLibraryA("icudt.dll");
45 module
= LoadLibraryA(ICU_UTIL_DATA_SHARED_MODULE_NAME
);
50 FARPROC addr
= GetProcAddress(module
, ICU_UTIL_DATA_SYMBOL
);
54 UErrorCode err
= U_ZERO_ERROR
;
55 udata_setCommonData(reinterpret_cast<void*>(addr
), &err
);
56 return err
== U_ZERO_ERROR
;
57 #elif (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_STATIC)
58 // Mac bundles the ICU data in.
60 #elif (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE)
61 // We expect to find the ICU data module alongside the current module.
62 u_setDataDirectory(".");
63 // Only look for the packaged data file;
64 // the default behavior is to look for individual files.
65 UErrorCode err
= U_ZERO_ERROR
;
66 udata_setFileAccess(UDATA_ONLY_PACKAGES
, &err
);
67 return err
== U_ZERO_ERROR
;
71 int main(int argc
, char **argv
) {
72 ::testing::InitGoogleTest(&argc
, argv
);
76 return RUN_ALL_TESTS();