Chris@0: /* Chris@0: ** Copyright (C) 2005-2011 Erik de Castro Lopo Chris@0: ** Chris@0: ** This program is free software; you can redistribute it and/or modify Chris@0: ** it under the terms of the GNU General Public License as published by Chris@0: ** the Free Software Foundation; either version 2 of the License, or Chris@0: ** (at your option) any later version. Chris@0: ** Chris@0: ** This program is distributed in the hope that it will be useful, Chris@0: ** but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: ** GNU General Public License for more details. Chris@0: ** Chris@0: ** You should have received a copy of the GNU General Public License Chris@0: ** along with this program; if not, write to the Free Software Chris@0: ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Chris@0: */ Chris@0: Chris@0: #include "sfconfig.h" Chris@0: Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: Chris@0: #if HAVE_UNISTD_H Chris@0: #include Chris@0: #endif Chris@0: Chris@0: #if HAVE_LOCALE_H Chris@0: #include Chris@0: #endif Chris@0: Chris@0: #if OS_IS_WIN32 Chris@0: #include Chris@0: #define ENABLE_SNDFILE_WINDOWS_PROTOTYPES 1 Chris@0: #endif Chris@0: Chris@0: #include "sndfile.h" Chris@0: #include "utils.h" Chris@0: Chris@0: static void utf8_test (void) ; Chris@0: static void wchar_test (void) ; Chris@0: Chris@0: int Chris@0: main (void) Chris@0: { Chris@0: utf8_test () ; Chris@0: wchar_test () ; Chris@0: Chris@0: return 0 ; Chris@0: } /* main */ Chris@0: Chris@0: /*============================================================================== Chris@0: */ Chris@0: Chris@0: static void Chris@0: wchar_test (void) Chris@0: { Chris@0: #if OS_IS_WIN32 Chris@0: SNDFILE * file ; Chris@0: SF_INFO info ; Chris@0: LPCWSTR filename = L"test.wav" ; Chris@0: Chris@0: print_test_name (__func__, "test.wav") ; Chris@0: Chris@0: info.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ; Chris@0: info.channels = 1 ; Chris@0: info.samplerate = 44100 ; Chris@0: Chris@0: file = sf_wchar_open (filename, SFM_WRITE, &info) ; Chris@0: exit_if_true (file == NULL, "\n\nLine %d : sf_wchar_open failed : %s\n\n", __LINE__, sf_strerror (NULL)) ; Chris@0: sf_close (file) ; Chris@0: Chris@0: /* This should check that the file did in fact get created with a Chris@0: ** wchar_t * filename. Chris@0: */ Chris@0: exit_if_true ( Chris@0: GetFileAttributesW (filename) == INVALID_FILE_ATTRIBUTES, Chris@0: "\n\nLine %d : GetFileAttributes failed.\n\n", __LINE__ Chris@0: ) ; Chris@0: Chris@0: /* Use this because the file was created with CreateFileW. */ Chris@0: DeleteFileW (filename) ; Chris@0: Chris@0: puts ("ok") ; Chris@0: #endif Chris@0: } /* wchar_test */ Chris@0: Chris@0: /*============================================================================== Chris@0: */ Chris@0: Chris@0: typedef struct Chris@0: { const char *locale ; Chris@0: int utf8 ; Chris@0: const char *filename ; Chris@0: int width ; Chris@0: } LOCALE_DATA ; Chris@0: Chris@0: static void locale_test (const LOCALE_DATA * locdata) ; Chris@0: Chris@0: static void Chris@0: utf8_test (void) Chris@0: { LOCALE_DATA ldata [] = Chris@0: { { "de_DE", 1, "F\303\274\303\237e.au", 7 }, Chris@0: { "en_AU", 1, "kangaroo.au", 11 }, Chris@0: { "POSIX", 0, "posix.au", 8 }, Chris@0: { "pt_PT", 1, "concei\303\247\303\243o.au", 12 }, Chris@0: Chris@0: #if OS_IS_WIN32 == 0 Chris@0: { "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: #endif Chris@0: Chris@0: { "vi_VN", 1, "qu\341\273\221c ng\341\273\257.au", 11 }, Chris@0: { NULL, 0, NULL, 0 } Chris@0: } ; Chris@0: int k ; Chris@0: Chris@0: for (k = 0 ; ldata [k].locale != NULL ; k++) Chris@0: locale_test (ldata + k) ; Chris@0: } /* utf8_test */ Chris@0: Chris@0: Chris@0: static void Chris@0: locale_test (const LOCALE_DATA * ldata) Chris@0: { Chris@0: #if (HAVE_LOCALE_H == 0 || HAVE_SETLOCALE == 0) Chris@0: locname = filename = NULL ; Chris@0: width = 0 ; Chris@0: return ; Chris@0: #else Chris@0: const short wdata [] = { 1, 2, 3, 4, 5, 6, 7, 8 } ; Chris@0: short rdata [ARRAY_LEN (wdata)] ; Chris@0: const char *old_locale ; Chris@0: char utf8_locname [32] ; Chris@0: SNDFILE *file ; Chris@0: SF_INFO sfinfo ; Chris@0: Chris@0: snprintf (utf8_locname, sizeof (utf8_locname), "%s%s", ldata->locale, ldata->utf8 ? ".UTF-8" : "") ; Chris@0: Chris@0: /* Change the locale saving the old one. */ Chris@0: if ((old_locale = setlocale (LC_CTYPE, utf8_locname)) == NULL) Chris@0: return ; Chris@0: Chris@0: printf (" locale_test %-8s : %s %*c ", ldata->locale, ldata->filename, 24 - ldata->width, ' ') ; Chris@0: fflush (stdout) ; Chris@0: Chris@0: sfinfo.format = SF_FORMAT_AU | SF_FORMAT_PCM_16 ; Chris@0: sfinfo.channels = 1 ; Chris@0: sfinfo.samplerate = 44100 ; Chris@0: Chris@0: file = test_open_file_or_die (ldata->filename, SFM_WRITE, &sfinfo, 0, __LINE__) ; Chris@0: test_write_short_or_die (file, 0, wdata, ARRAY_LEN (wdata), __LINE__) ; Chris@0: sf_close (file) ; Chris@0: Chris@0: file = test_open_file_or_die (ldata->filename, SFM_READ, &sfinfo, 0, __LINE__) ; Chris@0: test_read_short_or_die (file, 0, rdata, ARRAY_LEN (rdata), __LINE__) ; Chris@0: sf_close (file) ; Chris@0: Chris@0: unlink (ldata->filename) ; Chris@0: Chris@0: /* Restore old locale. */ Chris@0: setlocale (LC_CTYPE, old_locale) ; Chris@0: Chris@0: puts ("ok") ; Chris@0: #endif Chris@0: } /* locale_test */ Chris@0: