annotate src/libsndfile-1.0.25/tests/win32_ordinal_test.c @ 23:619f715526df sv_v2.1

Update Vamp plugin SDK to 2.5
author Chris Cannam
date Thu, 09 May 2013 10:52:46 +0100
parents c7265573341e
children
rev   line source
Chris@0 1 /*
Chris@0 2 ** Copyright (C) 2006-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 #include "sndfile.h"
Chris@0 21
Chris@0 22 #include <stdio.h>
Chris@0 23 #include <stdlib.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_DECL_S_IRGRP == 0)
Chris@0 30 #include <sf_unistd.h>
Chris@0 31 #endif
Chris@0 32
Chris@0 33 #include <string.h>
Chris@0 34 #include <fcntl.h>
Chris@0 35 #include <sys/types.h>
Chris@0 36
Chris@0 37 #include "utils.h"
Chris@0 38
Chris@0 39 #if (defined (WIN32) || defined (_WIN32) || defined (__CYGWIN__))
Chris@0 40 #define TEST_WIN32 1
Chris@0 41 #else
Chris@0 42 #define TEST_WIN32 0
Chris@0 43 #endif
Chris@0 44
Chris@0 45 #if TEST_WIN32
Chris@0 46 #include <windows.h>
Chris@0 47
Chris@0 48
Chris@0 49 static const char * locations [] =
Chris@0 50 { ".", "../src/", "src/", "../src/.libs/", "src/.libs/",
Chris@0 51 NULL
Chris@0 52 } ; /* locations. */
Chris@0 53
Chris@0 54 static int
Chris@0 55 test_ordinal (HMODULE hmod, const char * func_name, int ordinal)
Chris@0 56 { char *lpmsg ;
Chris@0 57 void *name, *ord ;
Chris@0 58
Chris@0 59 print_test_name ("win32_ordinal_test", func_name) ;
Chris@0 60
Chris@0 61 #if SIZEOF_VOIDP == 8
Chris@0 62 #define LPCSTR_OF_ORDINAL(x) ((LPCSTR) ((int64_t) (x)))
Chris@0 63 #else
Chris@0 64 #define LPCSTR_OF_ORDINAL(x) ((LPCSTR) (x))
Chris@0 65 #endif
Chris@0 66
Chris@0 67 ord = GetProcAddress (hmod, LPCSTR_OF_ORDINAL (ordinal)) ;
Chris@0 68 if ((name = GetProcAddress (hmod, func_name)) == NULL)
Chris@0 69 { FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError (),
Chris@0 70 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpmsg, 0, NULL) ;
Chris@0 71 /*-puts (lpmsg) ;-*/
Chris@0 72 } ;
Chris@0 73
Chris@0 74 if (name != NULL && ord != NULL && name == ord)
Chris@0 75 { puts ("ok") ;
Chris@0 76 return 0 ;
Chris@0 77 } ;
Chris@0 78
Chris@0 79 puts ("fail") ;
Chris@0 80 return 1 ;
Chris@0 81 } /* test_ordinal */
Chris@0 82
Chris@0 83 static void
Chris@0 84 win32_ordinal_test (void)
Chris@0 85 { static char buffer [1024] ;
Chris@0 86 static char func_name [1024] ;
Chris@0 87 HMODULE hmod = NULL ;
Chris@0 88 FILE * file = NULL ;
Chris@0 89 int k, ordinal, errors = 0 ;
Chris@0 90
Chris@0 91 for (k = 0 ; locations [k] != NULL ; k++)
Chris@0 92 { snprintf (buffer, sizeof (buffer), "%s/libsndfile-1.def", locations [k]) ;
Chris@0 93 if ((file = fopen (buffer, "r")) != NULL)
Chris@0 94 break ;
Chris@0 95 } ;
Chris@0 96
Chris@0 97 if (file == NULL)
Chris@0 98 { puts ("\n\nError : cannot open DEF file.\n") ;
Chris@0 99 exit (1) ;
Chris@0 100 } ;
Chris@0 101
Chris@0 102 for (k = 0 ; locations [k] != NULL ; k++)
Chris@0 103 { snprintf (buffer, sizeof (buffer), "%s/libsndfile-1.dll", locations [k]) ;
Chris@0 104 if ((hmod = (HMODULE) LoadLibrary (buffer)) != NULL)
Chris@0 105 break ;
Chris@0 106 } ;
Chris@0 107
Chris@0 108 if (hmod == NULL)
Chris@0 109 { puts ("\n\nError : cannot load DLL.\n") ;
Chris@0 110 exit (1) ;
Chris@0 111 } ;
Chris@0 112
Chris@0 113 while (fgets (buffer, sizeof (buffer), file) != NULL)
Chris@0 114 { func_name [0] = 0 ;
Chris@0 115 ordinal = 0 ;
Chris@0 116
Chris@0 117 if (sscanf (buffer, "%s @%d", func_name, &ordinal) != 2)
Chris@0 118 continue ;
Chris@0 119
Chris@0 120 errors += test_ordinal (hmod, func_name, ordinal) ;
Chris@0 121 } ;
Chris@0 122
Chris@0 123 FreeLibrary (hmod) ;
Chris@0 124
Chris@0 125 fclose (file) ;
Chris@0 126
Chris@0 127 if (errors > 0)
Chris@0 128 { printf ("\n\nErrors : %d\n\n", errors) ;
Chris@0 129 exit (1) ;
Chris@0 130 } ;
Chris@0 131
Chris@0 132 return ;
Chris@0 133 } /* win32_ordinal_test */
Chris@0 134
Chris@0 135 #endif
Chris@0 136
Chris@0 137 int
Chris@0 138 main (void)
Chris@0 139 {
Chris@0 140 #if (TEST_WIN32 && WIN32_TARGET_DLL)
Chris@0 141 win32_ordinal_test () ;
Chris@0 142 #endif
Chris@0 143
Chris@0 144 return 0 ;
Chris@0 145 } /* main */
Chris@0 146