added simple Drag & drop test
authorEdward Rudd <urkle@outoforder.cc>
Sat, 12 Oct 2013 11:21:40 -0400
changeset 780773da2747c268
parent 7806 03e6aaea8347
child 7808 627f256b0e56
added simple Drag & drop test
test/Makefile.in
test/testdropfile.c
     1.1 --- a/test/Makefile.in	Sat Oct 12 11:35:47 2013 -0300
     1.2 +++ b/test/Makefile.in	Sat Oct 12 11:21:40 2013 -0400
     1.3 @@ -4,7 +4,7 @@
     1.4  
     1.5  CC      = @CC@
     1.6  EXE	= @EXE@
     1.7 -CFLAGS  = @CFLAGS@
     1.8 +CFLAGS  = @CFLAGS@ -g
     1.9  LIBS	= @LIBS@
    1.10  
    1.11  TARGETS = \
    1.12 @@ -14,6 +14,7 @@
    1.13  	testautomation$(EXE) \
    1.14  	testdraw2$(EXE) \
    1.15  	testdrawchessboard$(EXE) \
    1.16 +	testdropfile$(EXE) \
    1.17  	testerror$(EXE) \
    1.18  	testfile$(EXE) \
    1.19  	testgamecontroller$(EXE) \
    1.20 @@ -108,6 +109,9 @@
    1.21  testdrawchessboard$(EXE): $(srcdir)/testdrawchessboard.c
    1.22  	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
    1.23  
    1.24 +testdropfile$(EXE): $(srcdir)/testdropfile.c
    1.25 +	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
    1.26 +
    1.27  testerror$(EXE): $(srcdir)/testerror.c
    1.28  	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
    1.29  
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/testdropfile.c	Sat Oct 12 11:21:40 2013 -0400
     2.3 @@ -0,0 +1,87 @@
     2.4 +/*
     2.5 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     2.6 +
     2.7 +  This software is provided 'as-is', without any express or implied
     2.8 +  warranty.  In no event will the authors be held liable for any damages
     2.9 +  arising from the use of this software.
    2.10 +
    2.11 +  Permission is granted to anyone to use this software for any purpose,
    2.12 +  including commercial applications, and to alter it and redistribute it
    2.13 +  freely.
    2.14 +*/
    2.15 +
    2.16 +#include <stdlib.h>
    2.17 +#include <stdio.h>
    2.18 +
    2.19 +#include "SDL_test_common.h"
    2.20 +
    2.21 +static SDLTest_CommonState *state;
    2.22 +
    2.23 +/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    2.24 +static void
    2.25 +quit(int rc)
    2.26 +{
    2.27 +    SDLTest_CommonQuit(state);
    2.28 +    exit(rc);
    2.29 +}
    2.30 +
    2.31 +int
    2.32 +main(int argc, char *argv[])
    2.33 +{
    2.34 +    int i, done;
    2.35 +    SDL_Event event;
    2.36 +
    2.37 +	/* Enable standard application logging */
    2.38 +    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
    2.39 +
    2.40 +    /* Initialize test framework */
    2.41 +    state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
    2.42 +    if (!state) {
    2.43 +        return 1;
    2.44 +    }
    2.45 +
    2.46 +    for (i = 1; i < argc;) {
    2.47 +        int consumed;
    2.48 +
    2.49 +        consumed = SDLTest_CommonArg(state, i);
    2.50 +        if (consumed == 0) {
    2.51 +            consumed = -1;
    2.52 +        }
    2.53 +        if (consumed < 0) {
    2.54 +            SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
    2.55 +            quit(1);
    2.56 +        }
    2.57 +        i += consumed;
    2.58 +    }
    2.59 +    if (!SDLTest_CommonInit(state)) {
    2.60 +        quit(2);
    2.61 +    }
    2.62 +
    2.63 +    for (i = 0; i < state->num_windows; ++i) {
    2.64 +        SDL_Renderer *renderer = state->renderers[i];
    2.65 +        SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
    2.66 +        SDL_RenderClear(renderer);
    2.67 +        SDL_RenderPresent(renderer);
    2.68 +    }
    2.69 +
    2.70 +    /* Main render loop */
    2.71 +    done = 0;
    2.72 +    while (!done) {
    2.73 +        /* Check for events */
    2.74 +        while (SDL_PollEvent(&event)) {
    2.75 +            SDLTest_CommonEvent(state, &event, &done);
    2.76 +
    2.77 +            if (event.type == SDL_DROPFILE) {
    2.78 +                char *dropped_filedir = event.drop.file;
    2.79 +                SDL_Log("File dropped on window: %s", dropped_filedir);
    2.80 +                SDL_free(dropped_filedir);
    2.81 +            }
    2.82 +        }
    2.83 +    }
    2.84 +
    2.85 +    quit(0);
    2.86 +    /* keep the compiler happy ... */
    2.87 +    return(0);
    2.88 +}
    2.89 +
    2.90 +/* vi: set ts=4 sw=4 expandtab: */