Merge lp:~linuxjedi/libdrizzle/5.1-tests into lp:libdrizzle

Proposed by Andrew Hutchings
Status: Merged
Approved by: Andrew Hutchings
Approved revision: 66
Merged at revision: 64
Proposed branch: lp:~linuxjedi/libdrizzle/5.1-tests
Merge into: lp:libdrizzle
Diff against target: 836 lines (+483/-51)
17 files modified
cli/drizzle_binlogs.c (+2/-1)
libdrizzle/column.cc (+1/-1)
libdrizzle/field.cc (+2/-2)
tests/unit/binlog.c (+20/-15)
tests/unit/column.c (+167/-0)
tests/unit/connect.c (+1/-2)
tests/unit/escape.c (+12/-3)
tests/unit/hex.c (+13/-3)
tests/unit/include.am (+10/-0)
tests/unit/insert_id.c (+12/-4)
tests/unit/passwd.c (+14/-3)
tests/unit/query.c (+21/-4)
tests/unit/row.c (+157/-0)
tests/unit/statement.c (+29/-5)
tests/unit/unbuffered_query.c (+22/-4)
tests/unit/version.c (+0/-2)
tests/unit/version_cxx.cc (+0/-2)
To merge this branch: bzr merge lp:~linuxjedi/libdrizzle/5.1-tests
Reviewer Review Type Date Requested Status
Andrew Hutchings Approve
Review via email: mp+141387@code.launchpad.net

Description of the change

* Adds test cases
* Cleans-up test cases
* Fixes column sizes bug

To post a comment you must log in.
Revision history for this message
Andrew Hutchings (linuxjedi) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cli/drizzle_binlogs.c'
2--- cli/drizzle_binlogs.c 2012-12-24 10:20:04 +0000
3+++ cli/drizzle_binlogs.c 2012-12-27 22:12:23 +0000
4@@ -34,9 +34,10 @@
5 *
6 */
7
8-#include "config.h"
9+#define _GNU_SOURCE 1
10 #include <libdrizzle-5.1/libdrizzle.h>
11 #include <stdlib.h>
12+#include <sys/types.h>
13 #include <glib.h>
14 #include <glib/gstdio.h>
15 #include <pwd.h>
16
17=== modified file 'libdrizzle/column.cc'
18--- libdrizzle/column.cc 2012-12-23 14:47:03 +0000
19+++ libdrizzle/column.cc 2012-12-27 22:12:23 +0000
20@@ -543,7 +543,7 @@
21
22 /* Skip one filler byte. */
23 column->charset= (drizzle_charset_t)drizzle_get_byte2(con->buffer_ptr + 1);
24- column->size= drizzle_get_byte4(con->buffer_ptr + 3);
25+ column->max_size= drizzle_get_byte4(con->buffer_ptr + 3);
26
27 column->type= drizzle_column_type_t(con->buffer_ptr[7]);
28
29
30=== modified file 'libdrizzle/field.cc'
31--- libdrizzle/field.cc 2012-12-23 01:05:57 +0000
32+++ libdrizzle/field.cc 2012-12-27 22:12:23 +0000
33@@ -283,10 +283,10 @@
34 con->result->field_total)
35 {
36 if (con->result->column_buffer != NULL &&
37- con->result->column_buffer[con->result->field_current].max_size <
38+ con->result->column_buffer[con->result->field_current].size <
39 con->result->field_total)
40 {
41- con->result->column_buffer[con->result->field_current].max_size=
42+ con->result->column_buffer[con->result->field_current].size=
43 con->result->field_total;
44 }
45
46
47=== modified file 'tests/unit/binlog.c'
48--- tests/unit/binlog.c 2012-12-27 12:30:14 +0000
49+++ tests/unit/binlog.c 2012-12-27 22:12:23 +0000
50@@ -35,12 +35,12 @@
51 *
52 */
53
54-#include "config.h"
55-
56 #include <libdrizzle-5.1/libdrizzle.h>
57 #include "libdrizzle/structs.h"
58 #include <stdio.h>
59 #include <stdlib.h>
60+#include <stdint.h>
61+#include <inttypes.h>
62
63 #ifndef EXIT_SKIP
64 # define EXIT_SKIP 77
65@@ -77,22 +77,27 @@
66
67 while (ret == DRIZZLE_RETURN_OK)
68 {
69- uint32_t i, length;
70- const uint8_t *data;
71+ uint32_t timestamp;
72 ret= drizzle_binlog_get_next_event(result);
73 if (ret != DRIZZLE_RETURN_OK)
74 break;
75- printf("Timestamp: %" PRIu32 "\n", drizzle_binlog_event_timestamp(result));
76- printf("Type: %"PRIu8"\n", drizzle_binlog_event_type(result));
77- printf("Server-id: %"PRIu32"\n", drizzle_binlog_event_server_id(result));
78- printf("Next-pos: %"PRIu32"\n", drizzle_binlog_event_next_pos(result));
79- length= drizzle_binlog_event_length(result);
80- printf("Length: %"PRIu32"\n", length);
81- data= drizzle_binlog_event_data(result);
82- printf("Data: 0x");
83- for (i=0; i<length; i++)
84- printf("%02X ", data[i]);
85- printf("\n\n");
86+ timestamp= drizzle_binlog_event_timestamp(result);
87+ /* Test to see if timestamp is greater than 2012-01-01 00:00:00, corrupted
88+ * timestamps will have weird values that shoud fail this after several
89+ * events. Also rotate event doesn't have a timestamp so need to add 0
90+ * to this test */
91+ if ((timestamp < 1325376000) && (timestamp != 0))
92+ {
93+ printf("Bad timestamp retrieved: %"PRIu32"\n", timestamp);
94+ return EXIT_FAILURE;
95+ }
96+ /* An event higher than the max known is bad, either we don't know about
97+ * new events or type is corrupted */
98+ if (drizzle_binlog_event_type(result) >= DRIZZLE_EVENT_TYPE_END)
99+ {
100+ printf("Bad event type: %d\n", drizzle_binlog_event_type(result));
101+ return EXIT_FAILURE;
102+ }
103 }
104
105 drizzle_quit(con);
106
107=== added file 'tests/unit/column.c'
108--- tests/unit/column.c 1970-01-01 00:00:00 +0000
109+++ tests/unit/column.c 2012-12-27 22:12:23 +0000
110@@ -0,0 +1,167 @@
111+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
112+ *
113+ * Drizzle Client & Protocol Library
114+ *
115+ * Copyright (C) 2012 Andrew Hutchings (andrew@linuxjedi.co.uk)
116+ * All rights reserved.
117+ *
118+ * Redistribution and use in source and binary forms, with or without
119+ * modification, are permitted provided that the following conditions are
120+ * met:
121+ *
122+ * * Redistributions of source code must retain the above copyright
123+ * notice, this list of conditions and the following disclaimer.
124+ *
125+ * * Redistributions in binary form must reproduce the above
126+ * copyright notice, this list of conditions and the following disclaimer
127+ * in the documentation and/or other materials provided with the
128+ * distribution.
129+ *
130+ * * The names of its contributors may not be used to endorse or
131+ * promote products derived from this software without specific prior
132+ * written permission.
133+ *
134+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145+ *
146+ */
147+
148+#include <libdrizzle-5.1/libdrizzle.h>
149+#include <stdio.h>
150+#include <string.h>
151+#include <stdlib.h>
152+
153+#ifndef EXIT_SKIP
154+# define EXIT_SKIP 77
155+#endif
156+
157+int main(int argc, char *argv[])
158+{
159+ (void) argc;
160+ (void) argv;
161+ drizzle_st *con;
162+ drizzle_return_t ret;
163+ drizzle_result_st *result;
164+ drizzle_row_t row;
165+ int num_fields;
166+
167+ con = drizzle_create_tcp("localhost", 3306, "root", "", "libdrizzle", 0);
168+ if (con == NULL)
169+ {
170+ printf("Drizzle connection object creation error\n");
171+ return EXIT_FAILURE;
172+ }
173+ ret = drizzle_connect(con);
174+ if (ret != DRIZZLE_RETURN_OK)
175+ {
176+ printf("Drizzle connection failure\n");
177+ return EXIT_SKIP;
178+ }
179+
180+ drizzle_query_str(con, "create table libdrizzle.t1 (a int primary key auto_increment, b varchar(255), c timestamp default current_timestamp)", &ret);
181+ if (ret != DRIZZLE_RETURN_OK)
182+ {
183+ printf("Create table failure\n");
184+ return EXIT_FAILURE;
185+ }
186+
187+ drizzle_query_str(con, "insert into libdrizzle.t1 (b) values ('this'),('is'),('war')", &ret);
188+ if (ret != DRIZZLE_RETURN_OK)
189+ {
190+ printf("Insert failure\n");
191+ return EXIT_FAILURE;
192+ }
193+
194+ result= drizzle_query_str(con, "select * from libdrizzle.t1", &ret);
195+ if (ret != DRIZZLE_RETURN_OK)
196+ {
197+ printf("Select failure\n");
198+ return EXIT_FAILURE;
199+ }
200+ drizzle_result_buffer(result);
201+ num_fields= drizzle_result_column_count(result);
202+
203+ if (num_fields != 3)
204+ {
205+ printf("Retrieved bad number of fields\n");
206+ return EXIT_FAILURE;
207+ }
208+ int i= 0;
209+ int j= 0;
210+ char buf[10];
211+ drizzle_column_st *column;
212+ while ((row = drizzle_row_next(result)))
213+ {
214+ drizzle_column_seek(result, 0);
215+ j= 0;
216+ i++;
217+ snprintf(buf, 10, "%d", i);
218+ if (strcmp(row[0], buf) != 0)
219+ {
220+ printf("Retrieved bad row value\n");
221+ return EXIT_FAILURE;
222+ }
223+ while ((column= drizzle_column_next(result)))
224+ {
225+ j++;
226+ if (strcmp(drizzle_column_db(column), "libdrizzle") != 0)
227+ {
228+ printf("Column has bad DB name\n");
229+ return EXIT_FAILURE;
230+ }
231+ if (strcmp(drizzle_column_table(column), "t1") != 0)
232+ {
233+ printf("Column had bad table name\n");
234+ return EXIT_FAILURE;
235+ }
236+ if ((j == 2) && (drizzle_column_max_size(column) != 255))
237+ {
238+ printf("Column max size wrong %lu != 255\n", drizzle_column_max_size(column));
239+ return EXIT_FAILURE;
240+ }
241+ if ((j == 2) && (drizzle_column_charset(column) != DRIZZLE_CHARSET_LATIN1_SWEDISH_CI))
242+ {
243+ printf("Column type wrong, %d != %d\n", drizzle_column_charset(column), DRIZZLE_CHARSET_UTF8_BIN);
244+ return EXIT_FAILURE;
245+ }
246+ if ((j == 3) && (drizzle_column_type(column) != DRIZZLE_COLUMN_TYPE_TIMESTAMP))
247+ {
248+ printf("Column type wrong\n");
249+ return EXIT_FAILURE;
250+ }
251+ }
252+ if (j != 3)
253+ {
254+ printf("Wrong column count\n");
255+ return EXIT_FAILURE;
256+ }
257+ }
258+ /* Should have had 3 rows */
259+ if (i != 3)
260+ {
261+ printf("Retrieved bad number of rows\n");
262+ return EXIT_FAILURE;
263+ }
264+
265+ drizzle_result_free(result);
266+
267+ drizzle_query_str(con, "drop table libdrizzle.t1", &ret);
268+ if (ret != DRIZZLE_RETURN_OK)
269+ {
270+ printf("Drop table failure\n");
271+ return EXIT_FAILURE;
272+ }
273+
274+
275+ drizzle_quit(con);
276+ return EXIT_SUCCESS;
277+}
278
279=== modified file 'tests/unit/connect.c'
280--- tests/unit/connect.c 2012-12-27 12:30:14 +0000
281+++ tests/unit/connect.c 2012-12-27 22:12:23 +0000
282@@ -35,11 +35,10 @@
283 *
284 */
285
286-#include "config.h"
287-
288 #include <libdrizzle-5.1/libdrizzle.h>
289 #include <stdio.h>
290 #include <stdlib.h>
291+#include <stdint.h>
292
293 #ifndef EXIT_SKIP
294 # define EXIT_SKIP 77
295
296=== modified file 'tests/unit/escape.c'
297--- tests/unit/escape.c 2012-12-24 10:20:04 +0000
298+++ tests/unit/escape.c 2012-12-27 22:12:23 +0000
299@@ -35,11 +35,11 @@
300 *
301 */
302
303-#include "config.h"
304-
305 #include <libdrizzle-5.1/libdrizzle.h>
306 #include <stdio.h>
307 #include <stdlib.h>
308+#include <stdint.h>
309+#include <string.h>
310
311 int main(int argc, char* argv[])
312 {
313@@ -56,6 +56,15 @@
314 return EXIT_FAILURE;
315
316 out_len= drizzle_escape_string(out, 255, in, strlen(in));
317- printf("%d\n%s\n", out_len, out);
318+ if (out_len != 17)
319+ {
320+ printf("Bad hex length output\n");
321+ return EXIT_FAILURE;
322+ }
323+ if (strcmp(out, "escape \\\"this\\\"\\n") != 0)
324+ {
325+ printf("Bad hex data output\n");
326+ return EXIT_FAILURE;
327+ }
328 return EXIT_SUCCESS;
329 }
330
331=== modified file 'tests/unit/hex.c'
332--- tests/unit/hex.c 2012-12-24 10:20:04 +0000
333+++ tests/unit/hex.c 2012-12-27 22:12:23 +0000
334@@ -35,11 +35,11 @@
335 *
336 */
337
338-#include "config.h"
339-
340 #include <libdrizzle-5.1/libdrizzle.h>
341 #include <stdio.h>
342+#include <string.h>
343 #include <stdlib.h>
344+#include <stdint.h>
345
346 int main(int argc, char* argv[])
347 {
348@@ -53,12 +53,22 @@
349 // Test for bad usage
350 result= drizzle_hex_string(out, in, 0);
351 if (result)
352+ {
353+ printf("Bad usage failure\n");
354 return EXIT_FAILURE;
355+ }
356
357 result= drizzle_hex_string(out, in, 6);
358 if (!result)
359+ {
360+ printf("Failed to get result\n");
361 return EXIT_FAILURE;
362+ }
363
364- printf("%s\n", out);
365+ if (strcmp(out, "00FF7F80B9C0") != 0)
366+ {
367+ printf("Bad result data\n");
368+ return EXIT_FAILURE;
369+ }
370 return EXIT_SUCCESS;
371 }
372
373=== modified file 'tests/unit/include.am'
374--- tests/unit/include.am 2012-12-23 01:05:57 +0000
375+++ tests/unit/include.am 2012-12-27 22:12:23 +0000
376@@ -22,6 +22,16 @@
377 check_PROGRAMS+= tests/unit/query
378 noinst_PROGRAMS+= tests/unit/query
379
380+tests_unit_column_SOURCES= tests/unit/column.c
381+tests_unit_column_LDADD= libdrizzle/libdrizzle.la
382+check_PROGRAMS+= tests/unit/column
383+noinst_PROGRAMS+= tests/unit/column
384+
385+tests_unit_row_SOURCES= tests/unit/row.c
386+tests_unit_row_LDADD= libdrizzle/libdrizzle.la
387+check_PROGRAMS+= tests/unit/row
388+noinst_PROGRAMS+= tests/unit/row
389+
390 tests_unit_version_SOURCES= tests/unit/version.c
391 tests_unit_version_LDADD= libdrizzle/libdrizzle.la
392 check_PROGRAMS+= tests/unit/version
393
394=== modified file 'tests/unit/insert_id.c'
395--- tests/unit/insert_id.c 2012-12-27 12:30:14 +0000
396+++ tests/unit/insert_id.c 2012-12-27 22:12:23 +0000
397@@ -35,11 +35,11 @@
398 *
399 */
400
401-#include "config.h"
402-
403 #include <libdrizzle-5.1/libdrizzle.h>
404 #include <stdio.h>
405 #include <stdlib.h>
406+#include <stdint.h>
407+#include <inttypes.h>
408
409 #ifndef EXIT_SKIP
410 # define EXIT_SKIP 77
411@@ -81,7 +81,11 @@
412 return EXIT_FAILURE;
413 }
414
415- printf("Insert id: %"PRIu64"\n", drizzle_result_insert_id(result));
416+ if (drizzle_result_insert_id(result) != 1)
417+ {
418+ printf("Got bad insert_id (expected 1, got %"PRIu64")", drizzle_result_insert_id(result));
419+ return EXIT_FAILURE;
420+ }
421 drizzle_result_free(result);
422
423 result= drizzle_query_str(con, "insert into libdrizzle.t1 (b) values (4),(5),(6)", &ret);
424@@ -91,7 +95,11 @@
425 return EXIT_FAILURE;
426 }
427
428- printf("Insert id: %"PRIu64"\n", drizzle_result_insert_id(result));
429+ if (drizzle_result_insert_id(result) != 4)
430+ {
431+ printf("Got bad insert_id (expected 4, got %"PRIu64")", drizzle_result_insert_id(result));
432+ return EXIT_FAILURE;
433+ }
434 drizzle_result_free(result);
435
436 drizzle_query_str(con, "drop table libdrizzle.t1", &ret);
437
438=== modified file 'tests/unit/passwd.c'
439--- tests/unit/passwd.c 2012-12-24 10:20:04 +0000
440+++ tests/unit/passwd.c 2012-12-27 22:12:23 +0000
441@@ -35,11 +35,12 @@
442 *
443 */
444
445-#include "config.h"
446-
447 #include <libdrizzle-5.1/libdrizzle.h>
448 #include <stdio.h>
449+#include <string.h>
450 #include <stdlib.h>
451+#include <stdint.h>
452+#include <string.h>
453
454 int main(int argc, char* argv[])
455 {
456@@ -53,12 +54,22 @@
457 // Test for bad usage
458 result= drizzle_mysql_password_hash(out, in, 0);
459 if (result)
460+ {
461+ printf("Usage test failure\n");
462 return EXIT_FAILURE;
463+ }
464
465 result= drizzle_mysql_password_hash(out, in, strlen(in));
466 if (!result)
467+ {
468+ printf("Didn't get a result failure\n");
469 return EXIT_FAILURE;
470+ }
471
472- printf("%s\n", out);
473+ if (strcmp(out, "597B78D6E0366308739CEBB0E221B246F117E111") != 0)
474+ {
475+ printf("Password output didn't match\n");
476+ return EXIT_FAILURE;
477+ }
478 return EXIT_SUCCESS;
479 }
480
481=== modified file 'tests/unit/query.c'
482--- tests/unit/query.c 2012-12-27 12:30:14 +0000
483+++ tests/unit/query.c 2012-12-27 22:12:23 +0000
484@@ -35,10 +35,9 @@
485 *
486 */
487
488-#include "config.h"
489-
490 #include <libdrizzle-5.1/libdrizzle.h>
491 #include <stdio.h>
492+#include <string.h>
493 #include <stdlib.h>
494
495 #ifndef EXIT_SKIP
496@@ -92,10 +91,28 @@
497 drizzle_result_buffer(result);
498 num_fields= drizzle_result_column_count(result);
499
500- printf("%d fields\n", num_fields);
501+ if (num_fields != 1)
502+ {
503+ printf("Retrieved bad number of fields\n");
504+ return EXIT_FAILURE;
505+ }
506+ int i= 0;
507+ char buf[10];
508 while ((row = drizzle_row_next(result)))
509 {
510- printf("Data: %s\n", row[0]);
511+ i++;
512+ snprintf(buf, 10, "%d", i);
513+ if (strcmp(row[0], buf) != 0)
514+ {
515+ printf("Retrieved bad row value\n");
516+ return EXIT_FAILURE;
517+ }
518+ }
519+ /* Should have had 3 rows */
520+ if (i != 3)
521+ {
522+ printf("Retrieved bad number of rows\n");
523+ return EXIT_FAILURE;
524 }
525
526 drizzle_result_free(result);
527
528=== added file 'tests/unit/row.c'
529--- tests/unit/row.c 1970-01-01 00:00:00 +0000
530+++ tests/unit/row.c 2012-12-27 22:12:23 +0000
531@@ -0,0 +1,157 @@
532+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
533+ *
534+ * Drizzle Client & Protocol Library
535+ *
536+ * Copyright (C) 2012 Andrew Hutchings (andrew@linuxjedi.co.uk)
537+ * All rights reserved.
538+ *
539+ * Redistribution and use in source and binary forms, with or without
540+ * modification, are permitted provided that the following conditions are
541+ * met:
542+ *
543+ * * Redistributions of source code must retain the above copyright
544+ * notice, this list of conditions and the following disclaimer.
545+ *
546+ * * Redistributions in binary form must reproduce the above
547+ * copyright notice, this list of conditions and the following disclaimer
548+ * in the documentation and/or other materials provided with the
549+ * distribution.
550+ *
551+ * * The names of its contributors may not be used to endorse or
552+ * promote products derived from this software without specific prior
553+ * written permission.
554+ *
555+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
556+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
557+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
558+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
559+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
560+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
561+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
562+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
563+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
564+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
565+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
566+ *
567+ */
568+
569+#include <libdrizzle-5.1/libdrizzle.h>
570+#include <stdio.h>
571+#include <string.h>
572+#include <stdlib.h>
573+
574+#ifndef EXIT_SKIP
575+# define EXIT_SKIP 77
576+#endif
577+
578+int main(int argc, char *argv[])
579+{
580+ (void) argc;
581+ (void) argv;
582+ drizzle_st *con;
583+ drizzle_return_t ret;
584+ drizzle_result_st *result;
585+ drizzle_row_t row;
586+ int num_fields;
587+
588+ con = drizzle_create_tcp("localhost", 3306, "root", "", "libdrizzle", 0);
589+ if (con == NULL)
590+ {
591+ printf("Drizzle connection object creation error\n");
592+ return EXIT_FAILURE;
593+ }
594+ ret = drizzle_connect(con);
595+ if (ret != DRIZZLE_RETURN_OK)
596+ {
597+ printf("Drizzle connection failure\n");
598+ return EXIT_SKIP;
599+ }
600+
601+ drizzle_query_str(con, "create table libdrizzle.t1 (a int)", &ret);
602+ if (ret != DRIZZLE_RETURN_OK)
603+ {
604+ printf("Create table failure\n");
605+ return EXIT_FAILURE;
606+ }
607+
608+ drizzle_query_str(con, "insert into libdrizzle.t1 values (1),(2),(3)", &ret);
609+ if (ret != DRIZZLE_RETURN_OK)
610+ {
611+ printf("Insert failure\n");
612+ return EXIT_FAILURE;
613+ }
614+
615+ result= drizzle_query_str(con, "select * from libdrizzle.t1", &ret);
616+ if (ret != DRIZZLE_RETURN_OK)
617+ {
618+ printf("Select failure\n");
619+ return EXIT_FAILURE;
620+ }
621+ drizzle_result_buffer(result);
622+ num_fields= drizzle_result_column_count(result);
623+
624+ if (num_fields != 1)
625+ {
626+ printf("Retrieved bad number of fields\n");
627+ return EXIT_FAILURE;
628+ }
629+ row = drizzle_row_next(result);
630+ if (row == NULL)
631+ {
632+ printf("Could not get the next row\n");
633+ return EXIT_FAILURE;
634+ }
635+
636+ if (strcmp(row[0], "1") != 0)
637+ {
638+ printf("Retrieved bad next row value\n");
639+ return EXIT_FAILURE;
640+ }
641+ drizzle_row_seek(result, 3);
642+ row = drizzle_row_prev(result);
643+ if (row == NULL)
644+ {
645+ printf("Could not get prev row\n");
646+ return EXIT_FAILURE;
647+ }
648+ if (strcmp(row[0], "3") != 0)
649+ {
650+ printf("Retrieved bad prev row value: %s\n", row[0]);
651+ return EXIT_FAILURE;
652+ }
653+ row = drizzle_row_index(result, 1);
654+ if (row == NULL)
655+ {
656+ printf("Could not get indexed row\n");
657+ return EXIT_FAILURE;
658+ }
659+ if (strcmp(row[0], "2") != 0)
660+ {
661+ printf("Retrieved bad indexed row value: %s\n", row[0]);
662+ return EXIT_FAILURE;
663+ }
664+ if (drizzle_row_current(result) != 2)
665+ {
666+ printf("Index at wrong pos\n");
667+ return EXIT_FAILURE;
668+ }
669+ size_t *sizes= drizzle_row_field_sizes(result);
670+ if (sizes[0] != 1)
671+ {
672+ printf("Row size mismatch (4 != %lu)\n", sizes[0]);
673+ return EXIT_FAILURE;
674+ }
675+
676+ drizzle_result_free(result);
677+
678+ drizzle_query_str(con, "drop table libdrizzle.t1", &ret);
679+ if (ret != DRIZZLE_RETURN_OK)
680+ {
681+ printf("Drop table failure\n");
682+ return EXIT_FAILURE;
683+ }
684+
685+
686+ drizzle_quit(con);
687+ return EXIT_SUCCESS;
688+}
689
690=== modified file 'tests/unit/statement.c'
691--- tests/unit/statement.c 2012-12-27 12:30:14 +0000
692+++ tests/unit/statement.c 2012-12-27 22:12:23 +0000
693@@ -35,11 +35,13 @@
694 *
695 */
696
697-#include "config.h"
698-
699 #include <libdrizzle-5.1/libdrizzle.h>
700 #include <stdio.h>
701 #include <stdlib.h>
702+#include <stdint.h>
703+#include <string.h>
704+#include <inttypes.h>
705+#include <string.h>
706
707 #ifndef EXIT_SKIP
708 # define EXIT_SKIP 77
709@@ -88,7 +90,12 @@
710 printf("Prepare failure\n");
711 return EXIT_FAILURE;
712 }
713- printf("Params: %" PRIu16 "\n", drizzle_stmt_param_count(stmt));
714+ /* Query should have 1 param */
715+ if (drizzle_stmt_param_count(stmt) != 1)
716+ {
717+ printf("Retrieved bad param count\n");
718+ return EXIT_FAILURE;
719+ }
720
721 uint32_t val= 1;
722 ret = drizzle_stmt_bind_param(stmt, 0, DRIZZLE_COLUMN_TYPE_LONG, &val, 4, DRIZZLE_BIND_OPTION_NONE);
723@@ -110,12 +117,29 @@
724 printf("Buffer failure\n");
725 return EXIT_FAILURE;
726 }
727- printf("Rows found: %" PRIu64 "\n", drizzle_stmt_row_count(stmt));
728+ /* Result should have 2 rows */
729+ if (drizzle_stmt_row_count(stmt) != 2)
730+ {
731+ printf("Retrieved bad row count\n");
732+ return EXIT_FAILURE;
733+ }
734+ uint32_t i= 1;
735 while (drizzle_stmt_fetch(stmt) != DRIZZLE_RETURN_ROW_END)
736 {
737 uint32_t *res_val;
738 res_val= (uint32_t*)drizzle_stmt_item_data(stmt, 0);
739- printf("Got value: %" PRIu32 "\n", *res_val);
740+ i++;
741+ if (*res_val != i)
742+ {
743+ printf("Retrieved unexpected value\n");
744+ return EXIT_FAILURE;
745+ }
746+ }
747+ /* Should have cycled through 2 rows (values 2 and 3) */
748+ if (i != 3)
749+ {
750+ printf("Retrieved bad number of rows\n");
751+ return EXIT_FAILURE;
752 }
753 ret = drizzle_stmt_close(stmt);
754 if (ret != DRIZZLE_RETURN_OK)
755
756=== modified file 'tests/unit/unbuffered_query.c'
757--- tests/unit/unbuffered_query.c 2012-12-27 12:30:14 +0000
758+++ tests/unit/unbuffered_query.c 2012-12-27 22:12:23 +0000
759@@ -35,11 +35,10 @@
760 *
761 */
762
763-#include "config.h"
764-
765 #include <libdrizzle-5.1/libdrizzle.h>
766 #include <stdio.h>
767 #include <stdlib.h>
768+#include <string.h>
769
770 #ifndef EXIT_SKIP
771 # define EXIT_SKIP 77
772@@ -97,7 +96,14 @@
773 }
774 num_fields= drizzle_result_column_count(result);
775
776- printf("%d fields\n", num_fields);
777+ if (num_fields != 1)
778+ {
779+ printf("Retrieved bad number of fields\n");
780+ return EXIT_FAILURE;
781+ }
782+
783+ int i= 0;
784+ char buf[10];
785 while(1)
786 {
787 row= drizzle_row_buffer(result, &ret);
788@@ -111,9 +117,21 @@
789 // EOF
790 break;
791 }
792- printf("Data: %s\n", row[0]);
793+ i++;
794+ snprintf(buf, 10, "%d", i);
795+ if (strcmp(row[0], buf) != 0)
796+ {
797+ printf("Retrieved bad row data\n");
798+ return EXIT_FAILURE;
799+ }
800 drizzle_row_free(result, row);
801 }
802+ /* we should have had 3 rows */
803+ if (i != 3)
804+ {
805+ printf("Retrieved bad number of rows\n");
806+ return EXIT_FAILURE;
807+ }
808
809 drizzle_result_free(result);
810
811
812=== modified file 'tests/unit/version.c'
813--- tests/unit/version.c 2012-12-24 10:20:04 +0000
814+++ tests/unit/version.c 2012-12-27 22:12:23 +0000
815@@ -35,8 +35,6 @@
816 *
817 */
818
819-#include "config.h"
820-
821 #include <libdrizzle-5.1/libdrizzle.h>
822
823 #include <stdio.h>
824
825=== modified file 'tests/unit/version_cxx.cc'
826--- tests/unit/version_cxx.cc 2012-12-24 10:20:04 +0000
827+++ tests/unit/version_cxx.cc 2012-12-27 22:12:23 +0000
828@@ -35,8 +35,6 @@
829 *
830 */
831
832-#include "config.h"
833-
834 #include <libdrizzle-5.1/libdrizzle.h>
835
836 #include <cstddef>

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: