test/testmessage.c
author Andreas Schiffler <aschiffler@ferzkopp.net>
Wed, 26 Dec 2012 22:26:44 -0800
changeset 6773 5ebc5a9e35b4
parent 6758 2a218048b45f
child 7088 664d8532219b
permissions -rw-r--r--
Add surface test suite; minor improvements to render suite; refactor image saving into test lib compare function; fix for Haiku build
slouken@6614
     1
/*
slouken@6614
     2
  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
slouken@6614
     3
slouken@6614
     4
  This software is provided 'as-is', without any express or implied
slouken@6614
     5
  warranty.  In no event will the authors be held liable for any damages
slouken@6614
     6
  arising from the use of this software.
slouken@6614
     7
slouken@6614
     8
  Permission is granted to anyone to use this software for any purpose,
slouken@6614
     9
  including commercial applications, and to alter it and redistribute it
slouken@6614
    10
  freely.
slouken@6614
    11
*/
slouken@6614
    12
slouken@6614
    13
/* Simple test of the SDL MessageBox API*/
slouken@6614
    14
slouken@6614
    15
#include <stdio.h>
slouken@6614
    16
#include <stdlib.h>
slouken@6614
    17
#include <signal.h>
slouken@6614
    18
slouken@6614
    19
#include "SDL.h"
slouken@6614
    20
#include "SDL_thread.h"
slouken@6614
    21
slouken@6614
    22
static int alive = 0;
slouken@6614
    23
slouken@6614
    24
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
slouken@6614
    25
static void
slouken@6614
    26
quit(int rc)
slouken@6614
    27
{
slouken@6614
    28
    SDL_Quit();
slouken@6614
    29
    exit(rc);
slouken@6614
    30
}
slouken@6614
    31
slouken@6614
    32
int
slouken@6614
    33
main(int argc, char *argv[])
slouken@6614
    34
{
slouken@6614
    35
    int success;
slouken@6614
    36
slouken@6614
    37
    /* Load the SDL library */
slouken@6614
    38
    if (SDL_Init(0) < 0) {
slouken@6614
    39
        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
slouken@6614
    40
        return (1);
slouken@6614
    41
    }
slouken@6614
    42
slouken@6614
    43
    success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
slouken@6614
    44
                "Simple MessageBox",
slouken@6614
    45
                "This is a simple error MessageBox",
slouken@6614
    46
                NULL);
slouken@6614
    47
    if (success == -1) {
slouken@6614
    48
        printf("Error Presenting MessageBox: %s\n", SDL_GetError());
slouken@6614
    49
        quit(1);
slouken@6614
    50
    }
slouken@6614
    51
icculus@6758
    52
    success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
icculus@6758
    53
                "Simple MessageBox",
icculus@6758
    54
                "This is a simple MessageBox with a newline:\r\nHello world!",
icculus@6758
    55
                NULL);
icculus@6758
    56
    if (success == -1) {
icculus@6758
    57
        printf("Error Presenting MessageBox: %s\n", SDL_GetError());
icculus@6758
    58
        quit(1);
icculus@6758
    59
    }
icculus@6758
    60
icculus@6722
    61
    /* Google says this is Traditional Chinese for "beef with broccoli" */
icculus@6722
    62
    success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
icculus@6722
    63
                "UTF-8 Simple MessageBox",
icculus@6722
    64
                "Unicode text: '牛肉西蘭花' ...",
icculus@6722
    65
                NULL);
icculus@6722
    66
    if (success == -1) {
icculus@6722
    67
        printf("Error Presenting MessageBox: %s\n", SDL_GetError());
icculus@6722
    68
        quit(1);
icculus@6722
    69
    }
icculus@6722
    70
icculus@6758
    71
    /* Google says this is Traditional Chinese for "beef with broccoli" */
icculus@6758
    72
    success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
icculus@6758
    73
                "UTF-8 Simple MessageBox",
icculus@6758
    74
                "Unicode text and newline:\r\n'牛肉西蘭花'\n'牛肉西蘭花'",
icculus@6758
    75
                NULL);
icculus@6758
    76
    if (success == -1) {
icculus@6758
    77
        printf("Error Presenting MessageBox: %s\n", SDL_GetError());
icculus@6758
    78
        quit(1);
icculus@6758
    79
    }
icculus@6758
    80
slouken@6614
    81
    {
slouken@6614
    82
        const SDL_MessageBoxButtonData buttons[] = {
slouken@6614
    83
            {
slouken@6614
    84
                SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT,
slouken@6614
    85
                0,
slouken@6614
    86
                "OK"
slouken@6614
    87
            },{
slouken@6614
    88
                SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT,
slouken@6614
    89
                1,
slouken@6614
    90
                "Cancel"
slouken@6614
    91
            },
slouken@6614
    92
        };
slouken@6614
    93
slouken@6614
    94
        SDL_MessageBoxData data = {
slouken@6614
    95
            SDL_MESSAGEBOX_INFORMATION,
slouken@6614
    96
            NULL, // no parent window
slouken@6614
    97
            "Custom MessageBox",
slouken@6614
    98
            "This is a custom messagebox",
slouken@6614
    99
            2,
slouken@6614
   100
            buttons,
slouken@6614
   101
            NULL // Default color scheme
slouken@6614
   102
        };
slouken@6614
   103
slouken@6614
   104
        int button = -1;
slouken@6614
   105
        success = SDL_ShowMessageBox(&data, &button);
slouken@6614
   106
        if (success == -1) {
slouken@6614
   107
            printf("Error Presenting MessageBox: %s\n", SDL_GetError());
slouken@6614
   108
            quit(2);
slouken@6614
   109
        }
slouken@6614
   110
        printf("Pressed button: %d, %s\n", button, button == 1 ? "Cancel" : "OK");
slouken@6614
   111
    }
slouken@6614
   112
slouken@6614
   113
    SDL_Quit();
slouken@6614
   114
    return (0);
slouken@6614
   115
}