1 /*
2  * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License, version 2.0,
6  * as published by the Free Software Foundation.
7  *
8  * This program is also distributed with certain software (including
9  * but not limited to OpenSSL) that is licensed under separate terms,
10  * as designated in a particular file or component or in included license
11  * documentation.  The authors of MySQL hereby grant you an additional
12  * permission to link the program and your derivative works with the
13  * separately licensed software that they have included with MySQL.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License, version 2.0, for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23  */
24 
25 #include "unittest/gunit/xplugin/xcl/protocol_t.h"
26 
27 namespace xcl {
28 namespace test {
29 
30 class Xcl_protocol_impl_error_tests : public Xcl_protocol_impl_tests {
31  public:
32   const int expected_error_code = 2333;
33   const char *expected_error_txt = "error text";
34 };
35 
TEST_F(Xcl_protocol_impl_error_tests,execute_close)36 TEST_F(Xcl_protocol_impl_error_tests, execute_close) {
37   XProtocol::Server_message_type_id out_smid;
38   XProtocol::Client_message_type_id out_cmid{
39       Mysqlx::ClientMessages::Type::ClientMessages_Type_CON_CLOSE};
40   XError out_error;
41   Mysqlx::Session::Reset reset;
42 
43   m_context->m_global_error = XError{expected_error_code, expected_error_txt};
44 
45   ASSERT_EQ(nullptr, m_sut->recv_single_message(&out_smid, &out_error));
46   ASSERT_EQ(expected_error_code, out_error.error());
47   ASSERT_STREQ(expected_error_txt, out_error.what());
48 
49   ASSERT_EQ(expected_error_code,
50             m_sut->send(out_cmid, *static_cast<XProtocol::Message *>(&reset))
51                 .error());
52 
53   ASSERT_EQ(expected_error_code,
54             m_sut->send(Mysqlx::Session::AuthenticateContinue()).error());
55 
56   ASSERT_EQ(expected_error_code, m_sut->send(Mysqlx::Session::Reset()).error());
57 
58   ASSERT_EQ(expected_error_code, m_sut->send(Mysqlx::Session::Close()).error());
59 
60   ASSERT_EQ(expected_error_code,
61             m_sut->send(Mysqlx::Sql::StmtExecute()).error());
62 
63   ASSERT_EQ(expected_error_code, m_sut->send(Mysqlx::Crud::Find()).error());
64 
65   ASSERT_EQ(expected_error_code, m_sut->send(Mysqlx::Crud::Insert()).error());
66 
67   ASSERT_EQ(expected_error_code, m_sut->send(Mysqlx::Crud::Update()).error());
68 
69   ASSERT_EQ(expected_error_code,
70             m_sut->send(Mysqlx::Crud::CreateView()).error());
71 
72   ASSERT_EQ(expected_error_code,
73             m_sut->send(Mysqlx::Crud::ModifyView()).error());
74 
75   ASSERT_EQ(expected_error_code, m_sut->send(Mysqlx::Crud::DropView()).error());
76 
77   ASSERT_EQ(expected_error_code, m_sut->send(Mysqlx::Expect::Open()).error());
78 
79   ASSERT_EQ(expected_error_code, m_sut->send(Mysqlx::Expect::Close()).error());
80 
81   ASSERT_EQ(expected_error_code,
82             m_sut->send(Mysqlx::Connection::CapabilitiesGet()).error());
83 
84   ASSERT_EQ(expected_error_code,
85             m_sut->send(Mysqlx::Connection::CapabilitiesSet()).error());
86 
87   ASSERT_EQ(expected_error_code,
88             m_sut->send(Mysqlx::Connection::Close()).error());
89 
90   ASSERT_EQ(nullptr, m_sut->recv_resultset(&out_error));
91   ASSERT_EQ(expected_error_code, out_error.error());
92   ASSERT_STREQ(expected_error_txt, out_error.what());
93 
94   ASSERT_EQ(expected_error_code, m_sut->recv_ok().error());
95 
96   ASSERT_EQ(expected_error_code, m_sut->execute_close().error());
97 
98   ASSERT_EQ(nullptr,
99             m_sut->execute_with_resultset(out_cmid, reset, &out_error));
100   ASSERT_EQ(expected_error_code, out_error.error());
101   ASSERT_STREQ(expected_error_txt, out_error.what());
102 
103   ASSERT_EQ(nullptr,
104             m_sut->execute_stmt(Mysqlx::Sql::StmtExecute(), &out_error));
105   ASSERT_EQ(expected_error_code, out_error.error());
106   ASSERT_STREQ(expected_error_txt, out_error.what());
107 
108   ASSERT_EQ(nullptr, m_sut->execute_find(Mysqlx::Crud::Find(), &out_error));
109   ASSERT_EQ(expected_error_code, out_error.error());
110   ASSERT_STREQ(expected_error_txt, out_error.what());
111 
112   ASSERT_EQ(nullptr, m_sut->execute_update(Mysqlx::Crud::Update(), &out_error));
113   ASSERT_EQ(expected_error_code, out_error.error());
114   ASSERT_STREQ(expected_error_txt, out_error.what());
115 
116   ASSERT_EQ(nullptr, m_sut->execute_insert(Mysqlx::Crud::Insert(), &out_error));
117   ASSERT_EQ(expected_error_code, out_error.error());
118   ASSERT_STREQ(expected_error_txt, out_error.what());
119 
120   ASSERT_EQ(nullptr, m_sut->execute_delete(Mysqlx::Crud::Delete(), &out_error));
121   ASSERT_EQ(expected_error_code, out_error.error());
122   ASSERT_STREQ(expected_error_txt, out_error.what());
123 
124   ASSERT_EQ(nullptr,
125             m_sut->execute_prep_stmt(Mysqlx::Prepare::Execute(), &out_error));
126   ASSERT_EQ(expected_error_code, out_error.error());
127   ASSERT_STREQ(expected_error_txt, out_error.what());
128 
129   ASSERT_EQ(nullptr, m_sut->execute_fetch_capabilities(&out_error));
130   ASSERT_EQ(expected_error_code, out_error.error());
131   ASSERT_STREQ(expected_error_txt, out_error.what());
132 
133   ASSERT_EQ(expected_error_code,
134             m_sut->execute_set_capability(Mysqlx::Connection::CapabilitiesSet())
135                 .error());
136 
137   ASSERT_EQ(expected_error_code,
138             m_sut->execute_authenticate("user", "pass", "db", "PLAIN").error());
139 
140   ASSERT_EQ(
141       expected_error_code,
142       m_sut->execute_authenticate("user", "pass", "db", "MYSQL41").error());
143 }
144 
145 }  // namespace test
146 }  // namespace xcl
147