Codebase list mozc / 52e3d29
Remove MOZC_USE_SEPARATE_DATASET macro This macro is no longer necessary because: - On Android and ChromeOS, model data is always loaded form a file. DataManager is used for this purpose. - On desktop (Win, Mac, Linux), model data is embedded in executables through OssDataManager. - In unit tests, MockDataManager or appropriate embedded data manager is used, so scoped_data_manager_initializer_for_testing is no longer necessary. BUG= TEST= REF_BUG=26841123 REF_CL=120318647 REF_TIME=2016-04-20T18:53:48+09:00 REF_TIME_RAW=1461146028 +0900 Noriyuki Takahashi 8 years ago
16 changed file(s) with 38 addition(s) and 233 deletion(s). Raw diff Collapse all Expand all
224224 {
225225 'target_name': 'assets_mozc_dataset',
226226 'type': 'none',
227 'conditions': [
228 ['use_separate_dataset==1',
229 {
230 'actions': [
231 {
232 'action_name': 'assets_copy_dataset',
233 'inputs': [
234 '<(mozc_dataset)',
235 ],
236 'outputs': [
237 '<(sdk_asset_dir)/mozc.imy',
238 ],
239 'action': [
240 # Note that multiple output files cannot be handled
241 # by copy_file script.
242 '<@(copy_file)', '<@(_inputs)', '<@(_outputs)',
243 ],
244 },
245 ],
246 },
247 ],
248 ],
227 'actions': [{
228 'action_name': 'assets_copy_dataset',
229 'inputs': [
230 '<(mozc_dataset)',
231 ],
232 'outputs': [
233 '<(sdk_asset_dir)/mozc.imy',
234 ],
235 'action': [
236 # Note that multiple output files cannot be handled
237 # by copy_file script.
238 '<@(copy_file)', '<@(_inputs)', '<@(_outputs)',
239 ],
240 }],
249241 },
250242 {
251243 # CAVEAT:
730730 # Dictionary configuration
731731 if target_platform == 'Android':
732732 gyp_options.extend(['-D', 'dictionary=small'])
733 gyp_options.extend(['-D', 'use_separate_dataset=1'])
734733 gyp_options.extend(['-D', 'use_1byte_cost_for_connection_data=1'])
735734 elif target_platform == 'NaCl':
736735 gyp_options.extend(['-D', 'dictionary=desktop'])
737 gyp_options.extend(['-D', 'use_separate_dataset=0'])
738736 gyp_options.extend(['-D', 'use_1byte_cost_for_connection_data=0'])
739737 else:
740738 gyp_options.extend(['-D', 'dictionary=desktop'])
741 gyp_options.extend(['-D', 'use_separate_dataset=0'])
742739 gyp_options.extend(['-D', 'use_1byte_cost_for_connection_data=0'])
743740
744741 if target_platform == 'NaCl':
4848 'dependencies': [
4949 '../composer/composer.gyp:composer',
5050 '../config/config.gyp:config_handler',
51 '../data_manager/data_manager_test.gyp:scoped_data_manager_initializer_for_testing',
5251 '../data_manager/testing/mock_data_manager.gyp:mock_data_manager',
5352 '../dictionary/dictionary.gyp:dictionary_mock',
5453 '../dictionary/dictionary.gyp:suffix_dictionary',
00 MAJOR=2
11 MINOR=18
2 BUILD=2552
2 BUILD=2553
33 REVISION=102
44 # CAUTION: NACL_DICTIONARY_VERSION is going to be migrated to ENGINE_VERSION.
55 # NACL_DICTIONARY_VERSION is the target version of the system dictionary to be
4949 ],
5050 },
5151 {
52 'target_name': 'scoped_data_manager_initializer_for_testing',
53 'type': 'static_library',
54 'toolsets': [ 'target' ],
55 'sources': [
56 'scoped_data_manager_initializer_for_testing.cc',
57 ],
58 'conditions': [
59 ['target_platform=="Android"', {
60 'dependencies': [
61 ':scoped_android_data_manager_initializer_for_testing'
62 ],
63 }],
64 ],
65 },
66 {
6752 'target_name': 'dataset_writer_test',
6853 'type': 'executable',
6954 'toolsets': [ 'target' ],
10691 ],
10792 },
10893 ],
109 'conditions': [
110 ['target_platform=="Android"', {
111 'targets': [
112 {
113 'target_name': 'scoped_android_data_manager_initializer_for_testing',
114 'type': 'static_library',
115 'toolsets': [ 'target' ],
116 'sources': [
117 'android/scoped_android_data_manager_initializer_for_testing.cc',
118 ],
119 },
120 ],
121 }],
122 ],
12394 }
3535 namespace oss {
3636 namespace {
3737
38 const char *g_mozc_data_address = nullptr;
39 size_t g_mozc_data_size = 0;
40
41 #ifdef MOZC_USE_SEPARATE_DATASET
42 const EmbeddedFile kOssMozcDataSet = {nullptr, 0};
43 #else
4438 // kOssMozcDataSet is embedded.
4539 #include "data_manager/oss/mozc_imy.h"
46 #endif // MOZC_USE_SEPARATE_DATASET
4740
4841 #ifndef MOZC_DATASET_MAGIC_NUMBER
4942 #error "MOZC_DATASET_MAGIC_NUMBER is not defined by build system"
5548
5649 OssDataManager::OssDataManager() {
5750 const StringPiece magic(kMagicNumber, arraysize(kMagicNumber) - 1);
58 if (g_mozc_data_address != nullptr) {
59 const StringPiece data(g_mozc_data_address, g_mozc_data_size);
60 CHECK_EQ(Status::OK, InitFromArray(data, magic))
61 << "Image set by SetMozcDataSet() is broken";
62 return;
63 }
64 #ifdef MOZC_USE_SEPARATE_DATASET
65 LOG(FATAL)
66 << "When MOZC_USE_SEPARATE_DATASET build flag is defined, "
67 << "OssDataManager::SetMozcDataSet() must be called before "
68 << "instantiation of OssDataManager instances.";
69 #endif // MOZC_USE_SEPARATE_DATASET
7051 CHECK_EQ(Status::OK, InitFromArray(LoadEmbeddedFile(kOssMozcDataSet), magic))
7152 << "Embedded mozc_imy.h for OSS is broken";
7253 }
7354
7455 OssDataManager::~OssDataManager() = default;
7556
76 // Both pointers can be nullptr when the DataManager is reset on testing.
77 void OssDataManager::SetMozcDataSet(void *address, size_t size) {
78 g_mozc_data_address = reinterpret_cast<char *>(address);
79 g_mozc_data_size = size;
80 }
81
8257 } // namespace oss
8358 } // namespace mozc
3535 namespace mozc {
3636 namespace oss {
3737
38 // This is a simple wrapper of DataManager that uses the embedded OSS data set.
39 // Note that linking against this module embeds OSS data set into executable.
3840 class OssDataManager : public DataManager {
3941 public:
4042 OssDataManager();
4143 ~OssDataManager() override;
42
43 static void SetMozcDataSet(void *address, size_t size);
4444
4545 private:
4646 DISALLOW_COPY_AND_ASSIGN(OssDataManager);
+0
-40
src/data_manager/scoped_data_manager_initializer_for_testing.cc less more
0 // Copyright 2010-2016, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 #include "data_manager/scoped_data_manager_initializer_for_testing.h"
30
31 namespace mozc {
32
33 scoped_data_manager_initializer_for_testing::
34 scoped_data_manager_initializer_for_testing() {}
35
36 scoped_data_manager_initializer_for_testing::
37 ~scoped_data_manager_initializer_for_testing() {}
38
39 } // namespace mozc
+0
-57
src/data_manager/scoped_data_manager_initializer_for_testing.h less more
0 // Copyright 2010-2016, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 #ifndef MOZC_DATA_MANAGER_SCOPED_DATA_MANAGER_INITIALIZER_FOR_TESTING_H_
30 #define MOZC_DATA_MANAGER_SCOPED_DATA_MANAGER_INITIALIZER_FOR_TESTING_H_
31
32 #include "base/port.h"
33
34 #ifdef OS_ANDROID
35 #include "data_manager/android/scoped_android_data_manager_initializer_for_testing.h"
36 #endif // OS_ANDROID
37
38 namespace mozc {
39
40 class scoped_data_manager_initializer_for_testing {
41 public:
42 scoped_data_manager_initializer_for_testing();
43 ~scoped_data_manager_initializer_for_testing();
44
45 private:
46 #ifdef OS_ANDROID
47 mozc::android::scoped_android_data_manager_initializer_for_testing
48 scoped_android_data_manager_initializer_for_testing_;
49 #endif // OS_ANDROID
50
51 DISALLOW_COPY_AND_ASSIGN(scoped_data_manager_initializer_for_testing);
52 };
53
54 } // namespace mozc
55
56 #endif // MOZC_DATA_MANAGER_SCOPED_DATA_MANAGER_INITIALIZER_FOR_TESTING_H_
3737
3838 # a flag whether the current build is dev-channel or not.
3939 'channel_dev%': '0',
40
41 # a flag whether the dataset is embedded or separated (for Android).
42 'use_separate_dataset%': '0',
4340
4441 # enable_cloud_handwriting represents if cloud handwriting feature is
4542 # enabled or not.
8986 ['channel_dev==1', {
9087 'defines': ['CHANNEL_DEV'],
9188 }],
92 ['use_separate_dataset==1', {
93 'defines': ['MOZC_USE_SEPARATE_DATASET'],
94 }],
9589 ['enable_cloud_handwriting==1', {
9690 'defines': ['ENABLE_CLOUD_HANDWRITING'],
9791 }],
4848 '../converter/converter_base.gyp:immutable_converter',
4949 '../converter/converter_base.gyp:segmenter',
5050 '../converter/converter_base.gyp:segments',
51 '../data_manager/data_manager_test.gyp:scoped_data_manager_initializer_for_testing',
5251 '../data_manager/testing/mock_data_manager.gyp:mock_data_manager',
5352 '../dictionary/dictionary.gyp:dictionary',
5453 '../dictionary/dictionary.gyp:dictionary_mock',
3838 #include "composer/composer.h"
3939 #include "config/config_handler.h"
4040 #include "converter/segments.h"
41 #include "data_manager/scoped_data_manager_initializer_for_testing.h"
4241 #include "data_manager/testing/mock_data_manager.h"
4342 #include "dictionary/dictionary_mock.h"
4443 #include "dictionary/pos_matcher.h"
6665
6766 class CheckCandSizePredictor : public PredictorInterface {
6867 public:
69 explicit CheckCandSizePredictor(int expected_cand_size) :
70 expected_cand_size_(expected_cand_size),
71 predictor_name_("CheckCandSizePredictor") {
72 }
73 virtual bool PredictForRequest(const ConversionRequest &request,
74 Segments *segments) const {
68 explicit CheckCandSizePredictor(int expected_cand_size)
69 : expected_cand_size_(expected_cand_size),
70 predictor_name_("CheckCandSizePredictor") {}
71
72 bool PredictForRequest(const ConversionRequest &request,
73 Segments *segments) const override {
7574 EXPECT_EQ(expected_cand_size_, segments->max_prediction_candidates_size());
7675 return true;
7776 }
78 virtual const string &GetPredictorName() const {
77
78 const string &GetPredictorName() const override {
7979 return predictor_name_;
8080 }
8181
8282 private:
83 int expected_cand_size_;
83 const int expected_cand_size_;
8484 const string predictor_name_;
85 scoped_data_manager_initializer_for_testing
86 scoped_data_manager_initializer_for_testing_;
8785 };
8886
8987 class NullPredictor : public PredictorInterface {
9189 explicit NullPredictor(bool ret)
9290 : return_value_(ret), predict_called_(false),
9391 predictor_name_("NullPredictor") {}
94 virtual bool PredictForRequest(const ConversionRequest &request,
95 Segments *segments) const {
92
93 bool PredictForRequest(const ConversionRequest &request,
94 Segments *segments) const override {
9695 predict_called_ = true;
9796 return return_value_;
9897 }
101100 return predict_called_;
102101 }
103102
104 virtual void Clear() {
103 void Clear() {
105104 predict_called_ = false;
106105 }
107106
108 virtual const string &GetPredictorName() const {
107 const string &GetPredictorName() const override {
109108 return predictor_name_;
110109 }
111110
117116
118117 class MockPredictor : public PredictorInterface {
119118 public:
120 MockPredictor() {}
121 virtual ~MockPredictor() {}
119 MockPredictor() = default;
120 ~MockPredictor() override = default;
122121 MOCK_CONST_METHOD2(
123122 PredictForRequest,
124123 bool(const ConversionRequest &request, Segments *segments));
129128
130129 class MobilePredictorTest : public ::testing::Test {
131130 protected:
132 virtual void SetUp() {
131 void SetUp() override {
133132 config_.reset(new config::Config);
134133 config::ConfigHandler::GetDefaultConfig(config_.get());
135134
3535
3636 #include "base/file_util.h"
3737 #include "base/port.h"
38 #include "data_manager/scoped_data_manager_initializer_for_testing.h"
3938 #include "engine/engine_factory.h"
4039 #include "protocol/commands.pb.h"
4140 #include "session/random_keyevents_generator.h"
6362 using session::testing::SessionHandlerTestBase;
6463 using session::testing::TestSessionClient;
6564
66 class SessionHandlerStressTest : public SessionHandlerTestBase {
67 protected:
68 virtual EngineInterface *CreateEngine() {
69 return EngineFactory::Create();
70 }
71
72 private:
73 scoped_data_manager_initializer_for_testing
74 scoped_data_manager_initializer_for_testing_;
75 };
76
77 TEST_F(SessionHandlerStressTest, BasicStressTest) {
65 TEST(SessionHandlerStressTest, BasicStressTest) {
7866 vector<commands::KeyEvent> keys;
7967 commands::Output output;
8068 std::unique_ptr<EngineInterface> engine(EngineFactory::Create());
3535 #include <string>
3636
3737 #include "base/port.h"
38 #include "data_manager/scoped_data_manager_initializer_for_testing.h"
3938 #include "protocol/commands.pb.h"
4039 #include "protocol/config.pb.h"
4140 #include "testing/base/public/gunit.h"
9392 int32 flags_last_command_timeout_backup_;
9493 int32 flags_last_create_session_timeout_backup_;
9594 bool flags_restricted_backup_;
96
97 scoped_data_manager_initializer_for_testing
98 scoped_data_manager_initializer_for_testing_;
9995 usage_stats::scoped_usage_stats_enabler usage_stats_enabler_;
10096
10197 DISALLOW_COPY_AND_ASSIGN(SessionHandlerTestBase);
4040 #include "composer/table.h"
4141 #include "config/config_handler.h"
4242 #include "converter/segments.h"
43 #include "data_manager/scoped_data_manager_initializer_for_testing.h"
4443 #include "engine/engine_factory.h"
4544 #include "protocol/candidates.pb.h"
4645 #include "protocol/commands.pb.h"
5554 #include "testing/base/public/googletest.h"
5655 #include "testing/base/public/gunit.h"
5756
58 DECLARE_string(test_srcdir);
59 DECLARE_string(test_tmpdir);
6057 DECLARE_bool(use_history_rewriter);
6158
6259 namespace mozc {
8582
8683 } // namespace
8784
88 class SessionRegressionTest : public testing::Test {
85 class SessionRegressionTest : public ::testing::Test {
8986 protected:
90 virtual void SetUp() {
87 void SetUp() override {
9188 SystemUtil::SetUserProfileDirectory(FLAGS_test_tmpdir);
9289
9390 orig_use_history_rewriter_ = FLAGS_use_history_rewriter;
10299 CHECK(session_.get());
103100 }
104101
105 virtual void TearDown() {
102 void TearDown() override {
106103 // just in case, reset the config in test_tmpdir
107104 config::Config config;
108105 config::ConfigHandler::GetDefaultConfig(&config);
159156 std::unique_ptr<session::Session> session_;
160157 std::unique_ptr<composer::Table> table_;
161158 config::Config config_;
162 scoped_data_manager_initializer_for_testing
163 scoped_data_manager_initializer_for_testing_;
164159 };
165160
166161
4141 'dependencies': [
4242 '../base/base.gyp:base',
4343 '../config/config.gyp:config_handler',
44 '../data_manager/data_manager_test.gyp:scoped_data_manager_initializer_for_testing',
4544 '../engine/engine.gyp:engine_factory',
4645 '../engine/engine.gyp:mock_data_engine_factory',
4746 '../protocol/protocol.gyp:commands_proto',
9796 'session_regression_test.cc',
9897 ],
9998 'dependencies': [
100 '../data_manager/data_manager_test.gyp:scoped_data_manager_initializer_for_testing',
10199 '../engine/engine.gyp:engine_factory',
102100 '../testing/testing.gyp:gtest_main',
103101 'session.gyp:session',
247245 'session_handler_stress_test.cc'
248246 ],
249247 'dependencies': [
250 '../data_manager/data_manager_test.gyp:scoped_data_manager_initializer_for_testing',
251248 '../engine/engine.gyp:engine_factory',
252249 '../testing/testing.gyp:gtest_main',
253250 'session.gyp:random_keyevents_generator',