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 // TODO(nona): Add more tests. 5 6 #include "chromeos/ime/ibus_text.h" 7 8 #include "testing/gtest/include/gtest/gtest.h" 9 10 namespace chromeos { 11 12 TEST(IBusTextTest, CopyTest) { 13 const char kSampleText[] = "Sample Text"; 14 const IBusText::UnderlineAttribute kSampleUnderlineAttribute1 = { 15 IBusText::IBUS_TEXT_UNDERLINE_SINGLE, 10, 20}; 16 17 const IBusText::UnderlineAttribute kSampleUnderlineAttribute2 = { 18 IBusText::IBUS_TEXT_UNDERLINE_DOUBLE, 11, 21}; 19 20 const IBusText::UnderlineAttribute kSampleUnderlineAttribute3 = { 21 IBusText::IBUS_TEXT_UNDERLINE_ERROR, 12, 22}; 22 23 // Make IBusText 24 IBusText text; 25 text.set_text(kSampleText); 26 std::vector<IBusText::UnderlineAttribute>* underline_attributes = 27 text.mutable_underline_attributes(); 28 underline_attributes->push_back(kSampleUnderlineAttribute1); 29 underline_attributes->push_back(kSampleUnderlineAttribute2); 30 underline_attributes->push_back(kSampleUnderlineAttribute3); 31 text.set_selection_start(30); 32 text.set_selection_end(40); 33 34 IBusText text2; 35 text2.CopyFrom(text); 36 37 EXPECT_EQ(text.text(), text2.text()); 38 EXPECT_EQ(text.underline_attributes().size(), 39 text2.underline_attributes().size()); 40 for (size_t i = 0; i < text.underline_attributes().size(); ++i) { 41 EXPECT_EQ(text.underline_attributes()[i].type, 42 text2.underline_attributes()[i].type); 43 EXPECT_EQ(text.underline_attributes()[i].start_index, 44 text2.underline_attributes()[i].start_index); 45 EXPECT_EQ(text.underline_attributes()[i].end_index, 46 text2.underline_attributes()[i].end_index); 47 } 48 49 EXPECT_EQ(text.selection_start(), text2.selection_start()); 50 EXPECT_EQ(text.selection_end(), text2.selection_end()); 51 } 52 53 } // namespace chromeos 54