2 ** Copyright 2011 Double Precision, Inc.
3 ** See COPYING for distribution information.
7 #include "unicode_config.h"
20 static int save_output(const char *p
, size_t n
, void *ptr
)
22 struct collect_buf
*cb
=(struct collect_buf
*)ptr
;
26 if (cb
->cnt
< cb
->size
)
27 cb
->ptr
[cb
->cnt
++]=*p
;
36 static const char teststr
[]= {
37 0x00, 0x00, 0x00, 0x41,
38 0x00, 0x00, 0x04, 0x14,
39 0x00, 0x00, 0x04, 0x30,
40 0x00, 0x00, 0x00, 0x42};
42 struct collect_buf cb
;
43 libmail_u_convert_handle_t h
;
48 cb
.size
=sizeof(outputbuf
);
50 if ((h
=libmail_u_convert_init("UCS-4BE", "ISO-8859-1",
51 save_output
, &cb
)) == NULL
)
53 perror("libmail_u_convert_init");
57 libmail_u_convert(h
, teststr
, sizeof(teststr
));
59 if (libmail_u_convert_deinit(h
, &checkflag
))
61 perror("libmail_u_convert_deinit");
64 if (cb
.cnt
!= 2 || memcmp(cb
.ptr
, "AB", 2) || !checkflag
)
66 fprintf(stderr
, "Unexpected result from convert()\n");
75 libmail_u_convert_handle_t h
=
76 libmail_u_convert_tou_init("utf-8", &ucptr
, &ucsize
, 1);
84 for (i
=0; i
<1024/32; ++i
)
85 libmail_u_convert(h
, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
88 if (libmail_u_convert_deinit(h
, NULL
) == 0 &&
91 for (i
=0; i
<1024; i
++)
97 h
=libmail_u_convert_fromu_init("utf-8",
103 libmail_u_convert_uc(h
, ucptr
, 1024);
104 if (libmail_u_convert_deinit(h
, NULL
)
105 == 0 && csize
== 1024+1)
107 for (i
=0; i
<1024; i
++)
119 fprintf(stderr
, "test2: failed");
126 int main(int argc
, char **argv
)
128 const char *chset
=unicode_x_imap_modutf7
;
131 if (argn
< argc
&& strcmp(argv
[argn
], "--smap") == 0)
133 chset
=unicode_x_imap_modutf7
" ./~:";
137 if (argn
< argc
&& strcmp(argv
[argn
], "--totitle") == 0)
143 char *p
=libmail_u_convert_tocase(argv
[argn
],
161 char *p
=libmail_u_convert_tobuf(argv
[argn
],
169 perror("libmail_u_convert");
175 fprintf(stderr
, "Conversion error?\n");
179 q
=libmail_u_convert_tobuf(p
, chset
, "utf-8", &errflag
);
182 perror("libmail_u_convert");
188 fprintf(stderr
, "Conversion error?\n");
191 if (strcmp(q
, argv
[argn
]))
193 fprintf(stderr
, "Round trip error\n");