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