cannam@85: /* cannam@85: ** Copyright (C) 2006-2011 Erik de Castro Lopo cannam@85: ** cannam@85: ** This program is free software; you can redistribute it and/or modify cannam@85: ** it under the terms of the GNU General Public License as published by cannam@85: ** the Free Software Foundation; either version 2 of the License, or cannam@85: ** (at your option) any later version. cannam@85: ** cannam@85: ** This program is distributed in the hope that it will be useful, cannam@85: ** but WITHOUT ANY WARRANTY; without even the implied warranty of cannam@85: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the cannam@85: ** GNU General Public License for more details. cannam@85: ** cannam@85: ** You should have received a copy of the GNU General Public License cannam@85: ** along with this program; if not, write to the Free Software cannam@85: ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. cannam@85: */ cannam@85: cannam@85: #include "sfconfig.h" cannam@85: #include "sndfile.h" cannam@85: cannam@85: #include cannam@85: #include cannam@85: cannam@85: #if HAVE_UNISTD_H cannam@85: #include cannam@85: #endif cannam@85: cannam@85: #if (HAVE_DECL_S_IRGRP == 0) cannam@85: #include cannam@85: #endif cannam@85: cannam@85: #include cannam@85: #include cannam@85: #include cannam@85: cannam@85: #include "utils.h" cannam@85: cannam@85: #if (defined (WIN32) || defined (_WIN32) || defined (__CYGWIN__)) cannam@85: #define TEST_WIN32 1 cannam@85: #else cannam@85: #define TEST_WIN32 0 cannam@85: #endif cannam@85: cannam@85: #if TEST_WIN32 cannam@85: #include cannam@85: cannam@85: cannam@85: static const char * locations [] = cannam@85: { ".", "../src/", "src/", "../src/.libs/", "src/.libs/", cannam@85: NULL cannam@85: } ; /* locations. */ cannam@85: cannam@85: static int cannam@85: test_ordinal (HMODULE hmod, const char * func_name, int ordinal) cannam@85: { char *lpmsg ; cannam@85: void *name, *ord ; cannam@85: cannam@85: print_test_name ("win32_ordinal_test", func_name) ; cannam@85: cannam@85: #if SIZEOF_VOIDP == 8 cannam@85: #define LPCSTR_OF_ORDINAL(x) ((LPCSTR) ((int64_t) (x))) cannam@85: #else cannam@85: #define LPCSTR_OF_ORDINAL(x) ((LPCSTR) (x)) cannam@85: #endif cannam@85: cannam@85: ord = GetProcAddress (hmod, LPCSTR_OF_ORDINAL (ordinal)) ; cannam@85: if ((name = GetProcAddress (hmod, func_name)) == NULL) cannam@85: { FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError (), cannam@85: MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpmsg, 0, NULL) ; cannam@85: /*-puts (lpmsg) ;-*/ cannam@85: } ; cannam@85: cannam@85: if (name != NULL && ord != NULL && name == ord) cannam@85: { puts ("ok") ; cannam@85: return 0 ; cannam@85: } ; cannam@85: cannam@85: puts ("fail") ; cannam@85: return 1 ; cannam@85: } /* test_ordinal */ cannam@85: cannam@85: static void cannam@85: win32_ordinal_test (void) cannam@85: { static char buffer [1024] ; cannam@85: static char func_name [1024] ; cannam@85: HMODULE hmod = NULL ; cannam@85: FILE * file = NULL ; cannam@85: int k, ordinal, errors = 0 ; cannam@85: cannam@85: for (k = 0 ; locations [k] != NULL ; k++) cannam@85: { snprintf (buffer, sizeof (buffer), "%s/libsndfile-1.def", locations [k]) ; cannam@85: if ((file = fopen (buffer, "r")) != NULL) cannam@85: break ; cannam@85: } ; cannam@85: cannam@85: if (file == NULL) cannam@85: { puts ("\n\nError : cannot open DEF file.\n") ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: for (k = 0 ; locations [k] != NULL ; k++) cannam@85: { snprintf (buffer, sizeof (buffer), "%s/libsndfile-1.dll", locations [k]) ; cannam@85: if ((hmod = (HMODULE) LoadLibrary (buffer)) != NULL) cannam@85: break ; cannam@85: } ; cannam@85: cannam@85: if (hmod == NULL) cannam@85: { puts ("\n\nError : cannot load DLL.\n") ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: while (fgets (buffer, sizeof (buffer), file) != NULL) cannam@85: { func_name [0] = 0 ; cannam@85: ordinal = 0 ; cannam@85: cannam@85: if (sscanf (buffer, "%s @%d", func_name, &ordinal) != 2) cannam@85: continue ; cannam@85: cannam@85: errors += test_ordinal (hmod, func_name, ordinal) ; cannam@85: } ; cannam@85: cannam@85: FreeLibrary (hmod) ; cannam@85: cannam@85: fclose (file) ; cannam@85: cannam@85: if (errors > 0) cannam@85: { printf ("\n\nErrors : %d\n\n", errors) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: return ; cannam@85: } /* win32_ordinal_test */ cannam@85: cannam@85: #endif cannam@85: cannam@85: int cannam@85: main (void) cannam@85: { cannam@85: #if (TEST_WIN32 && WIN32_TARGET_DLL) cannam@85: win32_ordinal_test () ; cannam@85: #endif cannam@85: cannam@85: return 0 ; cannam@85: } /* main */ cannam@85: