| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
#ifdef HAVE_CONFIG_H |
|---|
| 23 |
# include "config.h" |
|---|
| 24 |
#endif |
|---|
| 25 |
|
|---|
| 26 |
#include <vlc_common.h> |
|---|
| 27 |
#include "vlc_charset.h" |
|---|
| 28 |
|
|---|
| 29 |
#include <stdio.h> |
|---|
| 30 |
#include <stdlib.h> |
|---|
| 31 |
#include <stdbool.h> |
|---|
| 32 |
|
|---|
| 33 |
static void test (const char *in, const char *out) |
|---|
| 34 |
{ |
|---|
| 35 |
bool isutf8 = !strcmp (in, out); |
|---|
| 36 |
char *str = strdup (in); |
|---|
| 37 |
if (str == NULL) |
|---|
| 38 |
abort (); |
|---|
| 39 |
|
|---|
| 40 |
if (isutf8) |
|---|
| 41 |
printf ("\"%s\" should be accepted...\n", in); |
|---|
| 42 |
else |
|---|
| 43 |
printf ("\"%s\" should be rewritten as \"%s\"...\n", in, out); |
|---|
| 44 |
|
|---|
| 45 |
if ((IsUTF8 (in) != NULL) != isutf8) |
|---|
| 46 |
{ |
|---|
| 47 |
printf (" ERROR: IsUTF8 (%s) failed\n", in); |
|---|
| 48 |
exit (1); |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
if ((EnsureUTF8 (str) != NULL) != isutf8) |
|---|
| 52 |
{ |
|---|
| 53 |
printf (" ERROR: EnsureUTF8 (%s) failed\n", in); |
|---|
| 54 |
exit (2); |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
if (strcmp (str, out)) |
|---|
| 58 |
{ |
|---|
| 59 |
printf (" ERROR: got \"%s\"\n", str); |
|---|
| 60 |
exit (3); |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
if ((EnsureUTF8 (str) == NULL) || IsUTF8 (str) == NULL) |
|---|
| 64 |
{ |
|---|
| 65 |
printf (" ERROR: EnsureUTF8 (%s) is not UTF-8\n", in); |
|---|
| 66 |
exit (4); |
|---|
| 67 |
} |
|---|
| 68 |
free (str); |
|---|
| 69 |
} |
|---|
| 70 |
|
|---|
| 71 |
int main (void) |
|---|
| 72 |
{ |
|---|
| 73 |
(void)setvbuf (stdout, NULL, _IONBF, 0); |
|---|
| 74 |
test ("", ""); |
|---|
| 75 |
|
|---|
| 76 |
test ("this_should_not_be_modified_1234", |
|---|
| 77 |
"this_should_not_be_modified_1234"); |
|---|
| 78 |
|
|---|
| 79 |
test ("\xFF", "?"); |
|---|
| 80 |
test ("\xEF\xBB\xBFHello", "\xEF\xBB\xBFHello"); |
|---|
| 81 |
test ("\x00\xE9", ""); |
|---|
| 82 |
|
|---|
| 83 |
test ("T\xC3\xA9l\xC3\xA9vision \xE2\x82\xAC", "Télévision €"); |
|---|
| 84 |
test ("T\xE9l\xE9vision", "T?l?vision"); |
|---|
| 85 |
test ("\xC1\x94\xC3\xa9l\xC3\xA9vision", "??élévision"); |
|---|
| 86 |
|
|---|
| 87 |
test ("Hel\xF0\x83\x85\x87lo", "Hel????lo"); |
|---|
| 88 |
return 0; |
|---|
| 89 |
} |
|---|