The Battle for Wesnoth  1.15.3+dev
SkeletonTest.h
Go to the documentation of this file.
1 //
2 // M A R I A D B + +
3 //
4 // Copyright The ViaDuck Project 2016 - 2018.
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 
9 #ifndef MARIADBCLIENTPP_SKELETONTEST_H
10 #define MARIADBCLIENTPP_SKELETONTEST_H
11 
12 #include <mariadb++/connection.hpp>
13 #include <gtest/gtest.h>
14 
15 #include "test_config.h"
16 
17 using namespace mariadb;
18 
19 class SkeletonTest : public ::testing::Test {
20  public:
21  virtual void SetUp() override {
22  // get test names and concatenate them
23  const ::testing::TestInfo* const test_info =
24  ::testing::UnitTest::GetInstance()->current_test_info();
25  m_table_name =
26  std::string(test_info->test_case_name()) + "_" + std::string(test_info->name());
27 
28  // create user account
29  using TestConfig = mariadb::testing::TestConfig;
30  m_account_setup = account::create(TestConfig::Hostname, TestConfig::User, TestConfig::Password,
31  TestConfig::Database, TestConfig::Port, TestConfig::UnixSocket);
32  ASSERT_TRUE(!!m_account_setup);
33  m_account_setup->set_auto_commit(true);
34  m_account_setup->set_connect_option(MYSQL_OPT_CONNECT_TIMEOUT, 10);
35  ASSERT_EQ(1u, m_account_setup->connect_options().size());
36 
37  // create database connection
38  m_con = connection::create(m_account_setup);
39  ASSERT_TRUE(!!m_con);
40  ASSERT_TRUE(m_con->connect());
41  ASSERT_TRUE(m_con->connected());
42 
43  // drop table and call creation
44  m_con->execute("DROP TABLE IF EXISTS " + m_table_name);
45  CreateTestTable();
46  }
47 
48  virtual void TearDown() override { m_con->disconnect(); }
49 
50  protected:
51  virtual void CreateTestTable() = 0;
52 
55 
57 };
58 
59 #endif // MARIADBCLIENTPP_SKELETONTEST_H
std::shared_ptr< account > account_ref
Definition: account.hpp:19
account_ref m_account_setup
Definition: SkeletonTest.h:53
virtual void SetUp() override
Definition: SkeletonTest.h:21
connection_ref m_con
Definition: SkeletonTest.h:56
static connection_ref create(const account_ref &account)
Creates a new connection using the given account.
Definition: connection.cpp:28
static account_ref create(const std::string &host_name, const std::string &user_name, const std::string &password, const std::string &schema="", u32 port=3306, const std::string &unix_socket="")
Create an account.
Definition: account.cpp:100
std::string m_table_name
Definition: SkeletonTest.h:54
std::shared_ptr< connection > connection_ref
Definition: statement.hpp:33
virtual void TearDown() override
Definition: SkeletonTest.h:48