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 "unix/ibus/mozc_engine.h"
31 
32 #include <memory>
33 
34 #include "base/port.h"
35 #include "client/client_mock.h"
36 #include "protocol/commands.pb.h"
37 #include "testing/base/public/gunit.h"
38 
39 using std::unique_ptr;
40 
41 namespace mozc {
42 namespace ibus {
43 
44 class LaunchToolTest : public testing::Test {
45  public:
LaunchToolTest()46   LaunchToolTest() {
47     g_type_init();
48   }
49 
50  protected:
SetUp()51   virtual void SetUp() {
52     mozc_engine_.reset(new MozcEngine());
53 
54     mock_ = new client::ClientMock();
55     mock_->ClearFunctionCounter();
56     mozc_engine_->client_.reset(mock_);
57   }
58 
TearDown()59   virtual void TearDown() {
60     mozc_engine_.reset();
61   }
62 
63   client::ClientMock* mock_;
64   unique_ptr<MozcEngine> mozc_engine_;
65 
66  private:
67   DISALLOW_COPY_AND_ASSIGN(LaunchToolTest);
68 };
69 
TEST_F(LaunchToolTest,LaunchToolTest)70 TEST_F(LaunchToolTest, LaunchToolTest) {
71   commands::Output output;
72 
73   // Launch config dialog
74   mock_->ClearFunctionCounter();
75   mock_->SetBoolFunctionReturn("LaunchToolWithProtoBuf", true);
76   output.set_launch_tool_mode(commands::Output::CONFIG_DIALOG);
77   EXPECT_TRUE(mozc_engine_->LaunchTool(output));
78 
79   // Launch dictionary tool
80   mock_->ClearFunctionCounter();
81   mock_->SetBoolFunctionReturn("LaunchToolWithProtoBuf", true);
82   output.set_launch_tool_mode(commands::Output::DICTIONARY_TOOL);
83   EXPECT_TRUE(mozc_engine_->LaunchTool(output));
84 
85   // Launch word register dialog
86   mock_->ClearFunctionCounter();
87   mock_->SetBoolFunctionReturn("LaunchToolWithProtoBuf", true);
88   output.set_launch_tool_mode(commands::Output::WORD_REGISTER_DIALOG);
89   EXPECT_TRUE(mozc_engine_->LaunchTool(output));
90 
91   // Launch no tool(means do nothing)
92   mock_->ClearFunctionCounter();
93   mock_->SetBoolFunctionReturn("LaunchToolWithProtoBuf", false);
94   output.set_launch_tool_mode(commands::Output::NO_TOOL);
95   EXPECT_FALSE(mozc_engine_->LaunchTool(output));
96 
97   // Something occurring in client::Client::LaunchTool
98   mock_->ClearFunctionCounter();
99   mock_->SetBoolFunctionReturn("LaunchToolWithProtoBuf", false);
100   output.set_launch_tool_mode(commands::Output::CONFIG_DIALOG);
101   EXPECT_FALSE(mozc_engine_->LaunchTool(output));
102 }
103 
104 }  // namespace ibus
105 }  // namespace mozc
106