1
0

libopenmpt_test.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * libopenmpt_test.cpp
  3. * -------------------
  4. * Purpose: libopenmpt test suite driver
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #include "openmpt/all/BuildSettings.hpp"
  10. #include "libopenmpt_internal.h"
  11. #include "test/test.h"
  12. #include <iostream>
  13. #include <locale>
  14. #include <clocale>
  15. #include <cstdlib>
  16. using namespace OpenMPT;
  17. #if defined( LIBOPENMPT_BUILD_TEST )
  18. #if (defined(_WIN32) || defined(WIN32)) && (defined(_UNICODE) || defined(UNICODE))
  19. #if defined(__GNUC__) || (defined(__clang__) && !defined(_MSC_VER))
  20. // mingw-w64 g++ does only default to special C linkage for "main", but not for "wmain" (see <https://sourceforge.net/p/mingw-w64/wiki2/Unicode%20apps/>).
  21. extern "C" int wmain( int /*argc*/ , wchar_t * /*argv*/ [] );
  22. extern "C"
  23. #endif
  24. int wmain( int /*argc*/ , wchar_t * /*argv*/ [] ) {
  25. #else
  26. int main( int /*argc*/ , char * /*argv*/ [] ) {
  27. #endif
  28. try {
  29. // run test with "C" / classic() locale
  30. Test::DoTests();
  31. // try setting the C locale to the user locale
  32. setlocale( LC_ALL, "" );
  33. // run all tests again with a set C locale
  34. Test::DoTests();
  35. // try to set the C and C++ locales to the user locale
  36. try {
  37. std::locale old = std::locale::global( std::locale( "" ) );
  38. (void)old;
  39. } catch ( ... ) {
  40. // Setting c++ global locale does not work.
  41. // This is no problem for libopenmpt, just continue.
  42. }
  43. // and now, run all tests once again
  44. Test::DoTests();
  45. } catch ( const std::exception & e ) {
  46. std::cerr << "TEST ERROR: exception: " << ( e.what() ? e.what() : "" ) << std::endl;
  47. return -1;
  48. } catch ( ... ) {
  49. std::cerr << "TEST ERROR: unknown exception" << std::endl;
  50. return -1;
  51. }
  52. return 0;
  53. }
  54. #endif // LIBOPENMPT_BUILD_TEST