OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 char kAnnotation[] = "Annotation"; |
| 15 const char kDescriptionTitle[] = "Description Title"; |
| 16 const char kDescriptionBody[] = "Description Body"; |
| 17 const IBusText::UnderlineAttribute kSampleUnderlineAttribute1 = { |
| 18 IBusText::IBUS_TEXT_UNDERLINE_SINGLE, 10, 20}; |
| 19 |
| 20 const IBusText::UnderlineAttribute kSampleUnderlineAttribute2 = { |
| 21 IBusText::IBUS_TEXT_UNDERLINE_DOUBLE, 11, 21}; |
| 22 |
| 23 const IBusText::UnderlineAttribute kSampleUnderlineAttribute3 = { |
| 24 IBusText::IBUS_TEXT_UNDERLINE_ERROR, 12, 22}; |
| 25 |
| 26 const IBusText::SelectionAttribute kSampleSelectionAttribute = {30, 40}; |
| 27 |
| 28 // Make IBusText |
| 29 IBusText text; |
| 30 text.set_text(kSampleText); |
| 31 text.set_annotation(kAnnotation); |
| 32 text.set_description_title(kDescriptionTitle); |
| 33 text.set_description_body(kDescriptionBody); |
| 34 std::vector<IBusText::UnderlineAttribute>* underline_attributes = |
| 35 text.mutable_underline_attributes(); |
| 36 underline_attributes->push_back(kSampleUnderlineAttribute1); |
| 37 underline_attributes->push_back(kSampleUnderlineAttribute2); |
| 38 underline_attributes->push_back(kSampleUnderlineAttribute3); |
| 39 std::vector<IBusText::SelectionAttribute>* selection_attributes = |
| 40 text.mutable_selection_attributes(); |
| 41 selection_attributes->push_back(kSampleSelectionAttribute); |
| 42 |
| 43 IBusText text2; |
| 44 text2.CopyFrom(text); |
| 45 |
| 46 EXPECT_EQ(text.text(), text2.text()); |
| 47 EXPECT_EQ(text.annotation(), text2.annotation()); |
| 48 EXPECT_EQ(text.description_title(), text2.description_title()); |
| 49 EXPECT_EQ(text.description_body(), text2.description_body()); |
| 50 |
| 51 EXPECT_EQ(text.underline_attributes().size(), |
| 52 text2.underline_attributes().size()); |
| 53 for (size_t i = 0; i < text.underline_attributes().size(); ++i) { |
| 54 EXPECT_EQ(text.underline_attributes()[i].type, |
| 55 text2.underline_attributes()[i].type); |
| 56 EXPECT_EQ(text.underline_attributes()[i].start_index, |
| 57 text2.underline_attributes()[i].start_index); |
| 58 EXPECT_EQ(text.underline_attributes()[i].end_index, |
| 59 text2.underline_attributes()[i].end_index); |
| 60 } |
| 61 |
| 62 EXPECT_EQ(text.selection_attributes().size(), |
| 63 text2.selection_attributes().size()); |
| 64 for (size_t i = 0; i < text.selection_attributes().size(); ++i) { |
| 65 EXPECT_EQ(text.selection_attributes()[i].start_index, |
| 66 text2.selection_attributes()[i].start_index); |
| 67 EXPECT_EQ(text.selection_attributes()[i].end_index, |
| 68 text2.selection_attributes()[i].end_index); |
| 69 } |
| 70 } |
| 71 |
| 72 } // namespace chromeos |
OLD | NEW |