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