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