Merge lp:~linuxjedi/drizzle/trunk-bug-661431 into lp:~drizzle-trunk/drizzle/development

Proposed by Andrew Hutchings
Status: Merged
Approved by: Monty Taylor
Approved revision: 1858
Merged at revision: 1861
Proposed branch: lp:~linuxjedi/drizzle/trunk-bug-661431
Merge into: lp:~drizzle-trunk/drizzle/development
Diff against target: 135 lines (+81/-4)
3 files modified
libdrizzle/query.c (+19/-3)
unittests/include.am (+3/-1)
unittests/libdrizzle_test.cc (+59/-0)
To merge this branch: bzr merge lp:~linuxjedi/drizzle/trunk-bug-661431
Reviewer Review Type Date Requested Status
Drizzle Merge Team Pending
Review via email: mp+38658@code.launchpad.net

Description of the change

Add libdrizzle utility functions unit tests
Fix libdrizzle's drizzle_escape_string to escape correctly

To post a comment you must log in.
Revision history for this message
Lee Bieber (kalebral-deactivatedaccount) wrote :

Fails to run unit tests on OpenSUSE and FreeBSD

/libexec/ld-elf.so.1: /home/hudson/hudson/workspace/drizzle-build-freebsd-8.0/unittests/.libs/unittests: Undefined symbol "drizzle_mysql_password_hash"

Revision history for this message
Andrew Hutchings (linuxjedi) wrote :

because there is an old separate libdrizzle lying around on that server. That test is proving the server is bad and in fact will cause client problems ;)

Revision history for this message
Andrew Hutchings (linuxjedi) wrote :

we fixed the broken build bots. Monty says we shouldn't try to make things worse by trying to fix something that will never be hit in production. So can we re-approve it?

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'libdrizzle/query.c'
--- libdrizzle/query.c 2010-09-28 07:47:48 +0000
+++ libdrizzle/query.c 2010-10-17 16:11:09 +0000
@@ -325,29 +325,45 @@
325size_t drizzle_escape_string(char *to, const char *from, size_t from_size)325size_t drizzle_escape_string(char *to, const char *from, size_t from_size)
326{326{
327 size_t to_size= 0;327 size_t to_size= 0;
328 char newchar;
328329
329 while (from_size > 0)330 while (from_size > 0)
330 {331 {
332 newchar= 0;
331 /* All multi-byte UTF8 characters have the high bit set for all bytes. */333 /* All multi-byte UTF8 characters have the high bit set for all bytes. */
332 if (!(*from & 0x80))334 if (!(*from & 0x80))
333 {335 {
334 switch (*from)336 switch (*from)
335 {337 {
336 case 0:338 case 0:
339 newchar= '0';
340 break;
337 case '\n':341 case '\n':
342 newchar= 'n';
343 break;
338 case '\r':344 case '\r':
345 newchar= 'r';
346 break;
347 case '\032':
348 newchar= 'Z';
349 break;
339 case '\\':350 case '\\':
340 case '\'':351 case '\'':
341 case '"':352 case '"':
342 case '\032':
343 *to++= '\\';353 *to++= '\\';
344 to_size++;354 to_size++;
345 default:355 default:
346 break;356 break;
347 }357 }
348 }358 }
349359 if (newchar != 0)
350 *to++= *from++;360 {
361 *to++= '\\';
362 *to++= newchar;
363 to_size++;
364 }
365 else
366 *to++= *from++;
351 from_size--;367 from_size--;
352 to_size++;368 to_size++;
353 }369 }
354370
=== modified file 'unittests/include.am'
--- unittests/include.am 2010-09-21 17:31:14 +0000
+++ unittests/include.am 2010-10-17 16:11:09 +0000
@@ -27,6 +27,7 @@
27 unittests/date_test.cc \27 unittests/date_test.cc \
28 unittests/date_time_test.cc \28 unittests/date_time_test.cc \
29 unittests/generators.cc \29 unittests/generators.cc \
30 unittests/libdrizzle_test.cc \
30 unittests/main.cc \31 unittests/main.cc \
31 unittests/micro_timestamp_test.cc \32 unittests/micro_timestamp_test.cc \
32 unittests/nano_timestamp_test.cc \33 unittests/nano_timestamp_test.cc \
@@ -44,4 +45,5 @@
4445
45unittests_unittests_LDADD= \46unittests_unittests_LDADD= \
46 $(filter-out drizzled/main.$(OBJEXT), ${am_drizzled_drizzled_OBJECTS}) \47 $(filter-out drizzled/main.$(OBJEXT), ${am_drizzled_drizzled_OBJECTS}) \
47 ${drizzled_drizzled_LDADD} ${LTLIBGTEST} ${BOOST_LIBS}48 ${drizzled_drizzled_LDADD} ${LTLIBGTEST} ${BOOST_LIBS} \
49 libdrizzle/libdrizzle.la
4850
=== added file 'unittests/libdrizzle_test.cc'
--- unittests/libdrizzle_test.cc 1970-01-01 00:00:00 +0000
+++ unittests/libdrizzle_test.cc 2010-10-17 16:11:09 +0000
@@ -0,0 +1,59 @@
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
21#include "config.h"
22
23#include <gtest/gtest.h>
24#include <libdrizzle/drizzle_client.h>
25#include <libdrizzle/drizzle_server.h>
26
27TEST(libdrizzle, drizzle_escape_string)
28{
29 const char* orig= "hello \"world\"\n";
30 char out[255];
31 size_t out_len;
32
33 out_len= drizzle_escape_string(out, orig, strlen(orig));
34
35 EXPECT_EQ(17, out_len);
36 ASSERT_STREQ("hello \\\"world\\\"\\n", out);
37}
38
39TEST(libdrizzle, drizzle_hex_string)
40{
41 const unsigned char orig[5]= {0x34, 0x26, 0x80, 0x99, 0xFF};
42 char out[255];
43 size_t out_len;
44
45 out_len= drizzle_hex_string(out, (char*) orig, 5);
46
47 EXPECT_EQ(10, out_len);
48 ASSERT_STREQ("34268099FF", out);
49}
50
51TEST(libdrizzle, drizzle_mysql_password_hash)
52{
53 const char* orig= "test password";
54 char out[255];
55
56 drizzle_mysql_password_hash(out, orig, strlen(orig));
57
58 ASSERT_STREQ("3B942720DACACBBA7E3838AF03C5B6B5A6DFE0AB", out);
59}