1 // Copyright 2010-2018, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 //     * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 //     * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 //     * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 #include "composer/internal/composition_input.h"
31 
32 #include "composer/internal/transliterators.h"
33 #include "testing/base/public/gunit.h"
34 
35 namespace mozc {
36 namespace composer {
37 
TEST(CompositionInputTest,BasicTest)38 TEST(CompositionInputTest, BasicTest) {
39   const TransliteratorInterface *kT12r =
40     Transliterators::GetTransliterator(Transliterators::RAW_STRING);
41   CompositionInput input;
42 
43   {  // Initial status.
44     EXPECT_TRUE(input.Empty());
45     EXPECT_TRUE(input.raw().empty());
46     EXPECT_FALSE(input.has_conversion());
47     EXPECT_TRUE(input.conversion().empty());
48     EXPECT_FALSE(input.is_new_input());
49     EXPECT_TRUE(NULL == input.transliterator());
50   }
51 
52   {  // Value setting
53     input.set_raw("raw");
54     input.set_conversion("conversion");
55     input.set_is_new_input(true);
56     input.set_transliterator(kT12r);
57 
58     EXPECT_FALSE(input.Empty());
59     EXPECT_EQ("raw", input.raw());
60     EXPECT_TRUE(input.has_conversion());
61     EXPECT_EQ("conversion", input.conversion());
62     EXPECT_TRUE(input.is_new_input());
63     EXPECT_TRUE(kT12r == input.transliterator());
64   }
65 
66   CompositionInput input2;
67   {  // CopyFrom and Clear
68     input2.CopyFrom(input);
69     input.Clear();
70     EXPECT_TRUE(input.Empty());
71     EXPECT_TRUE(input.raw().empty());
72     EXPECT_FALSE(input.has_conversion());
73     EXPECT_TRUE(input.conversion().empty());
74     EXPECT_FALSE(input.is_new_input());
75     EXPECT_TRUE(NULL == input.transliterator());
76 
77     EXPECT_FALSE(input2.Empty());
78     EXPECT_EQ("raw", input2.raw());
79     EXPECT_TRUE(input2.has_conversion());
80     EXPECT_EQ("conversion", input2.conversion());
81     EXPECT_TRUE(input2.is_new_input());
82     EXPECT_TRUE(kT12r == input2.transliterator());
83   }
84 
85   {  // Empty conversion string is also a value value.
86     input2.set_conversion("");
87     EXPECT_TRUE(input2.conversion().empty());
88     EXPECT_TRUE(input2.has_conversion());
89   }
90 
91   {  // Mutable conversion
92     ASSERT_TRUE(input.Empty());
93     EXPECT_FALSE(input.has_conversion());
94     EXPECT_TRUE(input.mutable_conversion()->empty());
95     EXPECT_TRUE(input.has_conversion());
96     input.mutable_conversion()->assign("mutable_conversion");
97     EXPECT_EQ("mutable_conversion", input.conversion());
98 
99     ASSERT_FALSE(input2.Empty());
100     EXPECT_TRUE(input2.has_conversion());
101   }
102 }
103 
104 }  // namespace composer
105 }  // namespace mozc
106