~fboranek/mariadb++/vs10

« back to all changes in this revision

Viewing changes to unittest/test.cpp

  • Committer: Frantisek Boranek
  • Date: 2015-01-16 17:43:53 UTC
  • Revision ID: fboranek@atlas.cz-20150116174353-bcozr7536mymemz4
- fixed hang in connection due not NULL paramet passed as local socket
- fixed memory leak in destruction of connection
- generating config file
- force to chose throwing exception during build 
- fixed compilatin by VS2010

error C2065: '__PRETTY_FUNCTION__' : undeclared identifier      src\statement.cpp       33
error C2872: 'time' : ambiguous symbol  src\statement.cpp       163
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int       D:\Workspace\git.mailserver.8.5.X\connect\extLibs\mariadb++\src\statement.cpp   163     1
error C2143: syntax error : missing ',' before '&'  src\statement.cpp       163
error C2511: 'void mariadb::statement::set_time(mariadb::u32,const int)' : overloaded member function not found in 'mariadb::statement' src\statement.cpp       164
error C3861: 'round': identifier not found      src\decimal.cpp 25
error C2668: 'pow' : ambiguous call to overloaded function      src\decimal.cpp 32
error C2466: cannot allocate an array of constant size 0        src\decimal.cpp 32
error C2065: '__func__' : undeclared identifier src\date_time.cpp       144


src\bind.cpp(49): warning C4800: 'const my_bool' : forcing value to bool 'true' or 'false' (performance warning)
src\connection.cpp(238): warning C4244: '+=' : conversion from 'my_ulonglong' to 'mariadb::u32', possible loss of data
src\connection.cpp(269): warning C4244: 'return' : conversion from 'my_ulonglong' to 'mariadb::u32', possible loss of data
src\date_time.cpp(65): warning C4996: 'localtime': This function or variable may be unsafe. Consider using localtime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
src\date_time.cpp(633): warning C4996: 'localtime': This function or variable may be unsafe. Consider using localtime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
src\date_time.cpp(647): warning C4996: 'gmtime': This function or variable may be unsafe. Consider using gmtime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
src\date_time.cpp(673): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
src\date_time.cpp(675): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
src\date_time.cpp(684): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
src\date_time.cpp(493): warning C4244: 'initializing' : conversion from 'mariadb::s64' to 'mariadb::u32', possible loss of data
src\date_time.cpp(496): warning C4244: 'initializing' : conversion from 'mariadb::s64' to 'mariadb::u32', possible loss of data
src\date_time.cpp(499): warning C4244: 'initializing' : conversion from 'mariadb::s64' to 'mariadb::u32', possible loss of data
src\date_time.cpp(502): warning C4244: 'initializing' : conversion from 'mariadb::s64' to 'mariadb::u32', possible loss of data
src\date_time.cpp(586): warning C4244: 'argument' : conversion from 'mariadb::u16' to 'mariadb::u8', possible loss of data
src\date_time.cpp(658): warning C4244: 'initializing' : conversion from 'mariadb::u16' to 'mariadb::u8', possible loss of data
src\date_time.cpp(659): warning C4244: 'initializing' : conversion from 'mariadb::u16' to 'mariadb::u8', possible loss of data
src\decimal.cpp(173): warning C4244: 'argument' : conversion from 'mariadb::s64' to 'mariadb::u8', possible loss of data
src\result_set.cpp(264): warning C4800: 'mariadb::u64' : forcing value to bool 'true' or 'false' (performance warning)
src\result_set.cpp(272): warning C4244: 'return' : conversion from 'mariadb::u64' to 'mariadb::u8', possible loss of data
src\result_set.cpp(280): warning C4244: 'return' : conversion from 'mariadb::s64' to 'mariadb::s8', possible loss of data
src\result_set.cpp(288): warning C4244: 'return' : conversion from 'mariadb::u64' to 'mariadb::u16', possible loss of data
src\result_set.cpp(296): warning C4244: 'return' : conversion from 'mariadb::s64' to 'mariadb::s16', possible loss of data
src\result_set.cpp(304): warning C4244: 'return' : conversion from 'mariadb::u64' to 'mariadb::u32', possible loss of data
src\result_set.cpp(312): warning C4244: 'return' : conversion from 'mariadb::s64' to 'mariadb::s32', possible loss of data
src\save_point.cpp(33): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
src\save_point.cpp(35): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
src\save_point.cpp(49): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
src\save_point.cpp(64): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
src\statement.cpp(85): warning C4244: 'return' : conversion from 'my_ulonglong' to 'mariadb::s32', possible loss of data
src\statement.cpp(96): warning C4244: 'return' : conversion from 'my_ulonglong' to 'mariadb::u32', possible loss of data
src\statement.cpp(125): warning C4244: 'argument' : conversion from 'mariadb::u64' to 'unsigned long', possible loss of data
src\time.cpp(55): warning C4996: 'localtime': This function or variable may be unsafe. Consider using localtime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
src\time.cpp(366): warning C4244: 'initializing' : conversion from 'mariadb::s64' to 'mariadb::u32', possible loss of data
src\time.cpp(369): warning C4244: 'initializing' : conversion from 'mariadb::s64' to 'mariadb::u32', possible loss of data
src\time.cpp(372): warning C4244: 'initializing' : conversion from 'mariadb::s64' to 'mariadb::u32', possible loss of data
src\time.cpp(375): warning C4244: 'argument' : conversion from 'mariadb::s64' to 'mariadb::u32', possible loss of data
src\time.cpp(419): warning C4996: 'localtime': This function or variable may be unsafe. Consider using localtime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
src\time.cpp(427): warning C4996: 'gmtime': This function or variable may be unsafe. Consider using gmtime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
src\time.cpp(438): warning C4244: 'initializing' : conversion from 'mariadb::u16' to 'mariadb::u8', possible loss of data
src\time.cpp(444): warning C4244: '=' : conversion from 'mariadb::u16' to 'mariadb::u8', possible loss of data
src\time.cpp(450): warning C4244: 'initializing' : conversion from 'double' to 'mariadb::u16', possible loss of data
src\time.cpp(460): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
src\time.cpp(462): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
//  M A R I A D B + +
3
 
//
4
 
//      Author   : Sylvain Rochette Langlois
5
 
//      License  : Boost Software License (http://www.boost.org/users/license.html)
6
 
//
7
 
 
8
 
#include "test.hpp"
9
 
 
10
 
using namespace mariadb;
11
 
using namespace unittest;
12
 
 
13
 
//
14
 
// Constructor
15
 
//
16
 
test::test(const char* host_name, const char* user_name, const char* password, const char* schema, u32 port, const char* unix_socket)
17
 
{
18
 
        m_account_setup = account::create(host_name, user_name, password, NULL, port, unix_socket);
19
 
        m_account_setup->set_auto_commit(true);
20
 
 
21
 
        m_account_auto_commit = account::create(host_name, user_name, password, schema, port, unix_socket);
22
 
        m_account_auto_commit->set_auto_commit(true);
23
 
 
24
 
        m_account_transaction = account::create(host_name, user_name, password, schema, port, unix_socket);
25
 
        m_account_transaction->set_auto_commit(false);
26
 
}
27
 
 
28
 
//
29
 
// Destructor
30
 
//
31
 
test::~test()
32
 
{
33
 
}
34
 
 
35
 
//
36
 
// Run
37
 
//
38
 
int test::run()
39
 
{
40
 
        if (!create_test_db())
41
 
        {
42
 
                std::cout << "Unable to create test table in schema " << m_account_auto_commit->schema() << "!\n";
43
 
                return 0;
44
 
        }
45
 
 
46
 
        try
47
 
        {
48
 
                if (test_date_time() &&
49
 
                        test_time() &&
50
 
                        test_time_span() &&
51
 
                        test_decimal() &&
52
 
                        test_transaction() &&
53
 
                        test_save_point() &&
54
 
                        test_statement() &&
55
 
                        test_result_set() &&
56
 
                        test_concurrency())
57
 
                {
58
 
                        std::cout << "test succeed!\n";
59
 
                        drop_test_db();
60
 
                }
61
 
        }
62
 
        catch (const std::exception& e)
63
 
        {
64
 
                std::cout << e.what() << '\n';
65
 
        }
66
 
 
67
 
        return 0;
68
 
}
69
 
 
70
 
bool test::create_test_db()
71
 
{
72
 
        try
73
 
        {
74
 
                connection_ref con = connection::create(m_account_setup);
75
 
                statement_ref sta = con->create_statement("SELECT 1 FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = ?;");
76
 
                sta->set_string(0, m_account_auto_commit->schema().c_str());
77
 
                result_set_ref rs = sta->query();
78
 
 
79
 
                if (!rs ||
80
 
                        !rs->next())
81
 
                        con->execute(("CREATE DATABASE " + m_account_auto_commit->schema()).c_str());
82
 
        }
83
 
        catch (const std::exception& e)
84
 
        {
85
 
                std::cout << e.what() << '\n';
86
 
                return false;
87
 
        }
88
 
 
89
 
        return execute("DROP TABLE IF EXISTS test; CREATE TABLE test(id INT PRIMARY KEY AUTO_INCREMENT, data TINYBLOB NULL, str VARCHAR(50) NULL, dt DATETIME NULL, t TIME NULL, value INT NULL, deci DECIMAL(8,4) DEFAULT 0.0);");
90
 
}
91
 
 
92
 
void test::drop_test_db()
93
 
{
94
 
        execute("DROP TABLE IF EXISTS test;");
95
 
}
96
 
 
97
 
//
98
 
// Execute a query
99
 
//
100
 
int test::execute(const char* query)
101
 
{
102
 
        auto con = connection::create(m_account_auto_commit);
103
 
 
104
 
        try
105
 
        {
106
 
                return con->execute(query) || 1;
107
 
        }
108
 
        catch (const std::exception& e)
109
 
        {
110
 
                std::cout << e.what() << '\n';
111
 
                return 0;
112
 
        }
113
 
 
114
 
        return 1;
115
 
}
 
1
//
 
2
//  M A R I A D B + +
 
3
//
 
4
//      Author   : Sylvain Rochette Langlois
 
5
//      License  : Boost Software License (http://www.boost.org/users/license.html)
 
6
//
 
7
 
 
8
#include "test.hpp"
 
9
 
 
10
using namespace mariadb;
 
11
using namespace unittest;
 
12
 
 
13
//
 
14
// Constructor
 
15
//
 
16
test::test(const char* host_name, const char* user_name, const char* password, const char* schema, u32 port, const char* unix_socket)
 
17
{
 
18
        m_account_setup = account::create(host_name, user_name, password, NULL, port, unix_socket);
 
19
        m_account_setup->set_auto_commit(true);
 
20
 
 
21
        m_account_auto_commit = account::create(host_name, user_name, password, schema, port, unix_socket);
 
22
        m_account_auto_commit->set_auto_commit(true);
 
23
 
 
24
        m_account_transaction = account::create(host_name, user_name, password, schema, port, unix_socket);
 
25
        m_account_transaction->set_auto_commit(false);
 
26
}
 
27
 
 
28
//
 
29
// Destructor
 
30
//
 
31
test::~test()
 
32
{
 
33
}
 
34
 
 
35
//
 
36
// Run
 
37
//
 
38
int test::run()
 
39
{
 
40
        if (!create_test_db())
 
41
        {
 
42
                std::cout << "Unable to create test table in schema " << m_account_auto_commit->schema() << "!\n";
 
43
                return 0;
 
44
        }
 
45
 
 
46
        try
 
47
        {
 
48
                if (test_date_time() &&
 
49
                        test_time() &&
 
50
                        test_time_span() &&
 
51
                        test_decimal() &&
 
52
                        test_transaction() &&
 
53
                        test_save_point() &&
 
54
                        test_statement() &&
 
55
                        test_result_set() &&
 
56
                        test_concurrency())
 
57
                {
 
58
                        std::cout << "test succeed!\n";
 
59
                        drop_test_db();
 
60
                }
 
61
        }
 
62
        catch (const std::exception& e)
 
63
        {
 
64
                std::cout << e.what() << '\n';
 
65
        }
 
66
 
 
67
        return 0;
 
68
}
 
69
 
 
70
bool test::create_test_db()
 
71
{
 
72
        try
 
73
        {
 
74
                connection_ref con = connection::create(m_account_setup);
 
75
                statement_ref sta = con->create_statement("SELECT 1 FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = ?;");
 
76
                sta->set_string(0, m_account_auto_commit->schema().c_str());
 
77
                result_set_ref rs = sta->query();
 
78
 
 
79
                if (!rs ||
 
80
                        !rs->next())
 
81
                        con->execute(("CREATE DATABASE " + m_account_auto_commit->schema()).c_str());
 
82
        }
 
83
        catch (const std::exception& e)
 
84
        {
 
85
                std::cout << e.what() << '\n';
 
86
                return false;
 
87
        }
 
88
 
 
89
        return execute("DROP TABLE IF EXISTS test; CREATE TABLE test(id INT PRIMARY KEY AUTO_INCREMENT, data TINYBLOB NULL, str VARCHAR(50) NULL, dt DATETIME NULL, t TIME NULL, value INT NULL, deci DECIMAL(8,4) DEFAULT 0.0);");
 
90
}
 
91
 
 
92
void test::drop_test_db()
 
93
{
 
94
        execute("DROP TABLE IF EXISTS test;");
 
95
}
 
96
 
 
97
//
 
98
// Execute a query
 
99
//
 
100
int test::execute(const char* query)
 
101
{
 
102
        auto con = connection::create(m_account_auto_commit);
 
103
 
 
104
        try
 
105
        {
 
106
                return con->execute(query) || 1;
 
107
        }
 
108
        catch (const std::exception& e)
 
109
        {
 
110
                std::cout << e.what() << '\n';
 
111
                return 0;
 
112
        }
 
113
 
 
114
        return 1;
 
115
}