win32_ordinal_test.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. ** Copyright (C) 2006-2017 Erik de Castro Lopo <[email protected]>
  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. #include "sfconfig.h"
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #if HAVE_UNISTD_H
  22. #include <unistd.h>
  23. #endif
  24. #if (HAVE_DECL_S_IRGRP == 0)
  25. #include <sf_unistd.h>
  26. #endif
  27. #include <string.h>
  28. #include <fcntl.h>
  29. #ifdef HAVE_DIRECT_H
  30. #include <direct.h>
  31. #endif
  32. #include <sys/types.h>
  33. #include "utils.h"
  34. #if (defined (WIN32) || defined (_WIN32) || defined (__CYGWIN__))
  35. #define TEST_WIN32 1
  36. #else
  37. #define TEST_WIN32 0
  38. #endif
  39. #if TEST_WIN32
  40. #include <windows.h>
  41. static const char * locations [] =
  42. { ".", "../src/", "src/", "../src/.libs/", "src/.libs/",
  43. NULL
  44. } ; /* locations. */
  45. static int
  46. test_ordinal (HMODULE hmod, const char * func_name, int ordinal)
  47. { char *lpmsg ;
  48. void *name, *ord ;
  49. print_test_name ("win32_ordinal_test", func_name) ;
  50. #if SIZEOF_VOIDP == 8
  51. #define LPCSTR_OF_ORDINAL(x) ((LPCSTR) ((int64_t) (x)))
  52. #else
  53. #define LPCSTR_OF_ORDINAL(x) ((LPCSTR) (x))
  54. #endif
  55. ord = GetProcAddress (hmod, LPCSTR_OF_ORDINAL (ordinal)) ;
  56. if ((name = GetProcAddress (hmod, func_name)) == NULL)
  57. { FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError (),
  58. MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpmsg, 0, NULL) ;
  59. /*-puts (lpmsg) ;-*/
  60. } ;
  61. if (name != NULL && ord != NULL && name == ord)
  62. { puts ("ok") ;
  63. return 0 ;
  64. } ;
  65. puts ("fail") ;
  66. return 1 ;
  67. } /* test_ordinal */
  68. static void
  69. win32_ordinal_test (void)
  70. { static char buffer [1024] ;
  71. static char func_name [1024] ;
  72. HMODULE hmod = NULL ;
  73. FILE * file = NULL ;
  74. int k, ordinal, errors = 0 ;
  75. for (k = 0 ; locations [k] != NULL ; k++)
  76. { snprintf (buffer, sizeof (buffer), "%s/libsndfile-1.def", locations [k]) ;
  77. if ((file = fopen (buffer, "r")) != NULL)
  78. break ;
  79. } ;
  80. if (file == NULL)
  81. { puts ("\n\nError : cannot open DEF file.\n") ;
  82. exit (1) ;
  83. } ;
  84. for (k = 0 ; locations [k] != NULL ; k++)
  85. { snprintf (buffer, sizeof (buffer), "%s/libsndfile-1.dll", locations [k]) ;
  86. if ((hmod = (HMODULE) LoadLibrary (buffer)) != NULL)
  87. break ;
  88. } ;
  89. if (hmod == NULL)
  90. { printf ("\n\nError : cannot load DLL (cwd is %s).\n", getcwd (buffer, sizeof (buffer))) ;
  91. exit (1) ;
  92. } ;
  93. while (fgets (buffer, sizeof (buffer), file) != NULL)
  94. { func_name [0] = 0 ;
  95. ordinal = 0 ;
  96. if (sscanf (buffer, "%s @%d", func_name, &ordinal) != 2)
  97. continue ;
  98. errors += test_ordinal (hmod, func_name, ordinal) ;
  99. } ;
  100. FreeLibrary (hmod) ;
  101. fclose (file) ;
  102. if (errors > 0)
  103. { printf ("\n\nErrors : %d\n\n", errors) ;
  104. exit (1) ;
  105. } ;
  106. return ;
  107. } /* win32_ordinal_test */
  108. #endif
  109. int
  110. main (void)
  111. {
  112. #if (TEST_WIN32 && WIN32_TARGET_DLL)
  113. win32_ordinal_test () ;
  114. #endif
  115. return 0 ;
  116. } /* main */