Added test/testdisplayinfo.c
authorRyan C. Gordon <icculus@icculus.org>
Tue, 14 Jul 2015 21:28:26 -0400
changeset 9800978b538d177e
parent 9799 d1e20d38e5f5
child 9801 752406828724
Added test/testdisplayinfo.c
.hgignore
test/Makefile.in
test/testdisplayinfo.c
     1.1 --- a/.hgignore	Sat Jul 11 00:59:56 2015 -0400
     1.2 +++ b/.hgignore	Tue Jul 14 21:28:26 2015 -0400
     1.3 @@ -117,6 +117,7 @@
     1.4  test/testviewport
     1.5  test/testwm2
     1.6  test/torturethread
     1.7 +test/testdisplayinfo
     1.8  test/*.exe
     1.9  test/*.dSYM
    1.10  buildbot
     2.1 --- a/test/Makefile.in	Sat Jul 11 00:59:56 2015 -0400
     2.2 +++ b/test/Makefile.in	Tue Jul 14 21:28:26 2015 -0400
     2.3 @@ -60,6 +60,7 @@
     2.4  	torturethread$(EXE) \
     2.5  	testrendercopyex$(EXE) \
     2.6  	testmessage$(EXE) \
     2.7 +	testdisplayinfo$(EXE) \
     2.8  	controllermap$(EXE) \
     2.9  	
    2.10  all: Makefile $(TARGETS)
    2.11 @@ -266,6 +267,9 @@
    2.12  testmessage$(EXE): $(srcdir)/testmessage.c
    2.13  	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
    2.14  
    2.15 +testdisplayinfo$(EXE): $(srcdir)/testdisplayinfo.c
    2.16 +	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
    2.17 +
    2.18  controllermap$(EXE): $(srcdir)/controllermap.c
    2.19  	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
    2.20  
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/testdisplayinfo.c	Tue Jul 14 21:28:26 2015 -0400
     3.3 @@ -0,0 +1,88 @@
     3.4 +/*
     3.5 +  Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
     3.6 +
     3.7 +  This software is provided 'as-is', without any express or implied
     3.8 +  warranty.  In no event will the authors be held liable for any damages
     3.9 +  arising from the use of this software.
    3.10 +
    3.11 +  Permission is granted to anyone to use this software for any purpose,
    3.12 +  including commercial applications, and to alter it and redistribute it
    3.13 +  freely.
    3.14 +*/
    3.15 +
    3.16 +/* Program to test hotplugging of audio devices */
    3.17 +
    3.18 +#include "SDL.h"
    3.19 +
    3.20 +#include <stdio.h>
    3.21 +#include <stdlib.h>
    3.22 +
    3.23 +static void
    3.24 +print_mode(const char *prefix, const SDL_DisplayMode *mode)
    3.25 +{
    3.26 +    if (!mode)
    3.27 +        return;
    3.28 +
    3.29 +    SDL_Log("%s: fmt=%s w=%d h=%d refresh=%d\n",
    3.30 +            prefix, SDL_GetPixelFormatName(mode->format),
    3.31 +            mode->w, mode->h, mode->refresh_rate);
    3.32 +}
    3.33 +
    3.34 +int
    3.35 +main(int argc, char *argv[])
    3.36 +{
    3.37 +    SDL_DisplayMode mode;
    3.38 +    int num_displays, dpy;
    3.39 +
    3.40 +	/* Enable standard application logging */
    3.41 +	SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
    3.42 +
    3.43 +    /* Load the SDL library */
    3.44 +    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    3.45 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
    3.46 +        return 1;
    3.47 +    }
    3.48 +
    3.49 +    SDL_Log("Using video target '%s'.\n", SDL_GetCurrentVideoDriver());
    3.50 +    num_displays = SDL_GetNumVideoDisplays();
    3.51 +
    3.52 +    SDL_Log("See %d displays.\n", num_displays);
    3.53 +
    3.54 +    for (dpy = 0; dpy < num_displays; dpy++) {
    3.55 +        const int num_modes = SDL_GetNumDisplayModes(dpy);
    3.56 +        SDL_Rect rect = { 0, 0, 0, 0 };
    3.57 +        int m;
    3.58 +
    3.59 +        SDL_GetDisplayBounds(dpy, &rect);
    3.60 +        SDL_Log("%d: \"%s\" (%dx%d, (%d, %d)), %d modes.\n", dpy, SDL_GetDisplayName(dpy), rect.w, rect.h, rect.x, rect.y, num_modes);
    3.61 +
    3.62 +        if (SDL_GetCurrentDisplayMode(dpy, &mode) == -1) {
    3.63 +            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    CURRENT: failed to query (%s)\n", SDL_GetError());
    3.64 +        } else {
    3.65 +            print_mode("CURRENT", &mode);
    3.66 +        }
    3.67 +
    3.68 +        if (SDL_GetDesktopDisplayMode(dpy, &mode) == -1) {
    3.69 +            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    DESKTOP: failed to query (%s)\n", SDL_GetError());
    3.70 +        } else {
    3.71 +            print_mode("DESKTOP", &mode);
    3.72 +        }
    3.73 +
    3.74 +        for (m = 0; m < num_modes; m++) {
    3.75 +            if (SDL_GetDisplayMode(dpy, m, &mode) == -1) {
    3.76 +                SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    MODE %d: failed to query (%s)\n", m, SDL_GetError());
    3.77 +            } else {
    3.78 +                char prefix[64];
    3.79 +                SDL_snprintf(prefix, sizeof (prefix), "    MODE %d", m);
    3.80 +                print_mode(prefix, &mode);
    3.81 +            }
    3.82 +        }
    3.83 +
    3.84 +        SDL_Log("\n");
    3.85 +    }
    3.86 +
    3.87 +    return 0;
    3.88 +}
    3.89 +
    3.90 +/* vi: set ts=4 sw=4 expandtab: */
    3.91 +