xref: /haiku/src/tests/kits/app/bapplication/testapps/AppQuitTestApp2.cpp (revision ff952bade491ce49d08aa44886dfd20133fbb6d0)
1*ff952badSIngo Weinhold // AppQuitTestApp2.cpp
2*ff952badSIngo Weinhold 
3*ff952badSIngo Weinhold #include <stdio.h>
4*ff952badSIngo Weinhold 
5*ff952badSIngo Weinhold #include <OS.h>
6*ff952badSIngo Weinhold 
7*ff952badSIngo Weinhold #include "CommonTestApp.h"
8*ff952badSIngo Weinhold 
9*ff952badSIngo Weinhold enum {
10*ff952badSIngo Weinhold 	MSG_QUIT	= 'quit',
11*ff952badSIngo Weinhold };
12*ff952badSIngo Weinhold 
13*ff952badSIngo Weinhold class Quitter : public BHandler {
14*ff952badSIngo Weinhold public:
MessageReceived(BMessage * message)15*ff952badSIngo Weinhold 	virtual void MessageReceived(BMessage *message)
16*ff952badSIngo Weinhold 	{
17*ff952badSIngo Weinhold 		if (message->what == MSG_QUIT)
18*ff952badSIngo Weinhold 			be_app->Quit();
19*ff952badSIngo Weinhold 	}
20*ff952badSIngo Weinhold };
21*ff952badSIngo Weinhold 
22*ff952badSIngo Weinhold int
main()23*ff952badSIngo Weinhold main()
24*ff952badSIngo Weinhold {
25*ff952badSIngo Weinhold // R5: doesn't set the error variable in case of success
26*ff952badSIngo Weinhold #ifdef TEST_R5
27*ff952badSIngo Weinhold 	status_t error = B_OK;
28*ff952badSIngo Weinhold #else
29*ff952badSIngo Weinhold 	status_t error = B_ERROR;
30*ff952badSIngo Weinhold #endif
31*ff952badSIngo Weinhold 	CommonTestApp *app = new CommonTestApp(
32*ff952badSIngo Weinhold 		"application/x-vnd.obos-app-quit-testapp1", &error);
33*ff952badSIngo Weinhold 	init_connection();
34*ff952badSIngo Weinhold 	report("error: %lx\n", error);
35*ff952badSIngo Weinhold 	report("InitCheck(): %lx\n", app->InitCheck());
36*ff952badSIngo Weinhold 	app->SetReportDestruction(true);
37*ff952badSIngo Weinhold 	if (error == B_OK) {
38*ff952badSIngo Weinhold 		app->SetMessageHandler(new Quitter);
39*ff952badSIngo Weinhold 		app->PostMessage(MSG_QUIT, app);
40*ff952badSIngo Weinhold 		app->Run();
41*ff952badSIngo Weinhold 	}
42*ff952badSIngo Weinhold 	delete app;
43*ff952badSIngo Weinhold 	return 0;
44*ff952badSIngo Weinhold }
45*ff952badSIngo Weinhold 
46