test/testautomation_hints.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 28 Nov 2014 04:51:33 -0800
changeset 9246 a761913e5e91
parent 8645 d69fdbefeecf
permissions -rw-r--r--
Fixed bug 2786 - "UCS-2-INTERNAL" iconv encoding is not supported everywhere, use UTF-16LE instead

Jonas Kulla

src/main/windows/SDL_windows_main.c:137:
cmdline = SDL_iconv_string("UTF-8", "UCS-2-INTERNAL", (char *)(text), (SDL_wcslen(text)+1)*sizeof(WCHAR));

I'm trying to compile an SDL2 application for windows using the mingw-w64 32bit toolchain provided by my distro (Fedora 19). However, even the simplest test program that does nothing at all fails to startup with a "Fatal error - out of memory" message because the mingw iconv library provided by my distro does not support the "UCS-2-INTERNAL" encoding and the conversion returns null.

From my little bit of research, it turns out that even though this encoding is supported by the external GNU libiconv library, some glibc versions (?) don't support it with their internal iconv routines, and will instead provide the native endian encoding when "UCS-2" is specified.

Nonetheless, I wonder why the native endianness is considered in the first place when Windows doesn't even run on any big endian archs (to my knowledge). And true enough, 'WIN_StringToUTF8' from core/windows/SDL_windows.h is used everywhere else in the windows backend, which is just a macro to iconv with "UTF-16LE" as source. Therefore it would IMO make sense to use this macro here as well, which would solve my problem (patch attached).
aschiffler@8645
     1
/**
aschiffler@8645
     2
 * Hints test suite
aschiffler@8645
     3
 */
aschiffler@8645
     4
aschiffler@8645
     5
#include <stdio.h>
aschiffler@8645
     6
aschiffler@8645
     7
#include "SDL.h"
aschiffler@8645
     8
#include "SDL_test.h"
aschiffler@8645
     9
aschiffler@8645
    10
aschiffler@8645
    11
const int _numHintsEnum = 25;
aschiffler@8645
    12
char* _HintsEnum[] =
aschiffler@8645
    13
  {
aschiffler@8645
    14
    SDL_HINT_ACCELEROMETER_AS_JOYSTICK,
aschiffler@8645
    15
    SDL_HINT_FRAMEBUFFER_ACCELERATION,
aschiffler@8645
    16
    SDL_HINT_GAMECONTROLLERCONFIG,
aschiffler@8645
    17
    SDL_HINT_GRAB_KEYBOARD,
aschiffler@8645
    18
    SDL_HINT_IDLE_TIMER_DISABLED,
aschiffler@8645
    19
    SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS,
aschiffler@8645
    20
    SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK,
aschiffler@8645
    21
    SDL_HINT_MOUSE_RELATIVE_MODE_WARP,
aschiffler@8645
    22
    SDL_HINT_ORIENTATIONS,
aschiffler@8645
    23
    SDL_HINT_RENDER_DIRECT3D_THREADSAFE,
aschiffler@8645
    24
    SDL_HINT_RENDER_DRIVER,
aschiffler@8645
    25
    SDL_HINT_RENDER_OPENGL_SHADERS,
aschiffler@8645
    26
    SDL_HINT_RENDER_SCALE_QUALITY,
aschiffler@8645
    27
    SDL_HINT_RENDER_VSYNC,
aschiffler@8645
    28
    SDL_HINT_TIMER_RESOLUTION,
aschiffler@8645
    29
    SDL_HINT_VIDEO_ALLOW_SCREENSAVER,
aschiffler@8645
    30
    SDL_HINT_VIDEO_HIGHDPI_DISABLED,
aschiffler@8645
    31
    SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES,
aschiffler@8645
    32
    SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
aschiffler@8645
    33
    SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT,
aschiffler@8645
    34
    SDL_HINT_VIDEO_WIN_D3DCOMPILER,
aschiffler@8645
    35
    SDL_HINT_VIDEO_X11_XINERAMA,
aschiffler@8645
    36
    SDL_HINT_VIDEO_X11_XRANDR,
aschiffler@8645
    37
    SDL_HINT_VIDEO_X11_XVIDMODE,
aschiffler@8645
    38
    SDL_HINT_XINPUT_ENABLED,
aschiffler@8645
    39
  };
aschiffler@8645
    40
char* _HintsVerbose[] =
aschiffler@8645
    41
  {
aschiffler@8645
    42
    "SDL_HINT_ACCELEROMETER_AS_JOYSTICK",
aschiffler@8645
    43
    "SDL_HINT_FRAMEBUFFER_ACCELERATION",
aschiffler@8645
    44
    "SDL_HINT_GAMECONTROLLERCONFIG",
aschiffler@8645
    45
    "SDL_HINT_GRAB_KEYBOARD",
aschiffler@8645
    46
    "SDL_HINT_IDLE_TIMER_DISABLED",
aschiffler@8645
    47
    "SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS",
aschiffler@8645
    48
    "SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK",
aschiffler@8645
    49
    "SDL_HINT_MOUSE_RELATIVE_MODE_WARP",
aschiffler@8645
    50
    "SDL_HINT_ORIENTATIONS",
aschiffler@8645
    51
    "SDL_HINT_RENDER_DIRECT3D_THREADSAFE",
aschiffler@8645
    52
    "SDL_HINT_RENDER_DRIVER",
aschiffler@8645
    53
    "SDL_HINT_RENDER_OPENGL_SHADERS",
aschiffler@8645
    54
    "SDL_HINT_RENDER_SCALE_QUALITY",
aschiffler@8645
    55
    "SDL_HINT_RENDER_VSYNC",
aschiffler@8645
    56
    "SDL_HINT_TIMER_RESOLUTION",
aschiffler@8645
    57
    "SDL_HINT_VIDEO_ALLOW_SCREENSAVER",
aschiffler@8645
    58
    "SDL_HINT_VIDEO_HIGHDPI_DISABLED",
aschiffler@8645
    59
    "SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES",
aschiffler@8645
    60
    "SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS",
aschiffler@8645
    61
    "SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT",
aschiffler@8645
    62
    "SDL_HINT_VIDEO_WIN_D3DCOMPILER",
aschiffler@8645
    63
    "SDL_HINT_VIDEO_X11_XINERAMA",
aschiffler@8645
    64
    "SDL_HINT_VIDEO_X11_XRANDR",
aschiffler@8645
    65
    "SDL_HINT_VIDEO_X11_XVIDMODE",
aschiffler@8645
    66
    "SDL_HINT_XINPUT_ENABLED"
aschiffler@8645
    67
  };
aschiffler@8645
    68
aschiffler@8645
    69
aschiffler@8645
    70
/* Test case functions */
aschiffler@8645
    71
aschiffler@8645
    72
/**
aschiffler@8645
    73
 * @brief Call to SDL_GetHint
aschiffler@8645
    74
 */
aschiffler@8645
    75
int
aschiffler@8645
    76
hints_getHint(void *arg)
aschiffler@8645
    77
{
aschiffler@8645
    78
  char *result1;
aschiffler@8645
    79
  char *result2;
aschiffler@8645
    80
  int i;
aschiffler@8645
    81
    
aschiffler@8645
    82
  for (i=0; i<_numHintsEnum; i++) {
aschiffler@8645
    83
    result1 = (char *)SDL_GetHint((char*)_HintsEnum[i]);
aschiffler@8645
    84
    SDLTest_AssertPass("Call to SDL_GetHint(%s) - using define definition", (char*)_HintsEnum[i]);
aschiffler@8645
    85
    result2 = (char *)SDL_GetHint((char *)_HintsVerbose[i]);
aschiffler@8645
    86
    SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", (char*)_HintsVerbose[i]);
aschiffler@8645
    87
    SDLTest_AssertCheck(
aschiffler@8645
    88
      (result1 == NULL && result2 == NULL) || (SDL_strcmp(result1, result2) == 0),
aschiffler@8645
    89
      "Verify returned values are equal; got: result1='%s' result2='%s",
aschiffler@8645
    90
      (result1 == NULL) ? "null" : result1,
aschiffler@8645
    91
      (result2 == NULL) ? "null" : result2);
aschiffler@8645
    92
  }
aschiffler@8645
    93
  
aschiffler@8645
    94
  return TEST_COMPLETED;
aschiffler@8645
    95
}
aschiffler@8645
    96
aschiffler@8645
    97
/**
aschiffler@8645
    98
 * @brief Call to SDL_SetHint
aschiffler@8645
    99
 */
aschiffler@8645
   100
int
aschiffler@8645
   101
hints_setHint(void *arg)
aschiffler@8645
   102
{
aschiffler@8645
   103
  char *originalValue;
aschiffler@8645
   104
  char *value;
aschiffler@8645
   105
  char *testValue;
aschiffler@8645
   106
  SDL_bool result;
aschiffler@8645
   107
  int i, j;
aschiffler@8645
   108
aschiffler@8645
   109
  /* Create random values to set */                    
aschiffler@8645
   110
  value = SDLTest_RandomAsciiStringOfSize(10);
aschiffler@8645
   111
    
aschiffler@8645
   112
  for (i=0; i<_numHintsEnum; i++) {
aschiffler@8645
   113
    /* Capture current value */
aschiffler@8645
   114
    originalValue = (char *)SDL_GetHint((char*)_HintsEnum[i]);
aschiffler@8645
   115
    SDLTest_AssertPass("Call to SDL_GetHint(%s)", (char*)_HintsEnum[i]);
aschiffler@8645
   116
    
aschiffler@8645
   117
    /* Set value (twice) */
aschiffler@8645
   118
    for (j=1; j<=2; j++) {
aschiffler@8645
   119
      result = SDL_SetHint((char*)_HintsEnum[i], value);
aschiffler@8645
   120
      SDLTest_AssertPass("Call to SDL_SetHint(%s, %s) (iteration %i)", (char*)_HintsEnum[i], value, j);
aschiffler@8645
   121
      SDLTest_AssertCheck(
aschiffler@8645
   122
        result == SDL_TRUE || result == SDL_FALSE, 
aschiffler@8645
   123
        "Verify valid result was returned, got: %i",
aschiffler@8645
   124
        (int)result);
aschiffler@8645
   125
      testValue = (char *)SDL_GetHint((char*)_HintsEnum[i]);
aschiffler@8645
   126
      SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", (char*)_HintsVerbose[i]);
aschiffler@8645
   127
      SDLTest_AssertCheck(
aschiffler@8645
   128
        (SDL_strcmp(value, testValue) == 0),
aschiffler@8645
   129
        "Verify returned value equals set value; got: testValue='%s' value='%s",
aschiffler@8645
   130
        (testValue == NULL) ? "null" : testValue,
aschiffler@8645
   131
        value);
aschiffler@8645
   132
    }
aschiffler@8645
   133
      
aschiffler@8645
   134
    /* Reset original value */
aschiffler@8645
   135
    result = SDL_SetHint((char*)_HintsEnum[i], originalValue);
aschiffler@8645
   136
    SDLTest_AssertPass("Call to SDL_SetHint(%s, originalValue)", (char*)_HintsEnum[i]);
aschiffler@8645
   137
    SDLTest_AssertCheck(
aschiffler@8645
   138
      result == SDL_TRUE || result == SDL_FALSE, 
aschiffler@8645
   139
      "Verify valid result was returned, got: %i",
aschiffler@8645
   140
      (int)result);
aschiffler@8645
   141
  }
aschiffler@8645
   142
  
aschiffler@8645
   143
  SDL_free(value);
aschiffler@8645
   144
  
aschiffler@8645
   145
  return TEST_COMPLETED;
aschiffler@8645
   146
}
aschiffler@8645
   147
aschiffler@8645
   148
/* ================= Test References ================== */
aschiffler@8645
   149
aschiffler@8645
   150
/* Hints test cases */
aschiffler@8645
   151
static const SDLTest_TestCaseReference hintsTest1 =
aschiffler@8645
   152
        { (SDLTest_TestCaseFp)hints_getHint, "hints_getHint", "Call to SDL_GetHint", TEST_ENABLED };
aschiffler@8645
   153
aschiffler@8645
   154
static const SDLTest_TestCaseReference hintsTest2 =
aschiffler@8645
   155
        { (SDLTest_TestCaseFp)hints_setHint, "hints_setHint", "Call to SDL_SetHint", TEST_ENABLED };
aschiffler@8645
   156
aschiffler@8645
   157
/* Sequence of Hints test cases */
aschiffler@8645
   158
static const SDLTest_TestCaseReference *hintsTests[] =  {
aschiffler@8645
   159
    &hintsTest1, &hintsTest2, NULL
aschiffler@8645
   160
};
aschiffler@8645
   161
aschiffler@8645
   162
/* Hints test suite (global) */
aschiffler@8645
   163
SDLTest_TestSuiteReference hintsTestSuite = {
aschiffler@8645
   164
    "Hints",
aschiffler@8645
   165
    NULL,
aschiffler@8645
   166
    hintsTests,
aschiffler@8645
   167
    NULL
aschiffler@8645
   168
};