Add clipboard tests
authorAndreas Schiffler <aschiffler@ferzkopp.net>
Sat, 29 Oct 2011 23:34:19 -0700
changeset 60359494ca1b6cf5
parent 6034 e228e94fef7f
child 6036 f2a89f2a6157
Add clipboard tests
test/test-automation/tests/testclipboard/testclipboard.c
     1.1 --- a/test/test-automation/tests/testclipboard/testclipboard.c	Sat Oct 29 01:11:47 2011 -0400
     1.2 +++ b/test/test-automation/tests/testclipboard/testclipboard.c	Sat Oct 29 23:34:19 2011 -0700
     1.3 @@ -5,7 +5,6 @@
     1.4  #include "../../include/SDL_test.h"
     1.5  
     1.6  
     1.7 -
     1.8  /*!
     1.9   * Note: Add test for clipboard here
    1.10   *
    1.11 @@ -13,22 +12,157 @@
    1.12  
    1.13  /* Test cases */
    1.14  static const TestCaseReference test1 =
    1.15 -		(TestCaseReference){ "clipboard_test", "description", TEST_DISABLED, 0, 0 };
    1.16 +		(TestCaseReference){ "clipboard_testHasClipboardText", "Check call to SDL_HasClipboardText", TEST_ENABLED, 0, 0 };
    1.17 +
    1.18 +static const TestCaseReference test2 =
    1.19 +		(TestCaseReference){ "clipboard_testGetClipboardText", "Check call to SDL_GetClipboardText", TEST_ENABLED, 0, 0 };
    1.20 +
    1.21 +static const TestCaseReference test3 =
    1.22 +		(TestCaseReference){ "clipboard_testSetClipboardText", "Check call to SDL_SetClipboardText", TEST_ENABLED, 0, 0 };
    1.23 +
    1.24 +static const TestCaseReference test4 =
    1.25 +		(TestCaseReference){ "clipboard_testClipboardTextFunctions", "End-to-end test of SDL_xyzClipboardText functions", TEST_ENABLED, 0, 0 };
    1.26  
    1.27  /* Test suite */
    1.28  extern const TestCaseReference *testSuite[] =  {
    1.29 -	&test1, NULL
    1.30 +	&test1, &test2, &test3, &test4, NULL
    1.31  };
    1.32  
    1.33  TestCaseReference **QueryTestSuite() {
    1.34  	return (TestCaseReference **)testSuite;
    1.35  }
    1.36  
    1.37 +void
    1.38 +SetUp(void *arg)
    1.39 +{
    1.40 +  /* Start SDL video */
    1.41 +  int ret = SDL_InitSubSystem( SDL_INIT_VIDEO );
    1.42 +  AssertTrue(ret==0, "SDL_Init(SDL_INIT_VIDEO) failed: %s", SDL_GetError());
    1.43 +}
    1.44 +                        
    1.45 +void
    1.46 +TearDown(void *arg)
    1.47 +{
    1.48 +  /* Quit SDL video */
    1.49 + SDL_QuitSubSystem(SDL_INIT_VIDEO);
    1.50 +}
    1.51 +
    1.52  /**
    1.53 - * @brief Document test case here
    1.54 + * \brief Check call to SDL_HasClipboardText
    1.55 + *
    1.56 + * \sa 
    1.57 + * http://wiki.libsdl.org/moin.cgi/SDL_HasClipboardText
    1.58 + */
    1.59 +int
    1.60 +clipboard_testHasClipboardText(void *arg)
    1.61 +{
    1.62 +	SDL_bool result;
    1.63 +	result = SDL_HasClipboardText();
    1.64 +	AssertPass("Call to SDL_HasClipboardText succeeded");
    1.65 +}
    1.66 +
    1.67 +/**
    1.68 + * \brief Check call to SDL_GetClipboardText
    1.69 + *
    1.70 + * \sa 
    1.71 + * http://wiki.libsdl.org/moin.cgi/SDL_GetClipboardText
    1.72 + */
    1.73 +int
    1.74 +clipboard_testGetClipboardText(void *arg)
    1.75 +{
    1.76 +	char *result;
    1.77 +	result = SDL_GetClipboardText();
    1.78 +	AssertPass("Call to SDL_GetClipboardText succeeded");
    1.79 +}
    1.80 +
    1.81 +/**
    1.82 + * \brief Check call to SDL_SetClipboardText
    1.83 + * \sa 
    1.84 + * http://wiki.libsdl.org/moin.cgi/SDL_SetClipboardText
    1.85   */
    1.86  int
    1.87 -clipboard_test(void *arg)
    1.88 +clipboard_testSetClipboardText(void *arg)
    1.89 +{
    1.90 +	char *textRef = RandomAsciiString();
    1.91 +	char *text = strdup(textRef);
    1.92 +	int result;
    1.93 +	result = SDL_SetClipboardText((const char *)text);	
    1.94 +	AssertTrue(
    1.95 +		result == 0, 
    1.96 +		"Call to SDL_SetClipboardText failed with error %i: %s",
    1.97 +		result, SDL_GetError());
    1.98 +	AssertTrue(
    1.99 +		strcmp(textRef, text) == 0, 
   1.100 +		"SDL_SetClipboardText modified input string: expected %s, got %s",
   1.101 +		textRef, text);
   1.102 +		
   1.103 +        /* Cleanup */
   1.104 +        if (textRef) free(textRef);
   1.105 +        if (text) free(text);
   1.106 +}
   1.107 +
   1.108 +
   1.109 +/**
   1.110 + * \brief End-to-end test of SDL_xyzClipboardText functions
   1.111 + * \sa 
   1.112 + * http://wiki.libsdl.org/moin.cgi/SDL_HasClipboardText
   1.113 + * http://wiki.libsdl.org/moin.cgi/SDL_GetClipboardText
   1.114 + * http://wiki.libsdl.org/moin.cgi/SDL_SetClipboardText
   1.115 + */
   1.116 +int
   1.117 +clipboard_testClipboardTextFunctions(void *arg)
   1.118  {
   1.119 -	AssertPass("");
   1.120 +	char *textRef = RandomAsciiString();
   1.121 +	char *text = strdup(textRef);
   1.122 +	SDL_bool boolResult;
   1.123 +	int intResult;
   1.124 +	char *charResult;
   1.125 +	
   1.126 +	/* Clear clipboard text state */
   1.127 +	boolResult = SDL_HasClipboardText();
   1.128 +	if (boolResult == SDL_TRUE) {
   1.129 +             intResult = SDL_SetClipboardText((const char *)NULL);
   1.130 +	     AssertTrue(
   1.131 +		intResult == 0, 
   1.132 +		"Call to SDL_SetClipboardText("") failed with error %i: %s",
   1.133 +		intResult, SDL_GetError());
   1.134 +	     charResult = SDL_GetClipboardText();
   1.135 +	     boolResult = SDL_HasClipboardText();
   1.136 +	     AssertTrue(
   1.137 +                boolResult == SDL_FALSE,
   1.138 +	        "SDL_HasClipboardText returned TRUE, expected FALSE");        
   1.139 +        }
   1.140 +        
   1.141 +        /* Empty clipboard  */        
   1.142 +	charResult = SDL_GetClipboardText();
   1.143 +	AssertTrue(
   1.144 +		charResult != NULL,
   1.145 +		"SDL_GetClipboardText returned NULL");		
   1.146 +	AssertTrue(
   1.147 +		strlen(charResult) == 0,
   1.148 +		"SDL_GetClipboardText returned string with length >0: got length %i",
   1.149 +		strlen(charResult));
   1.150 +        intResult = SDL_SetClipboardText((const char *)text);	
   1.151 +	AssertTrue(
   1.152 +		intResult == 0, 
   1.153 +		"Call to SDL_SetClipboardText failed with error %i: %s",
   1.154 +		intResult, SDL_GetError());
   1.155 +	AssertTrue(
   1.156 +		strcmp(textRef, text) == 0, 
   1.157 +		"SDL_SetClipboardText modified input string: expected %s, got %s",
   1.158 +		textRef, text);
   1.159 +	boolResult = SDL_HasClipboardText();
   1.160 +	AssertTrue(
   1.161 +             boolResult == SDL_TRUE,
   1.162 +	     "SDL_HasClipboardText returned FALSE, expected TRUE");        
   1.163 +	charResult = SDL_GetClipboardText();
   1.164 +	AssertTrue(
   1.165 +		strcmp(textRef, charResult) == 0, 
   1.166 +		"SDL_GetClipboardText did not return correst string: expected %s, got %s",
   1.167 +		textRef, charResult);
   1.168 +
   1.169 +        /* Cleanup */
   1.170 +        if (textRef) free(textRef);
   1.171 +        if (text) free(text);
   1.172 +        if (charResult) free(charResult);
   1.173  }