diff --git a/docs/build_mozc_in_docker.md b/docs/build_mozc_in_docker.md index 7cd0e72..ff70d0a 100644 --- a/docs/build_mozc_in_docker.md +++ b/docs/build_mozc_in_docker.md @@ -33,6 +33,15 @@ python build_mozc.py runtests -c Debug ``` +Experimental: Instead of build_mozc.py, you can try to use Bazel. + +``` +bazel build package --config oss_linux +``` + +`package` is an alias to build `server:mozc_server` and `gui/tool:mozc_tool`. + + ### Build Mozc library for Android: Client code for Android apk is deprecated. @@ -42,9 +51,10 @@ The conversion engine for Android is built with Bazel. ``` -bazel build android/jni:mozc_lib --config oss_android +bazel build package --config oss_android ``` +`package` is an alias to build `android/jni:mozc_lib`. ## Build configurations for Linux desktop In `python build_mozc.py gyp` step, there are two different styles to customize configurations. One is `GYP_DEFINES` environment variable and the other is commandline option. diff --git a/src/BUILD b/src/BUILD index f7baec8..d45d556 100644 --- a/src/BUILD +++ b/src/BUILD @@ -31,6 +31,7 @@ # Description: # Declaration of package_group for visibility managing. +load("//:build_defs.bzl", "select_mozc") load("//tools/build_defs:stubs.bzl", "bzl_library") package_group( @@ -126,5 +127,17 @@ name = "build_defs_bzl", srcs = ["build_defs.bzl"], parse_tests = False, - visibility = ["//visibility:private"], + visibility = ["//:__subpackages__"], ) + +filegroup( + name = "package", + srcs = select_mozc( + default = [], + oss_android = ["//android/jni:mozc_lib"], + oss_linux = [ + "//gui/tool:mozc_tool", + "//server:mozc_server", + ], + ), +) diff --git a/src/BUILD.ja_usage_dict b/src/BUILD.ja_usage_dict new file mode 100644 index 0000000..9e26075 --- /dev/null +++ b/src/BUILD.ja_usage_dict @@ -0,0 +1,3 @@ +package(default_visibility = ["//visibility:public"]) + +exports_files(["usage_dict.txt"]) diff --git a/src/WORKSPACE b/src/WORKSPACE index ddac66a..500d674 100644 --- a/src/WORKSPACE +++ b/src/WORKSPACE @@ -36,6 +36,14 @@ # tag = "v3.6.0.1", # 2018-06-09 # ) +# Japanese Usage Dictionary +new_local_repository( + name = "ja_usage_dict", + path = "third_party/japanese_usage_dictionary", + build_file = "BUILD.ja_usage_dict", +) + +# Qt new_local_repository( name = "io_qt", # This path should be updated per the environment. diff --git a/src/android/gen_mozc_drawable.py b/src/android/gen_mozc_drawable.py index d792ad6..25f7b54 100644 --- a/src/android/gen_mozc_drawable.py +++ b/src/android/gen_mozc_drawable.py @@ -41,7 +41,7 @@ __author__ = "hidehiko" -import cStringIO as StringIO +import io import logging import optparse import os @@ -289,7 +289,7 @@ def _ConsumeFloatList(self, s, num): """Parses num floating values from s.""" result = [] - for _ in xrange(num): + for _ in range(num): value, s = self._ConsumeFloat(s) result.append(value) return result, s @@ -1035,12 +1035,12 @@ # Interface for drawable conversion. def ConvertPictureDrawable(self, path): - output = _OutputStream(StringIO.StringIO()) + output = _OutputStream(io.BytesIO()) self._ConvertPictureDrawableInternal(ElementTree.parse(path), output) return output.output.getvalue() def ConvertStateListDrawable(self, drawable_source_list): - output = _OutputStream(StringIO.StringIO()) + output = _OutputStream(io.BytesIO()) output.WriteByte(DRAWABLE_STATE_LIST) output.WriteByte(len(drawable_source_list)) for (state_list, path) in drawable_source_list: diff --git a/src/android/jni/BUILD b/src/android/jni/BUILD index 21052db..4b9111e 100644 --- a/src/android/jni/BUILD +++ b/src/android/jni/BUILD @@ -35,14 +35,12 @@ # Usage: # % blaze --blazerc android/blazerc build --config=android_arm android/jni:libmozc.so -load( - "//:build_defs.bzl", - "cc_library_mozc", -) +load("//:build_defs.bzl", "cc_library_mozc") cc_library_mozc( name = "mozc_lib", srcs = ["mozcjni.cc"], + visibility = ["//:__pkg__"], deps = [ "//base:logging", "//base:singleton", diff --git a/src/base/base.gyp b/src/base/base.gyp index 3a89905..ea8cde2 100644 --- a/src/base/base.gyp +++ b/src/base/base.gyp @@ -515,12 +515,12 @@ 'target_name': 'breakpad', 'type': 'none', 'variables': { - 'pbdir': '<(third_party_dir)/breakpad', + 'bpdir': '<(third_party_dir)/breakpad', }, 'actions': [{ 'action_name': 'build_breakpad', 'inputs': [ - '<(pbdir)/src/client/mac/Breakpad.xcodeproj/project.pbxproj', + '<(bpdir)/src/client/mac/Breakpad.xcodeproj/project.pbxproj', ], 'outputs': [ '<(mac_breakpad_dir)/Breakpad.framework', @@ -530,7 +530,7 @@ ], 'action': [ '<(python)', '../build_tools/build_breakpad.py', - '--pbdir', '<(pbdir)', + '--bpdir', '<(bpdir)', '--outdir', '<(mac_breakpad_dir)', '--sdk', 'macosx<(mac_sdk)', '--deployment_target', '<(mac_deployment_target)', diff --git a/src/base/hash.cc b/src/base/hash.cc index e6fbf2e..48a4fec 100644 --- a/src/base/hash.cc +++ b/src/base/hash.cc @@ -145,7 +145,7 @@ const uint32 lo = Fingerprint32WithSeed(str, kFingerPrintSeed1); uint64 result = static_cast(hi) << 32 | static_cast(lo); if ((hi == 0) && (lo < 2)) { - result ^= GG_ULONGLONG(0x130f9bef94a0a928); + result ^= 0x130f9bef94a0a928uLL; } return result; } diff --git a/src/base/iterator_adapter.h b/src/base/iterator_adapter.h index b1e4276..3ab125c 100644 --- a/src/base/iterator_adapter.h +++ b/src/base/iterator_adapter.h @@ -116,6 +116,10 @@ value_type operator*() { return adapter_(iter_); } + // MSVS 2017 requires this definition. + // See: https://github.com/tensorflow/tensorflow/issues/15925 + value_type operator*() const { return adapter_(iter_); } + pointer operator->() const { return &(operator*()); } IteratorAdapter &operator++() { diff --git a/src/base/number_util.cc b/src/base/number_util.cc index 934e858..b6288c7 100644 --- a/src/base/number_util.cc +++ b/src/base/number_util.cc @@ -538,7 +538,7 @@ // return false when an integer overflow happens. bool AddAndCheckOverflow(uint64 arg1, uint64 arg2, uint64 *output) { *output = arg1 + arg2; - if (arg2 > (kuint64max - arg1)) { + if (arg2 > (std::numeric_limits::max() - arg1)) { // overflow happens return false; } @@ -549,7 +549,7 @@ // return false when an integer overflow happens. bool MultiplyAndCheckOverflow(uint64 arg1, uint64 arg2, uint64 *output) { *output = arg1 * arg2; - if (arg1 != 0 && arg2 > (kuint64max / arg1)) { + if (arg1 != 0 && arg2 > (std::numeric_limits::max() / arg1)) { // overflow happens return false; } @@ -619,8 +619,8 @@ template <> bool SafeCast(int64 src, int16 *dest) { - if (src < static_cast(kint16min) || - static_cast(kint16max) < src) { + if (src < static_cast(std::numeric_limits::min()) || + static_cast(std::numeric_limits::max()) < src) { return false; } *dest = static_cast(src); @@ -629,8 +629,8 @@ template <> bool SafeCast(int64 src, int32 *dest) { - if (src < static_cast(kint32min) || - static_cast(kint32max) < src) { + if (src < static_cast(std::numeric_limits::min()) || + static_cast(std::numeric_limits::max()) < src) { return false; } *dest = static_cast(src); @@ -639,7 +639,7 @@ template <> bool SafeCast(uint64 src, int64 *dest) { - if (src > static_cast(kint64max)) { + if (src > static_cast(std::numeric_limits::max())) { return false; } *dest = static_cast(src); @@ -648,7 +648,7 @@ template <> bool SafeCast(uint64 src, uint16 *dest) { - if (src > static_cast(kuint16max)) { + if (src > static_cast(std::numeric_limits::max())) { return false; } *dest = static_cast(src); @@ -657,7 +657,7 @@ template <> bool SafeCast(uint64 src, uint32 *dest) { - if (src > static_cast(kuint32max)) { + if (src > static_cast(std::numeric_limits::max())) { return false; } *dest = static_cast(src); @@ -678,7 +678,7 @@ if (src == 0x8000000000000000ul) { // This is an exceptional case. |src| isn't in the range of int64, // but |-src| is in the range. - *dest = kint64min; + *dest = std::numeric_limits::min(); return true; } return false; @@ -966,7 +966,7 @@ // "一十二百" = [1, 10, 2, 100] => error bool InterpretNumbersInJapaneseWay(const std::vector &numbers, uint64 *output) { - uint64 last_base = kuint64max; + uint64 last_base = std::numeric_limits::max(); auto begin = numbers.begin(); *output = 0; do { diff --git a/src/base/number_util_test.cc b/src/base/number_util_test.cc index 23676db..387113f 100644 --- a/src/base/number_util_test.cc +++ b/src/base/number_util_test.cc @@ -29,6 +29,8 @@ #include "base/number_util.h" +#include + #include "base/port.h" #include "testing/base/public/googletest.h" #include "testing/base/public/gunit.h" @@ -72,10 +74,10 @@ EXPECT_EQ(-12345, value); value = 0x4321; EXPECT_TRUE(NumberUtil::SafeStrToInt16("-32768", &value)); - EXPECT_EQ(kint16min, value); // min of 16-bit signed integer + EXPECT_EQ(std::numeric_limits::min(), value); value = 0x4321; EXPECT_TRUE(NumberUtil::SafeStrToInt16("32767", &value)); - EXPECT_EQ(kint16max, value); // max of 16-bit signed integer + EXPECT_EQ(std::numeric_limits::max(), value); value = 0x4321; EXPECT_TRUE(NumberUtil::SafeStrToInt16(" 1", &value)); EXPECT_EQ(1, value); @@ -132,10 +134,10 @@ EXPECT_EQ(-12345678, value); value = 0xDEADBEEF; EXPECT_TRUE(NumberUtil::SafeStrToInt32("-2147483648", &value)); - EXPECT_EQ(kint32min, value); // min of 32-bit signed integer + EXPECT_EQ(std::numeric_limits::min(), value); value = 0xDEADBEEF; EXPECT_TRUE(NumberUtil::SafeStrToInt32("2147483647", &value)); - EXPECT_EQ(kint32max, value); // max of 32-bit signed integer + EXPECT_EQ(std::numeric_limits::max(), value); value = 0xDEADBEEF; EXPECT_TRUE(NumberUtil::SafeStrToInt32(" 1", &value)); EXPECT_EQ(1, value); @@ -193,10 +195,10 @@ EXPECT_EQ(-12345678, value); value = 0xDEADBEEF; EXPECT_TRUE(NumberUtil::SafeStrToInt64("-9223372036854775808", &value)); - EXPECT_EQ(kint64min, value); // min of 64-bit signed integer + EXPECT_EQ(std::numeric_limits::min(), value); value = 0xDEADBEEF; EXPECT_TRUE(NumberUtil::SafeStrToInt64("9223372036854775807", &value)); - EXPECT_EQ(kint64max, value); // max of 64-bit signed integer + EXPECT_EQ(std::numeric_limits::max(), value); EXPECT_FALSE(NumberUtil::SafeStrToInt64("-9223372036854775809", // overflow &value)); diff --git a/src/base/port.h b/src/base/port.h index 542042b..39a7ab0 100644 --- a/src/base/port.h +++ b/src/base/port.h @@ -76,70 +76,32 @@ #undef MOZC_OS_DEFINED -#ifndef _MSC_VER -#if !defined(__STDC_FORMAT_MACROS) -#define __STDC_FORMAT_MACROS -#endif // !__STDC_FORMAT_MACROS -#include -#endif // _MSC_VER -#include -#include -#include + +#ifdef GOOGLE_JAPANESE_INPUT_BUILD + +#include "absl/base/attributes.h" +#include "absl/base/integral_types.h" +#include "absl/base/macros.h" + +#else // GOOGLE_JAPANESE_INPUT_BUILD + +#include #include "absl/base/attributes.h" #include "absl/base/macros.h" -#ifdef GOOGLE_JAPANESE_INPUT_BUILD -#include "absl/base/integral_types.h" -#else // GOOGLE_JAPANESE_INPUT_BUILD +// Integral types. +typedef std::int8_t int8; +typedef std::int16_t int16; +typedef std::int32_t int32; +typedef std::int64_t int64; -// Integral types. -typedef signed char int8; -typedef short int16; // NOLINT -typedef int int32; -#ifdef COMPILER_MSVC -typedef __int64 int64; -#else -typedef long long int64; // NOLINT -#endif /* COMPILER_MSVC */ - -typedef unsigned char uint8; -typedef unsigned short uint16; // NOLINT -typedef unsigned int uint32; -#ifdef COMPILER_MSVC -typedef unsigned __int64 uint64; -#else -typedef unsigned long long uint64; // NOLINT -#endif /* COMPILER_MSVC */ +typedef std::uint8_t uint8; +typedef std::uint16_t uint16; +typedef std::uint32_t uint32; +typedef std::uint64_t uint64; typedef signed int char32; - -#ifdef COMPILER_MSVC /* if Visual C++ */ - -// VC++ long long suffixes -#define GG_LONGLONG(x) x##I64 -#define GG_ULONGLONG(x) x##UI64 - -#else /* not Visual C++ */ - -#define GG_LONGLONG(x) x##LL -#define GG_ULONGLONG(x) x##ULL - -#endif // COMPILER_MSVC - -// INT_MIN, INT_MAX, UINT_MAX family at Google -const uint8 kuint8max{0xFF}; -const uint16 kuint16max{0xFFFF}; -const uint32 kuint32max{0xFFFFFFFF}; -const uint64 kuint64max{GG_ULONGLONG(0xFFFFFFFFFFFFFFFF)}; -const int8 kint8min{~0x7F}; -const int8 kint8max{0x7F}; -const int16 kint16min{~0x7FFF}; -const int16 kint16max{0x7FFF}; -const int32 kint32min{~0x7FFFFFFF}; -const int32 kint32max{0x7FFFFFFF}; -const int64 kint64min{GG_LONGLONG(~0x7FFFFFFFFFFFFFFF)}; -const int64 kint64max{GG_LONGLONG(0x7FFFFFFFFFFFFFFF)}; #endif // GOOGLE_JAPANESE_INPUT_BUILD diff --git a/src/base/util_test.cc b/src/base/util_test.cc index ed5743e..f3dcdac 100644 --- a/src/base/util_test.cc +++ b/src/base/util_test.cc @@ -32,11 +32,11 @@ #include #include #include +#include #include #include #include -#include "base/compiler_specific.h" #include "base/file_stream.h" #include "base/file_util.h" #include "base/logging.h" @@ -1935,10 +1935,10 @@ uint64 value; } kCorrectPairs[] = { {"\x00\x00\x00\x00\x00\x00\x00\x00", 0}, - {"\x00\x00\x00\x00\x00\x00\x00\xFF", kuint8max}, - {"\x00\x00\x00\x00\x00\x00\xFF\xFF", kuint16max}, - {"\x00\x00\x00\x00\xFF\xFF\xFF\xFF", kuint32max}, - {"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", kuint64max}, + {"\x00\x00\x00\x00\x00\x00\x00\xFF", std::numeric_limits::max()}, + {"\x00\x00\x00\x00\x00\x00\xFF\xFF", std::numeric_limits::max()}, + {"\x00\x00\x00\x00\xFF\xFF\xFF\xFF", std::numeric_limits::max()}, + {"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", std::numeric_limits::max()}, {"\x01\x23\x45\x67\x89\xAB\xCD\xEF", 0x0123456789ABCDEF}, {"\xFE\xDC\xBA\x98\x76\x54\x32\x10", 0xFEDCBA9876543210}, }; diff --git a/src/build_defs.bzl b/src/build_defs.bzl index 6329c22..a95a361 100644 --- a/src/build_defs.bzl +++ b/src/build_defs.bzl @@ -33,6 +33,7 @@ # so required macros are defined by depending on it. load("//tools/build_defs:build_cleaner.bzl", "register_extension_info") +load("//tools/build_defs:stubs.bzl", "pytype_strict_binary", "pytype_strict_library") load("//tools/build_rules/android_cc_test:def.bzl", "android_cc_test") def cc_library_mozc(deps = [], **kwargs): @@ -92,11 +93,12 @@ label_regex_for_dep = "{extension_name}", ) -def py_library_mozc(name, srcs, **kwargs): +def py_library_mozc(name, srcs, srcs_version = "PY2AND3", **kwargs): """py_library wrapper generating import-modified python scripts for iOS.""" - native.py_library( + pytype_strict_library( name = name, srcs = srcs, + srcs_version = srcs_version, **kwargs ) @@ -105,16 +107,18 @@ label_regex_for_dep = "{extension_name}", ) -def py_binary_mozc(name, srcs, python_version = "PY3", **kwargs): +def py_binary_mozc(name, srcs, python_version = "PY3", srcs_version = "PY2AND3", **kwargs): """py_binary wrapper generating import-modified python script for iOS. To use this rule, corresponding py_library_mozc needs to be defined to generate iOS sources. """ - native.py_binary( + pytype_strict_binary( name = name, srcs = srcs, python_version = python_version, + srcs_version = srcs_version, + test_lib = True, # This main specifier is required because, without it, py_binary expects # that the file name of source containing main() is name.py. main = srcs[0], diff --git a/src/build_mozc.py b/src/build_mozc.py index c739e19..873b6ff 100644 --- a/src/build_mozc.py +++ b/src/build_mozc.py @@ -477,7 +477,7 @@ gyp_options.extend(['-D', 'target_platform=%s' % target_platform_value]) if IsWindows(): - gyp_options.extend(['-G', 'msvs_version=2015']) + gyp_options.extend(['-G', 'msvs_version=2017']) if (target_platform == 'Linux' and '%s/unix/ibus/ibus.gyp' % SRC_DIR in gyp_file_names): diff --git a/src/build_tools/BUILD b/src/build_tools/BUILD index eb3dbb7..e839dad 100644 --- a/src/build_tools/BUILD +++ b/src/build_tools/BUILD @@ -102,12 +102,6 @@ ], ) -py_library_mozc( - name = "replace_version_lib", - srcs = ["replace_version.py"], - deps = [":mozc_version_lib"], -) - py_binary_mozc( name = "replace_version", srcs = ["replace_version.py"], @@ -131,12 +125,7 @@ name = "zlib_util", srcs = ["zlib_util.py"], visibility = ["//:__subpackages__"], - deps = [":zlib_util_main_lib"], -) - -py_library( - name = "zlib_util_main_lib", - srcs = ["zlib_util.py"], + deps = [":zlib_util_lib"], ) py_library_mozc( diff --git a/src/build_tools/build_breakpad.py b/src/build_tools/build_breakpad.py index 4561ad3..deb0b25 100644 --- a/src/build_tools/build_breakpad.py +++ b/src/build_tools/build_breakpad.py @@ -31,7 +31,7 @@ """Script building Breakpad for Mozc/Mac. ././tools/build_breakpad.py - --pbdir ./third_party/breakpad --outdir /tmp/breakpad + --bpdir ./third_party/breakpad --outdir /tmp/breakpad """ from __future__ import absolute_import @@ -46,9 +46,9 @@ def ParseOption(): parser = optparse.OptionParser() - parser.add_option('--pbdir', default='./third_party/breakpad') + parser.add_option('--bpdir', default='./third_party/breakpad') parser.add_option('--outdir', default='./out_mac/Release/Breakpad') - parser.add_option('--sdk', default='macosx10.14') + parser.add_option('--sdk', default='macosx10.15') parser.add_option('--deployment_target', default='10.9') (opts, _) = parser.parse_args() @@ -91,19 +91,19 @@ Xcodebuild(projdir, 'symupload', 'x86_64', sdk, deployment_target, outdir) -def CreateOutDir(pbdir, outdir): +def CreateOutDir(bpdir, outdir): workdir = os.path.join(outdir, 'src') if not os.path.isdir(workdir): os.makedirs(workdir) - ProcessCall(['rsync', '-avH', os.path.join(pbdir, 'src/'), workdir]) + ProcessCall(['rsync', '-avH', os.path.join(bpdir, 'src/'), workdir]) def main(): opts = ParseOption() - pbdir = os.path.abspath(opts.pbdir) + bpdir = os.path.abspath(opts.bpdir) outdir = os.path.abspath(opts.outdir) - CreateOutDir(pbdir, outdir) + CreateOutDir(bpdir, outdir) BuildBreakpad(outdir, opts.sdk, opts.deployment_target) BuildDumpSyms(outdir, opts.sdk, opts.deployment_target) BuildSymupload(outdir, opts.sdk, opts.deployment_target) diff --git a/src/build_tools/code_generator_util.py b/src/build_tools/code_generator_util.py index 7beeb0d..35d807c 100644 --- a/src/build_tools/code_generator_util.py +++ b/src/build_tools/code_generator_util.py @@ -114,7 +114,7 @@ for word_index in range(0, len(data), 8): word_chunk = data[word_index:word_index + 8].ljust(8, '\x00') stream.write('0x%016X, ' % struct.unpack(' #include +#include #include #include #include @@ -222,7 +223,7 @@ ConverterImpl::ConverterImpl() : pos_matcher_(nullptr), immutable_converter_(nullptr), - general_noun_id_(kuint16max) {} + general_noun_id_(std::numeric_limits::max()) {} ConverterImpl::~ConverterImpl() = default; diff --git a/src/converter/gen_quality_regression_test_data.py b/src/converter/gen_quality_regression_test_data.py index 84cda5c..722c9b6 100644 --- a/src/converter/gen_quality_regression_test_data.py +++ b/src/converter/gen_quality_regression_test_data.py @@ -105,21 +105,23 @@ def GenerateHeader(files): - try: - print('namespace mozc{') - print('struct TestCase {') - print(' const bool enabled;') - print(' const char *tsv;') - print('} kTestData[] = {') - for file in files: + print('namespace mozc{') + print('struct TestCase {') + print(' const bool enabled;') + print(' const char *tsv;') + print('} kTestData[] = {') + + for file in files: + try: for enabled, line in ParseFile(file): print(' {%s, "%s"},' % (enabled, EscapeString(line))) - print(' {false, nullptr},') - print('};') - print('} // namespace mozc') - except: - print('cannot open %s' % (file)) - sys.exit(1) + except: + print('cannot open %s' % file) + sys.exit(1) + + print(' {false, nullptr},') + print('};') + print('} // namespace mozc') def main(): diff --git a/src/converter/segments.cc b/src/converter/segments.cc index 7598a3f..3f9a2fb 100644 --- a/src/converter/segments.cc +++ b/src/converter/segments.cc @@ -30,6 +30,7 @@ #include "converter/segments.h" #include +#include #include // For DebugString() #include @@ -115,8 +116,10 @@ size_t content_key_len, size_t content_value_len, uint32 *result) { - if (key_len > kuint8max || value_len > kuint8max || - content_key_len > kuint8max || content_value_len > kuint8max) { + if (key_len > std::numeric_limits::max() || + value_len > std::numeric_limits::max() || + content_key_len > std::numeric_limits::max() || + content_value_len > std::numeric_limits::max()) { return false; } *result = (static_cast(key_len) << 24) | diff --git a/src/data/emoji/BUILD b/src/data/emoji/BUILD index d35dcac..e58956f 100644 --- a/src/data/emoji/BUILD +++ b/src/data/emoji/BUILD @@ -33,7 +33,7 @@ py_binary( name = "filter", srcs = ["filter.py"], - python_version = "PY2", + python_version = "PY3", visibility = [ ], deps = ["//build_tools:code_generator_util"], diff --git a/src/data/version/mozc_version_template.bzl b/src/data/version/mozc_version_template.bzl index 460e17a..d151584 100644 --- a/src/data/version/mozc_version_template.bzl +++ b/src/data/version/mozc_version_template.bzl @@ -31,7 +31,11 @@ MAJOR = 2 MINOR = 25 + +# Number to be increased. This value may be replaced by other tools. BUILD = 4100 + +# Represent the platform and release channel. REVISION = 100 # This version represents the version of Mozc IME engine (converter, predictor, diff --git a/src/data_manager/BUILD b/src/data_manager/BUILD index 22d668d..3f46e95 100644 --- a/src/data_manager/BUILD +++ b/src/data_manager/BUILD @@ -113,7 +113,7 @@ py_binary_mozc( name = "gen_connection_data", srcs = ["gen_connection_data.py"], - python_version = "PY2", + python_version = "PY3", deps = [ ":gen_connection_data_lib", "//build_tools:code_generator_util", diff --git a/src/data_manager/dataset_reader_test.cc b/src/data_manager/dataset_reader_test.cc index 067db7e..56aa0a7 100644 --- a/src/data_manager/dataset_reader_test.cc +++ b/src/data_manager/dataset_reader_test.cc @@ -29,6 +29,7 @@ #include "data_manager/dataset_reader.h" +#include #include #include @@ -111,7 +112,7 @@ // Metadata size is too large. data = magic; data.append("content and metadata"); - data.append(Util::SerializeUint64(kuint64max)); + data.append(Util::SerializeUint64(std::numeric_limits::max())); EXPECT_FALSE(DataSetReader::VerifyChecksum(data)); EXPECT_FALSE(r.Init(data, magic)); @@ -162,7 +163,7 @@ auto e = md.add_entries(); e->set_name("google"); e->set_offset(content.size()); - e->set_size(kuint64max); // Too big size + e->set_size(std::numeric_limits::max()); // Too big size const string &md_str = md.SerializeAsString(); string image = content; image.append(md_str); diff --git a/src/data_manager/gen_connection_data.py b/src/data_manager/gen_connection_data.py index 06d934a..1b61af3 100644 --- a/src/data_manager/gen_connection_data.py +++ b/src/data_manager/gen_connection_data.py @@ -223,7 +223,7 @@ if cost == INVALID_COST: cost = INVALID_1BYTE_COST else: - cost /= resolution + cost //= resolution assert cost != INVALID_1BYTE_COST values.append(cost) diff --git a/src/data_manager/oss/BUILD b/src/data_manager/oss/BUILD index 73c7ea9..7f31fd8 100644 --- a/src/data_manager/oss/BUILD +++ b/src/data_manager/oss/BUILD @@ -93,7 +93,7 @@ "//data/typing:typing_model_qwerty_mobile-hiragana.tsv", "//data/typing:typing_model_toggle_flick-hiragana.tsv", ], - usage_dict = "//third_party/japanese_usage_dictionary:usage_dict.txt", + usage_dict = "@ja_usage_dict//:usage_dict.txt", use_1byte_cost = "false", user_pos_def = "//data/rules:user_pos.def", variant_rule = "//data/single_kanji:variant_rule.txt", diff --git a/src/data_manager/testing/BUILD b/src/data_manager/testing/BUILD index 94ae85f..d24de8a 100644 --- a/src/data_manager/testing/BUILD +++ b/src/data_manager/testing/BUILD @@ -128,7 +128,7 @@ "//data/typing:typing_model_qwerty_mobile-hiragana.tsv", "//data/typing:typing_model_toggle_flick-hiragana.tsv", ], - usage_dict = "//third_party/japanese_usage_dictionary:usage_dict.txt", + usage_dict = "@ja_usage_dict//:usage_dict.txt", use_1byte_cost = "false", user_pos_def = "//data/rules:user_pos.def", variant_rule = "//data/single_kanji:variant_rule.txt", diff --git a/src/dictionary/BUILD b/src/dictionary/BUILD index 7d75705..f95a1cf 100644 --- a/src/dictionary/BUILD +++ b/src/dictionary/BUILD @@ -574,7 +574,7 @@ py_binary_mozc( name = "gen_user_pos_data", srcs = ["gen_user_pos_data.py"], - python_version = "PY2", + python_version = "PY3", visibility = ["//:__subpackages__"], deps = [ ":gen_user_pos_data_lib", @@ -633,7 +633,7 @@ py_binary_mozc( name = "gen_pos_rewrite_rule", srcs = ["gen_pos_rewrite_rule.py"], - python_version = "PY2", + python_version = "PY3", visibility = ["//:__subpackages__"], deps = [":gen_pos_rewrite_rule_lib"], ) @@ -732,7 +732,7 @@ py_binary_mozc( name = "gen_suffix_data", srcs = ["gen_suffix_data.py"], - python_version = "PY2", + python_version = "PY3", visibility = ["//:__subpackages__"], deps = [ ":gen_suffix_data_lib", diff --git a/src/dictionary/gen_pos_matcher_code.py b/src/dictionary/gen_pos_matcher_code.py index 0df48ee..8237765 100644 --- a/src/dictionary/gen_pos_matcher_code.py +++ b/src/dictionary/gen_pos_matcher_code.py @@ -226,7 +226,7 @@ pos_database.Parse(options.id_file, options.special_pos_file) pos_matcher = pos_util.PosMatcher(pos_database) pos_matcher.Parse(options.pos_matcher_rule_file) - with codecs.open(options.output_pos_matcher_data, 'wb') as stream: + with open(options.output_pos_matcher_data, 'wb') as stream: OutputPosMatcherData(pos_matcher, stream) diff --git a/src/dictionary/system/system_dictionary_test.cc b/src/dictionary/system/system_dictionary_test.cc index 26f9ce1..30c5ce8 100644 --- a/src/dictionary/system/system_dictionary_test.cc +++ b/src/dictionary/system/system_dictionary_test.cc @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -84,7 +85,8 @@ // Don't use small cost encoding by default. original_flags_min_key_length_to_use_small_cost_encoding_ = FLAGS_min_key_length_to_use_small_cost_encoding; - FLAGS_min_key_length_to_use_small_cost_encoding = kint32max; + FLAGS_min_key_length_to_use_small_cost_encoding = + std::numeric_limits::max(); request_.Clear(); config::ConfigHandler::GetDefaultConfig(&config_); diff --git a/src/gui/about_dialog/BUILD b/src/gui/about_dialog/BUILD index 3c80f42..6daac8b 100644 --- a/src/gui/about_dialog/BUILD +++ b/src/gui/about_dialog/BUILD @@ -59,6 +59,8 @@ "about_dialog_en.qm", "about_dialog_ja.qm", "//data/images:product_icon_32bpp-128.png", + "//gui/base:tr_en.qm", + "//gui/base:tr_ja.qm", ], outs = ["qrc_about_dialog.cc"], qrc_file = "about_dialog.qrc", diff --git a/src/gui/about_dialog/about_dialog.cc b/src/gui/about_dialog/about_dialog.cc index 3b2e0b5..f95288f 100644 --- a/src/gui/about_dialog/about_dialog.cc +++ b/src/gui/about_dialog/about_dialog.cc @@ -39,6 +39,7 @@ #include "base/system_util.h" #include "base/util.h" #include "base/version.h" +#include "gui/base/util.h" namespace mozc { namespace gui { @@ -57,7 +58,7 @@ std::string tmp; const std::string file_path = FileUtil::JoinPath(SystemUtil::GetDocumentDirectory(), filenames[i]); - Util::StringReplace(*str, filenames[i], file_path, false, &tmp); + mozc::Util::StringReplace(*str, filenames[i], file_path, false, &tmp); *str = tmp; return true; } @@ -74,7 +75,8 @@ } // namespace -AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent), callback_(NULL) { +AboutDialog::AboutDialog(QWidget *parent) + : QDialog(parent), callback_(nullptr) { setupUi(this); setWindowFlags(Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint); setWindowModality(Qt::NonModal); @@ -86,6 +88,10 @@ version_info += Version::GetMozcVersion().c_str(); version_info += ")"; version_label->setText(version_info); + gui::Util::ReplaceTitle(this); + gui::Util::ReplaceLabel(label); + gui::Util::ReplaceLabel(label_credits); + gui::Util::ReplaceLabel(label_terms); QPalette palette; palette.setColor(QPalette::Window, QColor(236, 233, 216)); @@ -130,7 +136,7 @@ if (!RunLevel::IsValidClientRunLevel()) { return; } - if (callback_ != NULL) { + if (callback_ != nullptr) { callback_->linkActivated(link); } else { defaultLinkActivated(link); diff --git a/src/gui/about_dialog/about_dialog.qrc b/src/gui/about_dialog/about_dialog.qrc index 1af5bcc..9ddbe04 100644 --- a/src/gui/about_dialog/about_dialog.qrc +++ b/src/gui/about_dialog/about_dialog.qrc @@ -2,6 +2,8 @@ about_dialog_ja.qm about_dialog_en.qm + ../base/tr_ja.qm + ../base/tr_en.qm ../../data/images/product_icon_32bpp-128.png diff --git a/src/gui/about_dialog/about_dialog.ui b/src/gui/about_dialog/about_dialog.ui index 1580987..1732a92 100644 --- a/src/gui/about_dialog/about_dialog.ui +++ b/src/gui/about_dialog/about_dialog.ui @@ -59,7 +59,7 @@ - About Mozc + About [ProductName] @@ -95,7 +95,7 @@ 20 10 471 - 81 + 82 @@ -122,7 +122,7 @@ - <html><body>Mozc is made possible by <a href="file://credits_en.html"><span style=" text-decoration: underline; color:#0000ff;">open source software</span></a>.</body></html> + <html><body>[ProductName] is made possible by <a href="file://credits_en.html"><span style=" text-decoration: underline; color:#0000ff;">open source software</span></a>.</body></html> @@ -160,7 +160,7 @@ - <html><body>Mozc <a href="https://github.com/google/mozc"><span style=" text-decoration: underline; color:#0000ff;">product information</span></a> <a href="https://github.com/google/mozc/issues"><span style=" text-decoration: underline; color:#0000ff;">issues</span></a></body></html> + <html><body>[ProductName] <a href="https://github.com/google/mozc"><span style=" text-decoration: underline; color:#0000ff;">product information</span></a> <a href="https://github.com/google/mozc/issues"><span style=" text-decoration: underline; color:#0000ff;">issues</span></a></body></html> @@ -201,7 +201,7 @@ - Mozc + [ProductName] Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter diff --git a/src/gui/about_dialog/about_dialog_en.qtts b/src/gui/about_dialog/about_dialog_en.qtts index 6724d4a..acfad14 100644 --- a/src/gui/about_dialog/about_dialog_en.qtts +++ b/src/gui/about_dialog/about_dialog_en.qtts @@ -5,7 +5,7 @@ AboutDialog - About Mozc + About [ProductName] @@ -15,22 +15,22 @@ - Copyright © 2019 Google Inc. All rights reserved. + Copyright © 2020 Google Inc. All rights reserved. - <html><body>Mozc is made possible by <a href="file://credits_en.html"><span style=" text-decoration: underline; color:#0000ff;">open source software</span></a>.</body></html> + <html><body>[ProductName] is made possible by <a href="file://credits_en.html"><span style=" text-decoration: underline; color:#0000ff;">open source software</span></a>.</body></html> - <html><body>Mozc <a href="https://github.com/google/mozc"><span style=" text-decoration: underline; color:#0000ff;">product information</span></a> <a href="https://github.com/google/mozc/issues"><span style=" text-decoration: underline; color:#0000ff;">issues</span></a></body></html> + <html><body>[ProductName] <a href="https://github.com/google/mozc"><span style=" text-decoration: underline; color:#0000ff;">product information</span></a> <a href="https://github.com/google/mozc/issues"><span style=" text-decoration: underline; color:#0000ff;">issues</span></a></body></html> - Mozc + [ProductName] diff --git a/src/gui/about_dialog/about_dialog_ja.qm b/src/gui/about_dialog/about_dialog_ja.qm index 5df7e81..0505a32 100644 Binary files a/src/gui/about_dialog/about_dialog_ja.qm and b/src/gui/about_dialog/about_dialog_ja.qm differ diff --git a/src/gui/about_dialog/about_dialog_ja.qtts b/src/gui/about_dialog/about_dialog_ja.qtts index 98bfa4d..65fe742 100644 --- a/src/gui/about_dialog/about_dialog_ja.qtts +++ b/src/gui/about_dialog/about_dialog_ja.qtts @@ -5,8 +5,8 @@ AboutDialog - About Mozc - Mozcについて + About [ProductName] + [ProductName] について @@ -15,18 +15,18 @@ - Copyright © 2019 Google Inc. All rights reserved. + Copyright © 2020 Google Inc. All rights reserved. - <html><body>Mozc is made possible by <a href="file://credits_en.html"><span style=" text-decoration: underline; color:#0000ff;">open source software</span></a>.</body></html> - <html><body>Mozcは<a href="file://credits_en.html"><span style=" text-decoration: underline; color:#0000ff;">オープンソースソフトウェア</span></a>を利用しています。</body></html> + <html><body>[ProductName] is made possible by <a href="file://credits_en.html"><span style=" text-decoration: underline; color:#0000ff;">open source software</span></a>.</body></html> + <html><body>[ProductName] は<a href="file://credits_en.html"><span style=" text-decoration: underline; color:#0000ff;">オープンソースソフトウェア</span></a>を利用しています。</body></html> - <html><body>Mozc <a href="https://github.com/google/mozc"><span style=" text-decoration: underline; color:#0000ff;">product information</span></a> <a href="https://github.com/google/mozc/issues"><span style=" text-decoration: underline; color:#0000ff;">issues</span></a></body></html> - <html><body>Mozc <a href="https://github.com/google/mozc"><span style=" text-decoration: underline; color:#0000ff;">製品情報</span></a> <a href="https://github.com/google/mozc/issues"><span style=" text-decoration: underline; color:#0000ff;">issues</span></a></body></html> + <html><body>[ProductName] <a href="https://github.com/google/mozc"><span style=" text-decoration: underline; color:#0000ff;">product information</span></a> <a href="https://github.com/google/mozc/issues"><span style=" text-decoration: underline; color:#0000ff;">issues</span></a></body></html> + <html><body> [ProductName] <a href="https://github.com/google/mozc"><span style=" text-decoration: underline; color:#0000ff;">製品情報</span></a> <a href="https://github.com/google/mozc/issues"><span style=" text-decoration: underline; color:#0000ff;">issues</span></a></body></html> <html><body>Google <a href="file://privacy_en.html"><span style=" text-decoration: underline; color:#0000ff;">privacy policy</span></a></body></html> @@ -34,8 +34,8 @@ - Mozc - Mozc + [ProductName] + [ProductName] diff --git a/src/gui/about_dialog/about_dialog_libmain.cc b/src/gui/about_dialog/about_dialog_libmain.cc index 41ea3e6..56f5b84 100644 --- a/src/gui/about_dialog/about_dialog_libmain.cc +++ b/src/gui/about_dialog/about_dialog_libmain.cc @@ -50,6 +50,7 @@ } mozc::gui::LocaleUtil::InstallTranslationMessageAndFont("about_dialog"); + mozc::gui::LocaleUtil::InstallTranslationMessageAndFont("tr"); mozc::gui::AboutDialog about_dialog; about_dialog.show(); diff --git a/src/gui/base/BUILD b/src/gui/base/BUILD index 81b9d65..77bb801 100644 --- a/src/gui/base/BUILD +++ b/src/gui/base/BUILD @@ -62,6 +62,11 @@ srcs = ["window_title_modifier.h"], outs = ["moc_window_title_modifier.cc"], ) + +exports_files([ + "tr_en.qm", + "tr_ja.qm", +]) qt_rcc_mozc( name = "qrc_tr", diff --git a/src/gui/base/locale_util.cc b/src/gui/base/locale_util.cc index 43abeeb..0f7ac2e 100644 --- a/src/gui/base/locale_util.cc +++ b/src/gui/base/locale_util.cc @@ -50,11 +50,10 @@ #include #include +#include #include #include "base/logging.h" -#include "base/singleton.h" -#include "base/util.h" #ifdef MOZC_SHOW_BUILD_NUMBER_ON_TITLE #include "gui/base/window_title_modifier.h" @@ -64,75 +63,58 @@ namespace gui { namespace { -// sicnce Qtranslator and QFont must be available until -// application exits, allocate the data with Singleton. -class TranslationDataImpl { - public: - void InstallTranslationMessageAndFont(const char *resource_name); +void InstallEventFilter() { +#ifdef MOZC_SHOW_BUILD_NUMBER_ON_TITLE + static WindowTitleModifier window_title_modifier; + // Install WindowTilteModifier for official dev channel + // append a special footer (Dev x.x.x) to the all Windows. + qApp->installEventFilter(&window_title_modifier); +#endif // MOZC_SHOW_BUILD_NUMBER_ON_TITLE +} - TranslationDataImpl(); - ~TranslationDataImpl() { - for (std::map::iterator it = translators_.begin(); - it != translators_.end(); ++it) { - delete it->second; - } - translators_.clear(); - } - - private: - std::map translators_; - QTranslator default_translator_; - QFont font_; -#ifdef MOZC_SHOW_BUILD_NUMBER_ON_TITLE - WindowTitleModifier window_title_modifier_; -#endif // MOZC_SHOW_BUILD_NUMBER_ON_TITLE -}; - -TranslationDataImpl::TranslationDataImpl() { +void InstallDefaultTranslator() { // qApplication must be loaded first CHECK(qApp); - -#ifdef MOZC_SHOW_BUILD_NUMBER_ON_TITLE - // Install WindowTilteModifier for official dev channel - // append a special footer (Dev x.x.x) to the all Windows. - qApp->installEventFilter(&window_title_modifier_); -#endif // MOZC_SHOW_BUILD_NUMBER_ON_TITLE + static QTranslator translator; // Load "/qt_.qm" from a qrc file. - bool loaded = default_translator_.load( + bool loaded = translator.load( QLocale::system(), "qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath), ".qm"); if (!loaded) { // Load ":/qt_.qm" from a qrc file. - loaded = - default_translator_.load(QLocale::system(), "qt", "_", ":/", ".qm"); + loaded = translator.load(QLocale::system(), "qt", "_", ":/", ".qm"); } if (loaded) { - qApp->installTranslator(&default_translator_); + qApp->installTranslator(&translator); } } -void TranslationDataImpl::InstallTranslationMessageAndFont( - const char *resource_name) { - if (translators_.find(resource_name) != translators_.end()) { +void InstallTranslator(const char *resource_name) { + static std::map> translators; + if (translators.find(resource_name) != translators.end()) { return; } - QTranslator *translator = new QTranslator; - CHECK(translator); - translators_.insert(std::make_pair(resource_name, translator)); + std::unique_ptr translator(new QTranslator); // Load ":/_.qm" from a qrc file. if (translator->load(QLocale::system(), resource_name, "_", ":/", ".qm")) { - qApp->installTranslator(translator); + qApp->installTranslator(translator.get()); + translators.emplace(resource_name, std::move(translator)); } } } // namespace void LocaleUtil::InstallTranslationMessageAndFont(const char *resource_name) { - Singleton::get()->InstallTranslationMessageAndFont( - resource_name); + static bool called = false; + if (!called) { + called = true; + InstallEventFilter(); + InstallDefaultTranslator(); + } + InstallTranslator(resource_name); } } // namespace gui } // namespace mozc diff --git a/src/gui/base/msime_user_dictionary_importer.cc b/src/gui/base/msime_user_dictionary_importer.cc index 05abe0f..36cb9dc 100644 --- a/src/gui/base/msime_user_dictionary_importer.cc +++ b/src/gui/base/msime_user_dictionary_importer.cc @@ -73,7 +73,6 @@ #include #include -#include "base/compiler_specific.h" #include "base/hash.h" #include "base/logging.h" #include "base/mmap.h" @@ -130,7 +129,7 @@ explicit ScopedIFEDictionary(IFEDictionary *dic) : dic_(dic) {} ~ScopedIFEDictionary() { - if (dic_ != NULL) { + if (dic_ != nullptr) { dic_->Close(); dic_->Release(); } @@ -154,22 +153,22 @@ result_(E_FAIL), size_(0), index_(0) { - if (dic_.get() == NULL) { - LOG(ERROR) << "IFEDictionaryFactory returned NULL"; + if (dic_.get() == nullptr) { + LOG(ERROR) << "IFEDictionaryFactory returned nullptr"; return; } // open user dictionary - HRESULT result = dic_->Open(NULL, NULL); + HRESULT result = dic_->Open(nullptr, nullptr); if (S_OK != result) { LOG(ERROR) << "Cannot open user dictionary: " << result_; return; } - POSTBL *pos_table = NULL; + POSTBL *pos_table = nullptr; int pos_size = 0; result_ = dic_->GetPosTable(&pos_table, &pos_size); - if (S_OK != result_ || pos_table == NULL || pos_size == 0) { + if (S_OK != result_ || pos_table == nullptr || pos_size == 0) { LOG(ERROR) << "Cannot get POS table: " << result; result_ = E_FAIL; return; @@ -187,10 +186,11 @@ // Don't use auto-registered words, since Mozc may not be able to // handle auto_registered words correctly, and user is basically // unaware of auto-registered words. - result_ = dic_->GetWords(NULL, NULL, NULL, IFED_POS_ALL, IFED_SELECT_ALL, - IFED_REG_USER, // | FED_REG_AUTO - reinterpret_cast(&buf_[0]), - kBufferSize * sizeof(IMEWRD), &size_); + result_ = + dic_->GetWords(nullptr, nullptr, nullptr, IFED_POS_ALL, IFED_SELECT_ALL, + IFED_REG_USER, // | FED_REG_AUTO + reinterpret_cast(&buf_[0]), + kBufferSize * sizeof(IMEWRD), &size_); } bool IsAvailable() const { @@ -205,17 +205,17 @@ return false; } - if (entry == NULL) { - LOG(ERROR) << "Entry is NULL"; + if (entry == nullptr) { + LOG(ERROR) << "Entry is nullptr"; return false; } entry->Clear(); if (index_ < size_) { - if (buf_[index_].pwchReading == NULL || - buf_[index_].pwchDisplay == NULL) { + if (buf_[index_].pwchReading == nullptr || + buf_[index_].pwchDisplay == nullptr) { ++index_; - LOG(ERROR) << "pwchDisplay or pwchReading is NULL"; + LOG(ERROR) << "pwchDisplay or pwchReading is nullptr"; return true; } @@ -235,7 +235,7 @@ entry->pos = it->second; // set comment - if (buf_[index_].pvComment != NULL) { + if (buf_[index_].pvComment != nullptr) { if (buf_[index_].uct == IFED_UCT_STRING_SJIS) { EncodingUtil::SJISToUTF8( reinterpret_cast(buf_[index_].pvComment), diff --git a/src/gui/base/setup_util.cc b/src/gui/base/setup_util.cc index 0117109..e48a324 100644 --- a/src/gui/base/setup_util.cc +++ b/src/gui/base/setup_util.cc @@ -128,8 +128,8 @@ UserDictionaryStorage::UserDictionary *dic = storage_->GetUserDictionary(dic_id); - if (dic == NULL) { - LOG(ERROR) << "GetUserDictionary returned NULL"; + if (dic == nullptr) { + LOG(ERROR) << "GetUserDictionary returned nullptr"; return false; } diff --git a/src/gui/base/singleton_window_helper.cc b/src/gui/base/singleton_window_helper.cc index e906d51..960face 100644 --- a/src/gui/base/singleton_window_helper.cc +++ b/src/gui/base/singleton_window_helper.cc @@ -60,13 +60,13 @@ mozc::ScopedHandle handle( ::CreateFileW(wfilename.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - NULL, OPEN_EXISTING, 0, NULL)); - if (NULL == handle.get()) { + nullptr, OPEN_EXISTING, 0, nullptr)); + if (nullptr == handle.get()) { LOG(ERROR) << "cannot open: " << lock_name << " " << ::GetLastError(); return false; } - const DWORD size = ::GetFileSize(handle.get(), NULL); + const DWORD size = ::GetFileSize(handle.get(), nullptr); if (-1 == static_cast(size)) { LOG(ERROR) << "GetFileSize failed:" << ::GetLastError(); return false; @@ -81,7 +81,7 @@ std::unique_ptr buf(new char[size]); DWORD read_size = 0; - if (!::ReadFile(handle.get(), buf.get(), size, &read_size, NULL)) { + if (!::ReadFile(handle.get(), buf.get(), size, &read_size, nullptr)) { LOG(ERROR) << "ReadFile failed: " << ::GetLastError(); return false; } diff --git a/src/gui/base/table_util.cc b/src/gui/base/table_util.cc index 4b0f892..2119c0f 100644 --- a/src/gui/base/table_util.cc +++ b/src/gui/base/table_util.cc @@ -36,12 +36,12 @@ QString TableUtil::SafeGetItemText(const QTableWidget *table_widget, int row, int column) { - if (table_widget == NULL) { + if (table_widget == nullptr) { return QString(); } - // If |row| and/or |column| is out of range, we will get NULL anyway. + // If |row| and/or |column| is out of range, we will get nullptr anyway. const QTableWidgetItem *item = table_widget->item(row, column); - if (item == NULL) { + if (item == nullptr) { return QString(); } return item->text(); diff --git a/src/gui/base/util.cc b/src/gui/base/util.cc index c9ab388..6aabe68 100644 --- a/src/gui/base/util.cc +++ b/src/gui/base/util.cc @@ -53,6 +53,7 @@ #ifdef __APPLE__ app->setFont(QFont("Hiragino Sans")); #endif // __APPLE__ + return app; } @@ -66,5 +67,21 @@ return name; } +// static +void Util::ReplaceLabel(QLabel *label) { + label->setText(ReplaceString(label->text())); +} + +// static +void Util::ReplaceTitle(QWidget *widget) { + widget->setWindowTitle(Util::ReplaceString(widget->windowTitle())); +} + +// static +QString Util::ReplaceString(const QString &str) { + QString replaced(str); + return replaced.replace("[ProductName]", Util::ProductName()); +} + } // namespace gui } // namespace mozc diff --git a/src/gui/base/util.h b/src/gui/base/util.h index f5b9216..e461082 100644 --- a/src/gui/base/util.h +++ b/src/gui/base/util.h @@ -32,6 +32,7 @@ #include #include +#include #include namespace mozc { @@ -45,6 +46,15 @@ // Returns the product name. static const QString ProductName(); + // Replace placeholders in the label. + static void ReplaceLabel(QLabel *label); + + // Replace placeholders in the widget. + static void ReplaceTitle(QWidget *widget); + + // Replace placeholders in the string. + static QString ReplaceString(const QString &str); + private: Util() = delete; virtual ~Util() = delete; diff --git a/src/gui/base/win_util.cc b/src/gui/base/win_util.cc index 745f797..097c3d5 100644 --- a/src/gui/base/win_util.cc +++ b/src/gui/base/win_util.cc @@ -66,7 +66,7 @@ hr = link.CoCreateInstance(CLSID_ShellLink); if (FAILED(hr)) { DLOG(INFO) << "Failed to instantiate CLSID_ShellLink. hr = " << hr; - return NULL; + return nullptr; } { @@ -75,7 +75,7 @@ hr = link->SetPath(mozc_tool_path_wide.c_str()); if (FAILED(hr)) { DLOG(ERROR) << "SetPath failed. hr = " << hr; - return NULL; + return nullptr; } } @@ -85,14 +85,14 @@ hr = link->SetArguments(argument_wide.c_str()); if (FAILED(hr)) { DLOG(ERROR) << "SetArguments failed. hr = " << hr; - return NULL; + return nullptr; } } CComQIPtr property_store(link); - if (property_store == NULL) { + if (property_store == nullptr) { DLOG(ERROR) << "QueryInterface failed."; - return NULL; + return nullptr; } { @@ -102,7 +102,7 @@ hr = ::InitPropVariantFromString(item_title_wide.c_str(), &prop_variant); if (FAILED(hr)) { DLOG(ERROR) << "QueryInterface failed. hr = " << hr; - return NULL; + return nullptr; } hr = property_store->SetValue(PKEY_Title, prop_variant); ::PropVariantClear(&prop_variant); @@ -110,13 +110,13 @@ if (FAILED(hr)) { DLOG(ERROR) << "SetValue failed. hr = " << hr; - return NULL; + return nullptr; } hr = property_store->Commit(); if (FAILED(hr)) { DLOG(ERROR) << "Commit failed. hr = " << hr; - return NULL; + return nullptr; } return link; @@ -161,13 +161,13 @@ link = InitializeShellLinkItem(kLinks[i].argument, kLinks[i].title_english); } - if (link != NULL) { + if (link != nullptr) { object_collection->AddObject(link); } } CComQIPtr object_array(object_collection); - if (object_array == NULL) { + if (object_array == nullptr) { DLOG(ERROR) << "QueryInterface failed."; return false; } @@ -304,7 +304,7 @@ wchar_t data[4] = {}; ULONG num_chars = arraysize(data); result = key.QueryStringValue(kIMEHotKeyEntryValue, data, &num_chars); - // Returned |num_char| includes NULL character. + // Returned |num_char| includes nullptr character. // This is only the condition when this function // can return |true| @@ -363,8 +363,8 @@ #ifdef OS_WIN HRESULT hr = S_OK; - hr = - ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); + hr = ::CoInitializeEx(nullptr, + COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); if (FAILED(hr)) { DLOG(INFO) << "CoInitializeEx failed. hr = " << hr; return; diff --git a/src/gui/base/window_title_modifier.cc b/src/gui/base/window_title_modifier.cc index fae6f6d..48f92a7 100644 --- a/src/gui/base/window_title_modifier.cc +++ b/src/gui/base/window_title_modifier.cc @@ -40,19 +40,21 @@ namespace gui { bool WindowTitleModifier::eventFilter(QObject *obj, QEvent *event) { QWidget *w = QApplication::activeWindow(); - if (w != NULL && obj != NULL && w == obj && - QEvent::WindowActivate == event->type() && - w->windowTitle().indexOf(prefix_) == -1) { - w->setWindowTitle(w->windowTitle() + prefix_ + - Version::GetMozcVersion().c_str() + suffix_); + if (w == nullptr || obj != w || event->type() != QEvent::WindowActivate) { + return QObject::eventFilter(obj, event); + } + + const QString prefix = " (Dev "; + const QString& title = w->windowTitle(); + // The window title can be empty, even if it is specified. + // See: https://doc.qt.io/qt-5/qmessagebox.html#setWindowTitle + if (!title.isEmpty() && title.indexOf(prefix) == -1) { + const QString version = prefix + Version::GetMozcVersion().c_str() + ")"; + w->setWindowTitle(title + version); } return QObject::eventFilter(obj, event); } -WindowTitleModifier::WindowTitleModifier() : prefix_(" (Dev "), suffix_(")") {} - -WindowTitleModifier::~WindowTitleModifier() {} - } // namespace gui } // namespace mozc diff --git a/src/gui/base/window_title_modifier.h b/src/gui/base/window_title_modifier.h index 994c7b1..379c186 100644 --- a/src/gui/base/window_title_modifier.h +++ b/src/gui/base/window_title_modifier.h @@ -40,15 +40,11 @@ Q_OBJECT; public: - WindowTitleModifier(); - ~WindowTitleModifier(); + WindowTitleModifier() = default; + ~WindowTitleModifier() override = default; protected: bool eventFilter(QObject *obj, QEvent *event); - - private: - const QString prefix_; - const QString suffix_; }; } // namespace gui } // namespace mozc diff --git a/src/gui/config_dialog/character_form_editor.h b/src/gui/config_dialog/character_form_editor.h index c0ea0aa..7572e3b 100644 --- a/src/gui/config_dialog/character_form_editor.h +++ b/src/gui/config_dialog/character_form_editor.h @@ -49,7 +49,7 @@ class CharacterFormEditor : public QTableWidget { Q_OBJECT public: - explicit CharacterFormEditor(QWidget *parent = NULL); + explicit CharacterFormEditor(QWidget *parent = nullptr); virtual ~CharacterFormEditor(); void Load(const config::Config &config); diff --git a/src/gui/config_dialog/combobox_delegate.cc b/src/gui/config_dialog/combobox_delegate.cc index 2581952..4a751fd 100644 --- a/src/gui/config_dialog/combobox_delegate.cc +++ b/src/gui/config_dialog/combobox_delegate.cc @@ -59,7 +59,7 @@ const QModelIndex &index) const { QString str = index.model()->data(index, Qt::EditRole).toString(); QComboBox *comboBox = static_cast(editor); - if (comboBox == NULL) { + if (comboBox == nullptr) { return; } comboBox->setCurrentIndex(comboBox->findText(str)); @@ -68,7 +68,7 @@ void ComboBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { QComboBox *comboBox = static_cast(editor); - if (comboBox == NULL || model == NULL) { + if (comboBox == nullptr || model == nullptr) { return; } model->setData(index, comboBox->currentText(), Qt::EditRole); @@ -77,7 +77,7 @@ void ComboBoxDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const { - if (editor == NULL) { + if (editor == nullptr) { return; } editor->setGeometry(option.rect); diff --git a/src/gui/config_dialog/combobox_delegate.h b/src/gui/config_dialog/combobox_delegate.h index 7408a9a..1ee8e35 100644 --- a/src/gui/config_dialog/combobox_delegate.h +++ b/src/gui/config_dialog/combobox_delegate.h @@ -44,7 +44,7 @@ class ComboBoxDelegate : public QItemDelegate { Q_OBJECT public: - explicit ComboBoxDelegate(QObject *parent = NULL); + explicit ComboBoxDelegate(QObject *parent = nullptr); virtual ~ComboBoxDelegate(); void SetItemList(const QStringList &item_list); diff --git a/src/gui/config_dialog/config_dialog.cc b/src/gui/config_dialog/config_dialog.cc index 8b409a2..4c50014 100644 --- a/src/gui/config_dialog/config_dialog.cc +++ b/src/gui/config_dialog/config_dialog.cc @@ -754,7 +754,7 @@ keymap::KeyMapManager::GetKeyMapFileName(itr->second); std::unique_ptr ifs( ConfigFileStream::LegacyOpen(keymap_file)); - CHECK(ifs.get() != NULL); // should never happen + CHECK(ifs.get() != nullptr); // should never happen std::stringstream buffer; buffer << ifs->rdbuf(); current_keymap_table = buffer.str(); diff --git a/src/gui/config_dialog/generic_table_editor.cc b/src/gui/config_dialog/generic_table_editor.cc index d97a696..20c4458 100644 --- a/src/gui/config_dialog/generic_table_editor.cc +++ b/src/gui/config_dialog/generic_table_editor.cc @@ -153,12 +153,12 @@ // Choose next or prev item. QTableWidgetItem *item = editorTableWidget->item(rows.back() + 1, column); - if (item == NULL) { + if (item == nullptr) { item = editorTableWidget->item(rows.back() - 1, column); } // select item - if (item != NULL) { + if (item != nullptr) { editorTableWidget->setCurrentItem(item); } @@ -188,7 +188,7 @@ editorTableWidget->setItem(row, i, new QTableWidgetItem("")); } QTableWidgetItem *item = editorTableWidget->item(row, 0); - if (item != NULL) { + if (item != nullptr) { editorTableWidget->setCurrentItem(item); editorTableWidget->scrollToItem(item, QAbstractItemView::PositionAtCenter); editorTableWidget->editItem(item); @@ -209,7 +209,7 @@ void GenericTableEditorDialog::InsertItem() { QTableWidgetItem *current = editorTableWidget->currentItem(); - if (current == NULL) { + if (current == nullptr) { QMessageBox::warning(this, windowTitle(), tr("No entry is selected")); return; } @@ -297,12 +297,12 @@ void GenericTableEditorDialog::OnContextMenuRequested(const QPoint &pos) { QTableWidgetItem *item = editorTableWidget->itemAt(pos); - if (item == NULL) { + if (item == nullptr) { return; } QMenu *menu = new QMenu(this); - QAction *edit_action = NULL; + QAction *edit_action = nullptr; const QList selected_items = editorTableWidget->selectedItems(); if (selected_items.count() == 1) { @@ -312,7 +312,7 @@ QAction *delete_action = menu->addAction(tr("Remove entry")); QAction *selected_action = menu->exec(QCursor::pos()); - if (edit_action != NULL && selected_action == edit_action) { + if (edit_action != nullptr && selected_action == edit_action) { editorTableWidget->editItem(selected_items[0]); } else if (selected_action == rename_action) { AddNewItem(); @@ -323,7 +323,7 @@ void GenericTableEditorDialog::UpdateOKButton(bool status) { QPushButton *button = editorButtonBox->button(QDialogButtonBox::Ok); - if (button != NULL) { + if (button != nullptr) { button->setEnabled(status); } } diff --git a/src/gui/config_dialog/keybinding_editor.cc b/src/gui/config_dialog/keybinding_editor.cc index 35aeef8..9bf1401 100644 --- a/src/gui/config_dialog/keybinding_editor.cc +++ b/src/gui/config_dialog/keybinding_editor.cc @@ -488,7 +488,7 @@ QPushButton *ok_button = KeyBindingEditorbuttonBox->button(QDialogButtonBox::Ok); - CHECK(ok_button != NULL); + CHECK(ok_button != nullptr); filter_.reset(new KeyBindingFilter(KeyBindingLineEdit, ok_button)); KeyBindingLineEdit->installEventFilter(filter_.get()); diff --git a/src/gui/config_dialog/keybinding_editor_delegate.cc b/src/gui/config_dialog/keybinding_editor_delegate.cc index bba7be9..257c9ed 100644 --- a/src/gui/config_dialog/keybinding_editor_delegate.cc +++ b/src/gui/config_dialog/keybinding_editor_delegate.cc @@ -78,7 +78,7 @@ const QString str = index.model()->data(index, Qt::EditRole).toString(); KeyBindingEditorTriggerButton *button = static_cast(editor); - if (button == NULL) { + if (button == nullptr) { return; } button->setText(str); @@ -90,7 +90,7 @@ const QModelIndex &index) const { KeyBindingEditorTriggerButton *button = static_cast(editor); - if (model == NULL || button == NULL) { + if (model == nullptr || button == nullptr) { return; } model->setData(index, button->mutable_editor()->GetBinding(), Qt::EditRole); @@ -99,7 +99,7 @@ void KeyBindingEditorDelegate::updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const { - if (editor == NULL) { + if (editor == nullptr) { return; } editor->setGeometry(option.rect); @@ -110,7 +110,7 @@ KeyBindingEditorTriggerButton *button = static_cast( editor->mutable_trigger_parent()); - if (button == NULL) { + if (button == nullptr) { return; } emit commitData(button); @@ -122,7 +122,7 @@ KeyBindingEditorTriggerButton *button = static_cast( editor->mutable_trigger_parent()); - if (button == NULL) { + if (button == nullptr) { return; } emit closeEditor(button); diff --git a/src/gui/config_dialog/keybinding_editor_delegate.h b/src/gui/config_dialog/keybinding_editor_delegate.h index 28093d8..ba3963d 100644 --- a/src/gui/config_dialog/keybinding_editor_delegate.h +++ b/src/gui/config_dialog/keybinding_editor_delegate.h @@ -42,7 +42,7 @@ class KeyBindingEditorDelegate : public QItemDelegate { Q_OBJECT public: - explicit KeyBindingEditorDelegate(QObject *parent = NULL); + explicit KeyBindingEditorDelegate(QObject *parent = nullptr); virtual ~KeyBindingEditorDelegate(); QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, diff --git a/src/gui/config_dialog/keymap_editor.cc b/src/gui/config_dialog/keymap_editor.cc index 50eb971..865b0d6 100644 --- a/src/gui/config_dialog/keymap_editor.cc +++ b/src/gui/config_dialog/keymap_editor.cc @@ -318,7 +318,7 @@ KeyMapEditorDialog::~KeyMapEditorDialog() {} bool KeyMapEditorDialog::LoadFromStream(std::istream *is) { - if (is == NULL) { + if (is == nullptr) { return false; } @@ -499,7 +499,7 @@ keymap::KeyMapManager::GetKeyMapFileName(kKeyMaps[import_index]); std::unique_ptr ifs( ConfigFileStream::LegacyOpen(keymap_file)); - CHECK(ifs.get() != NULL); // should never happen + CHECK(ifs.get() != nullptr); // should never happen CHECK(LoadFromStream(ifs.get())); } } else if (action == actions_[EXPORT_TO_FILE_INDEX]) { diff --git a/src/gui/config_dialog/keymap_en.qm b/src/gui/config_dialog/keymap_en.qm index 6526406..09b80de 100644 Binary files a/src/gui/config_dialog/keymap_en.qm and b/src/gui/config_dialog/keymap_en.qm differ diff --git a/src/gui/config_dialog/roman_table_editor.cc b/src/gui/config_dialog/roman_table_editor.cc index 1207d8f..035ad6c 100644 --- a/src/gui/config_dialog/roman_table_editor.cc +++ b/src/gui/config_dialog/roman_table_editor.cc @@ -91,7 +91,7 @@ std::string RomanTableEditorDialog::GetDefaultRomanTable() { std::unique_ptr ifs( ConfigFileStream::LegacyOpen(kRomanTableFile)); - CHECK(ifs.get() != NULL); // should never happen + CHECK(ifs.get() != nullptr); // should never happen std::string line, result; std::vector fields; while (getline(*ifs.get(), line)) { @@ -171,7 +171,7 @@ bool RomanTableEditorDialog::LoadDefaultRomanTable() { std::unique_ptr ifs( ConfigFileStream::LegacyOpen(kRomanTableFile)); - CHECK(ifs.get() != NULL); // should never happen + CHECK(ifs.get() != nullptr); // should never happen CHECK(LoadFromStream(ifs.get())); return true; } diff --git a/src/gui/confirmation_dialog/confirmation_dialog.cc b/src/gui/confirmation_dialog/confirmation_dialog.cc index 23b5f98..3da442e 100644 --- a/src/gui/confirmation_dialog/confirmation_dialog.cc +++ b/src/gui/confirmation_dialog/confirmation_dialog.cc @@ -49,7 +49,7 @@ // Message QObject::tr("Invalid confirmation dialog. " "You specified less arguments."), - QMessageBox::Yes | QMessageBox::No, NULL, + QMessageBox::Yes | QMessageBox::No, nullptr, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowStaysOnTopHint); if (FLAGS_confirmation_type == "update") { @@ -59,11 +59,11 @@ "(Note: some features will not be available " "until you log out and log back in.)")); QAbstractButton *yes_button = message_box.button(QMessageBox::Yes); - if (yes_button != NULL) { + if (yes_button != nullptr) { yes_button->setText(QObject::tr("Activate now")); } QAbstractButton *no_button = message_box.button(QMessageBox::No); - if (no_button != NULL) { + if (no_button != nullptr) { no_button->setText(QObject::tr("Wait until logout")); } } else if (FLAGS_confirmation_type == "log_out") { @@ -71,11 +71,11 @@ QObject::tr("Mozc has been updated. " "Please log out and back in to enable the new version.")); QAbstractButton *yes_button = message_box.button(QMessageBox::Yes); - if (yes_button != NULL) { + if (yes_button != nullptr) { yes_button->setText(QObject::tr("Log out")); } QAbstractButton *no_button = message_box.button(QMessageBox::No); - if (no_button != NULL) { + if (no_button != nullptr) { no_button->setText(QObject::tr("Remind me in 1 hour")); } } diff --git a/src/gui/dictionary_tool/dictionary_content_table_widget.cc b/src/gui/dictionary_tool/dictionary_content_table_widget.cc index a7c8002..55d4216 100644 --- a/src/gui/dictionary_tool/dictionary_content_table_widget.cc +++ b/src/gui/dictionary_tool/dictionary_content_table_widget.cc @@ -53,7 +53,7 @@ alternate_index = 1; } else { QTableWidgetItem *last_item = item(rowCount() - 1, 0); - if (last_item == NULL) { + if (last_item == nullptr) { return; } rect = visualItemRect(last_item); @@ -78,7 +78,7 @@ // When empty area is double-clicked, emit a signal #ifdef __APPLE__ - if (NULL == itemAt(event->pos())) { + if (nullptr == itemAt(event->pos())) { emit emptyAreaClicked(); } #endif // __APPLE__ diff --git a/src/gui/dictionary_tool/dictionary_tool.cc b/src/gui/dictionary_tool/dictionary_tool.cc index 5f81c44..4a47a90 100644 --- a/src/gui/dictionary_tool/dictionary_tool.cc +++ b/src/gui/dictionary_tool/dictionary_tool.cc @@ -64,6 +64,7 @@ #include "dictionary/user_dictionary_util.h" #include "gui/base/encoding_util.h" #include "gui/base/msime_user_dictionary_importer.h" +#include "gui/base/util.h" #include "gui/config_dialog/combobox_delegate.h" #include "gui/dictionary_tool/find_dialog.h" #include "gui/dictionary_tool/import_dialog.h" @@ -232,10 +233,10 @@ // strip UTF8 BOM if (first_line_ && encoding_type_ == UserDictionaryImporter::UTF8) { - Util::StripUTF8BOM(line); - } - - Util::ChopReturns(line); + mozc::Util::StripUTF8BOM(line); + } + + mozc::Util::ChopReturns(line); first_line_ = false; return true; @@ -287,32 +288,32 @@ parent); break; default: - return NULL; - } - - return NULL; + return nullptr; + } + + return nullptr; } } // namespace DictionaryTool::DictionaryTool(QWidget *parent) : QMainWindow(parent), - import_dialog_(NULL), - find_dialog_(NULL), + import_dialog_(nullptr), + find_dialog_(nullptr), session_(new UserDictionarySession( UserDictionaryUtil::GetUserDictionaryFileName())), current_dic_id_(0), modified_(false), monitoring_user_edit_(false), - window_title_(tr("Mozc")), + window_title_(gui::Util::ProductName()), dic_menu_(new QMenu), - new_action_(NULL), - rename_action_(NULL), - delete_action_(NULL), - find_action_(NULL), - import_create_action_(NULL), - import_append_action_(NULL), - export_action_(NULL), - import_default_ime_action_(NULL), + new_action_(nullptr), + rename_action_(nullptr), + delete_action_(nullptr), + find_action_(nullptr), + import_create_action_(nullptr), + import_append_action_(nullptr), + export_action_(nullptr), + import_default_ime_action_(nullptr), client_(client::ClientFactory::NewClient()), is_available_(true), max_entry_size_(mozc::UserDictionaryStorage::max_entry_size()), @@ -581,7 +582,7 @@ SyncToStorage(); DictionaryInfo dic_info = current_dictionary(); - if (dic_info.item == NULL) { + if (dic_info.item == nullptr) { current_dic_id_ = 0; StopMonitoringUserEdit(); dic_content_->clearContents(); @@ -605,7 +606,7 @@ UserDictionary *dic = session_->mutable_storage()->GetUserDictionary(dic_info.id); - if (dic == NULL) { + if (dic == nullptr) { LOG(ERROR) << "Failed to load the dictionary: " << dic_info.id; ReportError(); return; @@ -681,7 +682,7 @@ void DictionaryTool::DeleteDictionary() { DictionaryInfo dic_info = current_dictionary(); - if (dic_info.item == NULL) { + if (dic_info.item == nullptr) { QMessageBox::information(this, window_title_, tr("No dictionary is selected.")); return; @@ -710,7 +711,7 @@ void DictionaryTool::RenameDictionary() { DictionaryInfo dic_info = current_dictionary(); - if (dic_info.item == NULL) { + if (dic_info.item == nullptr) { QMessageBox::information(this, window_title_, tr("No dictionary is selected.")); return; @@ -758,7 +759,7 @@ void DictionaryTool::ImportAndAppendDictionary() { DictionaryInfo dic_info = current_dictionary(); - if (dic_info.item == NULL) { + if (dic_info.item == nullptr) { LOG(WARNING) << "No dictionary to import is selected"; QMessageBox::information(this, window_title_, tr("No dictionary is selected.")); @@ -799,7 +800,7 @@ "unsupported file format.\n\n" "Please check the file format. " "ATOK11 or older format is not supported by " - "Mozc.")); + "%1.").arg(gui::Util::ProductName())); break; case UserDictionaryImporter::IMPORT_TOO_MANY_WORDS: QMessageBox::information( @@ -849,7 +850,7 @@ UserDictionary *dic = session_->mutable_storage()->GetUserDictionary(dic_id); - if (dic == NULL) { + if (dic == nullptr) { LOG(ERROR) << "Cannot find dictionary id: " << dic_id; ReportError(); return; @@ -867,8 +868,8 @@ // Open dictionary std::unique_ptr iter( CreateTextLineIterator(encoding_type, file_name, this)); - if (iter.get() == NULL) { - LOG(ERROR) << "CreateTextLineIterator returns NULL"; + if (iter == nullptr) { + LOG(ERROR) << "CreateTextLineIterator returns nullptr"; return; } @@ -906,7 +907,7 @@ } DictionaryInfo dic_info = current_dictionary(); - if (dic_info.item == NULL) { + if (dic_info.item == nullptr) { LOG(WARNING) << "No dictionary to import is selected"; QMessageBox::information(this, window_title_, tr("No dictionary is selected.")); @@ -955,7 +956,7 @@ void DictionaryTool::ExportDictionary() { DictionaryInfo dic_info = current_dictionary(); - if (dic_info.item == NULL) { + if (dic_info.item == nullptr) { LOG(WARNING) << "No dictionary to export is selected"; QMessageBox::information(this, window_title_, tr("No dictionary is selected.")); @@ -1040,7 +1041,7 @@ QList selected_dicts = dic_list_->selectedItems(); if (selected_dicts.isEmpty()) { LOG(WARNING) << "No current dictionary."; - return NULL; + return nullptr; } if (selected_dicts.size() > 1) { LOG(WARNING) << "Multiple items are selected."; @@ -1111,10 +1112,10 @@ } void DictionaryTool::MoveTo(int dictionary_row) { - UserDictionary *target_dict = NULL; + UserDictionary *target_dict = nullptr; { const QListWidgetItem *selected_dict = GetFirstSelectedDictionary(); - if (selected_dict == NULL) { + if (selected_dict == nullptr) { return; } QListWidgetItem *target_dict_item = dic_list_->item(dictionary_row); @@ -1250,7 +1251,7 @@ QTableWidgetItem *item = dic_content_->itemAt(pos); // When the mouse pointer is not on an item of the table widget, we // don't show context menu. - if (item == NULL) { + if (item == nullptr) { return; } @@ -1280,7 +1281,7 @@ change_dictionary_actions.reserve(dic_list_->count() - 1); { const QListWidgetItem *selected_dict = GetFirstSelectedDictionary(); - if (selected_dict != NULL) { + if (selected_dict != nullptr) { for (size_t i = 0; i < dic_list_->count(); ++i) { QListWidgetItem *item = dic_list_->item(i); DCHECK(item); @@ -1338,7 +1339,7 @@ void DictionaryTool::OnContextMenuRequestedForList(const QPoint &pos) { QListWidgetItem *item = dic_list_->itemAt(pos); - if (item == NULL) { + if (item == nullptr) { return; } @@ -1350,22 +1351,22 @@ QAction *export_action = menu->addAction(tr("Export this dictionary...")); QAction *selected_action = menu->exec(QCursor::pos()); - if ((rename_action != NULL) && (selected_action == rename_action)) { + if ((rename_action != nullptr) && (selected_action == rename_action)) { RenameDictionary(); - } else if ((delete_action != NULL) && (selected_action == delete_action)) { + } else if ((delete_action != nullptr) && (selected_action == delete_action)) { DeleteDictionary(); - } else if ((import_action != NULL) && (selected_action == import_action)) { + } else if ((import_action != nullptr) && (selected_action == import_action)) { ImportAndAppendDictionary(); - } else if ((export_action != NULL) && (selected_action == export_action)) { + } else if ((export_action != nullptr) && (selected_action == export_action)) { ExportDictionary(); } } DictionaryTool::DictionaryInfo DictionaryTool::current_dictionary() const { - DictionaryInfo retval = {-1, 0, NULL}; + DictionaryInfo retval = {-1, 0, nullptr}; QListWidgetItem *selected_dict = GetFirstSelectedDictionary(); - if (selected_dict == NULL) { + if (selected_dict == nullptr) { return retval; } @@ -1383,7 +1384,7 @@ UserDictionary *dic = session_->mutable_storage()->GetUserDictionary(current_dic_id_); - if (dic == NULL) { + if (dic == nullptr) { LOG(ERROR) << "No save dictionary: " << current_dic_id_; return; } @@ -1575,7 +1576,7 @@ delete_word_button_->setEnabled(dic_content_->rowCount() > 0); const DictionaryInfo dic_info = current_dictionary(); - if (dic_info.item != NULL) { + if (dic_info.item != nullptr) { statusbar_message_ = QString(tr("%1: %2 entries")) .arg(dic_info.item->text()) .arg(dic_content_->rowCount()); diff --git a/src/gui/dictionary_tool/dictionary_tool.h b/src/gui/dictionary_tool/dictionary_tool.h index 145c786..80b03cc 100644 --- a/src/gui/dictionary_tool/dictionary_tool.h +++ b/src/gui/dictionary_tool/dictionary_tool.h @@ -176,7 +176,7 @@ void GetSortedSelectedRows(std::vector *rows) const; // Returns a pointer to the first selected dictionary. - // Returns NULL if no dictionary is selected. + // Returns nullptr if no dictionary is selected. QListWidgetItem *GetFirstSelectedDictionary() const; ImportDialog *import_dialog_; diff --git a/src/gui/dictionary_tool/dictionary_tool_en.qm b/src/gui/dictionary_tool/dictionary_tool_en.qm index d2d5ea4..a556a4e 100644 Binary files a/src/gui/dictionary_tool/dictionary_tool_en.qm and b/src/gui/dictionary_tool/dictionary_tool_en.qm differ diff --git a/src/gui/dictionary_tool/dictionary_tool_en.qtts b/src/gui/dictionary_tool/dictionary_tool_en.qtts index ca94a99..f5e27d3 100644 --- a/src/gui/dictionary_tool/dictionary_tool_en.qtts +++ b/src/gui/dictionary_tool/dictionary_tool_en.qtts @@ -286,7 +286,7 @@ You have imported a file in an invalid or unsupported file format. -Please check the file format. ATOK11 or older format is not supported by Mozc. +Please check the file format. ATOK11 or older format is not supported by %1. diff --git a/src/gui/dictionary_tool/dictionary_tool_ja.qm b/src/gui/dictionary_tool/dictionary_tool_ja.qm index e994ebc..851c74c 100644 Binary files a/src/gui/dictionary_tool/dictionary_tool_ja.qm and b/src/gui/dictionary_tool/dictionary_tool_ja.qm differ diff --git a/src/gui/dictionary_tool/dictionary_tool_ja.qtts b/src/gui/dictionary_tool/dictionary_tool_ja.qtts index 0d454ac..fb5787a 100644 --- a/src/gui/dictionary_tool/dictionary_tool_ja.qtts +++ b/src/gui/dictionary_tool/dictionary_tool_ja.qtts @@ -199,8 +199,8 @@ You have imported a file in an invalid or unsupported file format. -Please check the file format. ATOK11 or older format is not supported by Mozc. - 指定されたファイルは Mozcでサポートされていないフォーマットで保存されています。 +Please check the file format. ATOK11 or older format is not supported by %1. + 指定されたファイルは %1 でサポートされていないフォーマットで保存されています。 インポート対象のファイルフォーマットを確認してください。 diff --git a/src/gui/dictionary_tool/find_dialog.cc b/src/gui/dictionary_tool/find_dialog.cc index 1fe33a2..aa0f2cb 100644 --- a/src/gui/dictionary_tool/find_dialog.cc +++ b/src/gui/dictionary_tool/find_dialog.cc @@ -45,7 +45,7 @@ FindDialog::FindDialog(QWidget *parent, QTableWidget *table) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint), table_(table), - last_item_(NULL) { + last_item_(nullptr) { setupUi(this); setModal(false); @@ -67,13 +67,13 @@ QuerylineEdit->selectAll(); } FindForwardpushButton->setDefault(true); - last_item_ = NULL; + last_item_ = nullptr; UpdateUIStatus(); } void FindDialog::closeEvent(QCloseEvent *event) { table_->setStyleSheet(""); - last_item_ = NULL; + last_item_ = nullptr; } void FindDialog::UpdateUIStatus() { @@ -83,7 +83,7 @@ } bool FindDialog::Match(const QString &query, int row, int column) { - if (last_item_ != NULL && last_item_ == table_->item(row, column)) { + if (last_item_ != nullptr && last_item_ == table_->item(row, column)) { return false; } const QString &value = table_->item(row, column)->text(); @@ -146,7 +146,7 @@ table_->setCurrentItem(item); table_->scrollToItem(item); } else { - last_item_ = NULL; + last_item_ = nullptr; QMessageBox::information(this, this->windowTitle(), tr("Cannot find pattern %1").arg(query)); } diff --git a/src/gui/dictionary_tool/import_dialog.cc b/src/gui/dictionary_tool/import_dialog.cc index 2b55599..cee8556 100644 --- a/src/gui/dictionary_tool/import_dialog.cc +++ b/src/gui/dictionary_tool/import_dialog.cc @@ -83,7 +83,7 @@ static_cast(UserDictionaryImporter::UTF8)); QPushButton *button = buttonbox_->button(QDialogButtonBox::Ok); - if (button != NULL) { + if (button != nullptr) { button->setText(tr("Import")); } @@ -142,7 +142,7 @@ void ImportDialog::OnFormValueChanged() { QPushButton *button = buttonbox_->button(QDialogButtonBox::Ok); - if (button != NULL) { + if (button != nullptr) { button->setEnabled(IsAcceptButtonEnabled()); } } diff --git a/src/gui/error_message_dialog/error_message_dialog.cc b/src/gui/error_message_dialog/error_message_dialog.cc index 57667f2..42cd450 100644 --- a/src/gui/error_message_dialog/error_message_dialog.cc +++ b/src/gui/error_message_dialog/error_message_dialog.cc @@ -47,7 +47,7 @@ // to set WindowStaysOnTopHint QMessageBox message_box( QMessageBox::Critical, QObject::tr("Mozc Fatal Error"), - message, QMessageBox::Ok, NULL, + message, QMessageBox::Ok, nullptr, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowStaysOnTopHint); DeleyedMessageDialogHandler handler(&message_box); handler.Exec(); @@ -64,7 +64,7 @@ const int kDisableInterval = 3000; QTimer::singleShot(kDisableInterval, this, SLOT(EnableOkButton())); QAbstractButton *button = message_box_->button(QMessageBox::Ok); - if (button != NULL) { + if (button != nullptr) { button->setEnabled(false); } message_box_->exec(); @@ -72,7 +72,7 @@ void DeleyedMessageDialogHandler::EnableOkButton() { QAbstractButton *button = message_box_->button(QMessageBox::Ok); - if (button != NULL) { + if (button != nullptr) { button->setEnabled(true); } } diff --git a/src/gui/tool/BUILD b/src/gui/tool/BUILD index af7875e..8fec6e2 100644 --- a/src/gui/tool/BUILD +++ b/src/gui/tool/BUILD @@ -89,6 +89,7 @@ cc_qt_binary_mozc( name = "mozc_tool", srcs = ["mozc_tool_main.cc"], + visibility = ["//:__pkg__"], deps = [ ":mozc_tool_lib", "//base:init_mozc", diff --git a/src/gui/word_register_dialog/word_register_dialog.cc b/src/gui/word_register_dialog/word_register_dialog.cc index cb559b6..6e8e3ae 100644 --- a/src/gui/word_register_dialog/word_register_dialog.cc +++ b/src/gui/word_register_dialog/word_register_dialog.cc @@ -76,7 +76,8 @@ #if defined(OS_WIN) std::wstring wenvname; mozc::Util::UTF8ToWide(envname, &wenvname); - const DWORD buffer_size = ::GetEnvironmentVariable(wenvname.c_str(), NULL, 0); + const DWORD buffer_size = + ::GetEnvironmentVariable(wenvname.c_str(), nullptr, 0); if (buffer_size == 0) { return ""; } @@ -226,7 +227,7 @@ QAbstractButton *button = WordRegisterDialogbuttonBox->button(QDialogButtonBox::Ok); - if (button != NULL) { + if (button != nullptr) { button->setEnabled(enabled); } } @@ -407,7 +408,7 @@ // Get default value from Clipboard void WordRegisterDialog::SetDefaultEntryFromClipboard() { - if (QApplication::clipboard() == NULL) { + if (QApplication::clipboard() == nullptr) { return; } CopyCurrentSelectionToClipboard(); @@ -419,12 +420,13 @@ void WordRegisterDialog::CopyCurrentSelectionToClipboard() { #ifdef OS_WIN const HWND foreground_window = ::GetForegroundWindow(); - if (foreground_window == NULL) { + if (foreground_window == nullptr) { LOG(ERROR) << "GetForegroundWindow() failed: " << ::GetLastError(); return; } - const DWORD thread_id = ::GetWindowThreadProcessId(foreground_window, NULL); + const DWORD thread_id = + ::GetWindowThreadProcessId(foreground_window, nullptr); if (!::AttachThreadInput(::GetCurrentThreadId(), thread_id, TRUE)) { LOG(ERROR) << "AttachThreadInput failed: " << ::GetLastError(); @@ -435,7 +437,7 @@ ::AttachThreadInput(::GetCurrentThreadId(), thread_id, FALSE); - if (focus_window == NULL || !::IsWindow(focus_window)) { + if (focus_window == nullptr || !::IsWindow(focus_window)) { LOG(WARNING) << "No focus window"; return; } @@ -478,7 +480,7 @@ #ifdef OS_WIN // TODO(taku): implement it for other platform. HIMC himc = ::ImmGetContext(reinterpret_cast(winId())); - if (himc != NULL) { + if (himc != nullptr) { ::ImmSetOpenStatus(himc, TRUE); } #endif // OS_WIN diff --git a/src/gyp/common.gypi b/src/gyp/common.gypi index 4e78489..3d4de4c 100644 --- a/src/gyp/common.gypi +++ b/src/gyp/common.gypi @@ -46,7 +46,7 @@ 'compiler_host_version_int%': '0', # (major_ver) * 100 + (minor_ver) # Versioning stuff for Mac. - 'mac_sdk%': '10.14', + 'mac_sdk%': '10.15', 'mac_deployment_target%': '10.9', # Flag to specify if the build target is for simulator or not. diff --git a/src/gyp/common_win.gypi b/src/gyp/common_win.gypi index 1fad807..eb4e97a 100644 --- a/src/gyp/common_win.gypi +++ b/src/gyp/common_win.gypi @@ -54,6 +54,12 @@ 'compiler_host': 'msvs', 'compiler_host_version_int': 1900, # Visual C++ 2015 or higher }], + ['MSVS_VERSION=="2017"', { + 'compiler_target': 'msvs', + 'compiler_target_version_int': 1910, # Visual C++ 2017 or higher + 'compiler_host': 'msvs', + 'compiler_host_version_int': 1910, # Visual C++ 2017 or higher + }], ], 'msvc_disabled_warnings': [ # 'expression' : signed/unsigned mismatch diff --git a/src/net/http_client.cc b/src/net/http_client.cc index 1ab4f36..a45c99a 100644 --- a/src/net/http_client.cc +++ b/src/net/http_client.cc @@ -40,7 +40,6 @@ #endif // GOOGLE_JAPANESE_INPUT_BUILD -#include "base/compiler_specific.h" #include "base/logging.h" #include "base/port.h" #include "base/singleton.h" diff --git a/src/net/json_util_test.cc b/src/net/json_util_test.cc index 3bd1f7c..8d7db39 100644 --- a/src/net/json_util_test.cc +++ b/src/net/json_util_test.cc @@ -29,6 +29,7 @@ #include "net/json_util.h" +#include #include #include @@ -247,7 +248,7 @@ EXPECT_PROTO_EQ(msg, new_msg); } -TEST(JsonUtilTest, ConvertItemTest){ +TEST(JsonUtilTest, ConvertItemTest) { #define TEST_CONVERT_ITEM(proto_setter, proto_value, json_name, json_value) \ { \ TestMsg msg; \ @@ -263,313 +264,164 @@ FillRequiredFields(&msg); \ EXPECT_PROTO_EQ(msg, new_msg); \ } - TEST_CONVERT_ITEM( - set_double_value, - 1.0, "double_value", 1.0) TEST_CONVERT_ITEM(set_float_value, 2.0, - "float_value", 2.0) TEST_CONVERT_ITEM(set_int32_value, - 3, - "int32_value", Json::Int(3)) TEST_CONVERT_ITEM(set_int32_value, - -3, - "int32_value", Json::Int(-3)) TEST_CONVERT_ITEM(set_int32_value, - kint32min, - "int32_value", Json::Int(kint32min)) TEST_CONVERT_ITEM(set_int32_value, - kint32max, - "int32_value", - Json::Int( - kint32max)) TEST_CONVERT_ITEM(set_int64_value, - 4, - "int64_value", - "4") TEST_CONVERT_ITEM(set_int64_value, - -4, - "int64_value", - "-4") TEST_CONVERT_ITEM(set_int64_value, - kint64min, - "int64_value", - "-9223372036854775808") TEST_CONVERT_ITEM(set_int64_value, - kint64max, - "int64_value", - "9223372036854775807") TEST_CONVERT_ITEM(set_uint32_value, - 5, - "uint32_value", - Json::UInt( - 5)) TEST_CONVERT_ITEM(set_uint32_value, - kuint32max, - "uint32_value", - Json:: - UInt( - kuint32max)) TEST_CONVERT_ITEM(set_uint64_value, - 6, - "uint64_value", - "6") TEST_CONVERT_ITEM(set_uint64_value, - kuint64max, - "uint64_value", - "18446744073709551615") TEST_CONVERT_ITEM(set_sint32_value, - 7, - "sint32_value", - Json::Int(7)) TEST_CONVERT_ITEM(set_sint32_value, - -7, - "sint32_value", Json::Int(-7)) TEST_CONVERT_ITEM(set_sint32_value, - kint32min, - "sint32_value", - Json::Int( - kint32min)) TEST_CONVERT_ITEM(set_sint32_value, - kint32max, - "sint32_value", - Json:: - Int(kint32max)) TEST_CONVERT_ITEM(set_sint64_value, - 8, - "sint64_value", - "8") TEST_CONVERT_ITEM(set_sint64_value, - -8, - "sint64_value", - "-8") TEST_CONVERT_ITEM(set_sint64_value, - kint64min, - "sint64_value", - "-9223372036854775808") TEST_CONVERT_ITEM(set_sint64_value, - kint64max, - "sint64_value", - "9223372036854775807") TEST_CONVERT_ITEM(set_fixed32_value, - 9, - "fixed32_value", Json::UInt(9)) TEST_CONVERT_ITEM(set_fixed32_value, - kuint32max, - "fixed32_value", - Json:: - UInt(kuint32max)) TEST_CONVERT_ITEM(set_fixed64_value, - 10, - "fixed64_value", - "10") TEST_CONVERT_ITEM(set_fixed64_value, - kuint64max, - "fixed64_value", - "18446744073709551615") TEST_CONVERT_ITEM(set_sfixed32_value, - 11, - "sfixed32_value", - Json::Int( - 11)) TEST_CONVERT_ITEM(set_sfixed32_value, - -11, - "sfixed32_value", - Json:: - Int(-11)) TEST_CONVERT_ITEM(set_sfixed32_value, - kint32min, - "sfixed32_value", - Json:: - Int(kint32min)) TEST_CONVERT_ITEM(set_sfixed32_value, - kint32max, - "sfixed32_value", - Json::Int(kint32max)) TEST_CONVERT_ITEM(set_sfixed64_value, - 12, - "sfixed64_value", - "12") TEST_CONVERT_ITEM(set_sfixed64_value, - -12, - "sfixed64_value", - "-12") TEST_CONVERT_ITEM(set_sfixed64_value, - kint64min, - "sfixed64_value", - "-9223372036854775808") TEST_CONVERT_ITEM(set_sfixed64_value, - kint64max, - "sfixed64_value", - "9223372036854775807") TEST_CONVERT_ITEM(set_bool_value, - true, - "bool_value", - true) TEST_CONVERT_ITEM(set_bool_value, - false, - "bool_value", false) TEST_CONVERT_ITEM(set_string_value, - "string", - "string_value", - "string") TEST_CONVERT_ITEM(set_bytes_value, - "bytes", - "bytes_value", - "bytes") TEST_CONVERT_ITEM(set_enum_value, - ENUM_A, - "enum_value", - "ENUM_A") TEST_CONVERT_ITEM(set_innerenum_value, TestMsg::ENUM_1, - "innerenum_value", - "ENUM_1") - - TEST_CONVERT_ITEM(set_required_double_value, - 1.0, "required_double_value", 1.0) TEST_CONVERT_ITEM(set_required_float_value, - 2.0, - "required_float_value", - 2.0) - TEST_CONVERT_ITEM(set_required_int32_value, - 3, "required_int32_value", Json::Int(3)) TEST_CONVERT_ITEM(set_required_int32_value, - -3, - "required_int32_value", - Json::Int( - -3)) - TEST_CONVERT_ITEM( - set_required_int32_value, - kint32min, "required_int32_value", Json::Int(kint32min)) - TEST_CONVERT_ITEM( - set_required_int32_value, - kint32max, "required_int32_value", Json::Int(kint32max)) - TEST_CONVERT_ITEM( - set_required_int64_value, - 4, "required_int64_value", - "4") TEST_CONVERT_ITEM(set_required_int64_value, -4, - "required_int64_value", - "-4") - TEST_CONVERT_ITEM( - set_required_int64_value, - kint64min, - "required_int64_value", - "-9223372036854775808") - TEST_CONVERT_ITEM( - set_required_int64_value, - kint64max, - "required_int64_value", - "9223372036854775807") - TEST_CONVERT_ITEM(set_required_uint32_value, - 5, "required_uint32_value", - Json:: - UInt(5)) TEST_CONVERT_ITEM(set_required_uint32_value, - kuint32max, - "required_uint32_value", - Json:: - UInt( - kuint32max)) - TEST_CONVERT_ITEM( - set_required_uint64_value, - 6, "required_uint64_value", - "6") TEST_CONVERT_ITEM(set_required_uint64_value, - kuint64max, - "required_" - "uint64_" - "value", - "18446744073" - "709551615") - TEST_CONVERT_ITEM( - set_required_sint32_value, 7, - "required_sint32_value", - Json::Int(7)) - TEST_CONVERT_ITEM(set_required_sint32_value, - -7, - "required_" - "sint32_" - "value", - Json::Int(-7)) - TEST_CONVERT_ITEM(set_required_sint32_value, - kint32min, - "required" - "_sint32_" - "value", - Json::Int( - kint32min)) - TEST_CONVERT_ITEM( - set_required_sint32_value, - kint32max, - "required_sint32_" - "value", - Json::Int( - kint32max)) - TEST_CONVERT_ITEM( - set_required_sint64_value, - 8, - "required_" - "sint64_value", - "8") - TEST_CONVERT_ITEM( - set_required_sint64_value, - -8, - "required_" - "sint64_" - "value", - "-8") - TEST_CONVERT_ITEM( - set_required_sint64_value, - kint64min, - "requir" - "ed_" - "sint64" - "_valu" - "e", - "-92233" - "720368" - "547758" - "08") TEST_CONVERT_ITEM(set_required_sint64_value, - kint64max, - "required_sint64_value", - "9223372036854775807") TEST_CONVERT_ITEM(set_required_fixed32_value, - 9, - "required_fixed32_value", Json::UInt(9)) TEST_CONVERT_ITEM(set_required_fixed32_value, kuint32max, - "required_fixed32_value", - Json::UInt(kuint32max)) TEST_CONVERT_ITEM(set_required_fixed64_value, - 10, - "required_fixed64_value", - "10") TEST_CONVERT_ITEM(set_required_fixed64_value, kuint64max, - "required_fixed64_value", - "18446744073709551615") TEST_CONVERT_ITEM(set_required_sfixed32_value, - 11, - "required_sfixed32_value", Json::Int(11)) - TEST_CONVERT_ITEM( - set_required_sfixed32_value, - -11, - "re" - "qu" - "ir" - "ed" - "_s" - "fi" - "xe" - "d3" - "2_" - "va" - "lu" - "e", - Json::Int( - -11)) - TEST_CONVERT_ITEM( - set_required_sfixed32_value, - kint32min, - "required_sfixed32_value", - Json::Int( - kint32min)) - TEST_CONVERT_ITEM(set_required_sfixed32_value, - kint32max, - "required_sfixed32_value", - Json::Int(kint32max)) TEST_CONVERT_ITEM(set_required_sfixed64_value, - 12, - "required_sfixed64_value", - "12") TEST_CONVERT_ITEM(set_required_sfixed64_value, - -12, - "required_sfixed64_value", - "-12") TEST_CONVERT_ITEM(set_required_sfixed64_value, - kint64min, - "required_sfixed64_value", - "-9223372036854775808") TEST_CONVERT_ITEM(set_required_sfixed64_value, - kint64max, - "required_sfixed64_value", - "9223372036854775807") TEST_CONVERT_ITEM(set_required_bool_value, - true, - "required_bool_value", - true) TEST_CONVERT_ITEM(set_required_bool_value, - false, - "required_bool_value", - false) - TEST_CONVERT_ITEM( - set_required_string_value, - "string", - "required_string_value", - "string") - TEST_CONVERT_ITEM( - set_required_bytes_value, - "bytes", - "required_bytes_value", - "bytes") - TEST_CONVERT_ITEM( - set_required_enum_value, - ENUM_A, - "required_enum_value", - "ENUM_A") - TEST_CONVERT_ITEM( - set_required_innerenum_value, - TestMsg:: - ENUM_1, - "required_innerenum_value", - "ENUM_1") + TEST_CONVERT_ITEM(set_double_value, 1.0, "double_value", 1.0); + TEST_CONVERT_ITEM(set_float_value, 2.0, "float_value", 2.0); + TEST_CONVERT_ITEM(set_int32_value, 3, "int32_value", Json::Int(3)); + TEST_CONVERT_ITEM(set_int32_value, -3, "int32_value", Json::Int(-3)); + TEST_CONVERT_ITEM(set_int32_value, std::numeric_limits::min(), + "int32_value", + Json::Int(std::numeric_limits::min())); + TEST_CONVERT_ITEM(set_int32_value, std::numeric_limits::max(), + "int32_value", + Json::Int(std::numeric_limits::max())); + TEST_CONVERT_ITEM(set_int64_value, 4, "int64_value", "4"); + TEST_CONVERT_ITEM(set_int64_value, -4, "int64_value", "-4"); + TEST_CONVERT_ITEM(set_int64_value, std::numeric_limits::min(), + "int64_value", "-9223372036854775808"); + TEST_CONVERT_ITEM(set_int64_value, std::numeric_limits::max(), + "int64_value", "9223372036854775807"); + TEST_CONVERT_ITEM(set_uint32_value, 5, "uint32_value", Json::UInt(5)); + TEST_CONVERT_ITEM(set_uint32_value, std::numeric_limits::max(), + "uint32_value", + Json::UInt(std::numeric_limits::max())); + TEST_CONVERT_ITEM(set_uint64_value, 6, "uint64_value", "6"); + TEST_CONVERT_ITEM(set_uint64_value, std::numeric_limits::max(), + "uint64_value", "18446744073709551615"); + TEST_CONVERT_ITEM(set_sint32_value, 7, "sint32_value", Json::Int(7)); + TEST_CONVERT_ITEM(set_sint32_value, -7, "sint32_value", Json::Int(-7)); + TEST_CONVERT_ITEM(set_sint32_value, std::numeric_limits::min(), + "sint32_value", + Json::Int(std::numeric_limits::min())); + TEST_CONVERT_ITEM(set_sint32_value, std::numeric_limits::max(), + "sint32_value", + Json::Int(std::numeric_limits::max())); + TEST_CONVERT_ITEM(set_sint64_value, 8, "sint64_value", "8"); + TEST_CONVERT_ITEM(set_sint64_value, -8, "sint64_value", "-8"); + TEST_CONVERT_ITEM(set_sint64_value, std::numeric_limits::min(), + "sint64_value", "-9223372036854775808"); + TEST_CONVERT_ITEM(set_sint64_value, std::numeric_limits::max(), + "sint64_value", "9223372036854775807"); + TEST_CONVERT_ITEM(set_fixed32_value, 9, "fixed32_value", Json::UInt(9)); + TEST_CONVERT_ITEM(set_fixed32_value, std::numeric_limits::max(), + "fixed32_value", + Json::UInt(std::numeric_limits::max())); + TEST_CONVERT_ITEM(set_fixed64_value, 10, "fixed64_value", "10"); + TEST_CONVERT_ITEM(set_fixed64_value, std::numeric_limits::max(), + "fixed64_value", "18446744073709551615"); + TEST_CONVERT_ITEM(set_sfixed32_value, 11, "sfixed32_value", Json::Int(11)); + TEST_CONVERT_ITEM(set_sfixed32_value, -11, "sfixed32_value", Json::Int(-11)); + TEST_CONVERT_ITEM(set_sfixed32_value, std::numeric_limits::min(), + "sfixed32_value", + Json::Int(std::numeric_limits::min())); + TEST_CONVERT_ITEM(set_sfixed32_value, std::numeric_limits::max(), + "sfixed32_value", + Json::Int(std::numeric_limits::max())); + TEST_CONVERT_ITEM(set_sfixed64_value, 12, "sfixed64_value", "12"); + TEST_CONVERT_ITEM(set_sfixed64_value, -12, "sfixed64_value", "-12"); + TEST_CONVERT_ITEM(set_sfixed64_value, std::numeric_limits::min(), + "sfixed64_value", "-9223372036854775808"); + TEST_CONVERT_ITEM(set_sfixed64_value, std::numeric_limits::max(), + "sfixed64_value", "9223372036854775807"); + TEST_CONVERT_ITEM(set_bool_value, true, "bool_value", true); + TEST_CONVERT_ITEM(set_bool_value, false, "bool_value", false); + TEST_CONVERT_ITEM(set_string_value, "string", "string_value", "string"); + TEST_CONVERT_ITEM(set_bytes_value, "bytes", "bytes_value", "bytes"); + TEST_CONVERT_ITEM(set_enum_value, ENUM_A, "enum_value", "ENUM_A"); + TEST_CONVERT_ITEM(set_innerenum_value, TestMsg::ENUM_1, "innerenum_value", + "ENUM_1"); + + TEST_CONVERT_ITEM(set_required_double_value, 1.0, "required_double_value", + 1.0); + TEST_CONVERT_ITEM(set_required_float_value, 2.0, "required_float_value", 2.0); + TEST_CONVERT_ITEM(set_required_int32_value, 3, "required_int32_value", + Json::Int(3)); + TEST_CONVERT_ITEM(set_required_int32_value, -3, "required_int32_value", + Json::Int(-3)); + TEST_CONVERT_ITEM(set_required_int32_value, std::numeric_limits::min(), + "required_int32_value", + Json::Int(std::numeric_limits::min())); + TEST_CONVERT_ITEM(set_required_int32_value, std::numeric_limits::max(), + "required_int32_value", + Json::Int(std::numeric_limits::max())); + TEST_CONVERT_ITEM(set_required_int64_value, 4, "required_int64_value", "4"); + TEST_CONVERT_ITEM(set_required_int64_value, -4, "required_int64_value", "-4"); + TEST_CONVERT_ITEM(set_required_int64_value, std::numeric_limits::min(), + "required_int64_value", "-9223372036854775808"); + TEST_CONVERT_ITEM(set_required_int64_value, std::numeric_limits::max(), + "required_int64_value", "9223372036854775807"); + TEST_CONVERT_ITEM(set_required_uint32_value, 5, "required_uint32_value", + Json::UInt(5)); + TEST_CONVERT_ITEM(set_required_uint32_value, + std::numeric_limits::max(), "required_uint32_value", + Json::UInt(std::numeric_limits::max())); + TEST_CONVERT_ITEM(set_required_uint64_value, 6, "required_uint64_value", "6"); + TEST_CONVERT_ITEM(set_required_uint64_value, + std::numeric_limits::max(), "required_uint64_value", + "18446744073709551615"); + TEST_CONVERT_ITEM(set_required_sint32_value, 7, "required_sint32_value", + Json::Int(7)); + TEST_CONVERT_ITEM(set_required_sint32_value, -7, "required_sint32_value", + Json::Int(-7)); + TEST_CONVERT_ITEM(set_required_sint32_value, + std::numeric_limits::min(), "required_sint32_value", + Json::Int(std::numeric_limits::min())); + TEST_CONVERT_ITEM(set_required_sint32_value, + std::numeric_limits::max(), "required_sint32_value", + Json::Int(std::numeric_limits::max())); + TEST_CONVERT_ITEM(set_required_sint64_value, 8, "required_sint64_value", "8"); + TEST_CONVERT_ITEM(set_required_sint64_value, -8, "required_sint64_value", + "-8"); + TEST_CONVERT_ITEM(set_required_sint64_value, + std::numeric_limits::min(), "required_sint64_value", + "-9223372036854775808"); + TEST_CONVERT_ITEM(set_required_sint64_value, + std::numeric_limits::max(), "required_sint64_value", + "9223372036854775807"); + TEST_CONVERT_ITEM(set_required_fixed32_value, 9, "required_fixed32_value", + Json::UInt(9)); + TEST_CONVERT_ITEM( + set_required_fixed32_value, std::numeric_limits::max(), + "required_fixed32_value", Json::UInt(std::numeric_limits::max())); + TEST_CONVERT_ITEM(set_required_fixed64_value, 10, "required_fixed64_value", + "10"); + TEST_CONVERT_ITEM(set_required_fixed64_value, + std::numeric_limits::max(), + "required_fixed64_value", "18446744073709551615"); + TEST_CONVERT_ITEM(set_required_sfixed32_value, 11, "required_sfixed32_value", + Json::Int(11)); + TEST_CONVERT_ITEM(set_required_sfixed32_value, -11, "required_sfixed32_value", + Json::Int(-11)); + TEST_CONVERT_ITEM( + set_required_sfixed32_value, std::numeric_limits::min(), + "required_sfixed32_value", Json::Int(std::numeric_limits::min())); + TEST_CONVERT_ITEM( + set_required_sfixed32_value, std::numeric_limits::max(), + "required_sfixed32_value", Json::Int(std::numeric_limits::max())); + TEST_CONVERT_ITEM(set_required_sfixed64_value, 12, "required_sfixed64_value", + "12"); + TEST_CONVERT_ITEM(set_required_sfixed64_value, -12, "required_sfixed64_value", + "-12"); + TEST_CONVERT_ITEM(set_required_sfixed64_value, + std::numeric_limits::min(), + "required_sfixed64_value", "-9223372036854775808"); + TEST_CONVERT_ITEM(set_required_sfixed64_value, + std::numeric_limits::max(), + "required_sfixed64_value", "9223372036854775807"); + TEST_CONVERT_ITEM(set_required_bool_value, true, "required_bool_value", true); + TEST_CONVERT_ITEM(set_required_bool_value, false, "required_bool_value", + false); + TEST_CONVERT_ITEM(set_required_string_value, "string", + "required_string_value", "string"); + TEST_CONVERT_ITEM(set_required_bytes_value, "bytes", "required_bytes_value", + "bytes"); + TEST_CONVERT_ITEM(set_required_enum_value, ENUM_A, "required_enum_value", + "ENUM_A"); + TEST_CONVERT_ITEM(set_required_innerenum_value, TestMsg::ENUM_1, + "required_innerenum_value", "ENUM_1"); #undef TEST_CONVERT_ITEM } -TEST(JsonUtilTest, ConvertRepeatedItemTest){ +TEST(JsonUtilTest, ConvertRepeatedItemTest) { #define TEST_CONVERT_REPEATED_ITEM(proto_adder, proto_value1, proto_value2, \ proto_value3, json_name, json_value1, \ json_value2, json_value3) \ @@ -591,258 +443,136 @@ FillRequiredFields(&msg); \ EXPECT_PROTO_EQ(msg, new_msg); \ } - TEST_CONVERT_REPEATED_ITEM(add_repeated_double_value, 1.0, 2.0, 3.0, - "repeated_double_value", 1.0, 2.0, 3.0) - TEST_CONVERT_REPEATED_ITEM( - add_repeated_float_value, 1.0, 2.0, - 3.0, "repeated_float_value", 1.0, 2.0, 3.0) TEST_CONVERT_REPEATED_ITEM(add_repeated_int32_value, - 1, - 2, 3, - "repeated_int32_value", Json::Int(1), Json::Int(2), Json::Int(3)) TEST_CONVERT_REPEATED_ITEM(add_repeated_int32_value, kint32min, - kint32min, - kint32min, - "repeated_int32_value", Json::Int(kint32min), Json::Int(kint32min), Json::Int(kint32min)) TEST_CONVERT_REPEATED_ITEM(add_repeated_int32_value, - kint32max, - kint32max, - kint32max, - "repeated_int32_value", Json::Int(kint32max), Json::Int(kint32max), - Json:: - Int(kint32max)) TEST_CONVERT_REPEATED_ITEM(add_repeated_int64_value, - 1, - 2, - 3, - "repeated_int64_value", - "1", - "2", - "3") TEST_CONVERT_REPEATED_ITEM(add_repeated_int64_value, - kint64min, - kint64min, - kint64min, - "repeated_int64_value", - "-9223372036854775808", - "-9223372036854775808", - "-9223372036854775808") TEST_CONVERT_REPEATED_ITEM(add_repeated_int64_value, - kint64max, kint64max, kint64max, - "repeated_int64_value", - "9223372036854775807", - "9223372036854775807", - "9223372036854775807") TEST_CONVERT_REPEATED_ITEM(add_repeated_uint32_value, - 1, - 2, - 3, - "repeated_uint32_value", Json::UInt(1), - Json::UInt(2), Json::UInt(3)) TEST_CONVERT_REPEATED_ITEM(add_repeated_uint32_value, - kuint32max, - kuint32max, - kuint32max, - "repeated_uint32_value", - Json::UInt(kuint32max), Json::UInt(kuint32max), - Json::UInt( - kuint32max)) TEST_CONVERT_REPEATED_ITEM(add_repeated_uint64_value, - 1, - 2, - 3, - "repeated_uint64_value", - "1", - "2", - "3") TEST_CONVERT_REPEATED_ITEM(add_repeated_uint64_value, - kuint64max, - kuint64max, - kuint64max, - "repeated_uint64_value", - "18446744073709551615", - "18446744073709551615", - "18446744073709551615") TEST_CONVERT_REPEATED_ITEM(add_repeated_sint32_value, - 1, - 2, - 3, - "repeated_sint32_value", Json::Int(1), Json::Int(2), - Json:: - Int(3)) - TEST_CONVERT_REPEATED_ITEM( - add_repeated_sint32_value, - kint32min, kint32min, kint32min, "repeated_sint32_value", - Json::Int(kint32min), - Json::Int(kint32min), - Json::Int(kint32min)) - TEST_CONVERT_REPEATED_ITEM( - add_repeated_sint32_value, - kint32max, kint32max, kint32max, - "repeated_sint32_value", Json::Int(kint32max), - Json::Int(kint32max), Json::Int(kint32max)) - TEST_CONVERT_REPEATED_ITEM( - add_repeated_sint64_value, - 1, 2, 3, "repeated_sint64_value", "1", - "2", "3") TEST_CONVERT_REPEATED_ITEM(add_repeated_sint64_value, - kint64min, - kint64min, - kint64min, - "repeated_sint64_" - "value", - "-9223372036854775" - "808", - "-9223372036854775" - "808", - "-9223372036854775" - "808") - TEST_CONVERT_REPEATED_ITEM( - add_repeated_sint64_value, - kint64max, kint64max, kint64max, - "repeated_sint64_value", "9223372036854775807", - "9223372036854775807", "9223372036854775807") - TEST_CONVERT_REPEATED_ITEM( - add_repeated_fixed32_value, - 1, 2, 3, "repeated_fixed32_value", - Json::UInt(1), Json::UInt(2), - Json::UInt(3)) - TEST_CONVERT_REPEATED_ITEM( - add_repeated_fixed32_value, - kuint32max, - kuint32max, - kuint32max, - "repeated_fixed32_value", - Json::UInt(kuint32max), - Json::UInt(kuint32max), - Json::UInt( - kuint32max)) TEST_CONVERT_REPEATED_ITEM(add_repeated_fixed64_value, 1, - 2, - 3, - "repeated_fixed64_value", - "1", - "2", - "3") - TEST_CONVERT_REPEATED_ITEM( - add_repeated_fixed64_value, - kuint64max, - kuint64max, - kuint64max, - "repeated_fixed64_value", - "18446744073709551615", - "18446744073709551615", - "18446744073709551615") - TEST_CONVERT_REPEATED_ITEM( - add_repeated_sfixed32_value, 1, - 2, 3, - "repeated_sfixed32_value", - Json::Int(1), - Json::Int(2), - Json::Int(3)) - TEST_CONVERT_REPEATED_ITEM( - add_repeated_sfixed32_value, - kint32min, kint32min, kint32min, - "repeated_sfixed32_value", - Json::Int(kint32min), - Json::Int(kint32min), - Json::Int(kint32min)) - TEST_CONVERT_REPEATED_ITEM( - add_repeated_sfixed32_value, - kint32max, kint32max, - kint32max, - "repeated_sfixed32_value", - Json::Int(kint32max), - Json::Int(kint32max), - Json::Int(kint32max)) - TEST_CONVERT_REPEATED_ITEM( - add_repeated_sfixed64_value, - 1, 2, 3, - "repeated_sfixed64_" - "value", - "1", "2", "3") - TEST_CONVERT_REPEATED_ITEM( - add_repeated_sfixed64_value, - kint64min, - kint64min, - kint64min, - "repeated_sfixed64_" - "value", - "-92233720368547758" - "08", - "-92233720368547758" - "08", - "-92233720368547758" - "08") - TEST_CONVERT_REPEATED_ITEM( - add_repeated_sfixed64_value, - kint64max, - kint64max, - kint64max, - "repeated_" - "sfixed64_" - "value", - "92233720368547" - "75807", - "92233720368547" - "75807", - "92233720368547" - "75807") - TEST_CONVERT_REPEATED_ITEM( - add_repeated_bool_value, - true, true, - false, - "repeated_" - "bool_" - "value", - true, true, - false) - TEST_CONVERT_REPEATED_ITEM( - add_repeated_string_value, - "ABC", - "DEF", - "GHQ", - "repeat" - "ed_" - "string" - "_valu" - "e", - "ABC", - "DEF", - "GHQ") - TEST_CONVERT_REPEATED_ITEM( - add_repeated_bytes_value, - "AB" - "C", - "DE" - "F", - "GH" - "Q", - "re" - "pe" - "at" - "ed" - "_b" - "yt" - "es" - "_v" - "al" - "u" - "e", - "AB" - "C", - "DE" - "F", - "GH" - "Q") - TEST_CONVERT_REPEATED_ITEM( - add_repeated_enum_value, - ENUM_A, - ENUM_C, - ENUM_B, - "repeated_enum_value", - "ENUM_A", - "ENUM_C", - "ENUM_B") - TEST_CONVERT_REPEATED_ITEM( - add_repeated_innerenum_value, - TestMsg:: - ENUM_1, - TestMsg:: - ENUM_2, - TestMsg:: - ENUM_0, - "repeated_innerenum_value", - "ENUM_1", - "ENUM_2", - "ENUM_0") + TEST_CONVERT_REPEATED_ITEM(add_repeated_double_value, 1.0, 2.0, 3.0, + "repeated_double_value", 1.0, 2.0, 3.0); + TEST_CONVERT_REPEATED_ITEM(add_repeated_float_value, 1.0, 2.0, 3.0, + "repeated_float_value", 1.0, 2.0, 3.0); + TEST_CONVERT_REPEATED_ITEM(add_repeated_int32_value, 1, 2, 3, + "repeated_int32_value", Json::Int(1), Json::Int(2), + Json::Int(3)); + TEST_CONVERT_REPEATED_ITEM( + add_repeated_int32_value, std::numeric_limits::min(), + std::numeric_limits::min(), std::numeric_limits::min(), + "repeated_int32_value", Json::Int(std::numeric_limits::min()), + Json::Int(std::numeric_limits::min()), + Json::Int(std::numeric_limits::min())); + TEST_CONVERT_REPEATED_ITEM( + add_repeated_int32_value, std::numeric_limits::max(), + std::numeric_limits::max(), std::numeric_limits::max(), + "repeated_int32_value", Json::Int(std::numeric_limits::max()), + Json::Int(std::numeric_limits::max()), + Json::Int(std::numeric_limits::max())); + TEST_CONVERT_REPEATED_ITEM(add_repeated_int64_value, 1, 2, 3, + "repeated_int64_value", "1", "2", "3"); + TEST_CONVERT_REPEATED_ITEM( + add_repeated_int64_value, std::numeric_limits::min(), + std::numeric_limits::min(), std::numeric_limits::min(), + "repeated_int64_value", "-9223372036854775808", "-9223372036854775808", + "-9223372036854775808"); + TEST_CONVERT_REPEATED_ITEM( + add_repeated_int64_value, std::numeric_limits::max(), + std::numeric_limits::max(), std::numeric_limits::max(), + "repeated_int64_value", "9223372036854775807", "9223372036854775807", + "9223372036854775807"); + TEST_CONVERT_REPEATED_ITEM(add_repeated_uint32_value, 1, 2, 3, + "repeated_uint32_value", Json::UInt(1), + Json::UInt(2), Json::UInt(3)); + TEST_CONVERT_REPEATED_ITEM( + add_repeated_uint32_value, std::numeric_limits::max(), + std::numeric_limits::max(), std::numeric_limits::max(), + "repeated_uint32_value", Json::UInt(std::numeric_limits::max()), + Json::UInt(std::numeric_limits::max()), + Json::UInt(std::numeric_limits::max())); + TEST_CONVERT_REPEATED_ITEM(add_repeated_uint64_value, 1, 2, 3, + "repeated_uint64_value", "1", "2", "3"); + TEST_CONVERT_REPEATED_ITEM( + add_repeated_uint64_value, std::numeric_limits::max(), + std::numeric_limits::max(), std::numeric_limits::max(), + "repeated_uint64_value", "18446744073709551615", "18446744073709551615", + "18446744073709551615"); + TEST_CONVERT_REPEATED_ITEM(add_repeated_sint32_value, 1, 2, 3, + "repeated_sint32_value", Json::Int(1), + Json::Int(2), Json::Int(3)); + TEST_CONVERT_REPEATED_ITEM( + add_repeated_sint32_value, std::numeric_limits::min(), + std::numeric_limits::min(), std::numeric_limits::min(), + "repeated_sint32_value", Json::Int(std::numeric_limits::min()), + Json::Int(std::numeric_limits::min()), + Json::Int(std::numeric_limits::min())); + TEST_CONVERT_REPEATED_ITEM( + add_repeated_sint32_value, std::numeric_limits::max(), + std::numeric_limits::max(), std::numeric_limits::max(), + "repeated_sint32_value", Json::Int(std::numeric_limits::max()), + Json::Int(std::numeric_limits::max()), + Json::Int(std::numeric_limits::max())); + TEST_CONVERT_REPEATED_ITEM(add_repeated_sint64_value, 1, 2, 3, + "repeated_sint64_value", "1", "2", "3"); + TEST_CONVERT_REPEATED_ITEM( + add_repeated_sint64_value, std::numeric_limits::min(), + std::numeric_limits::min(), std::numeric_limits::min(), + "repeated_sint64_value", "-9223372036854775808", "-9223372036854775808", + "-9223372036854775808"); + TEST_CONVERT_REPEATED_ITEM( + add_repeated_sint64_value, std::numeric_limits::max(), + std::numeric_limits::max(), std::numeric_limits::max(), + "repeated_sint64_value", "9223372036854775807", "9223372036854775807", + "9223372036854775807"); + TEST_CONVERT_REPEATED_ITEM(add_repeated_fixed32_value, 1, 2, 3, + "repeated_fixed32_value", Json::UInt(1), + Json::UInt(2), Json::UInt(3)); + TEST_CONVERT_REPEATED_ITEM( + add_repeated_fixed32_value, std::numeric_limits::max(), + std::numeric_limits::max(), std::numeric_limits::max(), + "repeated_fixed32_value", Json::UInt(std::numeric_limits::max()), + Json::UInt(std::numeric_limits::max()), + Json::UInt(std::numeric_limits::max())); + TEST_CONVERT_REPEATED_ITEM(add_repeated_fixed64_value, 1, 2, 3, + "repeated_fixed64_value", "1", "2", "3"); + TEST_CONVERT_REPEATED_ITEM( + add_repeated_fixed64_value, std::numeric_limits::max(), + std::numeric_limits::max(), std::numeric_limits::max(), + "repeated_fixed64_value", "18446744073709551615", "18446744073709551615", + "18446744073709551615"); + TEST_CONVERT_REPEATED_ITEM(add_repeated_sfixed32_value, 1, 2, 3, + "repeated_sfixed32_value", Json::Int(1), + Json::Int(2), Json::Int(3)); + TEST_CONVERT_REPEATED_ITEM( + add_repeated_sfixed32_value, std::numeric_limits::min(), + std::numeric_limits::min(), std::numeric_limits::min(), + "repeated_sfixed32_value", Json::Int(std::numeric_limits::min()), + Json::Int(std::numeric_limits::min()), + Json::Int(std::numeric_limits::min())); + TEST_CONVERT_REPEATED_ITEM( + add_repeated_sfixed32_value, std::numeric_limits::max(), + std::numeric_limits::max(), std::numeric_limits::max(), + "repeated_sfixed32_value", Json::Int(std::numeric_limits::max()), + Json::Int(std::numeric_limits::max()), + Json::Int(std::numeric_limits::max())); + TEST_CONVERT_REPEATED_ITEM(add_repeated_sfixed64_value, 1, 2, 3, + "repeated_sfixed64_value", "1", "2", "3"); + TEST_CONVERT_REPEATED_ITEM( + add_repeated_sfixed64_value, std::numeric_limits::min(), + std::numeric_limits::min(), std::numeric_limits::min(), + "repeated_sfixed64_value", "-9223372036854775808", "-9223372036854775808", + "-9223372036854775808"); + TEST_CONVERT_REPEATED_ITEM( + add_repeated_sfixed64_value, std::numeric_limits::max(), + std::numeric_limits::max(), std::numeric_limits::max(), + "repeated_sfixed64_value", "9223372036854775807", "9223372036854775807", + "9223372036854775807"); + TEST_CONVERT_REPEATED_ITEM(add_repeated_bool_value, true, true, false, + "repeated_bool_value", true, true, false); + TEST_CONVERT_REPEATED_ITEM(add_repeated_string_value, "ABC", "DEF", "GHQ", + "repeated_string_value", "ABC", "DEF", "GHQ"); + TEST_CONVERT_REPEATED_ITEM(add_repeated_bytes_value, "ABC", "DEF", "GHQ", + "repeated_bytes_value", "ABC", "DEF", "GHQ"); + TEST_CONVERT_REPEATED_ITEM(add_repeated_enum_value, ENUM_A, ENUM_C, ENUM_B, + "repeated_enum_value", "ENUM_A", "ENUM_C", + "ENUM_B"); + TEST_CONVERT_REPEATED_ITEM(add_repeated_innerenum_value, TestMsg::ENUM_1, + TestMsg::ENUM_2, TestMsg::ENUM_0, + "repeated_innerenum_value", "ENUM_1", "ENUM_2", + "ENUM_0"); #undef TEST_CONVERT_REPEATED_ITEM } @@ -955,23 +685,23 @@ // signed int 32 EXPECT_FALSE(ParseToMessage("{\"int32_value\": -2147483649}", &msg)); EXPECT_TRUE(ParseToMessage("{\"int32_value\": -2147483648}", &msg)); - EXPECT_EQ(kint32min, msg.int32_value()); + EXPECT_EQ(std::numeric_limits::min(), msg.int32_value()); EXPECT_TRUE(ParseToMessage("{\"int32_value\": 2147483647}", &msg)); - EXPECT_EQ(kint32max, msg.int32_value()); + EXPECT_EQ(std::numeric_limits::max(), msg.int32_value()); EXPECT_FALSE(ParseToMessage("{\"int32_value\": 2147483648}", &msg)); EXPECT_FALSE(ParseToMessage("{\"sint32_value\": -2147483649}", &msg)); EXPECT_TRUE(ParseToMessage("{\"sint32_value\": -2147483648}", &msg)); - EXPECT_EQ(kint32min, msg.sint32_value()); + EXPECT_EQ(std::numeric_limits::min(), msg.sint32_value()); EXPECT_TRUE(ParseToMessage("{\"sint32_value\": 2147483647}", &msg)); - EXPECT_EQ(kint32max, msg.sint32_value()); + EXPECT_EQ(std::numeric_limits::max(), msg.sint32_value()); EXPECT_FALSE(ParseToMessage("{\"sint32_value\": 2147483648}", &msg)); EXPECT_FALSE(ParseToMessage("{\"sfixed32_value\": -2147483649}", &msg)); EXPECT_TRUE(ParseToMessage("{\"sfixed32_value\": -2147483648}", &msg)); - EXPECT_EQ(kint32min, msg.sfixed32_value()); + EXPECT_EQ(std::numeric_limits::min(), msg.sfixed32_value()); EXPECT_TRUE(ParseToMessage("{\"sfixed32_value\": 2147483647}", &msg)); - EXPECT_EQ(kint32max, msg.sfixed32_value()); + EXPECT_EQ(std::numeric_limits::max(), msg.sfixed32_value()); EXPECT_FALSE(ParseToMessage("{\"sfixed32_value\": 2147483648}", &msg)); // unsigned int 32 @@ -979,14 +709,14 @@ EXPECT_TRUE(ParseToMessage("{\"uint32_value\": 0}", &msg)); EXPECT_EQ(0, msg.uint32_value()); EXPECT_TRUE(ParseToMessage("{\"uint32_value\": 4294967295}", &msg)); - EXPECT_EQ(kuint32max, msg.uint32_value()); + EXPECT_EQ(std::numeric_limits::max(), msg.uint32_value()); EXPECT_FALSE(ParseToMessage("{\"uint32_value\": 4294967296}", &msg)); EXPECT_FALSE(ParseToMessage("{\"fixed32_value\": -1}", &msg)); EXPECT_TRUE(ParseToMessage("{\"fixed32_value\": 0}", &msg)); EXPECT_EQ(0, msg.fixed32_value()); EXPECT_TRUE(ParseToMessage("{\"fixed32_value\": 4294967295}", &msg)); - EXPECT_EQ(kuint32max, msg.fixed32_value()); + EXPECT_EQ(std::numeric_limits::max(), msg.fixed32_value()); EXPECT_FALSE(ParseToMessage("{\"fixed32_value\": 4294967296}", &msg)); // signed int 64 @@ -994,10 +724,10 @@ ParseToMessage("{\"int64_value\": \"-9223372036854775809\"}", &msg)); EXPECT_TRUE( ParseToMessage("{\"int64_value\": \"-9223372036854775808\"}", &msg)); - EXPECT_EQ(kint64min, msg.int64_value()); + EXPECT_EQ(std::numeric_limits::min(), msg.int64_value()); EXPECT_TRUE( ParseToMessage("{\"int64_value\": \"9223372036854775807\"}", &msg)); - EXPECT_EQ(kint64max, msg.int64_value()); + EXPECT_EQ(std::numeric_limits::max(), msg.int64_value()); EXPECT_FALSE( ParseToMessage("{\"int64_value\": \"9223372036854775808\"}", &msg)); @@ -1005,10 +735,10 @@ ParseToMessage("{\"sint64_value\": \"-9223372036854775809\"}", &msg)); EXPECT_TRUE( ParseToMessage("{\"sint64_value\": \"-9223372036854775808\"}", &msg)); - EXPECT_EQ(kint64min, msg.sint64_value()); + EXPECT_EQ(std::numeric_limits::min(), msg.sint64_value()); EXPECT_TRUE( ParseToMessage("{\"sint64_value\": \"9223372036854775807\"}", &msg)); - EXPECT_EQ(kint64max, msg.sint64_value()); + EXPECT_EQ(std::numeric_limits::max(), msg.sint64_value()); EXPECT_FALSE( ParseToMessage("{\"sint64_value\": \"9223372036854775808\"}", &msg)); @@ -1016,10 +746,10 @@ ParseToMessage("{\"sfixed64_value\": \"-9223372036854775809\"}", &msg)); EXPECT_TRUE( ParseToMessage("{\"sfixed64_value\": \"-9223372036854775808\"}", &msg)); - EXPECT_EQ(kint64min, msg.sfixed64_value()); + EXPECT_EQ(std::numeric_limits::min(), msg.sfixed64_value()); EXPECT_TRUE( ParseToMessage("{\"sfixed64_value\": \"9223372036854775807\"}", &msg)); - EXPECT_EQ(kint64max, msg.sfixed64_value()); + EXPECT_EQ(std::numeric_limits::max(), msg.sfixed64_value()); EXPECT_FALSE( ParseToMessage("{\"sfixed64_value\": \"9223372036854775808\"}", &msg)); @@ -1029,7 +759,7 @@ EXPECT_EQ(0, msg.uint64_value()); EXPECT_TRUE( ParseToMessage("{\"uint64_value\": \"18446744073709551615\"}", &msg)); - EXPECT_EQ(kuint64max, msg.uint64_value()); + EXPECT_EQ(std::numeric_limits::max(), msg.uint64_value()); EXPECT_FALSE( ParseToMessage("{\"uint64_value\": \"18446744073709551616\"}", &msg)); @@ -1038,7 +768,7 @@ EXPECT_EQ(0, msg.fixed64_value()); EXPECT_TRUE( ParseToMessage("{\"fixed64_value\": \"18446744073709551615\"}", &msg)); - EXPECT_EQ(kuint64max, msg.fixed64_value()); + EXPECT_EQ(std::numeric_limits::max(), msg.fixed64_value()); EXPECT_FALSE( ParseToMessage("{\"fixed64_value\": \"18446744073709551616\"}", &msg)); } diff --git a/src/net/jsonpath.cc b/src/net/jsonpath.cc index c1f8268..475e9fa 100644 --- a/src/net/jsonpath.cc +++ b/src/net/jsonpath.cc @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -53,7 +54,7 @@ int slice_end; int slice_step; - static constexpr int kSliceUndef = kint32max; + static constexpr int kSliceUndef = std::numeric_limits::max(); static bool IsUndef(int n) { return n == kSliceUndef; } diff --git a/src/prediction/BUILD b/src/prediction/BUILD index 6301442..7b640fa 100644 --- a/src/prediction/BUILD +++ b/src/prediction/BUILD @@ -366,7 +366,7 @@ py_binary_mozc( name = "gen_zero_query_number_data", srcs = ["gen_zero_query_number_data.py"], - python_version = "PY2", + python_version = "PY3", deps = [ ":gen_zero_query_number_data_lib", ":gen_zero_query_util", @@ -385,7 +385,7 @@ py_binary_mozc( name = "gen_zero_query_data", srcs = ["gen_zero_query_data.py"], - python_version = "PY2", + python_version = "PY3", deps = [ ":gen_zero_query_data_lib", ":gen_zero_query_util", diff --git a/src/prediction/user_history_predictor.cc b/src/prediction/user_history_predictor.cc index 3d42c14..1a29599 100644 --- a/src/prediction/user_history_predictor.cc +++ b/src/prediction/user_history_predictor.cc @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -1455,7 +1456,7 @@ target_next_entry = entry->add_next_entries(); } else { // Otherwise, find the oldest next_entry. - uint64 last_access_time = kuint64max; + uint64 last_access_time = std::numeric_limits::max(); for (int i = 0; i < entry->next_entries_size(); ++i) { // Already has the same id if (next_entry.entry_fp() == entry->next_entries(i).entry_fp()) { diff --git a/src/rewriter/BUILD b/src/rewriter/BUILD index 62c7bed..bdcdaff 100644 --- a/src/rewriter/BUILD +++ b/src/rewriter/BUILD @@ -925,7 +925,7 @@ py_binary_mozc( name = "gen_emoji_rewriter_data", srcs = ["gen_emoji_rewriter_data.py"], - python_version = "PY2", + python_version = "PY3", deps = [ ":gen_emoji_rewriter_data_lib", "//build_tools:code_generator_util", @@ -1022,7 +1022,7 @@ py_binary_mozc( name = "gen_single_kanji_rewriter_data", srcs = ["gen_single_kanji_rewriter_data.py"], - python_version = "PY2", + python_version = "PY3", deps = [ ":gen_single_kanji_rewriter_data_lib", "//build_tools:code_generator_util", @@ -1074,7 +1074,7 @@ py_binary_mozc( name = "gen_counter_suffix_array", srcs = ["gen_counter_suffix_array.py"], - python_version = "PY2", + python_version = "PY3", deps = [ ":gen_counter_suffix_array_lib", "//build_tools:code_generator_util", @@ -1386,7 +1386,7 @@ py_binary_mozc( name = "gen_reading_correction_data", srcs = ["gen_reading_correction_data.py"], - python_version = "PY2", + python_version = "PY3", deps = [ ":gen_reading_correction_data_lib", "//build_tools:code_generator_util", diff --git a/src/rewriter/calculator/calculator.cc b/src/rewriter/calculator/calculator.cc index ed4f739..ffa51a7 100644 --- a/src/rewriter/calculator/calculator.cc +++ b/src/rewriter/calculator/calculator.cc @@ -46,7 +46,6 @@ #include #include -#include "base/compiler_specific.h" #include "base/logging.h" #include "base/number_util.h" #include "base/singleton.h" diff --git a/src/rewriter/calculator/calculator_test.cc b/src/rewriter/calculator/calculator_test.cc index f664d3d..0c8f7aa 100644 --- a/src/rewriter/calculator/calculator_test.cc +++ b/src/rewriter/calculator/calculator_test.cc @@ -32,7 +32,6 @@ #include #include -#include "base/compiler_specific.h" #include "base/file_util.h" #include "base/logging.h" #include "rewriter/calculator/calculator_interface.h" diff --git a/src/rewriter/collocation_rewriter.cc b/src/rewriter/collocation_rewriter.cc index 7e14bf5..59bc53a 100644 --- a/src/rewriter/collocation_rewriter.cc +++ b/src/rewriter/collocation_rewriter.cc @@ -573,7 +573,9 @@ bool CollocationRewriter::IsName(const Segment::Candidate &cand) const { const bool ret = (cand.lid == last_name_id_ || cand.lid == first_name_id_); - VLOG_IF(3, ret) << cand.value << " is name sagment"; + if (ret) { + VLOG(3) << cand.value << " is name sagment"; + } return ret; } @@ -606,8 +608,10 @@ cur.clear(); CollocationUtil::GetNormalizedScript(curs[j], false, &cur); if (collocation_filter_->Exists(prev, cur)) { - VLOG_IF(3, i != 0) << prev << cur << " " << seg->candidate(0).value - << "->" << seg->candidate(i).value; + if (i != 0) { + VLOG(3) << prev << cur << " " << seg->candidate(0).value << "->" + << seg->candidate(i).value; + } seg->move_candidate(i, 0); seg->mutable_candidate(0)->attributes |= Segment::Candidate::CONTEXT_SENSITIVE; diff --git a/src/rewriter/gen_emoji_rewriter_data.py b/src/rewriter/gen_emoji_rewriter_data.py index 937ca15..9c91d6c 100644 --- a/src/rewriter/gen_emoji_rewriter_data.py +++ b/src/rewriter/gen_emoji_rewriter_data.py @@ -59,7 +59,6 @@ import sys import six -from six import unichr # pylint: disable=redefined-builtin from build_tools import code_generator_util from build_tools import serialized_string_array_builder @@ -90,7 +89,7 @@ def NormalizeString(string): """Normalize full width ascii characters to half width characters.""" offset = ord(u'A') - ord(u'A') - normalized = _FULLWIDTH_RE.sub(lambda x: unichr(ord(x.group(0)) - offset), + normalized = _FULLWIDTH_RE.sub(lambda x: six.unichr(ord(x.group(0)) - offset), six.ensure_text(string)) return normalized diff --git a/src/rewriter/variants_rewriter.cc b/src/rewriter/variants_rewriter.cc index 847c239..1eb8332 100644 --- a/src/rewriter/variants_rewriter.cc +++ b/src/rewriter/variants_rewriter.cc @@ -424,7 +424,9 @@ // dangerous. So here checks the validity. For invalid candidate, inner // segment boundary is ignored. const bool is_valid = original.IsValid(); - VLOG_IF(2, !is_valid) << "Invalid candidate: " << original.DebugString(); + if (!is_valid) { + VLOG(2) << "Invalid candidate: " << original.DebugString(); + } if (original.inner_segment_boundary.empty() || !is_valid) { if (!manager->ConvertConversionStringWithAlternative( original.value, default_value, alternative_value)) { diff --git a/src/server/BUILD b/src/server/BUILD index e57b813..0bf666d 100644 --- a/src/server/BUILD +++ b/src/server/BUILD @@ -31,10 +31,7 @@ # Visibility: please choose a more appropriate default for the package, # and update any rules that should be different. -load( - "//:build_defs.bzl", - "cc_binary_mozc", -) +load("//:build_defs.bzl", "cc_binary_mozc") package(default_visibility = ["//:__subpackages__"]) diff --git a/src/session/session_usage_observer.cc b/src/session/session_usage_observer.cc index 30666a4..0c74729 100644 --- a/src/session/session_usage_observer.cc +++ b/src/session/session_usage_observer.cc @@ -30,6 +30,7 @@ #include "session/session_usage_observer.h" #include +#include #include #include #include @@ -76,7 +77,7 @@ uint32 GetDuration(uint64 base_value) { const uint64 result = GetTimeInMilliSecond() - base_value; if (result != static_cast(result)) { - return kuint32max; + return std::numeric_limits::max(); } return result; } diff --git a/src/tools/build_defs/stubs.bzl b/src/tools/build_defs/stubs.bzl index ba5c7e9..c39461f 100644 --- a/src/tools/build_defs/stubs.bzl +++ b/src/tools/build_defs/stubs.bzl @@ -47,3 +47,11 @@ def py2and3_test(**kwargs): native.py_test(**kwargs) pass + +def pytype_strict_library(**kwargs): + native.py_library(**kwargs) + pass + +def pytype_strict_binary(test_lib = True, **kwargs): + native.py_binary(**kwargs) + pass diff --git a/src/win32/ime/ime_candidate_info.cc b/src/win32/ime/ime_candidate_info.cc index a62010d..7854284 100644 --- a/src/win32/ime/ime_candidate_info.cc +++ b/src/win32/ime/ime_candidate_info.cc @@ -34,6 +34,7 @@ #include // windows.h must be included before strsafe.h #include +#include #include "google/protobuf/stubs/common.h" #include "base/logging.h" @@ -55,17 +56,21 @@ // Since IMM32 uses DWORD rather than size_t for data size in data structures, // relevant data size are stored into DWORD constants here. -static_assert(sizeof(DWORD) <= kint32max, "Check DWORD size."); +static_assert(sizeof(DWORD) <= std::numeric_limits::max(), + "Check DWORD size."); const DWORD kSizeOfDWORD = static_cast(sizeof(DWORD)); -static_assert(sizeof(wchar_t) <= kint32max, "Check wchar_t size."); +static_assert(sizeof(wchar_t) <= std::numeric_limits::max(), + "Check wchar_t size."); const DWORD kSizeOfWCHAR = static_cast(sizeof(wchar_t)); -static_assert(sizeof(CANDIDATEINFO) <= kint32max, "Check CANDIDATEINFO size."); +static_assert(sizeof(CANDIDATEINFO) <= std::numeric_limits::max(), + "Check CANDIDATEINFO size."); const DWORD kSizeOfCANDIDATEINFO = static_cast(sizeof(CANDIDATEINFO)); -static_assert(sizeof(CANDIDATELIST) <= kint32max, "Check CANDIDATELIST size."); +static_assert(sizeof(CANDIDATELIST) <= std::numeric_limits::max(), + "Check CANDIDATELIST size."); const DWORD kSizeOfCANDIDATELIST = static_cast(sizeof(CANDIDATELIST)); static_assert(sizeof(CANDIDATELIST) > sizeof(DWORD), @@ -74,7 +79,8 @@ static_cast(sizeof(CANDIDATELIST) - sizeof(DWORD)); static_assert((static_cast(sizeof(CANDIDATEINFO)) + - static_cast(sizeof(CANDIDATELIST))) < kint32max, + static_cast(sizeof(CANDIDATELIST))) < + std::numeric_limits::max(), "Check CANDIDATEINFO + CANDIDATELIST size."); const DWORD kSizeOfCANDIDATEINFOAndCANDIDATELIST = static_cast(sizeof(CANDIDATEINFO) + sizeof(CANDIDATELIST)); diff --git a/src/win32/ime/ime_impl_imm.cc b/src/win32/ime/ime_impl_imm.cc index ff3937b..5320bbb 100644 --- a/src/win32/ime/ime_impl_imm.cc +++ b/src/win32/ime/ime_impl_imm.cc @@ -33,8 +33,9 @@ #include "win32/ime/ime_impl_imm.h" #include - #include + +#include #include "google/protobuf/stubs/common.h" #include "base/const.h" @@ -183,7 +184,7 @@ return; } int32 revision = GetContextRevision(); - if (revision < kint32max) { + if (revision < std::numeric_limits::max()) { ++revision; } else { revision = 0; diff --git a/src/win32/installer/wix.gypi b/src/win32/installer/wix.gypi index 8c21a2d..0b60264 100644 --- a/src/win32/installer/wix.gypi +++ b/src/win32/installer/wix.gypi @@ -114,6 +114,11 @@ r'-dUCRTDir=C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\x86', ], }], + ['MSVS_VERSION=="2017" and use_qt=="YES"', { + 'additional_args': [ + r'-dUCRTDir=C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\x86', + ], + }], ], 'omaha_guid': 'DDCCD2A9-025E-4142-BCEB-F467B88CF830', 'omaha_client_key': r'Software\Google\Update\Clients\{<(omaha_guid)}', diff --git a/src/win32/tip/tip_thread_context.cc b/src/win32/tip/tip_thread_context.cc index 9c9460c..e9f02f3 100644 --- a/src/win32/tip/tip_thread_context.cc +++ b/src/win32/tip/tip_thread_context.cc @@ -29,6 +29,7 @@ #include "win32/tip/tip_thread_context.h" +#include #include #include "base/win_util.h" @@ -84,7 +85,7 @@ } void TipThreadContext::IncrementFocusRevision() { - if (state_->focus_revision < kint32max) { + if (state_->focus_revision < std::numeric_limits::max()) { state_->focus_revision++; } else { state_->focus_revision = 0;