xref: /haiku/src/tools/cppunit/TestUtils.cpp (revision 5d9e40fe9252c8f9c5e5e41594545bfa4419fcc7)
1 // TestUtils.cpp
2 
3 #include <TestUtils.h>
4 #include <TestShell.h>
5 #include <stdio.h>
6 #include <iostream>
7 
8 _EXPORT
9 status_t DecodeResult(status_t result) {
10 	if (!BTestShell::GlobalBeVerbose())
11 		return result;
12 
13 	string str;
14 	switch (result) {
15 
16 		case B_OK:
17 			str = "B_OK";
18 			break;
19 
20 		case B_ERROR:
21 			str = "B_ERROR";
22 			break;
23 
24 
25 		// Storage Kit Errors
26 		case B_FILE_ERROR:
27 			str = "B_FILE_ERROR";
28 			break;
29 
30 		case B_FILE_NOT_FOUND:
31 			str = "B_FILE_NOT_FOUND";
32 			break;
33 
34 		case B_FILE_EXISTS:
35 			str = "B_FILE_EXISTS";
36 			break;
37 
38 		case B_ENTRY_NOT_FOUND:
39 			str = "B_ENTRY_NOT_FOUND";
40 			break;
41 
42 		case B_NAME_TOO_LONG:
43 			str = "B_NAME_TOO_LONG";
44 			break;
45 
46 		case B_DIRECTORY_NOT_EMPTY:
47 			str = "B_DIRECTORY_NOT_EMPTY";
48 			break;
49 
50 		case B_DEVICE_FULL:
51 			str = "B_DEVICE_FULL";
52 			break;
53 
54 		case B_READ_ONLY_DEVICE:
55 			str = "B_READ_ONLY_DEVICE";
56 			break;
57 
58 		case B_IS_A_DIRECTORY:
59 			str = "B_IS_A_DIRECTORY";
60 			break;
61 
62 		case B_NO_MORE_FDS:
63 			str = "B_NO_MORE_FDS";
64 			break;
65 
66 		case B_CROSS_DEVICE_LINK:
67 			str = "B_CROSS_DEVICE_LINK";
68 			break;
69 
70 		case B_LINK_LIMIT:
71 			str = "B_LINK_LIMIT";
72 			break;
73 
74 		case B_BUSTED_PIPE:
75 			str = "B_BUSTED_PIPE";
76 			break;
77 
78 		case B_UNSUPPORTED:
79 			str = "B_UNSUPPORTED";
80 			break;
81 
82 		case B_PARTITION_TOO_SMALL:
83 			str = "B_PARTITION_TOO_SMALL";
84 			break;
85 
86 		case B_BAD_MIME_SNIFFER_RULE:
87 			str = "B_BAD_MIME_SNIFFER_RULE";
88 			break;
89 
90 		// General Errors
91 		case B_NO_MEMORY:
92 			str = "B_NO_MEMORY";
93 			break;
94 
95 		case B_IO_ERROR:
96 			str = "B_IO_ERROR";
97 			break;
98 
99 		case B_PERMISSION_DENIED:
100 			str = "B_PERMISSION_DENIED";
101 			break;
102 
103 		case B_BAD_INDEX:
104 			str = "B_BAD_INDEX";
105 			break;
106 
107 		case B_BAD_TYPE:
108 			str = "B_BAD_TYPE";
109 			break;
110 
111 		case B_BAD_VALUE:
112 			str = "B_BAD_VALUE";
113 			break;
114 
115 		case B_MISMATCHED_VALUES:
116 			str = "B_MISMATCHED_VALUES";
117 			break;
118 
119 		case B_NAME_NOT_FOUND:
120 			str = "B_NAME_NOT_FOUND";
121 			break;
122 
123 		case B_NAME_IN_USE:
124 			str = "B_NAME_IN_USE";
125 			break;
126 
127 		case B_TIMED_OUT:
128 			str = "B_TIMED_OUT";
129 			break;
130 
131 		case B_INTERRUPTED:
132 			str = "B_INTERRUPTED";
133 			break;
134 
135 		case B_WOULD_BLOCK:
136 			str = "B_WOULD_BLOCK";
137 			break;
138 
139 		case B_CANCELED:
140 			str = "B_CANCELED";
141 			break;
142 
143 		case B_NO_INIT:
144 			str = "B_NO_INIT";
145 			break;
146 
147 		case B_BUSY:
148 			str = "B_BUSY";
149 			break;
150 
151 		case B_NOT_ALLOWED:
152 			str = "B_NOT_ALLOWED";
153 			break;
154 
155 
156 		// Kernel Errors
157 		case B_BAD_ADDRESS:
158 			str = "B_BAD_ADDRESS";
159 			break;
160 
161 		case B_BAD_TEAM_ID:
162 			str = "B_BAD_TEAM_ID";
163 			break;
164 
165 		// OS Errors
166 		case B_BAD_PORT_ID:
167 			str = "B_BAD_PORT_ID";
168 			break;
169 
170 		// Anything Else
171 		default:
172 			str = "??????????";
173 			break;
174 
175 	}
176 
177 	cout << endl << "DecodeResult() -- " "0x" << hex << result << " (" << dec << result << ") == " << str << endl;
178 
179 	return result;
180 }
181 
182 _EXPORT
183 string IntToStr(int i) {
184 	char num[32];
185 	sprintf(num, "%d", i);
186 	return string(num);
187 }
188 
189 _EXPORT
190 void ExecCommand(const char *command) {
191 	if (command)
192 		system(command);
193 }
194 
195 _EXPORT
196 void ExecCommand(const char *command, const char *parameter) {
197 	if (command && parameter) {
198 		char *cmdLine = new char[strlen(command) + strlen(parameter) + 1];
199 		strcpy(cmdLine, command);
200 		strcat(cmdLine, parameter);
201 		system(cmdLine);
202 		delete[] cmdLine;
203 	}
204 }
205 
206 _EXPORT
207 void ExecCommand(const char *command, const char *parameter1,
208 							const char *parameter2) {
209 	if (command && parameter1 && parameter2) {
210 		char *cmdLine = new char[strlen(command) + strlen(parameter1)
211 								 + 1 + strlen(parameter2) + 1];
212 		strcpy(cmdLine, command);
213 		strcat(cmdLine, parameter1);
214 		strcat(cmdLine, " ");
215 		strcat(cmdLine, parameter2);
216 		system(cmdLine);
217 		delete[] cmdLine;
218 	}
219 }
220