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
1=== modified file 'libdrizzle/query.c'
2--- libdrizzle/query.c 2010-09-28 07:47:48 +0000
3+++ libdrizzle/query.c 2010-10-17 16:11:09 +0000
4@@ -325,29 +325,45 @@
5 size_t drizzle_escape_string(char *to, const char *from, size_t from_size)
6 {
7 size_t to_size= 0;
8+ char newchar;
9
10 while (from_size > 0)
11 {
12+ newchar= 0;
13 /* All multi-byte UTF8 characters have the high bit set for all bytes. */
14 if (!(*from & 0x80))
15 {
16 switch (*from)
17 {
18 case 0:
19+ newchar= '0';
20+ break;
21 case '\n':
22+ newchar= 'n';
23+ break;
24 case '\r':
25+ newchar= 'r';
26+ break;
27+ case '\032':
28+ newchar= 'Z';
29+ break;
30 case '\\':
31 case '\'':
32 case '"':
33- case '\032':
34 *to++= '\\';
35 to_size++;
36 default:
37 break;
38 }
39 }
40-
41- *to++= *from++;
42+ if (newchar != 0)
43+ {
44+ *to++= '\\';
45+ *to++= newchar;
46+ to_size++;
47+ }
48+ else
49+ *to++= *from++;
50 from_size--;
51 to_size++;
52 }
53
54=== modified file 'unittests/include.am'
55--- unittests/include.am 2010-09-21 17:31:14 +0000
56+++ unittests/include.am 2010-10-17 16:11:09 +0000
57@@ -27,6 +27,7 @@
58 unittests/date_test.cc \
59 unittests/date_time_test.cc \
60 unittests/generators.cc \
61+ unittests/libdrizzle_test.cc \
62 unittests/main.cc \
63 unittests/micro_timestamp_test.cc \
64 unittests/nano_timestamp_test.cc \
65@@ -44,4 +45,5 @@
66
67 unittests_unittests_LDADD= \
68 $(filter-out drizzled/main.$(OBJEXT), ${am_drizzled_drizzled_OBJECTS}) \
69- ${drizzled_drizzled_LDADD} ${LTLIBGTEST} ${BOOST_LIBS}
70+ ${drizzled_drizzled_LDADD} ${LTLIBGTEST} ${BOOST_LIBS} \
71+ libdrizzle/libdrizzle.la
72
73=== added file 'unittests/libdrizzle_test.cc'
74--- unittests/libdrizzle_test.cc 1970-01-01 00:00:00 +0000
75+++ unittests/libdrizzle_test.cc 2010-10-17 16:11:09 +0000
76@@ -0,0 +1,59 @@
77+/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
78+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
79+ *
80+ * Copyright (C) 2010 Andrew Hutchings
81+ *
82+ * This program is free software; you can redistribute it and/or modify
83+ * it under the terms of the GNU General Public License as published by
84+ * the Free Software Foundation; either version 2 of the License, or
85+ * (at your option) any later version.
86+ *
87+ * This program is distributed in the hope that it will be useful,
88+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
89+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
90+ * GNU General Public License for more details.
91+ *
92+ * You should have received a copy of the GNU General Public License
93+ * along with this program; if not, write to the Free Software
94+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
95+ */
96+
97+#include "config.h"
98+
99+#include <gtest/gtest.h>
100+#include <libdrizzle/drizzle_client.h>
101+#include <libdrizzle/drizzle_server.h>
102+
103+TEST(libdrizzle, drizzle_escape_string)
104+{
105+ const char* orig= "hello \"world\"\n";
106+ char out[255];
107+ size_t out_len;
108+
109+ out_len= drizzle_escape_string(out, orig, strlen(orig));
110+
111+ EXPECT_EQ(17, out_len);
112+ ASSERT_STREQ("hello \\\"world\\\"\\n", out);
113+}
114+
115+TEST(libdrizzle, drizzle_hex_string)
116+{
117+ const unsigned char orig[5]= {0x34, 0x26, 0x80, 0x99, 0xFF};
118+ char out[255];
119+ size_t out_len;
120+
121+ out_len= drizzle_hex_string(out, (char*) orig, 5);
122+
123+ EXPECT_EQ(10, out_len);
124+ ASSERT_STREQ("34268099FF", out);
125+}
126+
127+TEST(libdrizzle, drizzle_mysql_password_hash)
128+{
129+ const char* orig= "test password";
130+ char out[255];
131+
132+ drizzle_mysql_password_hash(out, orig, strlen(orig));
133+
134+ ASSERT_STREQ("3B942720DACACBBA7E3838AF03C5B6B5A6DFE0AB", out);
135+}