libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / tools / cppunit / TestUtils.cpp
blob524718e379160ea47fac2016b8a4514a24b26d02
1 // TestUtils.cpp
3 #include <TestUtils.h>
4 #include <TestShell.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <iostream>
10 using std::cout;
11 using std::dec;
12 using std::endl;
13 using std::hex;
14 using std::string;
16 _EXPORT
17 status_t DecodeResult(status_t result) {
18 if (!BTestShell::GlobalBeVerbose())
19 return result;
21 string str;
22 switch (result) {
24 case B_OK:
25 str = "B_OK";
26 break;
28 case B_ERROR:
29 str = "B_ERROR";
30 break;
33 // Storage Kit Errors
34 case B_FILE_ERROR:
35 str = "B_FILE_ERROR";
36 break;
38 case B_FILE_NOT_FOUND:
39 str = "B_FILE_NOT_FOUND";
40 break;
42 case B_FILE_EXISTS:
43 str = "B_FILE_EXISTS";
44 break;
46 case B_ENTRY_NOT_FOUND:
47 str = "B_ENTRY_NOT_FOUND";
48 break;
50 case B_NAME_TOO_LONG:
51 str = "B_NAME_TOO_LONG";
52 break;
54 case B_DIRECTORY_NOT_EMPTY:
55 str = "B_DIRECTORY_NOT_EMPTY";
56 break;
58 case B_DEVICE_FULL:
59 str = "B_DEVICE_FULL";
60 break;
62 case B_READ_ONLY_DEVICE:
63 str = "B_READ_ONLY_DEVICE";
64 break;
66 case B_IS_A_DIRECTORY:
67 str = "B_IS_A_DIRECTORY";
68 break;
70 case B_NO_MORE_FDS:
71 str = "B_NO_MORE_FDS";
72 break;
74 case B_CROSS_DEVICE_LINK:
75 str = "B_CROSS_DEVICE_LINK";
76 break;
78 case B_LINK_LIMIT:
79 str = "B_LINK_LIMIT";
80 break;
82 case B_BUSTED_PIPE:
83 str = "B_BUSTED_PIPE";
84 break;
86 case B_UNSUPPORTED:
87 str = "B_UNSUPPORTED";
88 break;
90 case B_PARTITION_TOO_SMALL:
91 str = "B_PARTITION_TOO_SMALL";
92 break;
94 case B_PARTIAL_READ:
95 str = "B_PARTIAL_READ";
96 break;
98 case B_PARTIAL_WRITE:
99 str = "B_PARTIAL_WRITE";
100 break;
102 case B_BAD_MIME_SNIFFER_RULE:
103 str = "B_BAD_MIME_SNIFFER_RULE";
104 break;
106 // General Errors
107 case B_NO_MEMORY:
108 str = "B_NO_MEMORY";
109 break;
111 case B_IO_ERROR:
112 str = "B_IO_ERROR";
113 break;
115 case B_PERMISSION_DENIED:
116 str = "B_PERMISSION_DENIED";
117 break;
119 case B_BAD_INDEX:
120 str = "B_BAD_INDEX";
121 break;
123 case B_BAD_TYPE:
124 str = "B_BAD_TYPE";
125 break;
127 case B_BAD_VALUE:
128 str = "B_BAD_VALUE";
129 break;
131 case B_MISMATCHED_VALUES:
132 str = "B_MISMATCHED_VALUES";
133 break;
135 case B_NAME_NOT_FOUND:
136 str = "B_NAME_NOT_FOUND";
137 break;
139 case B_NAME_IN_USE:
140 str = "B_NAME_IN_USE";
141 break;
143 case B_TIMED_OUT:
144 str = "B_TIMED_OUT";
145 break;
147 case B_INTERRUPTED:
148 str = "B_INTERRUPTED";
149 break;
151 case B_WOULD_BLOCK:
152 str = "B_WOULD_BLOCK";
153 break;
155 case B_CANCELED:
156 str = "B_CANCELED";
157 break;
159 case B_NO_INIT:
160 str = "B_NO_INIT";
161 break;
163 case B_BUSY:
164 str = "B_BUSY";
165 break;
167 case B_NOT_ALLOWED:
168 str = "B_NOT_ALLOWED";
169 break;
172 // Kernel Errors
173 case B_BAD_ADDRESS:
174 str = "B_BAD_ADDRESS";
175 break;
177 case B_BAD_TEAM_ID:
178 str = "B_BAD_TEAM_ID";
179 break;
181 // OS Errors
182 case B_BAD_PORT_ID:
183 str = "B_BAD_PORT_ID";
184 break;
186 // Anything Else
187 default:
188 str = "??????????";
189 break;
193 cout << endl << "DecodeResult() -- " "0x" << hex << result << " (" << dec << result << ") == " << str << endl;
195 return result;
198 _EXPORT
199 string IntToStr(int i) {
200 char num[32];
201 sprintf(num, "%d", i);
202 return string(num);
205 _EXPORT
206 void ExecCommand(const char *command) {
207 if (command)
208 system(command);
211 _EXPORT
212 void ExecCommand(const char *command, const char *parameter) {
213 if (command && parameter) {
214 char *cmdLine = new char[strlen(command) + strlen(parameter) + 1];
215 strcpy(cmdLine, command);
216 strcat(cmdLine, parameter);
217 system(cmdLine);
218 delete[] cmdLine;
222 _EXPORT
223 void ExecCommand(const char *command, const char *parameter1,
224 const char *parameter2) {
225 if (command && parameter1 && parameter2) {
226 char *cmdLine = new char[strlen(command) + strlen(parameter1)
227 + 1 + strlen(parameter2) + 1];
228 strcpy(cmdLine, command);
229 strcat(cmdLine, parameter1);
230 strcat(cmdLine, " ");
231 strcat(cmdLine, parameter2);
232 system(cmdLine);
233 delete[] cmdLine;