test/testmessage.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Wed, 17 Aug 2016 21:04:50 +0200
changeset 10275 ba7dc3ebb81e
parent 9998 f67cf37e9cd4
permissions -rw-r--r--
Emscripten: Fixed opening previously closed joystick.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6614
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9922
diff changeset
     2
  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
6614
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     3
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
  This software is provided 'as-is', without any express or implied
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     5
  warranty.  In no event will the authors be held liable for any damages
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     6
  arising from the use of this software.
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     7
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
  Permission is granted to anyone to use this software for any purpose,
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     9
  including commercial applications, and to alter it and redistribute it
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    10
  freely.
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    11
*/
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
7677
871d43c6968a OCD fixes: Adds a space before */
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7663
diff changeset
    13
/* Simple test of the SDL MessageBox API */
6614
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    14
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    15
#include <stdio.h>
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    16
#include <stdlib.h>
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    17
#include <signal.h>
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    18
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    19
#include "SDL.h"
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
static void
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
quit(int rc)
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
{
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
    SDL_Quit();
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
    exit(rc);
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
}
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
7088
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    29
static int
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    30
button_messagebox(void *eventNumber)
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    31
{
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    32
    const SDL_MessageBoxButtonData buttons[] = {
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    33
        {
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    34
            SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT,
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    35
            0,
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    36
            "OK"
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    37
        },{
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    38
            SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT,
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    39
            1,
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    40
            "Cancel"
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    41
        },
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    42
    };
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    43
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    44
    SDL_MessageBoxData data = {
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    45
        SDL_MESSAGEBOX_INFORMATION,
7663
53fe1b64eb2d More non C89 compliant comments
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7639
diff changeset
    46
        NULL, /* no parent window */
7088
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    47
        "Custom MessageBox",
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    48
        "This is a custom messagebox",
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    49
        2,
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    50
        buttons,
7663
53fe1b64eb2d More non C89 compliant comments
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7639
diff changeset
    51
        NULL /* Default color scheme */
7088
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    52
    };
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    53
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    54
    int button = -1;
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    55
    int success = 0;
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    56
    if (eventNumber) {
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    57
        data.message = "This is a custom messagebox from a background thread.";
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    58
    }
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    59
7458
648067e9073a Re-enabled other messagebox tests, moved the SDL_Init() call as late as possible to show the circumstances where it's needed.
Sam Lantinga <slouken@libsdl.org>
parents: 7456
diff changeset
    60
    success = SDL_ShowMessageBox(&data, &button);
7088
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    61
    if (success == -1) {
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
    62
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
7088
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    63
        if (eventNumber) {
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    64
            SDL_UserEvent event;
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    65
            event.type = (intptr_t)eventNumber;
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    66
            SDL_PushEvent((SDL_Event*)&event);
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    67
            return 1;
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    68
        } else {
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    69
            quit(2);
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    70
        }
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    71
    }
9694
b847b89f4a64 testmessage.c should report when message boxes were closed.
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
    72
    SDL_Log("Pressed button: %d, %s\n", button, button == -1 ? "[closed]" : button == 1 ? "Cancel" : "OK");
7088
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    73
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    74
    if (eventNumber) {
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    75
        SDL_UserEvent event;
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    76
        event.type = (intptr_t)eventNumber;
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    77
        SDL_PushEvent((SDL_Event*)&event);
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    78
    }
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    79
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    80
    return 0;
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    81
}
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
    82
6614
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
int
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
main(int argc, char *argv[])
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
{
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
    int success;
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
9922
b066d5fd5fa7 Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9697
diff changeset
    88
    /* Enable standard application logging */
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
    89
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
    90
6614
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
    success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    92
                "Simple MessageBox",
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
                "This is a simple error MessageBox",
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    94
                NULL);
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    95
    if (success == -1) {
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
    96
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
6614
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
        quit(1);
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
    }
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
6758
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   100
    success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   101
                "Simple MessageBox",
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   102
                "This is a simple MessageBox with a newline:\r\nHello world!",
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   103
                NULL);
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   104
    if (success == -1) {
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
   105
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
6758
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   106
        quit(1);
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   107
    }
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   108
6722
37283d4416e0 testmessage should test Unicode strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6614
diff changeset
   109
    /* Google says this is Traditional Chinese for "beef with broccoli" */
37283d4416e0 testmessage should test Unicode strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6614
diff changeset
   110
    success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
37283d4416e0 testmessage should test Unicode strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6614
diff changeset
   111
                "UTF-8 Simple MessageBox",
37283d4416e0 testmessage should test Unicode strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6614
diff changeset
   112
                "Unicode text: '牛肉西蘭花' ...",
37283d4416e0 testmessage should test Unicode strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6614
diff changeset
   113
                NULL);
37283d4416e0 testmessage should test Unicode strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6614
diff changeset
   114
    if (success == -1) {
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
   115
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
6722
37283d4416e0 testmessage should test Unicode strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6614
diff changeset
   116
        quit(1);
37283d4416e0 testmessage should test Unicode strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6614
diff changeset
   117
    }
37283d4416e0 testmessage should test Unicode strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 6614
diff changeset
   118
6758
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   119
    /* Google says this is Traditional Chinese for "beef with broccoli" */
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   120
    success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   121
                "UTF-8 Simple MessageBox",
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   122
                "Unicode text and newline:\r\n'牛肉西蘭花'\n'牛肉西蘭花'",
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   123
                NULL);
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   124
    if (success == -1) {
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
   125
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
6758
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   126
        quit(1);
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   127
    }
2a218048b45f X11 messageboxes should treat "\r\n" as "\n" by ignoring the '\r' char.
Ryan C. Gordon <icculus@icculus.org>
parents: 6722
diff changeset
   128
9697
152b686b9a75 testmessage: Try Unicode chars in the title, too.
Ryan C. Gordon <icculus@icculus.org>
parents: 9694
diff changeset
   129
    /* Google says this is Traditional Chinese for "beef with broccoli" */
152b686b9a75 testmessage: Try Unicode chars in the title, too.
Ryan C. Gordon <icculus@icculus.org>
parents: 9694
diff changeset
   130
    success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
152b686b9a75 testmessage: Try Unicode chars in the title, too.
Ryan C. Gordon <icculus@icculus.org>
parents: 9694
diff changeset
   131
                "牛肉西蘭花",
152b686b9a75 testmessage: Try Unicode chars in the title, too.
Ryan C. Gordon <icculus@icculus.org>
parents: 9694
diff changeset
   132
                "Unicode text in the title.",
152b686b9a75 testmessage: Try Unicode chars in the title, too.
Ryan C. Gordon <icculus@icculus.org>
parents: 9694
diff changeset
   133
                NULL);
152b686b9a75 testmessage: Try Unicode chars in the title, too.
Ryan C. Gordon <icculus@icculus.org>
parents: 9694
diff changeset
   134
    if (success == -1) {
152b686b9a75 testmessage: Try Unicode chars in the title, too.
Ryan C. Gordon <icculus@icculus.org>
parents: 9694
diff changeset
   135
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
152b686b9a75 testmessage: Try Unicode chars in the title, too.
Ryan C. Gordon <icculus@icculus.org>
parents: 9694
diff changeset
   136
        quit(1);
152b686b9a75 testmessage: Try Unicode chars in the title, too.
Ryan C. Gordon <icculus@icculus.org>
parents: 9694
diff changeset
   137
    }
152b686b9a75 testmessage: Try Unicode chars in the title, too.
Ryan C. Gordon <icculus@icculus.org>
parents: 9694
diff changeset
   138
7088
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   139
    button_messagebox(NULL);
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   140
7458
648067e9073a Re-enabled other messagebox tests, moved the SDL_Init() call as late as possible to show the circumstances where it's needed.
Sam Lantinga <slouken@libsdl.org>
parents: 7456
diff changeset
   141
    /* Test showing a message box from a background thread.
648067e9073a Re-enabled other messagebox tests, moved the SDL_Init() call as late as possible to show the circumstances where it's needed.
Sam Lantinga <slouken@libsdl.org>
parents: 7456
diff changeset
   142
648067e9073a Re-enabled other messagebox tests, moved the SDL_Init() call as late as possible to show the circumstances where it's needed.
Sam Lantinga <slouken@libsdl.org>
parents: 7456
diff changeset
   143
       On Mac OS X, the video subsystem needs to be initialized for this
648067e9073a Re-enabled other messagebox tests, moved the SDL_Init() call as late as possible to show the circumstances where it's needed.
Sam Lantinga <slouken@libsdl.org>
parents: 7456
diff changeset
   144
       to work, since the message box events are dispatched by the Cocoa
648067e9073a Re-enabled other messagebox tests, moved the SDL_Init() call as late as possible to show the circumstances where it's needed.
Sam Lantinga <slouken@libsdl.org>
parents: 7456
diff changeset
   145
       subsystem on the main thread.
648067e9073a Re-enabled other messagebox tests, moved the SDL_Init() call as late as possible to show the circumstances where it's needed.
Sam Lantinga <slouken@libsdl.org>
parents: 7456
diff changeset
   146
     */
648067e9073a Re-enabled other messagebox tests, moved the SDL_Init() call as late as possible to show the circumstances where it's needed.
Sam Lantinga <slouken@libsdl.org>
parents: 7456
diff changeset
   147
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
   148
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL video subsystem: %s\n", SDL_GetError());
7458
648067e9073a Re-enabled other messagebox tests, moved the SDL_Init() call as late as possible to show the circumstances where it's needed.
Sam Lantinga <slouken@libsdl.org>
parents: 7456
diff changeset
   149
        return (1);
648067e9073a Re-enabled other messagebox tests, moved the SDL_Init() call as late as possible to show the circumstances where it's needed.
Sam Lantinga <slouken@libsdl.org>
parents: 7456
diff changeset
   150
    }
6614
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
    {
7088
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   152
        int status = 0;
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   153
        SDL_Event event;
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   154
        intptr_t eventNumber = SDL_RegisterEvents(1);
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   155
        SDL_Thread* thread = SDL_CreateThread(&button_messagebox, "MessageBox", (void*)eventNumber);
6614
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
7088
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   157
        while (SDL_WaitEvent(&event))
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   158
        {
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   159
            if (event.type == eventNumber) {
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   160
                break;
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   161
            }
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   162
        }
6614
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
7088
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   164
        SDL_WaitThread(thread, &status);
664d8532219b Make Cocoa_ShowMessageBox work in background threads.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 6758
diff changeset
   165
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
   166
        SDL_Log("Message box thread return %i\n", status);
6614
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
    }
7456
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   168
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   169
    /* Test showing a message box with a parent window */
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   170
    {
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   171
        SDL_Event event;
7478
0d02f6a323f5 Removed not needed SDL_WINDOW_SHOWN from test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7458
diff changeset
   172
        SDL_Window *window = SDL_CreateWindow("Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, 0);
7456
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   173
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   174
        success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   175
                    "Simple MessageBox",
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   176
                    "This is a simple error MessageBox with a parent window",
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   177
                    window);
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   178
        if (success == -1) {
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
   179
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
7456
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   180
            quit(1);
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   181
        }
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   182
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   183
        while (SDL_WaitEvent(&event))
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   184
        {
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   185
            if (event.type == SDL_QUIT || event.type == SDL_KEYUP) {
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   186
                break;
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   187
            }
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   188
        }
193c9a1723ad Added testing of messagebox with a parent window
Sam Lantinga <slouken@libsdl.org>
parents: 7088
diff changeset
   189
    }
6614
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   190
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   191
    SDL_Quit();
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   192
    return (0);
92925281e7ca tree 46b4d59cbfb1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   193
}