Stop using PackedDataManager in unit tests
This CL eliminates the use of PackedDataManager except in Chrome OS.
BUG=
TEST=
REF_BUG=26841123
REF_CL=117309545
REF_TIME=2016-03-16T13:47:37+09:00
REF_TIME_RAW=1458103657 +0900
Noriyuki Takahashi
8 years ago
173 | 173 | '../../config/config.gyp:config_handler', |
174 | 174 | '../../dictionary/dictionary_base.gyp:user_dictionary', |
175 | 175 | '../../dictionary/dictionary_base.gyp:user_pos', |
176 | '../../engine/engine.gyp:packed_engine_factory', | |
176 | 177 | '../../net/net.gyp:http_client', |
177 | 178 | '../../net/net.gyp:json_util', |
178 | 179 | '../../protocol/protocol.gyp:commands_proto', |
54 | 54 | #include "data_manager/packed/packed_data_manager.h" |
55 | 55 | #include "dictionary/user_dictionary_util.h" |
56 | 56 | #include "dictionary/user_pos.h" |
57 | #include "engine/engine_factory.h" | |
57 | #include "engine/packed_engine_factory.h" | |
58 | 58 | #include "net/http_client.h" |
59 | 59 | #include "net/http_client_pepper.h" |
60 | 60 | #include "net/json_util.h" |
201 | 201 | user_pos_.reset(dictionary::UserPOS::CreateFromDataManager( |
202 | 202 | *packed::PackedDataManager::GetUserPosManager())); |
203 | 203 | |
204 | engine_.reset(mozc::EngineFactory::Create()); | |
204 | engine_.reset(mozc::PackedEngineFactory::Create()); | |
205 | 205 | handler_.reset(new SessionHandler(engine_.get())); |
206 | 206 | |
207 | 207 | #ifdef GOOGLE_JAPANESE_INPUT_BUILD |
42 | 42 | #include "protocol/config.pb.h" |
43 | 43 | #include "request/conversion_request.h" |
44 | 44 | #include "testing/base/public/gunit.h" |
45 | ||
46 | #ifdef MOZC_USE_PACKED_DICTIONARY | |
47 | #ifdef MOZC_BUILD | |
48 | #include "data_manager/packed/packed_data_oss.h" | |
49 | #endif // MOZC_BUILD | |
50 | ||
51 | #include "data_manager/packed/packed_data_manager.h" | |
52 | #endif // MOZC_USE_PACKED_DICTIONARY | |
53 | ||
54 | DECLARE_string(test_srcdir); | |
55 | DECLARE_string(test_tmpdir); | |
45 | #include "testing/base/public/mozctest.h" | |
56 | 46 | |
57 | 47 | namespace mozc { |
58 | 48 | |
63 | 53 | using mozc::config::ConfigHandler; |
64 | 54 | |
65 | 55 | class ConverterRegressionTest : public ::testing::Test { |
66 | protected: | |
67 | ConverterRegressionTest() { | |
68 | } | |
69 | virtual ~ConverterRegressionTest() { | |
70 | } | |
71 | ||
72 | virtual void SetUp() { | |
73 | user_profile_directory_backup_ = SystemUtil::GetUserProfileDirectory(); | |
74 | SystemUtil::SetUserProfileDirectory(FLAGS_test_tmpdir); | |
75 | #ifdef MOZC_USE_PACKED_DICTIONARY | |
76 | // Use a full-size dictionary for regression tests. | |
77 | std::unique_ptr<mozc::packed::PackedDataManager> | |
78 | data_manager(new mozc::packed::PackedDataManager); | |
79 | CHECK(data_manager->Init(string(kPackedSystemDictionary_data, | |
80 | kPackedSystemDictionary_size))); | |
81 | mozc::packed::RegisterPackedDataManager(data_manager.release()); | |
82 | #endif // MOZC_USE_PACKED_DICTIONARY | |
83 | } | |
84 | ||
85 | virtual void TearDown() { | |
86 | #ifdef MOZC_USE_PACKED_DICTIONARY | |
87 | mozc::packed::RegisterPackedDataManager(nullptr); | |
88 | #endif // MOZC_USE_PACKED_DICTIONARY | |
89 | SystemUtil::SetUserProfileDirectory(user_profile_directory_backup_); | |
90 | } | |
91 | ||
92 | 56 | private: |
93 | string user_profile_directory_backup_; | |
57 | const testing::ScopedTmpUserProfileDirectory scoped_profile_dir_; | |
94 | 58 | }; |
95 | 59 | |
96 | 60 | TEST_F(ConverterRegressionTest, QueryOfDeathTest) { |
91 | 91 | '../protocol/protocol.gyp:commands_proto', |
92 | 92 | '../session/session_base.gyp:request_test_util', |
93 | 93 | '../testing/testing.gyp:gtest_main', |
94 | ], | |
95 | 'conditions': [ | |
96 | ['use_packed_dictionary==1 and branding=="Mozc"', { | |
97 | 'dependencies': [ | |
98 | '../data_manager/packed/packed_data_manager.gyp:gen_packed_data_header_oss#host', | |
99 | '../data_manager/packed/packed_data_manager_base.gyp:packed_data_manager', | |
100 | ], | |
101 | }], | |
94 | '../testing/testing.gyp:mozctest', | |
102 | 95 | ], |
103 | 96 | }, |
104 | 97 | { |
45 | 45 | #include "protocol/commands.pb.h" |
46 | 46 | #include "protocol/config.pb.h" |
47 | 47 | #include "session/request_test_util.h" |
48 | #include "testing/base/public/googletest.h" | |
49 | 48 | #include "testing/base/public/gunit.h" |
50 | ||
51 | #ifdef MOZC_USE_PACKED_DICTIONARY | |
52 | #include "data_manager/packed/packed_data_oss.h" | |
53 | #include "data_manager/packed/packed_data_manager.h" | |
54 | #endif // MOZC_USE_PACKED_DICTIONARY | |
49 | #include "testing/base/public/mozctest.h" | |
55 | 50 | |
56 | 51 | using mozc::quality_regression::QualityRegressionUtil; |
57 | 52 | |
66 | 61 | |
67 | 62 | namespace { |
68 | 63 | |
69 | class QualityRegressionTest : public testing::Test { | |
64 | class QualityRegressionTest : public ::testing::Test { | |
70 | 65 | protected: |
71 | virtual void SetUp() { | |
72 | SystemUtil::SetUserProfileDirectory(FLAGS_test_tmpdir); | |
73 | ||
74 | #ifdef MOZC_USE_PACKED_DICTIONARY | |
75 | // Registers full-size PackedDataManager. | |
76 | std::unique_ptr<mozc::packed::PackedDataManager> data_manager( | |
77 | new mozc::packed::PackedDataManager()); | |
78 | CHECK(data_manager->Init(string(kPackedSystemDictionary_data, | |
79 | kPackedSystemDictionary_size))); | |
80 | mozc::packed::RegisterPackedDataManager(data_manager.release()); | |
81 | #endif // MOZC_USE_PACKED_DICTIONARY | |
82 | } | |
83 | ||
84 | virtual void TearDown() { | |
85 | #ifdef MOZC_USE_PACKED_DICTIONARY | |
86 | // Unregisters mocked PackedDataManager. | |
87 | mozc::packed::RegisterPackedDataManager(nullptr); | |
88 | #endif // MOZC_USE_PACKED_DICTIONARY | |
89 | } | |
90 | ||
91 | 66 | static void RunTestForPlatform(uint32 platform, QualityRegressionUtil *util) { |
92 | 67 | CHECK(util); |
93 | 68 | map<string, vector<pair<float, string>>> results, disabled_results; |
176 | 151 | } |
177 | 152 | } |
178 | 153 | } |
154 | ||
155 | private: | |
156 | const testing::ScopedTmpUserProfileDirectory scoped_profile_dir_; | |
179 | 157 | }; |
180 | 158 | |
181 | 159 |
134 | 134 | 'oss_engine_factory', |
135 | 135 | ], |
136 | 136 | 'conditions': [ |
137 | ['use_packed_dictionary==1', { | |
138 | 'dependencies': [ | |
139 | 'packed_engine_factory' | |
140 | ], | |
141 | 'dependencies!': [ | |
142 | 'oss_engine_factory', | |
143 | ] | |
144 | }], | |
145 | 137 | ], |
146 | 138 | }, |
147 | 139 | ], |
30 | 30 | #define MOZC_ENGINE_ENGINE_FACTORY_H_ |
31 | 31 | |
32 | 32 | |
33 | #if defined(MOZC_USE_PACKED_DICTIONARY) | |
34 | #include "engine/packed_engine_factory.h" | |
35 | namespace mozc { | |
36 | typedef PackedEngineFactory EngineFactory; | |
37 | } | |
38 | #else // !MOZC_USE_PACKED_DICTIONARY | |
39 | 33 | #include "engine/oss_engine_factory.h" |
40 | 34 | namespace mozc { |
41 | 35 | typedef OssEngineFactory EngineFactory; |
42 | 36 | } |
43 | #endif // MOZC_USE_PACKED_DICTIONARY | |
44 | 37 | |
45 | 38 | #endif // MOZC_ENGINE_ENGINE_FACTORY_H_ |
32 | 32 | #include <string> |
33 | 33 | |
34 | 34 | #include "base/logging.h" |
35 | #ifdef MOZC_USE_PACKED_DICTIONARY | |
36 | #include "data_manager/packed/packed_data_manager.h" | |
37 | #include "data_manager/packed/packed_data_mock.h" | |
38 | #endif // MOZC_USE_PACKED_DICTIONARY | |
39 | 35 | #include "engine/engine_interface.h" |
40 | 36 | #include "prediction/predictor_interface.h" |
41 | 37 | #include "testing/base/public/gunit.h" |
42 | 38 | |
43 | 39 | namespace mozc { |
44 | 40 | |
45 | class EngineFactoryTest : public testing::Test { | |
46 | protected: | |
47 | virtual void SetUp() { | |
48 | #ifdef MOZC_USE_PACKED_DICTIONARY | |
49 | // Registers mocked PackedDataManager. | |
50 | std::unique_ptr<packed::PackedDataManager> | |
51 | data_manager(new packed::PackedDataManager()); | |
52 | CHECK(data_manager->Init(string(kPackedSystemDictionary_data, | |
53 | kPackedSystemDictionary_size))); | |
54 | packed::RegisterPackedDataManager(data_manager.release()); | |
55 | #endif // MOZC_USE_PACKED_DICTIONARY | |
56 | } | |
57 | ||
58 | virtual void TearDown() { | |
59 | #ifdef MOZC_USE_PACKED_DICTIONARY | |
60 | // Unregisters mocked PackedDataManager. | |
61 | packed::RegisterPackedDataManager(nullptr); | |
62 | #endif // MOZC_USE_PACKED_DICTIONARY | |
63 | } | |
64 | }; | |
65 | ||
66 | TEST_F(EngineFactoryTest, MobilePredictorOnAndroid) { | |
41 | TEST(EngineFactoryTest, MobilePredictorOnAndroid) { | |
67 | 42 | std::unique_ptr<EngineInterface> engine(EngineFactory::Create()); |
68 | 43 | PredictorInterface *predictor = engine->GetPredictor(); |
69 | 44 | #ifdef OS_ANDROID |