Home | History | Annotate | Download | only in ime
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "chromeos/ime/extension_ime_util.h"
      6 
      7 #include <string>
      8 
      9 #include "testing/gtest/include/gtest/gtest.h"
     10 
     11 namespace chromeos {
     12 
     13 TEST(ExtensionIMEUtilTest, GetInputMethodIDTest) {
     14   EXPECT_EQ("_ext_ime_ABCDE12345",
     15             extension_ime_util::GetInputMethodID("ABCDE", "12345"));
     16 }
     17 
     18 TEST(ExtensionIMEUtilTest, GetComponentInputMethodID) {
     19   EXPECT_EQ("_comp_ime_ABCDE12345",
     20             extension_ime_util::GetComponentInputMethodID("ABCDE", "12345"));
     21 }
     22 
     23 TEST(ExtensionIMEUtilTest, GetExtensionIDFromInputMethodIDTest) {
     24   EXPECT_EQ("",
     25             extension_ime_util::GetExtensionIDFromInputMethodID("mozc"));
     26   EXPECT_EQ("12345678901234567890123456789012",
     27             extension_ime_util::GetExtensionIDFromInputMethodID(
     28               extension_ime_util::GetInputMethodID(
     29                   "12345678901234567890123456789012",
     30                   "mozc")));
     31   EXPECT_EQ("12345678901234567890123456789012",
     32             extension_ime_util::GetExtensionIDFromInputMethodID(
     33               extension_ime_util::GetComponentInputMethodID(
     34                   "12345678901234567890123456789012",
     35                   "mozc")));
     36 }
     37 
     38 TEST(ExtensionIMEUtilTest, IsExtensionIMETest) {
     39   EXPECT_TRUE(extension_ime_util::IsExtensionIME(
     40       extension_ime_util::GetInputMethodID(
     41           "abcde_xxxxxxxxxxxxxxxxxxxxxxxxxx", "12345")));
     42   EXPECT_FALSE(extension_ime_util::IsExtensionIME(
     43       extension_ime_util::GetComponentInputMethodID(
     44           "abcde_xxxxxxxxxxxxxxxxxxxxxxxxxx", "12345")));
     45   EXPECT_FALSE(extension_ime_util::IsExtensionIME(""));
     46   EXPECT_FALSE(extension_ime_util::IsExtensionIME("mozc"));
     47 }
     48 
     49 TEST(ExtensionIMEUtilTest, IsComponentExtensionIMETest) {
     50   EXPECT_TRUE(extension_ime_util::IsComponentExtensionIME(
     51       extension_ime_util::GetComponentInputMethodID(
     52           "abcde_xxxxxxxxxxxxxxxxxxxxxxxxxx", "12345")));
     53   EXPECT_FALSE(extension_ime_util::IsComponentExtensionIME(
     54       extension_ime_util::GetInputMethodID(
     55           "abcde_xxxxxxxxxxxxxxxxxxxxxxxxxx", "12345")));
     56   EXPECT_FALSE(extension_ime_util::IsComponentExtensionIME(""));
     57   EXPECT_FALSE(extension_ime_util::IsComponentExtensionIME("mozc"));
     58 }
     59 
     60 TEST(ExtensionIMEUtilTest, IsMemberOfExtension) {
     61   const char* extention1 = "abcdefg";
     62   const char* extention2 = "hijklmn";
     63   const char* extention3 = "opqrstu";
     64   const char* engine_id1 = "12345";
     65   const char* engine_id2 = "67890";
     66   const char* engine_id3 = "31415";
     67 
     68   const std::string extention_1_engine_1 =
     69       extension_ime_util::GetInputMethodID(extention1, engine_id1);
     70   const std::string extention_1_engine_2 =
     71       extension_ime_util::GetInputMethodID(extention1, engine_id2);
     72   const std::string component_3_engine_3 =
     73       extension_ime_util::GetComponentInputMethodID(extention3, engine_id3);
     74 
     75   EXPECT_TRUE(extension_ime_util::IsMemberOfExtension(extention_1_engine_1,
     76                                                       extention1));
     77   EXPECT_TRUE(extension_ime_util::IsMemberOfExtension(extention_1_engine_2,
     78                                                       extention1));
     79   EXPECT_FALSE(extension_ime_util::IsMemberOfExtension(extention_1_engine_1,
     80                                                        extention2));
     81   EXPECT_FALSE(extension_ime_util::IsMemberOfExtension(extention_1_engine_2,
     82                                                        extention2));
     83   EXPECT_FALSE(extension_ime_util::IsMemberOfExtension(component_3_engine_3,
     84                                                        extention3));
     85 }
     86 
     87 }  // namespace chromeos
     88