Debian Codegraph @

src/interfaces/ecpg/test/compat_informix/rfmtdate.pgc

raw
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <pgtypes_error.h>
4 #include <sqltypes.h>
5
6 /*
7 * This file tests various forms of date-input/output by means of
8 * rfmtdate / rdefmtdate / rstrdate
9 */
10
11
12 static void
13 check_return(int ret);
14
15 static void
16 date_test_strdate(const char *input)
17 {
18 static int i;
19 date d;
20 int r, q;
21 char dbuf[11];
22
23 r = rstrdate(input, &d);
24 printf("r: %d ", r);
25 if (r == 0)
26 {
27 q = rdatestr(d, dbuf);
28 printf("q: %d ", q);
29 if (q == 0)
30 {
31 printf("date %d: %s\n", i++, dbuf);
32 }
33 else
34 printf("\n");
35 }
36 else
37 check_return(r);
38 }
39
40 static void
41 date_test_defmt(const char *fmt, const char *input)
42 {
43 static int i;
44 char dbuf[11];
45 date d;
46 int q, r;
47
48 r = rdefmtdate(&d, fmt, input);
49 printf("r: %d ", r);
50 if (r == 0)
51 {
52 q = rdatestr(d, dbuf);
53 printf("q: %d ", q);
54 if (q == 0)
55 {
56 printf("date %d: %s\n", i++, dbuf);
57 }
58 else
59 printf("\n");
60 }
61 else
62 check_return(r);
63 }
64
65 static void
66 date_test_fmt(date d, const char *fmt)
67 {
68 static int i;
69 char buf[200];
70 int r;
71
72 r = rfmtdate(d, fmt, buf);
73 printf("r: %d ", r);
74 if (r != 0)
75 check_return(r);
76 else
77 printf("date: %d: %s\n", i++, buf);
78 }
79
80
81 int
82 main(void)
83 {
84 short mdy[3] = { 11, 23, 1959 };
85 char dbuf[11];
86 date d;
87 int r;
88
89 ECPGdebug(1, stderr);
90
91 r = rmdyjul(mdy, &d);
92 printf("create: r: %d\n", r);
93 if (r == 0)
94 {
95 rdatestr(d, dbuf);
96 printf("date: %s\n", dbuf);
97 }
98
99 /* input mask is mmddyyyy */
100 date_test_strdate("12031994");
101 date_test_strdate("9.6.1994");
102
103 date_test_fmt(d, "mmddyy");
104 date_test_fmt(d, "ddmmyy");
105 date_test_fmt(d, "yymmdd");
106 date_test_fmt(d, "yy/mm/dd");
107 date_test_fmt(d, "yy mm dd");
108 date_test_fmt(d, "yy.mm.dd");
109 date_test_fmt(d, ".mm.yyyy.dd.");
110 date_test_fmt(d, "mmm. dd, yyyy");
111 date_test_fmt(d, "mmm dd yyyy");
112 date_test_fmt(d, "yyyy dd mm");
113 date_test_fmt(d, "ddd, mmm. dd, yyyy");
114 date_test_fmt(d, "(ddd) mmm. dd, yyyy");
115
116 date_test_defmt("ddmmyy", "21-2-54");
117 date_test_defmt("ddmmyy", "2-12-54");
118 date_test_defmt("ddmmyy", "20111954");
119 date_test_defmt("ddmmyy", "130464");
120 date_test_defmt("mmm.dd.yyyy", "MAR-12-1967");
121 date_test_defmt("yy/mm/dd", "1954, February 3rd");
122 date_test_defmt("mmm.dd.yyyy", "041269");
123 date_test_defmt("yy/mm/dd", "In the year 2525, in the month of July, mankind will be alive on the 28th day");
124 date_test_defmt("dd-mm-yy", "I said on the 28th of July in the year 2525");
125 date_test_defmt("mmm.dd.yyyy", "9/14/58");
126 date_test_defmt("yy/mm/dd", "47/03/29");
127 date_test_defmt("mmm.dd.yyyy", "oct 28 1975");
128 date_test_defmt("mmddyy", "Nov 14th, 1985");
129 /* ok: still contains dd mm yy */
130 date_test_defmt("bladdfoommbaryybong", "20/11/1954");
131 /* 1994 is not a leap year, it accepts the date as 01-03-1994 */
132 date_test_defmt("ddmmyy", "29-02-1994");
133
134 /* ECPG_INFORMIX_ENOTDMY, need "dd", "mm" and "yy" */
135 date_test_defmt("dmy", "20/11/1954");
136
137 /* ECPG_INFORMIX_ENOSHORTDATE */
138 date_test_defmt("ddmmyy", "21254");
139 date_test_defmt("ddmmyy", " 21254 ");
140
141 /* ECPG_INFORMIX_BAD_DAY */
142 date_test_defmt("ddmmyy", "320494");
143
144 /* ECPG_INFORMIX_BAD_MONTH */
145 date_test_defmt("mm-yyyy-dd", "13-1993-21");
146
147 /* ECPG_INFORMIX_BAD_YEAR */
148 /* ??? */
149
150 return 0;
151 }
152
153 static void
154 check_return(int ret)
155 {
156 switch(ret)
157 {
158 case ECPG_INFORMIX_ENOTDMY:
159 printf("(ECPG_INFORMIX_ENOTDMY)");
160 break;
161 case ECPG_INFORMIX_ENOSHORTDATE:
162 printf("(ECPG_INFORMIX_ENOSHORTDATE)");
163 break;
164 case ECPG_INFORMIX_BAD_DAY:
165 printf("(ECPG_INFORMIX_BAD_DAY)");
166 break;
167 case ECPG_INFORMIX_BAD_MONTH:
168 printf("(ECPG_INFORMIX_BAD_MONTH)");
169 break;
170 default:
171 printf("(unknown ret: %d)", ret);
172 break;
173 }
174 printf("\n");
175 }