annotate src/libsndfile-1.0.27/tests/win32_ordinal_test.c @ 84:08ae793730bd

Add null config files
author Chris Cannam
date Mon, 02 Mar 2020 14:03:47 +0000
parents 1df64224f5ac
children
rev   line source
Chris@40 1 /*
Chris@40 2 ** Copyright (C) 2006-2014 Erik de Castro Lopo <erikd@mega-nerd.com>
Chris@40 3 **
Chris@40 4 ** This program is free software; you can redistribute it and/or modify
Chris@40 5 ** it under the terms of the GNU General Public License as published by
Chris@40 6 ** the Free Software Foundation; either version 2 of the License, or
Chris@40 7 ** (at your option) any later version.
Chris@40 8 **
Chris@40 9 ** This program is distributed in the hope that it will be useful,
Chris@40 10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@40 11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@40 12 ** GNU General Public License for more details.
Chris@40 13 **
Chris@40 14 ** You should have received a copy of the GNU General Public License
Chris@40 15 ** along with this program; if not, write to the Free Software
Chris@40 16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Chris@40 17 */
Chris@40 18
Chris@40 19 #include "sfconfig.h"
Chris@40 20
Chris@40 21 #include <stdio.h>
Chris@40 22 #include <stdlib.h>
Chris@40 23
Chris@40 24 #if HAVE_UNISTD_H
Chris@40 25 #include <unistd.h>
Chris@40 26 #endif
Chris@40 27
Chris@40 28 #if (HAVE_DECL_S_IRGRP == 0)
Chris@40 29 #include <sf_unistd.h>
Chris@40 30 #endif
Chris@40 31
Chris@40 32 #include <string.h>
Chris@40 33 #include <fcntl.h>
Chris@40 34 #include <sys/types.h>
Chris@40 35
Chris@40 36 #include "utils.h"
Chris@40 37
Chris@40 38 #if (defined (WIN32) || defined (_WIN32) || defined (__CYGWIN__))
Chris@40 39 #define TEST_WIN32 1
Chris@40 40 #else
Chris@40 41 #define TEST_WIN32 0
Chris@40 42 #endif
Chris@40 43
Chris@40 44 #if TEST_WIN32
Chris@40 45 #include <windows.h>
Chris@40 46
Chris@40 47
Chris@40 48 static const char * locations [] =
Chris@40 49 { ".", "../src/", "src/", "../src/.libs/", "src/.libs/",
Chris@40 50 NULL
Chris@40 51 } ; /* locations. */
Chris@40 52
Chris@40 53 static int
Chris@40 54 test_ordinal (HMODULE hmod, const char * func_name, int ordinal)
Chris@40 55 { char *lpmsg ;
Chris@40 56 void *name, *ord ;
Chris@40 57
Chris@40 58 print_test_name ("win32_ordinal_test", func_name) ;
Chris@40 59
Chris@40 60 #if SIZEOF_VOIDP == 8
Chris@40 61 #define LPCSTR_OF_ORDINAL(x) ((LPCSTR) ((int64_t) (x)))
Chris@40 62 #else
Chris@40 63 #define LPCSTR_OF_ORDINAL(x) ((LPCSTR) (x))
Chris@40 64 #endif
Chris@40 65
Chris@40 66 ord = GetProcAddress (hmod, LPCSTR_OF_ORDINAL (ordinal)) ;
Chris@40 67 if ((name = GetProcAddress (hmod, func_name)) == NULL)
Chris@40 68 { FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError (),
Chris@40 69 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpmsg, 0, NULL) ;
Chris@40 70 /*-puts (lpmsg) ;-*/
Chris@40 71 } ;
Chris@40 72
Chris@40 73 if (name != NULL && ord != NULL && name == ord)
Chris@40 74 { puts ("ok") ;
Chris@40 75 return 0 ;
Chris@40 76 } ;
Chris@40 77
Chris@40 78 puts ("fail") ;
Chris@40 79 return 1 ;
Chris@40 80 } /* test_ordinal */
Chris@40 81
Chris@40 82 static void
Chris@40 83 win32_ordinal_test (void)
Chris@40 84 { static char buffer [1024] ;
Chris@40 85 static char func_name [1024] ;
Chris@40 86 HMODULE hmod = NULL ;
Chris@40 87 FILE * file = NULL ;
Chris@40 88 int k, ordinal, errors = 0 ;
Chris@40 89
Chris@40 90 for (k = 0 ; locations [k] != NULL ; k++)
Chris@40 91 { snprintf (buffer, sizeof (buffer), "%s/libsndfile-1.def", locations [k]) ;
Chris@40 92 if ((file = fopen (buffer, "r")) != NULL)
Chris@40 93 break ;
Chris@40 94 } ;
Chris@40 95
Chris@40 96 if (file == NULL)
Chris@40 97 { puts ("\n\nError : cannot open DEF file.\n") ;
Chris@40 98 exit (1) ;
Chris@40 99 } ;
Chris@40 100
Chris@40 101 for (k = 0 ; locations [k] != NULL ; k++)
Chris@40 102 { snprintf (buffer, sizeof (buffer), "%s/libsndfile-1.dll", locations [k]) ;
Chris@40 103 if ((hmod = (HMODULE) LoadLibrary (buffer)) != NULL)
Chris@40 104 break ;
Chris@40 105 } ;
Chris@40 106
Chris@40 107 if (hmod == NULL)
Chris@40 108 { printf ("\n\nError : cannot load DLL (cwd is %s).\n", getcwd (buffer, sizeof (buffer))) ;
Chris@40 109 exit (1) ;
Chris@40 110 } ;
Chris@40 111
Chris@40 112 while (fgets (buffer, sizeof (buffer), file) != NULL)
Chris@40 113 { func_name [0] = 0 ;
Chris@40 114 ordinal = 0 ;
Chris@40 115
Chris@40 116 if (sscanf (buffer, "%s @%d", func_name, &ordinal) != 2)
Chris@40 117 continue ;
Chris@40 118
Chris@40 119 errors += test_ordinal (hmod, func_name, ordinal) ;
Chris@40 120 } ;
Chris@40 121
Chris@40 122 FreeLibrary (hmod) ;
Chris@40 123
Chris@40 124 fclose (file) ;
Chris@40 125
Chris@40 126 if (errors > 0)
Chris@40 127 { printf ("\n\nErrors : %d\n\n", errors) ;
Chris@40 128 exit (1) ;
Chris@40 129 } ;
Chris@40 130
Chris@40 131 return ;
Chris@40 132 } /* win32_ordinal_test */
Chris@40 133
Chris@40 134 #endif
Chris@40 135
Chris@40 136 int
Chris@40 137 main (void)
Chris@40 138 {
Chris@40 139 #if (TEST_WIN32 && WIN32_TARGET_DLL)
Chris@40 140 win32_ordinal_test () ;
Chris@40 141 #endif
Chris@40 142
Chris@40 143 return 0 ;
Chris@40 144 } /* main */
Chris@40 145