Line data Source code
1 : /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2 : * Copyright (C) 2010-2018 Frediano Ziglio
3 : *
4 : * This library is free software; you can redistribute it and/or
5 : * modify it under the terms of the GNU Library General Public
6 : * License as published by the Free Software Foundation; either
7 : * version 2 of the License, or (at your option) any later version.
8 : *
9 : * This library is distributed in the hope that it will be useful,
10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 : * Library General Public License for more details.
13 : *
14 : * You should have received a copy of the GNU Library General Public
15 : * License along with this library; if not, write to the
16 : * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 : * Boston, MA 02111-1307, USA.
18 : */
19 :
20 : #define TDS_INTERNAL_TEST 1
21 :
22 : #include <config.h>
23 :
24 : #include <stdarg.h>
25 : #include <stdio.h>
26 : #include <stdlib.h>
27 :
28 : #if HAVE_STRING_H
29 : #include <string.h>
30 : #endif /* HAVE_STRING_H */
31 :
32 : #include <freetds/replacements.h>
33 :
34 : static void
35 48 : test(const char *s, const char *sep)
36 : {
37 48 : size_t len = strlen(s);
38 48 : char *c1 = (char*) malloc(len+1);
39 48 : char *c2 = (char*) malloc(len+1);
40 48 : char *last = NULL, *s1, *s2;
41 : const char *p1, *p2;
42 :
43 48 : printf("testint '%s' with '%s' separator(s)\n", s, sep);
44 48 : strcpy(c1, s);
45 48 : strcpy(c2, s);
46 :
47 48 : s1 = c1;
48 48 : s2 = c2;
49 : for (;;) {
50 240 : p1 = strtok(s1, sep);
51 144 : p2 = strtok_r(s2, sep, &last);
52 144 : s1 = s2 = NULL;
53 144 : if ((p1 && !p2) || (!p1 && p2)) {
54 0 : fprintf(stderr, "ptr mistmach %p %p\n", p1, p2);
55 0 : exit(1);
56 : }
57 144 : if (!p1)
58 : break;
59 96 : if (strcmp(p1, p2) != 0) {
60 0 : fprintf(stderr, "string mistmach '%s' '%s'\n", p1, p2);
61 0 : exit(1);
62 : }
63 96 : printf("got string %s\n", p1);
64 : }
65 48 : printf("\n");
66 48 : free(c1);
67 48 : free(c2);
68 48 : }
69 :
70 : int
71 8 : main(void)
72 : {
73 8 : test("a b\tc", "\t ");
74 8 : test(" x y \t z", " \t");
75 8 : test("a;b;c;", ";");
76 8 : test("a;b; c;;", ";");
77 8 : test("", ";");
78 8 : test(";;;", ";");
79 : return 0;
80 : }
|