Add file under gui/pythonmod to .gitignore
[gnash.git] / testsuite / libmedia.all / test_videoinput.cpp
blob2f9fdbeb2966f21ff8376b83c7ce46fa645e1323
1 //
2 // Copyright (C) 2009, 2010 Free Software Foundation, Inc.
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 #ifdef HAVE_CONFIG_H
19 #include "gnashconfig.h"
20 #endif
22 #ifdef HAVE_DEJAGNU_H
24 #include <string>
25 #include <cstdio>
26 #include <unistd.h>
27 #include <sys/stat.h>
29 #include "dejagnu.h"
30 #include "log.h"
32 #include "gst/VideoInputGst.h"
33 #include <vector>
36 using namespace gnash;
37 using namespace media;
38 using namespace gst;
39 using namespace std;
41 static TestState runtest;
43 static string infile;
45 void test_client();
47 LogFile& dbglogfile = LogFile::getDefaultInstance();
49 int
50 main()
52 test_client();
53 return 0;
56 void test_client()
59 std::vector<std::string> names;
60 VideoInputGst::getNames(names);
62 if (names.empty()) {
63 runtest.fail("the video vector was not created by find_vid_devs");
64 } else {
65 runtest.pass("the video vector was created");
69 if (names.at(0) != "videotest") {
70 runtest.fail("the zeroth element doesn't contain the right product name info");
71 } else {
72 runtest.pass("the zeroth vid_vect element contains the right product name info");
75 VideoInputGst vig;
77 int devselect = vig.makeWebcamDeviceSelection();
79 bool ret = vig.setWebcam(devselect);
80 if (!ret) {
81 runtest.fail("the transferToPrivate function didn't return anything");
82 } else {
83 runtest.pass("the transferToPrivate function returned a GnashWebcamPrivate ptr");
85 if (devselect == 0) {
86 if (vig.name() != "videotest") {
87 runtest.fail("webcam doesn't have the right _deviceName value");
88 } else {
89 runtest.pass("webcam has the right _deviceName value");
91 } else {
92 //real camera source tests
93 if (vig.name().empty()) {
94 runtest.fail("_deviceName isn't set in GnashWebcamPrivate class");
95 } else {
96 runtest.pass("_deviceName is set in GnashWebcamPrivate class");
100 bool result = vig.init();
101 if (result != true) {
102 runtest.fail("Webcam inititalization");
103 } else {
104 runtest.pass("Webcam initialization was okay");
107 result = false;
108 result = vig.webcamCreateSaveBin();
109 if (result != true) {
110 runtest.fail("webcamCreateSaveBin() reported an error");
111 } else {
112 runtest.pass("webcamCreateSaveBin() didn't report any errors");
114 result = false;
115 result = vig.webcamMakeVideoSaveLink();
116 if (result != true) {
117 runtest.fail("webcamMakeVideoSaveLink() reported an error");
118 } else {
119 runtest.pass("webcamMakeVideoSaveLink() didn't report errors");
122 //end of setup tests, now startup the webcamPipeline, run for a few seconds
123 //and then make sure there is a file present after running
124 result = vig.play();
125 if (result != true) {
126 runtest.fail("play() function reported an error");
127 } else {
128 runtest.pass("play() function reported no errors");
131 g_print(" NOTE: the output window will close automatically\n");
133 sleep(2);
134 result = vig.stop();
135 if (result != true) {
136 runtest.fail("webcamStop() function reported an error");
137 } else {
138 runtest.pass("webcamStop() function reported no errors");
141 struct stat st;
142 std::string file = "./vidoutput.ogg";
144 if (stat(file.c_str(), &st) == 0) {
145 runtest.pass("vidoutput.ogg file is in testsuite/libmedia.all");
146 if (st.st_blocks == 0) {
147 runtest.fail("the output file is there, but there's no information in it!");
148 } else {
149 runtest.pass("the output file has data in it");
151 } else {
152 runtest.fail("there's no output video file in testsuite/libmedia.all");
155 //delete the old vidoutput.ogg file
156 if (unlink(file.c_str()) == 0) {
157 g_print(" NOTE: deleting output file...\n");
160 result = vig.webcamBreakVideoDisplayLink();
161 if (result != true) {
162 runtest.fail("the webcamBreakVideoDisplayLink() function reported an error");
163 } else {
164 runtest.pass("the webcamBreakVideoDisplayLink() function reported no errors");
167 result = vig.play();
168 if (result != true) {
169 runtest.fail("play() reported errors after breaking display link");
170 } else {
171 runtest.pass("play() still works after breaking display link");
173 g_print(" NOTE: sleeping for 5 seconds here....\n");
174 sleep(2);
176 result = vig.stop();
177 if (result != true) {
178 runtest.fail("webcamStop() reported errors after breaking display link");
179 } else {
180 runtest.pass("webcamStop() reported success after breaking display link");
183 if (stat(file.c_str(), &st) == 0) {
184 runtest.pass("the a new vidoput.ogg file was created");
185 } else {
186 runtest.fail("there's no new vidoutput.ogg file!");
189 //delete the old vidoutput.ogg file
190 if (unlink(file.c_str()) == 0) {
191 g_print(" NOTE: deleting output file...\n");
194 result = vig.webcamBreakVideoSaveLink();
195 if (result != true) {
196 runtest.fail("breaking the videoSaveLink failed");
197 } else {
198 runtest.pass("breaking the videoSaveLink was successful");
201 result = vig.webcamMakeVideoDisplayLink();
202 if (result != true) {
203 runtest.fail("making videosrc -> display link failed");
204 } else {
205 runtest.pass("making videosrc -> display link succeeded");
208 result = vig.play();
209 if (result != true) {
210 runtest.fail("play() reported errors after relinking display");
211 } else {
212 runtest.pass("play() still works after relinking display");
214 g_print(" NOTE: sleeping for 5 seconds here....\n");
215 sleep(2);
217 result = vig.stop();
218 if (result != true) {
219 runtest.fail("webcamStop() reported errors after breaking display link");
220 } else {
221 runtest.pass("webcamStop() reported success after breaking display link");
224 if (stat(file.c_str(), &st) == 0) {
225 runtest.fail("a vidoutput.ogg file was created, and it shouldn't be");
226 } else {
227 runtest.pass("no vidoutput.ogg file wasn't created");
230 result = vig.webcamMakeVideoSaveLink();
231 if (result != true) {
232 runtest.fail("webcamMakeVideoSaveLink() reported an error");
233 } else {
234 runtest.pass("webcamMakeVideoSaveLink() reported no errors");
237 result = vig.play();
238 if (result != true) {
239 runtest.fail("play() reported errors");
240 } else {
241 runtest.pass("play() reported no errors");
244 g_print(" NOTE: sleeping for 5 seconds here....\n");
245 sleep(2);
247 result = vig.stop();
248 if (result != true) {
249 runtest.fail("webcamStop() reported errors after breaking display link");
250 } else {
251 runtest.pass("webcamStop() reported success after breaking display link");
254 if (stat(file.c_str(), &st) == 0) {
255 runtest.pass("the a new vidoput.ogg file was created");
256 } else {
257 runtest.fail("there's no new vidoutput.ogg file!");
259 //delete the old vidoutput.ogg file
260 if (unlink(file.c_str()) == 0) {
261 g_print(" NOTE: deleting output file...\n");
264 //end unit tests
266 //tests more similar to execution flow
267 gst::VideoInputGst* video = new VideoInputGst;
268 if (video == NULL) {
269 runtest.fail("new VideoInputGst didn't work");
270 } else {
271 runtest.pass("new VideoInputGst returned a value");
274 //get global webcam reference for use below
275 result = video->webcamMakeVideoDisplayLink();
276 if (result != true) {
277 runtest.fail("webcamMakeVideoDisplayLink reported errors");
278 } else {
279 runtest.pass("webcamMakeVideoDisplayLink reported no errors");
282 result = video->play();
283 if (result != true) {
284 runtest.fail("play reported errors");
285 } else {
286 runtest.pass("play reported no errors");
289 g_print(" NOTE: sleeping for 5 seconds here....\n");
290 sleep(2);
292 result = video->stop();
293 if (result != true) {
294 runtest.fail("webcamStop reported errors");
295 } else {
296 runtest.pass("webcamStop reported no errors");
299 g_print(" NOTE: changing values (display window should be bigger)....\n");
301 video->requestMode(800, 600, 30, true);
303 result = video->play();
304 if (result != true) {
305 runtest.fail("play reported errors");
306 } else {
307 runtest.pass("play reported no errors");
310 g_print(" NOTE: sleeping for 5 seconds here....\n");
311 sleep(2);
313 result = video->stop();
314 if (result != true) {
315 runtest.fail("webcamStop reported errors");
316 } else {
317 runtest.pass("webcamStop reported no errors");
320 result = video->webcamMakeVideoSaveLink();
321 if (result != true) {
322 runtest.fail("webcamMakeVideoSaveLink reported errors");
323 } else {
324 runtest.pass("webcamMakeVideoSaveLink reported no errors");
327 result = video->play();
328 if (result != true) {
329 runtest.fail("play reported errors");
330 } else {
331 runtest.pass("play reported no errors");
334 g_print(" NOTE: sleeping for 5 seconds here....\n");
335 sleep(2);
337 result = video->stop();
338 if (result != true) {
339 runtest.fail("webcamStop reported errors");
340 } else {
341 runtest.pass("webcamStop reported no errors");
343 if (stat(file.c_str(), &st) == 0) {
344 runtest.pass("the a new vidoput.ogg file was created");
345 } else {
346 runtest.fail("there's no new vidoutput.ogg file!");
348 //delete the old vidoutput.ogg file
349 if (unlink(file.c_str()) == 0) {
350 g_print(" NOTE: deleting output file...\n");
353 result = video->webcamBreakVideoDisplayLink();
354 if (result != true) {
355 runtest.fail("webcamBreakVideoDisplayLink reported errors");
356 } else {
357 runtest.pass("webcamBreakVideoDisplayLink reported no errors");
360 result = video->play();
361 if (result != true) {
362 runtest.fail("play reported errors");
363 } else {
364 runtest.pass("play reported no errors");
367 g_print(" NOTE: sleeping for 5 seconds here....\n");
368 sleep(2);
370 result = video->stop();
371 if (result != true) {
372 runtest.fail("webcamStop reported errors");
373 } else {
374 runtest.pass("webcamStop reported no errors");
376 if (stat(file.c_str(), &st) == 0) {
377 runtest.pass("the a new vidoput.ogg file was created");
378 } else {
379 runtest.fail("there's no new vidoutput.ogg file!");
382 //delete the old vidoutput.ogg file
383 if (unlink(file.c_str()) == 0) {
384 g_print(" NOTE: deleting output file...\n");
387 result = video->webcamMakeVideoDisplayLink();
388 if (result != true) {
389 runtest.fail("webcamMakeVideoDisplayLink failed after breaking the link");
390 } else {
391 runtest.pass("webcamMakeVideoDisplayLink reported no errors");
394 result = video->webcamBreakVideoSaveLink();
395 if (result != true) {
396 runtest.fail("webcamBreakVideoSaveLink function reported errors");
397 } else {
398 runtest.pass("webcamBreakVideoSaveLink function reported no errors");
401 result = video->play();
402 if (result != true) {
403 runtest.fail("play reported errors");
404 } else {
405 runtest.pass("play reported no errors");
408 g_print(" NOTE: sleeping for 5 seconds here....\n");
409 sleep(2);
411 result = video->stop();
412 if (result != true) {
413 runtest.fail("webcamStop reported errors");
414 } else {
415 runtest.pass("webcamStop reported no errors");
418 if (stat(file.c_str(), &st) == 0) {
419 runtest.fail("a vidoutput.ogg file was created, and it shouldn't be");
420 } else {
421 runtest.pass("no vidoutput.ogg file wasn't created");
427 #else
430 main(int /*argc*/, char /* *argv[]*/)
432 // nop
433 cerr << "This program needs to have DejaGnu installed!" << endl;
434 return 0;
437 #endif