Skip to content

Commit

Permalink
Add unittest for drizzle_options_* API
Browse files Browse the repository at this point in the history
Check API functions which get or set a drizzle_option
  • Loading branch information
andreas-bok-sociomantic authored and bokchan committed Jun 2, 2020
1 parent c429b2a commit 2f9fd02
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
91 changes: 91 additions & 0 deletions tests/unit/drizzle_options.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
*
* Drizzle Client & Protocol Library
*
* Copyright dunnhumby Germany GmbH 2019
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* * The names of its contributors may not be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

#include <yatl/lite.h>
#include <libdrizzle-redux/libdrizzle.h>
#include "tests/unit/common.h"

/**
* @brief Macro to setter and getter API functions for a specific drizzle_option
* @details [long description]
*
* @param api_func_set pointer to a setter function
* @param api_func_get pointer to a getter function
*
* @return [description]
*/
#define CHECK_DRIZZLE_OPTION(api_func_set, api_func_get) \
do \
{ \
api_func_set(opts, true); \
ASSERT_TRUE(api_func_get(opts)); \
api_func_set(NULL, false); \
ASSERT_TRUE(api_func_get(opts)); \
ASSERT_FALSE(api_func_get(NULL)); \
api_func_set(opts, false); \
ASSERT_FALSE(api_func_get(opts)); \
} \
while (0)


int main(int argc, char *argv[]) {
(void)argc;
(void)argv;

opts = drizzle_options_create();
CHECK_DRIZZLE_OPTION(drizzle_options_set_non_blocking, drizzle_options_get_non_blocking);
CHECK_DRIZZLE_OPTION(drizzle_options_set_raw_scramble, drizzle_options_get_raw_scramble);
CHECK_DRIZZLE_OPTION(drizzle_options_set_found_rows, drizzle_options_get_found_rows);
CHECK_DRIZZLE_OPTION(drizzle_options_set_interactive, drizzle_options_get_interactive);
CHECK_DRIZZLE_OPTION(drizzle_options_set_multi_statements, drizzle_options_get_multi_statements);
CHECK_DRIZZLE_OPTION(drizzle_options_set_auth_plugin, drizzle_options_get_auth_plugin);

drizzle_options_set_socket_owner(NULL, DRIZZLE_SOCKET_OWNER_CLIENT);
ASSERT_EQ(DRIZZLE_SOCKET_OWNER_NATIVE, drizzle_options_get_socket_owner(opts));
drizzle_options_set_socket_owner(opts, DRIZZLE_SOCKET_OWNER_CLIENT);
ASSERT_EQ(DRIZZLE_SOCKET_OWNER_NATIVE, drizzle_options_get_socket_owner(NULL));

con = drizzle_create(getenv("MYSQL_SERVER"),
getenv("MYSQL_PORT") ? atoi(getenv("MYSQL_PORT"))
: DRIZZLE_DEFAULT_TCP_PORT,
getenv("MYSQL_USER"),
getenv("MYSQL_PASSWORD"),
getenv("MYSQL_SCHEMA"), opts);
ASSERT_NOT_NULL_(con, "Drizzle connection object creation error");

close_connection_on_exit();
}
9 changes: 9 additions & 0 deletions tests/unit/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ gdb-ssl: tests/unit/ssl
check-ssl: tests/unit/ssl
tests/unit/ssl

tests_unit_drizzle_options_SOURCES= tests/unit/drizzle_options.c tests/unit/common.c
tests_unit_drizzle_options_LDADD= src/libdrizzle-redux@LIBDRIZZLE_MAJOR@.la
nodist_EXTRA_tests_unit_drizzle_options_SOURCES = dummy.cxx
check_PROGRAMS+= tests/unit/drizzle_options
noinst_PROGRAMS+= tests/unit/drizzle_options

check-drizzle_options: tests/unit/drizzle_options
tests/unit/drizzle_options

api-sanity-checker:
${abs_top_srcdir}/configure --prefix=/usr --srcdir=${abs_top_srcdir}
$(MAKE) DESTDIR=${abs_builddir}/install install
Expand Down

0 comments on commit 2f9fd02

Please sign in to comment.