@@ -295,132 +295,6 @@ TEST_F(UserDictionaryStorageTest, GetUserDictionaryIdTest) {
295
295
EXPECT_EQ (ret_id[1 ], id[1 ]);
296
296
}
297
297
298
- TEST_F (UserDictionaryStorageTest, ConvertSyncDictionariesToNormalDictionaries) {
299
- // "名詞"
300
- const UserDictionary::PosType kPos = UserDictionary::NOUN;
301
-
302
- const struct TestData {
303
- bool is_sync_dictionary;
304
- bool is_removed_dictionary;
305
- bool has_normal_entry;
306
- bool has_removed_entry;
307
- std::string dictionary_name;
308
- } test_data[] = {
309
- {false , false , false , false , " non-sync dictionary (empty)" },
310
- {false , false , true , false , " non-sync dictionary (normal entry)" },
311
- {true , false , false , false , " sync dictionary (empty)" },
312
- {true , false , false , true , " sync dictionary (removed entry)" },
313
- {true , false , true , false , " sync dictionary (normal entry)" },
314
- {true , false , true , true , " sync dictionary (normal & removed entries)" },
315
- {true , true , false , false , " removed sync dictionary (empty)" },
316
- {true , true , false , true , " removed sync dictionary (removed entry)" },
317
- {true , true , true , false , " removed sync dictionary (normal entry)" },
318
- {true , true , true , true ,
319
- " removed sync dictionary (normal & removed entries)" },
320
- {true , false , true , false ,
321
- UserDictionaryStorage::default_sync_dictionary_name ()},
322
- };
323
-
324
- UserDictionaryStorage storage (GetUserDictionaryFile ());
325
- EXPECT_FALSE (storage.Load ().ok ())
326
- << " At first, we expect there is not user dictionary file." ;
327
- EXPECT_FALSE (storage.ConvertSyncDictionariesToNormalDictionaries ())
328
- << " No sync dictionary available." ;
329
-
330
- for (size_t i = 0 ; i < std::size (test_data); ++i) {
331
- SCOPED_TRACE (absl::StrFormat (" add %d" , static_cast <int >(i)));
332
- const TestData &data = test_data[i];
333
- CHECK (data.is_sync_dictionary ||
334
- !(data.is_removed_dictionary || data.has_removed_entry ))
335
- << " Non-sync dictionary should NOT have removed dictionary / entry." ;
336
-
337
- uint64_t dict_id = 0 ;
338
- ASSERT_TRUE (storage.CreateDictionary (data.dictionary_name , &dict_id));
339
- UserDictionaryStorage::UserDictionary *dict =
340
- storage.GetProto ().mutable_dictionaries (
341
- storage.GetUserDictionaryIndex (dict_id));
342
- dict->set_syncable (data.is_sync_dictionary );
343
- dict->set_removed (data.is_removed_dictionary );
344
- if (data.has_normal_entry ) {
345
- UserDictionaryStorage::UserDictionaryEntry *entry = dict->add_entries ();
346
- entry->set_key (" normal" );
347
- entry->set_value (" normal entry" );
348
- entry->set_pos (kPos );
349
- }
350
- if (data.has_removed_entry ) {
351
- UserDictionaryStorage::UserDictionaryEntry *entry = dict->add_entries ();
352
- entry->set_key (" removed" );
353
- entry->set_value (" removed entry" );
354
- entry->set_pos (kPos );
355
- entry->set_removed (true );
356
- }
357
- }
358
- EXPECT_EQ (
359
- UserDictionaryStorage::CountSyncableDictionaries (storage.GetProto ()), 9 );
360
-
361
- ASSERT_TRUE (storage.ConvertSyncDictionariesToNormalDictionaries ());
362
-
363
- constexpr char kDictionaryNameConvertedFromSyncableDictionary [] =
364
- " 同期用辞書" ;
365
- const struct ExpectedData {
366
- bool has_normal_entry;
367
- std::string dictionary_name;
368
- } expected_data[] = {
369
- {false , " non-sync dictionary (empty)" },
370
- {true , " non-sync dictionary (normal entry)" },
371
- {true , " sync dictionary (normal entry)" },
372
- {true , " sync dictionary (normal & removed entries)" },
373
- {true , kDictionaryNameConvertedFromSyncableDictionary },
374
- };
375
-
376
- EXPECT_EQ (
377
- 0 , UserDictionaryStorage::CountSyncableDictionaries (storage.GetProto ()));
378
- ASSERT_EQ (std::size (expected_data), storage.GetProto ().dictionaries_size ());
379
- for (size_t i = 0 ; i < std::size (expected_data); ++i) {
380
- SCOPED_TRACE (absl::StrFormat (" verify %d" , static_cast <int >(i)));
381
- const ExpectedData &expected = expected_data[i];
382
- const UserDictionaryStorage::UserDictionary &dict =
383
- storage.GetProto ().dictionaries (i);
384
-
385
- EXPECT_EQ (dict.name (), expected.dictionary_name );
386
- EXPECT_FALSE (dict.syncable ());
387
- EXPECT_FALSE (dict.removed ());
388
- if (expected.has_normal_entry ) {
389
- ASSERT_EQ (dict.entries_size (), 1 );
390
- EXPECT_EQ (dict.entries (0 ).key (), " normal" );
391
- } else {
392
- EXPECT_EQ (dict.entries_size (), 0 );
393
- }
394
- }
395
-
396
- // Test duplicated dictionary name.
397
- storage.GetProto ().Clear ();
398
- {
399
- uint64_t dict_id = 0 ;
400
- storage.CreateDictionary (
401
- UserDictionaryStorage::default_sync_dictionary_name (), &dict_id);
402
- storage.CreateDictionary (kDictionaryNameConvertedFromSyncableDictionary ,
403
- &dict_id);
404
- ASSERT_EQ (2 , storage.GetProto ().dictionaries_size ());
405
- UserDictionaryStorage::UserDictionary *dict;
406
- dict = storage.GetProto ().mutable_dictionaries (0 );
407
- dict->set_syncable (true );
408
- dict->add_entries ()->set_key (" 0" );
409
- dict = storage.GetProto ().mutable_dictionaries (1 );
410
- dict->set_syncable (false );
411
- dict->add_entries ()->set_key (" 1" );
412
- }
413
- ASSERT_TRUE (storage.ConvertSyncDictionariesToNormalDictionaries ());
414
- EXPECT_EQ (
415
- UserDictionaryStorage::CountSyncableDictionaries (storage.GetProto ()), 0 );
416
- EXPECT_EQ (storage.GetProto ().dictionaries_size (), 2 );
417
- EXPECT_EQ (
418
- storage.GetProto ().dictionaries (0 ).name (),
419
- absl::StrFormat (" %s_1" , kDictionaryNameConvertedFromSyncableDictionary ));
420
- EXPECT_EQ (storage.GetProto ().dictionaries (1 ).name (),
421
- kDictionaryNameConvertedFromSyncableDictionary );
422
- }
423
-
424
298
TEST_F (UserDictionaryStorageTest, Export) {
425
299
constexpr int kDummyDictionaryId = 10 ;
426
300
TempDirectory temp_dir = testing::MakeTempDirectoryOrDie ();
0 commit comments