1 //------------------------------------------------------------------------------
2 // AppQuitRequestedTester.cpp
3 //
4 //------------------------------------------------------------------------------
5
6 // Standard Includes -----------------------------------------------------------
7 #include <stdio.h>
8
9 // System Includes -------------------------------------------------------------
10 #include <Message.h>
11 #include <OS.h>
12 #include <Application.h>
13 #include <Handler.h>
14 #include <Looper.h>
15 #include <String.h>
16
17 // Project Includes ------------------------------------------------------------
18 #include <TestShell.h>
19 #include <TestUtils.h>
20 #include <cppunit/TestAssert.h>
21
22 // Local Includes --------------------------------------------------------------
23 #include "AppRunner.h"
24 #include "AppQuitRequestedTester.h"
25
26 // Local Defines ---------------------------------------------------------------
27
28 // Globals ---------------------------------------------------------------------
29
30 //------------------------------------------------------------------------------
31
32 // check_output
33 static
34 void
check_output(AppRunner & runner,const char * expectedOutput)35 check_output(AppRunner &runner, const char *expectedOutput)
36 {
37 BString buffer;
38 CHK(runner.GetOutput(&buffer) == B_OK);
39 if (buffer != expectedOutput)
40 printf("result is `%s', but should be `%s'\n", buffer.String(),
41 expectedOutput);
42 CHK(buffer == expectedOutput);
43 }
44
45 /*
46 bool QuitRequested()
47 @case 1 return false the first time, true the second time it is
48 invoked
49 @results Should not quit after the first time, but after the
50 second one.
51 */
QuitRequestedTest1()52 void AppQuitRequestedTester::QuitRequestedTest1()
53 {
54 BApplication app("application/x-vnd.obos-app-quit-requested-test");
55 const char *output =
56 "error: 0\n"
57 "InitCheck(): 0\n"
58 "BApplication::ReadyToRun()\n"
59 "BApplication::QuitRequested()\n"
60 "BApplication::QuitRequested()\n"
61 "BApplication::Run() done: 1\n"
62 "BApplication::~BApplication()\n";
63 // run the app
64 AppRunner runner;
65 CHK(runner.Run("AppQuitRequestedTestApp1") == B_OK);
66 runner.WaitFor(false);
67 // get the output and compare the result
68 check_output(runner, output);
69 }
70
71
Suite()72 Test* AppQuitRequestedTester::Suite()
73 {
74 TestSuite* SuiteOfTests = new TestSuite;
75
76 ADD_TEST4(BApplication, SuiteOfTests, AppQuitRequestedTester,
77 QuitRequestedTest1);
78
79 return SuiteOfTests;
80 }
81
82
83
84