test/testloadso.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 12 Aug 2016 19:59:00 -0400
changeset 10266 c09f06c4e8c8
parent 9998 f67cf37e9cd4
permissions -rw-r--r--
emscripten: send fake mouse events for touches, like other targets do. (This really should be handled at the higher level and not in the individual targets, but this fixes the immediate bug.)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 3338
diff changeset
     1
/*
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9619
diff changeset
     2
  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 3338
diff changeset
     3
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 3338
diff changeset
     4
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 3338
diff changeset
     5
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 3338
diff changeset
     6
  arising from the use of this software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 3338
diff changeset
     7
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 3338
diff changeset
     8
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 3338
diff changeset
     9
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 3338
diff changeset
    10
  freely.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 3338
diff changeset
    11
*/
2067
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
3338
9de326b3099c Fixed bug #817
Sam Lantinga <slouken@libsdl.org>
parents: 2120
diff changeset
    13
/* Test program to test dynamic loading with the loadso subsystem.
2067
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
*/
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
#include <stdio.h>
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
#include <stdlib.h>
3338
9de326b3099c Fixed bug #817
Sam Lantinga <slouken@libsdl.org>
parents: 2120
diff changeset
    18
#include <string.h>
2067
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
#include "SDL.h"
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
2120
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    22
typedef int (*fntype) (const char *);
2067
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
2120
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    24
int
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    25
main(int argc, char *argv[])
2067
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
{
2120
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    27
    int retval = 0;
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    28
    int hello = 0;
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    29
    const char *libname = NULL;
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    30
    const char *symname = NULL;
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    31
    void *lib = NULL;
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    32
    fntype fn = NULL;
2067
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
2120
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    34
    if (argc != 3) {
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    35
        const char *app = argv[0];
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
    36
        SDL_Log("USAGE: %s <library> <functionname>\n", app);
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
    37
        SDL_Log("       %s --hello <lib with puts()>\n", app);
2120
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    38
        return 1;
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    39
    }
2067
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
2120
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    41
    /* Initialize SDL */
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    42
    if (SDL_Init(0) < 0) {
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
    43
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
2120
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    44
        return 2;
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    45
    }
2067
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
2120
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    47
    if (strcmp(argv[1], "--hello") == 0) {
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    48
        hello = 1;
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    49
        libname = argv[2];
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    50
        symname = "puts";
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    51
    } else {
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    52
        libname = argv[1];
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    53
        symname = argv[2];
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    54
    }
2067
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
2120
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    56
    lib = SDL_LoadObject(libname);
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    57
    if (lib == NULL) {
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
    58
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_LoadObject('%s') failed: %s\n",
2120
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    59
                libname, SDL_GetError());
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    60
        retval = 3;
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    61
    } else {
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    62
        fn = (fntype) SDL_LoadFunction(lib, symname);
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    63
        if (fn == NULL) {
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
    64
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_LoadFunction('%s') failed: %s\n",
2120
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    65
                    symname, SDL_GetError());
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    66
            retval = 4;
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    67
        } else {
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
    68
            SDL_Log("Found %s in %s at %p\n", symname, libname, fn);
2120
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    69
            if (hello) {
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
    70
                SDL_Log("Calling function...\n");
2120
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    71
                fflush(stdout);
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    72
                fn("     HELLO, WORLD!\n");
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
    73
                SDL_Log("...apparently, we survived.  :)\n");
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
    74
                SDL_Log("Unloading library...\n");
2120
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    75
                fflush(stdout);
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    76
            }
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    77
        }
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    78
        SDL_UnloadObject(lib);
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    79
    }
2c835d58faad make indent
Sam Lantinga <slouken@libsdl.org>
parents: 2068
diff changeset
    80
    SDL_Quit();
7437
964e8876ad3b Fixed compiler warnings in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 5535
diff changeset
    81
    return retval;
2067
dcdb175c2829 Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
}