test/testautomation_syswm.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 28 Nov 2014 04:51:33 -0800
changeset 9246 a761913e5e91
parent 9219 c65108ddbeb0
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@6800
     1
/**
aschiffler@6800
     2
 * SysWM test suite
aschiffler@6800
     3
 */
aschiffler@6800
     4
aschiffler@6800
     5
#include <stdio.h>
aschiffler@6800
     6
aschiffler@6800
     7
#include "SDL.h"
aschiffler@6800
     8
#include "SDL_syswm.h"
aschiffler@6800
     9
#include "SDL_test.h"
aschiffler@6800
    10
aschiffler@6800
    11
/* Test case functions */
aschiffler@6800
    12
aschiffler@6800
    13
/**
aschiffler@6800
    14
 * @brief Call to SDL_GetWindowWMInfo
aschiffler@6800
    15
 */
aschiffler@6800
    16
int
aschiffler@6800
    17
syswm_getWindowWMInfo(void *arg)
aschiffler@6800
    18
{
aschiffler@6800
    19
  SDL_bool result;
slouken@7191
    20
  SDL_Window *window;
aschiffler@6800
    21
  SDL_SysWMinfo info;
slouken@7191
    22
aschiffler@6800
    23
  window = SDL_CreateWindow("", 0, 0, 0, 0, SDL_WINDOW_HIDDEN);
aschiffler@6800
    24
  SDLTest_AssertPass("Call to SDL_CreateWindow()");
aschiffler@6800
    25
  SDLTest_AssertCheck(window != NULL, "Check that value returned from SDL_CreateWindow is not NULL");
aschiffler@6800
    26
  if (window == NULL) {
aschiffler@6800
    27
     return TEST_ABORTED;
aschiffler@6800
    28
  }
slouken@7191
    29
aschiffler@6800
    30
  /* Initialize info structure with SDL version info */
slouken@7191
    31
  SDL_VERSION(&info.version);
slouken@7191
    32
aschiffler@6800
    33
  /* Make call */
aschiffler@6800
    34
  result = SDL_GetWindowWMInfo(window, &info);
philipp@9219
    35
  SDLTest_AssertPass("Call to SDL_GetWindowWMInfo()");
aschiffler@6800
    36
  SDLTest_Log((result == SDL_TRUE) ? "Got window information" : "Couldn't get window information");
slouken@7191
    37
aschiffler@6800
    38
  SDL_DestroyWindow(window);
aschiffler@6800
    39
  SDLTest_AssertPass("Call to SDL_DestroyWindow()");
slouken@7191
    40
aschiffler@6800
    41
  return TEST_COMPLETED;
aschiffler@6800
    42
}
aschiffler@6800
    43
aschiffler@6800
    44
/* ================= Test References ================== */
aschiffler@6800
    45
aschiffler@6800
    46
/* SysWM test cases */
aschiffler@6800
    47
static const SDLTest_TestCaseReference syswmTest1 =
slouken@7191
    48
        { (SDLTest_TestCaseFp)syswm_getWindowWMInfo, "syswm_getWindowWMInfo", "Call to SDL_GetWindowWMInfo", TEST_ENABLED };
aschiffler@6800
    49
aschiffler@6800
    50
/* Sequence of SysWM test cases */
aschiffler@6800
    51
static const SDLTest_TestCaseReference *syswmTests[] =  {
slouken@7191
    52
    &syswmTest1, NULL
aschiffler@6800
    53
};
aschiffler@6800
    54
aschiffler@6800
    55
/* SysWM test suite (global) */
aschiffler@6800
    56
SDLTest_TestSuiteReference syswmTestSuite = {
slouken@7191
    57
    "SysWM",
slouken@7191
    58
    NULL,
slouken@7191
    59
    syswmTests,
slouken@7191
    60
    NULL
aschiffler@6800
    61
};