test/testautomation_clipboard.c
changeset 6769 b49778d885cd
parent 6760 04dcce3081e6
child 6822 18f6818ba281
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/testautomation_clipboard.c	Sat Dec 22 17:24:42 2012 -0800
     1.3 @@ -0,0 +1,182 @@
     1.4 +/**
     1.5 + * New/updated tests: aschiffler at ferzkopp dot net
     1.6 + */
     1.7 +
     1.8 +#include <stdio.h>
     1.9 +#include <string.h>
    1.10 +
    1.11 +#include "SDL.h"
    1.12 +#include "SDL_test.h"
    1.13 +
    1.14 +/* ================= Test Case Implementation ================== */
    1.15 +
    1.16 +/* Test case functions */
    1.17 +
    1.18 +/**
    1.19 + * \brief Check call to SDL_HasClipboardText
    1.20 + *
    1.21 + * \sa
    1.22 + * http://wiki.libsdl.org/moin.cgi/SDL_HasClipboardText
    1.23 + */
    1.24 +int
    1.25 +clipboard_testHasClipboardText(void *arg)
    1.26 +{
    1.27 +	SDL_bool result;
    1.28 +	result = SDL_HasClipboardText();
    1.29 +	SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
    1.30 +
    1.31 +    return TEST_COMPLETED;
    1.32 +}
    1.33 +
    1.34 +/**
    1.35 + * \brief Check call to SDL_GetClipboardText
    1.36 + *
    1.37 + * \sa
    1.38 + * http://wiki.libsdl.org/moin.cgi/SDL_GetClipboardText
    1.39 + */
    1.40 +int
    1.41 +clipboard_testGetClipboardText(void *arg)
    1.42 +{
    1.43 +	char *charResult;
    1.44 +	charResult = SDL_GetClipboardText();
    1.45 +	SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
    1.46 +
    1.47 +	if (charResult) SDL_free(charResult);
    1.48 +
    1.49 +    return TEST_COMPLETED;
    1.50 +}
    1.51 +
    1.52 +/**
    1.53 + * \brief Check call to SDL_SetClipboardText
    1.54 + * \sa
    1.55 + * http://wiki.libsdl.org/moin.cgi/SDL_SetClipboardText
    1.56 + */
    1.57 +int
    1.58 +clipboard_testSetClipboardText(void *arg)
    1.59 +{
    1.60 +	char *textRef = SDLTest_RandomAsciiString();
    1.61 +	char *text = SDL_strdup(textRef);
    1.62 +	int result;
    1.63 +	result = SDL_SetClipboardText((const char *)text);
    1.64 +	SDLTest_AssertPass("Call to SDL_SetClipboardText succeeded");
    1.65 +	SDLTest_AssertCheck(
    1.66 +		result == 0,
    1.67 +		"Validate SDL_SetClipboardText result, expected 0, got %i",
    1.68 +		result);
    1.69 +	SDLTest_AssertCheck(
    1.70 +		SDL_strcmp(textRef, text) == 0,
    1.71 +		"Verify SDL_SetClipboardText did not modify input string, expected '%s', got '%s'",
    1.72 +		textRef, text);
    1.73 +
    1.74 +    /* Cleanup */
    1.75 +    if (textRef) SDL_free(textRef);
    1.76 +    if (text) SDL_free(text);
    1.77 +
    1.78 +   return TEST_COMPLETED;
    1.79 +}
    1.80 +
    1.81 +/**
    1.82 + * \brief End-to-end test of SDL_xyzClipboardText functions
    1.83 + * \sa
    1.84 + * http://wiki.libsdl.org/moin.cgi/SDL_HasClipboardText
    1.85 + * http://wiki.libsdl.org/moin.cgi/SDL_GetClipboardText
    1.86 + * http://wiki.libsdl.org/moin.cgi/SDL_SetClipboardText
    1.87 + */
    1.88 +int
    1.89 +clipboard_testClipboardTextFunctions(void *arg)
    1.90 +{
    1.91 +	char *textRef = SDLTest_RandomAsciiString();
    1.92 +	char *text = SDL_strdup(textRef);
    1.93 +	SDL_bool boolResult;
    1.94 +	int intResult;
    1.95 +	char *charResult;
    1.96 +
    1.97 +	/* Clear clipboard text state */
    1.98 +	boolResult = SDL_HasClipboardText();
    1.99 +	SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
   1.100 +	if (boolResult == SDL_TRUE) {
   1.101 +        intResult = SDL_SetClipboardText((const char *)NULL);
   1.102 +		SDLTest_AssertPass("Call to DL_SetClipboardText(NULL) succeeded");
   1.103 +	    SDLTest_AssertCheck(
   1.104 +			intResult == 0,
   1.105 +			"Verify result from SDL_SetClipboardText(NULL), expected 0, got %i",
   1.106 +			intResult);
   1.107 +	    charResult = SDL_GetClipboardText();
   1.108 +		SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
   1.109 +	    boolResult = SDL_HasClipboardText();
   1.110 +		SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
   1.111 +	    SDLTest_AssertCheck(
   1.112 +            boolResult == SDL_FALSE,
   1.113 +	        "Verify SDL_HasClipboardText returned SDL_FALSE, got %s",
   1.114 +			(boolResult) ? "SDL_TRUE" : "SDL_FALSE");
   1.115 +    }
   1.116 +
   1.117 +    /* Empty clipboard  */
   1.118 +	charResult = SDL_GetClipboardText();
   1.119 +	SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
   1.120 +	SDLTest_AssertCheck(
   1.121 +		charResult != NULL,
   1.122 +		"Verify SDL_GetClipboardText did not return NULL");
   1.123 +	SDLTest_AssertCheck(
   1.124 +		strlen(charResult) == 0,
   1.125 +		"Verify SDL_GetClipboardText returned string with length 0, got length %i",
   1.126 +		strlen(charResult));
   1.127 +    intResult = SDL_SetClipboardText((const char *)text);
   1.128 +	SDLTest_AssertPass("Call to SDL_SetClipboardText succeeded");
   1.129 +	SDLTest_AssertCheck(
   1.130 +		intResult == 0,
   1.131 +		"Verify result from SDL_SetClipboardText(NULL), expected 0, got %i",
   1.132 +		intResult);
   1.133 +	SDLTest_AssertCheck(
   1.134 +		strcmp(textRef, text) == 0,
   1.135 +		"Verify SDL_SetClipboardText did not modify input string, expected '%s', got '%s'",
   1.136 +		textRef, text);
   1.137 +	boolResult = SDL_HasClipboardText();
   1.138 +	SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
   1.139 +	SDLTest_AssertCheck(
   1.140 +        boolResult == SDL_TRUE,
   1.141 +	    "Verify SDL_HasClipboardText returned SDL_TRUE, got %s",
   1.142 +		(boolResult) ? "SDL_TRUE" : "SDL_FALSE");
   1.143 +	charResult = SDL_GetClipboardText();
   1.144 +	SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
   1.145 +	SDLTest_AssertCheck(
   1.146 +		strcmp(textRef, charResult) == 0,
   1.147 +		"Verify SDL_GetClipboardText returned correct string, expected '%s', got '%s'",
   1.148 +		textRef, charResult);
   1.149 +
   1.150 +    /* Cleanup */
   1.151 +    if (textRef) SDL_free(textRef);
   1.152 +    if (text) SDL_free(text);
   1.153 +    if (charResult) SDL_free(charResult);
   1.154 +
   1.155 +   return TEST_COMPLETED;
   1.156 +}
   1.157 +
   1.158 +
   1.159 +/* ================= Test References ================== */
   1.160 +
   1.161 +/* Clipboard test cases */
   1.162 +static const SDLTest_TestCaseReference clipboardTest1 =
   1.163 +		{ (SDLTest_TestCaseFp)clipboard_testHasClipboardText, "clipboard_testHasClipboardText", "Check call to SDL_HasClipboardText", TEST_ENABLED };
   1.164 +
   1.165 +static const SDLTest_TestCaseReference clipboardTest2 =
   1.166 +		{ (SDLTest_TestCaseFp)clipboard_testGetClipboardText, "clipboard_testGetClipboardText", "Check call to SDL_GetClipboardText", TEST_ENABLED };
   1.167 +
   1.168 +static const SDLTest_TestCaseReference clipboardTest3 =
   1.169 +		{ (SDLTest_TestCaseFp)clipboard_testSetClipboardText, "clipboard_testSetClipboardText", "Check call to SDL_SetClipboardText", TEST_ENABLED };
   1.170 +
   1.171 +static const SDLTest_TestCaseReference clipboardTest4 =
   1.172 +		{ (SDLTest_TestCaseFp)clipboard_testClipboardTextFunctions, "clipboard_testClipboardTextFunctions", "End-to-end test of SDL_xyzClipboardText functions", TEST_ENABLED };
   1.173 +
   1.174 +/* Sequence of Clipboard test cases */
   1.175 +static const SDLTest_TestCaseReference *clipboardTests[] =  {
   1.176 +	&clipboardTest1, &clipboardTest2, &clipboardTest3, &clipboardTest4, NULL
   1.177 +};
   1.178 +
   1.179 +/* Clipboard test suite (global) */
   1.180 +SDLTest_TestSuiteReference clipboardTestSuite = {
   1.181 +	"Clipboard",
   1.182 +	NULL,
   1.183 +	clipboardTests,
   1.184 +	NULL
   1.185 +};