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("abcde", "12345")));
     41   EXPECT_FALSE(extension_ime_util::IsExtensionIME(
     42       extension_ime_util::GetComponentInputMethodID("abcde", "12345")));
     43   EXPECT_FALSE(extension_ime_util::IsExtensionIME(""));
     44   EXPECT_FALSE(extension_ime_util::IsExtensionIME("mozc"));
     45 }
     46 
     47 TEST(ExtensionIMEUtilTest, IsComponentExtensionIMETest) {
     48   EXPECT_TRUE(extension_ime_util::IsComponentExtensionIME(
     49       extension_ime_util::GetComponentInputMethodID("abcde", "12345")));
     50   EXPECT_FALSE(extension_ime_util::IsComponentExtensionIME(
     51       extension_ime_util::GetInputMethodID("abcde", "12345")));
     52   EXPECT_FALSE(extension_ime_util::IsComponentExtensionIME(""));
     53   EXPECT_FALSE(extension_ime_util::IsComponentExtensionIME("mozc"));
     54 }
     55 
     56 TEST(ExtensionIMEUtilTest, IsMemberOfExtension) {
     57   const char* extention1 = "abcdefg";
     58   const char* extention2 = "hijklmn";
     59   const char* extention3 = "opqrstu";
     60   const char* engine_id1 = "12345";
     61   const char* engine_id2 = "67890";
     62   const char* engine_id3 = "31415";
     63 
     64   const std::string extention_1_engine_1 =
     65       extension_ime_util::GetInputMethodID(extention1, engine_id1);
     66   const std::string extention_1_engine_2 =
     67       extension_ime_util::GetInputMethodID(extention1, engine_id2);
     68   const std::string component_3_engine_3 =
     69       extension_ime_util::GetComponentInputMethodID(extention3, engine_id3);
     70 
     71   EXPECT_TRUE(extension_ime_util::IsMemberOfExtension(extention_1_engine_1,
     72                                                       extention1));
     73   EXPECT_TRUE(extension_ime_util::IsMemberOfExtension(extention_1_engine_2,
     74                                                       extention1));
     75   EXPECT_FALSE(extension_ime_util::IsMemberOfExtension(extention_1_engine_1,
     76                                                        extention2));
     77   EXPECT_FALSE(extension_ime_util::IsMemberOfExtension(extention_1_engine_2,
     78                                                        extention2));
     79   EXPECT_FALSE(extension_ime_util::IsMemberOfExtension(component_3_engine_3,
     80                                                        extention3));
     81 }
     82 
     83 }  // namespace chromeos
     84