Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
182 lines (157 loc) · 5.84 KB

testautomation_clipboard.c

File metadata and controls

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