test/testautomation_clipboard.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 07 Dec 2017 16:08:09 -0800
changeset 11730 ac6c607e065c
parent 10782 1de6d4633ee6
permissions -rw-r--r--
Enable building the Metal renderer by default, and weak link the Metal framework so the SDL library is safe to use on older Macs
Also generate iOS versions of the Metal shaders
aschiffler@6760
     1
/**
aschiffler@6760
     2
 * New/updated tests: aschiffler at ferzkopp dot net
aschiffler@6760
     3
 */
aschiffler@6760
     4
aschiffler@6760
     5
#include <stdio.h>
aschiffler@6760
     6
#include <string.h>
aschiffler@6760
     7
aschiffler@6760
     8
#include "SDL.h"
aschiffler@6760
     9
#include "SDL_test.h"
aschiffler@6760
    10
aschiffler@6760
    11
/* ================= Test Case Implementation ================== */
aschiffler@6760
    12
aschiffler@6760
    13
/* Test case functions */
aschiffler@6760
    14
aschiffler@6760
    15
/**
aschiffler@6760
    16
 * \brief Check call to SDL_HasClipboardText
aschiffler@6760
    17
 *
aschiffler@6760
    18
 * \sa
aschiffler@6760
    19
 * http://wiki.libsdl.org/moin.cgi/SDL_HasClipboardText
aschiffler@6760
    20
 */
aschiffler@6760
    21
int
aschiffler@6760
    22
clipboard_testHasClipboardText(void *arg)
aschiffler@6760
    23
{
slouken@7191
    24
    SDL_bool result;
slouken@7191
    25
    result = SDL_HasClipboardText();
slouken@7191
    26
    SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
aschiffler@6760
    27
aschiffler@6760
    28
    return TEST_COMPLETED;
aschiffler@6760
    29
}
aschiffler@6760
    30
aschiffler@6760
    31
/**
aschiffler@6760
    32
 * \brief Check call to SDL_GetClipboardText
aschiffler@6760
    33
 *
aschiffler@6760
    34
 * \sa
aschiffler@6760
    35
 * http://wiki.libsdl.org/moin.cgi/SDL_GetClipboardText
aschiffler@6760
    36
 */
aschiffler@6760
    37
int
aschiffler@6760
    38
clipboard_testGetClipboardText(void *arg)
aschiffler@6760
    39
{
slouken@7191
    40
    char *charResult;
slouken@7191
    41
    charResult = SDL_GetClipboardText();
slouken@7191
    42
    SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
aschiffler@6760
    43
slouken@7719
    44
    SDL_free(charResult);
aschiffler@6760
    45
aschiffler@6760
    46
    return TEST_COMPLETED;
aschiffler@6760
    47
}
aschiffler@6760
    48
aschiffler@6760
    49
/**
aschiffler@6760
    50
 * \brief Check call to SDL_SetClipboardText
aschiffler@6760
    51
 * \sa
aschiffler@6760
    52
 * http://wiki.libsdl.org/moin.cgi/SDL_SetClipboardText
aschiffler@6760
    53
 */
aschiffler@6760
    54
int
aschiffler@6760
    55
clipboard_testSetClipboardText(void *arg)
aschiffler@6760
    56
{
slouken@7191
    57
    char *textRef = SDLTest_RandomAsciiString();
slouken@7191
    58
    char *text = SDL_strdup(textRef);
slouken@7191
    59
    int result;
slouken@7191
    60
    result = SDL_SetClipboardText((const char *)text);
slouken@7191
    61
    SDLTest_AssertPass("Call to SDL_SetClipboardText succeeded");
slouken@7191
    62
    SDLTest_AssertCheck(
slouken@7191
    63
        result == 0,
slouken@7191
    64
        "Validate SDL_SetClipboardText result, expected 0, got %i",
slouken@7191
    65
        result);
slouken@7191
    66
    SDLTest_AssertCheck(
slouken@7191
    67
        SDL_strcmp(textRef, text) == 0,
slouken@7191
    68
        "Verify SDL_SetClipboardText did not modify input string, expected '%s', got '%s'",
slouken@7191
    69
        textRef, text);
aschiffler@6760
    70
aschiffler@6760
    71
    /* Cleanup */
slouken@7719
    72
    SDL_free(textRef);
slouken@7719
    73
    SDL_free(text);
aschiffler@6760
    74
aschiffler@6760
    75
   return TEST_COMPLETED;
aschiffler@6760
    76
}
aschiffler@6760
    77
aschiffler@6760
    78
/**
aschiffler@6760
    79
 * \brief End-to-end test of SDL_xyzClipboardText functions
aschiffler@6760
    80
 * \sa
aschiffler@6760
    81
 * http://wiki.libsdl.org/moin.cgi/SDL_HasClipboardText
aschiffler@6760
    82
 * http://wiki.libsdl.org/moin.cgi/SDL_GetClipboardText
aschiffler@6760
    83
 * http://wiki.libsdl.org/moin.cgi/SDL_SetClipboardText
aschiffler@6760
    84
 */
aschiffler@6760
    85
int
aschiffler@6760
    86
clipboard_testClipboardTextFunctions(void *arg)
aschiffler@6760
    87
{
slouken@7191
    88
    char *textRef = SDLTest_RandomAsciiString();
slouken@7191
    89
    char *text = SDL_strdup(textRef);
slouken@7191
    90
    SDL_bool boolResult;
slouken@7191
    91
    int intResult;
slouken@7191
    92
    char *charResult;
aschiffler@6760
    93
slouken@7191
    94
    /* Clear clipboard text state */
slouken@7191
    95
    boolResult = SDL_HasClipboardText();
slouken@7191
    96
    SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
slouken@7191
    97
    if (boolResult == SDL_TRUE) {
aschiffler@6760
    98
        intResult = SDL_SetClipboardText((const char *)NULL);
philipp@7144
    99
        SDLTest_AssertPass("Call to SDL_SetClipboardText(NULL) succeeded");
slouken@7191
   100
        SDLTest_AssertCheck(
slouken@7191
   101
            intResult == 0,
slouken@7191
   102
            "Verify result from SDL_SetClipboardText(NULL), expected 0, got %i",
slouken@7191
   103
            intResult);
slouken@7191
   104
        charResult = SDL_GetClipboardText();
slouken@7191
   105
        SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
slouken@9617
   106
        SDL_free(charResult);
slouken@7191
   107
        boolResult = SDL_HasClipboardText();
slouken@7191
   108
        SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
slouken@7191
   109
        SDLTest_AssertCheck(
aschiffler@6760
   110
            boolResult == SDL_FALSE,
slouken@7191
   111
            "Verify SDL_HasClipboardText returned SDL_FALSE, got %s",
slouken@7191
   112
            (boolResult) ? "SDL_TRUE" : "SDL_FALSE");
aschiffler@6760
   113
    }
aschiffler@6760
   114
aschiffler@6760
   115
    /* Empty clipboard  */
slouken@7191
   116
    charResult = SDL_GetClipboardText();
slouken@7191
   117
    SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
slouken@7191
   118
    SDLTest_AssertCheck(
slouken@7191
   119
        charResult != NULL,
slouken@7191
   120
        "Verify SDL_GetClipboardText did not return NULL");
slouken@7191
   121
    SDLTest_AssertCheck(
slouken@7721
   122
        charResult[0] == '\0',
slouken@7191
   123
        "Verify SDL_GetClipboardText returned string with length 0, got length %i",
icculus@10782
   124
        (int) SDL_strlen(charResult));
aschiffler@6760
   125
    intResult = SDL_SetClipboardText((const char *)text);
slouken@7191
   126
    SDLTest_AssertPass("Call to SDL_SetClipboardText succeeded");
slouken@7191
   127
    SDLTest_AssertCheck(
slouken@7191
   128
        intResult == 0,
slouken@7191
   129
        "Verify result from SDL_SetClipboardText(NULL), expected 0, got %i",
slouken@7191
   130
        intResult);
slouken@7191
   131
    SDLTest_AssertCheck(
slouken@7191
   132
        SDL_strcmp(textRef, text) == 0,
slouken@7191
   133
        "Verify SDL_SetClipboardText did not modify input string, expected '%s', got '%s'",
slouken@7191
   134
        textRef, text);
slouken@7191
   135
    boolResult = SDL_HasClipboardText();
slouken@7191
   136
    SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
slouken@7191
   137
    SDLTest_AssertCheck(
aschiffler@6760
   138
        boolResult == SDL_TRUE,
slouken@7191
   139
        "Verify SDL_HasClipboardText returned SDL_TRUE, got %s",
slouken@7191
   140
        (boolResult) ? "SDL_TRUE" : "SDL_FALSE");
slouken@9617
   141
    SDL_free(charResult);
slouken@7191
   142
    charResult = SDL_GetClipboardText();
slouken@7191
   143
    SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
slouken@7191
   144
    SDLTest_AssertCheck(
philipp@7477
   145
        SDL_strcmp(textRef, charResult) == 0,
slouken@7191
   146
        "Verify SDL_GetClipboardText returned correct string, expected '%s', got '%s'",
slouken@7191
   147
        textRef, charResult);
aschiffler@6760
   148
aschiffler@6760
   149
    /* Cleanup */
slouken@7719
   150
    SDL_free(textRef);
slouken@7719
   151
    SDL_free(text);
slouken@7719
   152
    SDL_free(charResult);
aschiffler@6760
   153
aschiffler@6760
   154
   return TEST_COMPLETED;
aschiffler@6760
   155
}
aschiffler@6760
   156
aschiffler@6760
   157
aschiffler@6760
   158
/* ================= Test References ================== */
aschiffler@6760
   159
aschiffler@6760
   160
/* Clipboard test cases */
aschiffler@6760
   161
static const SDLTest_TestCaseReference clipboardTest1 =
slouken@7191
   162
        { (SDLTest_TestCaseFp)clipboard_testHasClipboardText, "clipboard_testHasClipboardText", "Check call to SDL_HasClipboardText", TEST_ENABLED };
aschiffler@6760
   163
aschiffler@6760
   164
static const SDLTest_TestCaseReference clipboardTest2 =
slouken@7191
   165
        { (SDLTest_TestCaseFp)clipboard_testGetClipboardText, "clipboard_testGetClipboardText", "Check call to SDL_GetClipboardText", TEST_ENABLED };
aschiffler@6760
   166
aschiffler@6760
   167
static const SDLTest_TestCaseReference clipboardTest3 =
slouken@7191
   168
        { (SDLTest_TestCaseFp)clipboard_testSetClipboardText, "clipboard_testSetClipboardText", "Check call to SDL_SetClipboardText", TEST_ENABLED };
aschiffler@6760
   169
aschiffler@6760
   170
static const SDLTest_TestCaseReference clipboardTest4 =
slouken@7191
   171
        { (SDLTest_TestCaseFp)clipboard_testClipboardTextFunctions, "clipboard_testClipboardTextFunctions", "End-to-end test of SDL_xyzClipboardText functions", TEST_ENABLED };
aschiffler@6760
   172
aschiffler@6760
   173
/* Sequence of Clipboard test cases */
aschiffler@6760
   174
static const SDLTest_TestCaseReference *clipboardTests[] =  {
slouken@7191
   175
    &clipboardTest1, &clipboardTest2, &clipboardTest3, &clipboardTest4, NULL
aschiffler@6760
   176
};
aschiffler@6760
   177
aschiffler@6760
   178
/* Clipboard test suite (global) */
aschiffler@6760
   179
SDLTest_TestSuiteReference clipboardTestSuite = {
slouken@7191
   180
    "Clipboard",
slouken@7191
   181
    NULL,
slouken@7191
   182
    clipboardTests,
slouken@7191
   183
    NULL
aschiffler@6760
   184
};