[Tizen] Support Autoconf 2.71
[platform/upstream/SDL.git] / test / testdropfile.c
1 /*
2   Copyright (C) 1997-2020 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 #include <stdlib.h>
14 #include <stdio.h>
15
16 #include "SDL_test_common.h"
17
18 static SDLTest_CommonState *state;
19
20 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
21 static void
22 quit(int rc)
23 {
24     SDLTest_CommonQuit(state);
25     exit(rc);
26 }
27 int
28 main(int argc, char *argv[])
29 {
30     int i, done;
31     SDL_Event event;
32
33     /* Enable standard application logging */
34     SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
35
36     /* Initialize test framework */
37     state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
38     if (!state) {
39         return 1;
40     }
41
42     for (i = 1; i < argc;) {
43         int consumed;
44
45         consumed = SDLTest_CommonArg(state, i);
46         /* needed voodoo to allow app to launch via OS X Finder */
47         if (SDL_strncmp(argv[i], "-psn", 4)==0) {
48             consumed = 1;
49         }
50         if (consumed == 0) {
51             consumed = -1;
52         }
53         if (consumed < 0) {
54             SDLTest_CommonLogUsage(state, argv[0], NULL);
55             quit(1);
56         }
57         i += consumed;
58     }
59     if (!SDLTest_CommonInit(state)) {
60         quit(2);
61     }
62
63     for (i = 0; i < state->num_windows; ++i) {
64         SDL_Renderer *renderer = state->renderers[i];
65         SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
66         SDL_RenderClear(renderer);
67         SDL_RenderPresent(renderer);
68     }
69
70     SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
71
72     /* Main render loop */
73     done = 0;
74     while (!done) {
75         /* Check for events */
76         while (SDL_PollEvent(&event)) {
77             if (event.type == SDL_DROPBEGIN) {
78                 SDL_Log("Drop beginning on window %u", (unsigned int) event.drop.windowID);
79             } else if (event.type == SDL_DROPCOMPLETE) {
80                 SDL_Log("Drop complete on window %u", (unsigned int) event.drop.windowID);
81             } else if ((event.type == SDL_DROPFILE) || (event.type == SDL_DROPTEXT)) {
82                 const char *typestr = (event.type == SDL_DROPFILE) ? "File" : "Text";
83                 char *dropped_filedir = event.drop.file;
84                 SDL_Log("%s dropped on window %u: %s", typestr, (unsigned int) event.drop.windowID, dropped_filedir);
85                 /* Normally you'd have to do this, but this is freed in SDLTest_CommonEvent() */
86                 /*SDL_free(dropped_filedir);*/
87             }
88
89             SDLTest_CommonEvent(state, &event, &done);
90         }
91     }
92
93     quit(0);
94     /* keep the compiler happy ... */
95     return(0);
96 }
97
98 /* vi: set ts=4 sw=4 expandtab: */