2097.2.4
by Andrew Hutchings
Convert all unit tests to boost::test |
1 |
/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2010 Andrew Hutchings
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; either version 2 of the License, or
|
|
9 |
* (at your option) any later version.
|
|
10 |
*
|
|
11 |
* This program is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License
|
|
17 |
* along with this program; if not, write to the Free Software
|
|
18 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
19 |
*/
|
|
20 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
21 |
#include <config.h> |
2097.2.4
by Andrew Hutchings
Convert all unit tests to boost::test |
22 |
|
23 |
#define BOOST_TEST_DYN_LINK
|
|
24 |
#include <boost/test/unit_test.hpp> |
|
25 |
||
2472.1.6
by Brian Aker
Break up unit tests |
26 |
#include <libdrizzle-1.0/drizzle_client.h> |
27 |
#include <libdrizzle-1.0/drizzle_server.h> |
|
2097.2.4
by Andrew Hutchings
Convert all unit tests to boost::test |
28 |
|
29 |
BOOST_AUTO_TEST_SUITE(LibDrizzle) |
|
30 |
BOOST_AUTO_TEST_CASE(drizzleEscapeString) |
|
31 |
{
|
|
32 |
const char* orig= "hello \"world\"\n"; |
|
33 |
char out[255]; |
|
34 |
||
2472.1.6
by Brian Aker
Break up unit tests |
35 |
ssize_t out_len= drizzle_safe_escape_string(out, sizeof(out), orig, strlen(orig)); |
2097.2.4
by Andrew Hutchings
Convert all unit tests to boost::test |
36 |
|
37 |
BOOST_REQUIRE_EQUAL(17, out_len); |
|
38 |
BOOST_REQUIRE_EQUAL("hello \\\"world\\\"\\n", out); |
|
39 |
}
|
|
40 |
||
2210.2.1
by Andrew Hutchings
Fix libdrizzle byte count handling for drizzle_escape_string and add unittest |
41 |
BOOST_AUTO_TEST_CASE(drizzleEscapeStringBinary) |
42 |
{
|
|
43 |
const char orig[6]= {0x00, 0x01, 0x02, 0x03, 0x04, 0x05}; |
|
44 |
char out[255]; |
|
45 |
||
2472.1.6
by Brian Aker
Break up unit tests |
46 |
ssize_t out_len= drizzle_safe_escape_string(out, sizeof(out), orig, 6); |
2210.2.1
by Andrew Hutchings
Fix libdrizzle byte count handling for drizzle_escape_string and add unittest |
47 |
|
48 |
BOOST_REQUIRE_EQUAL(7, out_len); |
|
49 |
BOOST_REQUIRE_EQUAL("\\0\1\2\3\4\5", out); |
|
50 |
}
|
|
51 |
||
2235.1.2
by Andrew Hutchings
Add drizzle_safe_escape_string() function |
52 |
BOOST_AUTO_TEST_CASE(drizzleSafeEscapeString) |
53 |
{
|
|
54 |
const char* orig= "hello \"world\"\n"; |
|
55 |
char out[255]; |
|
56 |
||
2472.1.6
by Brian Aker
Break up unit tests |
57 |
ssize_t out_len= drizzle_safe_escape_string(out, sizeof(out), orig, strlen(orig)); |
2235.1.2
by Andrew Hutchings
Add drizzle_safe_escape_string() function |
58 |
|
59 |
BOOST_REQUIRE_EQUAL(17, out_len); |
|
60 |
BOOST_REQUIRE_EQUAL("hello \\\"world\\\"\\n", out); |
|
61 |
}
|
|
62 |
||
63 |
BOOST_AUTO_TEST_CASE(drizzleSafeEscapeStringFail) |
|
64 |
{
|
|
65 |
const char* orig= "hello \"world\"\n"; |
|
66 |
char out[5]; |
|
67 |
||
2472.1.6
by Brian Aker
Break up unit tests |
68 |
ssize_t out_len= drizzle_safe_escape_string(out, sizeof(out), orig, strlen(orig)); |
2235.1.2
by Andrew Hutchings
Add drizzle_safe_escape_string() function |
69 |
|
70 |
BOOST_REQUIRE_EQUAL(-1, out_len); |
|
71 |
}
|
|
2210.2.1
by Andrew Hutchings
Fix libdrizzle byte count handling for drizzle_escape_string and add unittest |
72 |
|
2097.2.4
by Andrew Hutchings
Convert all unit tests to boost::test |
73 |
BOOST_AUTO_TEST_CASE(drizzleHexString) |
74 |
{
|
|
75 |
const unsigned char orig[5]= {0x34, 0x26, 0x80, 0x99, 0xFF}; |
|
76 |
char out[255]; |
|
77 |
||
2461.1.1
by Brian Aker
Fix safety issues around calling API with no check for NULL |
78 |
size_t out_len= drizzle_hex_string(out, (char*) orig, 5); |
2097.2.4
by Andrew Hutchings
Convert all unit tests to boost::test |
79 |
|
80 |
BOOST_REQUIRE_EQUAL(10, out_len); |
|
81 |
BOOST_REQUIRE_EQUAL("34268099FF", out); |
|
82 |
}
|
|
83 |
||
84 |
BOOST_AUTO_TEST_CASE(drizzleMysqlPasswordHash) |
|
85 |
{
|
|
86 |
const char* orig= "test password"; |
|
87 |
char out[255]; |
|
88 |
||
89 |
drizzle_mysql_password_hash(out, orig, strlen(orig)); |
|
90 |
||
91 |
BOOST_REQUIRE_EQUAL("3B942720DACACBBA7E3838AF03C5B6B5A6DFE0AB", out); |
|
92 |
}
|
|
93 |
BOOST_AUTO_TEST_SUITE_END() |