Chris@0
|
1 /*
|
Chris@0
|
2 ** Copyright (C) 2005-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
Chris@0
|
3 **
|
Chris@0
|
4 ** This program is free software; you can redistribute it and/or modify
|
Chris@0
|
5 ** it under the terms of the GNU General Public License as published by
|
Chris@0
|
6 ** the Free Software Foundation; either version 2 of the License, or
|
Chris@0
|
7 ** (at your option) any later version.
|
Chris@0
|
8 **
|
Chris@0
|
9 ** This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 ** GNU General Public License for more details.
|
Chris@0
|
13 **
|
Chris@0
|
14 ** You should have received a copy of the GNU General Public License
|
Chris@0
|
15 ** along with this program; if not, write to the Free Software
|
Chris@0
|
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Chris@0
|
17 */
|
Chris@0
|
18
|
Chris@0
|
19 #include "sfconfig.h"
|
Chris@0
|
20
|
Chris@0
|
21 #include <stdio.h>
|
Chris@0
|
22 #include <stdlib.h>
|
Chris@0
|
23 #include <string.h>
|
Chris@0
|
24
|
Chris@0
|
25 #if HAVE_UNISTD_H
|
Chris@0
|
26 #include <unistd.h>
|
Chris@0
|
27 #endif
|
Chris@0
|
28
|
Chris@0
|
29 #if HAVE_LOCALE_H
|
Chris@0
|
30 #include <locale.h>
|
Chris@0
|
31 #endif
|
Chris@0
|
32
|
Chris@0
|
33 #if OS_IS_WIN32
|
Chris@0
|
34 #include <windows.h>
|
Chris@0
|
35 #define ENABLE_SNDFILE_WINDOWS_PROTOTYPES 1
|
Chris@0
|
36 #endif
|
Chris@0
|
37
|
Chris@0
|
38 #include "sndfile.h"
|
Chris@0
|
39 #include "utils.h"
|
Chris@0
|
40
|
Chris@0
|
41 static void utf8_test (void) ;
|
Chris@0
|
42 static void wchar_test (void) ;
|
Chris@0
|
43
|
Chris@0
|
44 int
|
Chris@0
|
45 main (void)
|
Chris@0
|
46 {
|
Chris@0
|
47 utf8_test () ;
|
Chris@0
|
48 wchar_test () ;
|
Chris@0
|
49
|
Chris@0
|
50 return 0 ;
|
Chris@0
|
51 } /* main */
|
Chris@0
|
52
|
Chris@0
|
53 /*==============================================================================
|
Chris@0
|
54 */
|
Chris@0
|
55
|
Chris@0
|
56 static void
|
Chris@0
|
57 wchar_test (void)
|
Chris@0
|
58 {
|
Chris@0
|
59 #if OS_IS_WIN32
|
Chris@0
|
60 SNDFILE * file ;
|
Chris@0
|
61 SF_INFO info ;
|
Chris@0
|
62 LPCWSTR filename = L"test.wav" ;
|
Chris@0
|
63
|
Chris@0
|
64 print_test_name (__func__, "test.wav") ;
|
Chris@0
|
65
|
Chris@0
|
66 info.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ;
|
Chris@0
|
67 info.channels = 1 ;
|
Chris@0
|
68 info.samplerate = 44100 ;
|
Chris@0
|
69
|
Chris@0
|
70 file = sf_wchar_open (filename, SFM_WRITE, &info) ;
|
Chris@0
|
71 exit_if_true (file == NULL, "\n\nLine %d : sf_wchar_open failed : %s\n\n", __LINE__, sf_strerror (NULL)) ;
|
Chris@0
|
72 sf_close (file) ;
|
Chris@0
|
73
|
Chris@0
|
74 /* This should check that the file did in fact get created with a
|
Chris@0
|
75 ** wchar_t * filename.
|
Chris@0
|
76 */
|
Chris@0
|
77 exit_if_true (
|
Chris@0
|
78 GetFileAttributesW (filename) == INVALID_FILE_ATTRIBUTES,
|
Chris@0
|
79 "\n\nLine %d : GetFileAttributes failed.\n\n", __LINE__
|
Chris@0
|
80 ) ;
|
Chris@0
|
81
|
Chris@0
|
82 /* Use this because the file was created with CreateFileW. */
|
Chris@0
|
83 DeleteFileW (filename) ;
|
Chris@0
|
84
|
Chris@0
|
85 puts ("ok") ;
|
Chris@0
|
86 #endif
|
Chris@0
|
87 } /* wchar_test */
|
Chris@0
|
88
|
Chris@0
|
89 /*==============================================================================
|
Chris@0
|
90 */
|
Chris@0
|
91
|
Chris@0
|
92 typedef struct
|
Chris@0
|
93 { const char *locale ;
|
Chris@0
|
94 int utf8 ;
|
Chris@0
|
95 const char *filename ;
|
Chris@0
|
96 int width ;
|
Chris@0
|
97 } LOCALE_DATA ;
|
Chris@0
|
98
|
Chris@0
|
99 static void locale_test (const LOCALE_DATA * locdata) ;
|
Chris@0
|
100
|
Chris@0
|
101 static void
|
Chris@0
|
102 utf8_test (void)
|
Chris@0
|
103 { LOCALE_DATA ldata [] =
|
Chris@0
|
104 { { "de_DE", 1, "F\303\274\303\237e.au", 7 },
|
Chris@0
|
105 { "en_AU", 1, "kangaroo.au", 11 },
|
Chris@0
|
106 { "POSIX", 0, "posix.au", 8 },
|
Chris@0
|
107 { "pt_PT", 1, "concei\303\247\303\243o.au", 12 },
|
Chris@0
|
108
|
Chris@0
|
109 #if OS_IS_WIN32 == 0
|
Chris@0
|
110 { "ja_JP", 1, "\343\201\212\343\201\257\343\202\210\343\201\206\343\201\224\343\201\226\343\201\204\343\201\276\343\201\231.au", 21 },
|
Chris@0
|
111 #endif
|
Chris@0
|
112
|
Chris@0
|
113 { "vi_VN", 1, "qu\341\273\221c ng\341\273\257.au", 11 },
|
Chris@0
|
114 { NULL, 0, NULL, 0 }
|
Chris@0
|
115 } ;
|
Chris@0
|
116 int k ;
|
Chris@0
|
117
|
Chris@0
|
118 for (k = 0 ; ldata [k].locale != NULL ; k++)
|
Chris@0
|
119 locale_test (ldata + k) ;
|
Chris@0
|
120 } /* utf8_test */
|
Chris@0
|
121
|
Chris@0
|
122
|
Chris@0
|
123 static void
|
Chris@0
|
124 locale_test (const LOCALE_DATA * ldata)
|
Chris@0
|
125 {
|
Chris@0
|
126 #if (HAVE_LOCALE_H == 0 || HAVE_SETLOCALE == 0)
|
Chris@0
|
127 locname = filename = NULL ;
|
Chris@0
|
128 width = 0 ;
|
Chris@0
|
129 return ;
|
Chris@0
|
130 #else
|
Chris@0
|
131 const short wdata [] = { 1, 2, 3, 4, 5, 6, 7, 8 } ;
|
Chris@0
|
132 short rdata [ARRAY_LEN (wdata)] ;
|
Chris@0
|
133 const char *old_locale ;
|
Chris@0
|
134 char utf8_locname [32] ;
|
Chris@0
|
135 SNDFILE *file ;
|
Chris@0
|
136 SF_INFO sfinfo ;
|
Chris@0
|
137
|
Chris@0
|
138 snprintf (utf8_locname, sizeof (utf8_locname), "%s%s", ldata->locale, ldata->utf8 ? ".UTF-8" : "") ;
|
Chris@0
|
139
|
Chris@0
|
140 /* Change the locale saving the old one. */
|
Chris@0
|
141 if ((old_locale = setlocale (LC_CTYPE, utf8_locname)) == NULL)
|
Chris@0
|
142 return ;
|
Chris@0
|
143
|
Chris@0
|
144 printf (" locale_test %-8s : %s %*c ", ldata->locale, ldata->filename, 24 - ldata->width, ' ') ;
|
Chris@0
|
145 fflush (stdout) ;
|
Chris@0
|
146
|
Chris@0
|
147 sfinfo.format = SF_FORMAT_AU | SF_FORMAT_PCM_16 ;
|
Chris@0
|
148 sfinfo.channels = 1 ;
|
Chris@0
|
149 sfinfo.samplerate = 44100 ;
|
Chris@0
|
150
|
Chris@0
|
151 file = test_open_file_or_die (ldata->filename, SFM_WRITE, &sfinfo, 0, __LINE__) ;
|
Chris@0
|
152 test_write_short_or_die (file, 0, wdata, ARRAY_LEN (wdata), __LINE__) ;
|
Chris@0
|
153 sf_close (file) ;
|
Chris@0
|
154
|
Chris@0
|
155 file = test_open_file_or_die (ldata->filename, SFM_READ, &sfinfo, 0, __LINE__) ;
|
Chris@0
|
156 test_read_short_or_die (file, 0, rdata, ARRAY_LEN (rdata), __LINE__) ;
|
Chris@0
|
157 sf_close (file) ;
|
Chris@0
|
158
|
Chris@0
|
159 unlink (ldata->filename) ;
|
Chris@0
|
160
|
Chris@0
|
161 /* Restore old locale. */
|
Chris@0
|
162 setlocale (LC_CTYPE, old_locale) ;
|
Chris@0
|
163
|
Chris@0
|
164 puts ("ok") ;
|
Chris@0
|
165 #endif
|
Chris@0
|
166 } /* locale_test */
|
Chris@0
|
167
|