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