Chris@0: /* Chris@0: ** Copyright (C) 2006-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: #include "sndfile.h" Chris@0: 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_DECL_S_IRGRP == 0) Chris@0: #include Chris@0: #endif Chris@0: Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: Chris@0: #include "utils.h" Chris@0: Chris@0: #if (defined (WIN32) || defined (_WIN32) || defined (__CYGWIN__)) Chris@0: #define TEST_WIN32 1 Chris@0: #else Chris@0: #define TEST_WIN32 0 Chris@0: #endif Chris@0: Chris@0: #if TEST_WIN32 Chris@0: #include Chris@0: Chris@0: Chris@0: static const char * locations [] = Chris@0: { ".", "../src/", "src/", "../src/.libs/", "src/.libs/", Chris@0: NULL Chris@0: } ; /* locations. */ Chris@0: Chris@0: static int Chris@0: test_ordinal (HMODULE hmod, const char * func_name, int ordinal) Chris@0: { char *lpmsg ; Chris@0: void *name, *ord ; Chris@0: Chris@0: print_test_name ("win32_ordinal_test", func_name) ; Chris@0: Chris@0: #if SIZEOF_VOIDP == 8 Chris@0: #define LPCSTR_OF_ORDINAL(x) ((LPCSTR) ((int64_t) (x))) Chris@0: #else Chris@0: #define LPCSTR_OF_ORDINAL(x) ((LPCSTR) (x)) Chris@0: #endif Chris@0: Chris@0: ord = GetProcAddress (hmod, LPCSTR_OF_ORDINAL (ordinal)) ; Chris@0: if ((name = GetProcAddress (hmod, func_name)) == NULL) Chris@0: { FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError (), Chris@0: MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpmsg, 0, NULL) ; Chris@0: /*-puts (lpmsg) ;-*/ Chris@0: } ; Chris@0: Chris@0: if (name != NULL && ord != NULL && name == ord) Chris@0: { puts ("ok") ; Chris@0: return 0 ; Chris@0: } ; Chris@0: Chris@0: puts ("fail") ; Chris@0: return 1 ; Chris@0: } /* test_ordinal */ Chris@0: Chris@0: static void Chris@0: win32_ordinal_test (void) Chris@0: { static char buffer [1024] ; Chris@0: static char func_name [1024] ; Chris@0: HMODULE hmod = NULL ; Chris@0: FILE * file = NULL ; Chris@0: int k, ordinal, errors = 0 ; Chris@0: Chris@0: for (k = 0 ; locations [k] != NULL ; k++) Chris@0: { snprintf (buffer, sizeof (buffer), "%s/libsndfile-1.def", locations [k]) ; Chris@0: if ((file = fopen (buffer, "r")) != NULL) Chris@0: break ; Chris@0: } ; Chris@0: Chris@0: if (file == NULL) Chris@0: { puts ("\n\nError : cannot open DEF file.\n") ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: for (k = 0 ; locations [k] != NULL ; k++) Chris@0: { snprintf (buffer, sizeof (buffer), "%s/libsndfile-1.dll", locations [k]) ; Chris@0: if ((hmod = (HMODULE) LoadLibrary (buffer)) != NULL) Chris@0: break ; Chris@0: } ; Chris@0: Chris@0: if (hmod == NULL) Chris@0: { puts ("\n\nError : cannot load DLL.\n") ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: while (fgets (buffer, sizeof (buffer), file) != NULL) Chris@0: { func_name [0] = 0 ; Chris@0: ordinal = 0 ; Chris@0: Chris@0: if (sscanf (buffer, "%s @%d", func_name, &ordinal) != 2) Chris@0: continue ; Chris@0: Chris@0: errors += test_ordinal (hmod, func_name, ordinal) ; Chris@0: } ; Chris@0: Chris@0: FreeLibrary (hmod) ; Chris@0: Chris@0: fclose (file) ; Chris@0: Chris@0: if (errors > 0) Chris@0: { printf ("\n\nErrors : %d\n\n", errors) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* win32_ordinal_test */ Chris@0: Chris@0: #endif Chris@0: Chris@0: int Chris@0: main (void) Chris@0: { Chris@0: #if (TEST_WIN32 && WIN32_TARGET_DLL) Chris@0: win32_ordinal_test () ; Chris@0: #endif Chris@0: Chris@0: return 0 ; Chris@0: } /* main */ Chris@0: