xref: /haiku/src/tests/kits/app/bmessage/MessageDestructTest.cpp (revision 221abfb27f0322f7d248ef1c5d00140690fb20f6)
1 //------------------------------------------------------------------------------
2 //	MessageDestructTest.cpp
3 //
4 //------------------------------------------------------------------------------
5 
6 // Standard Includes -----------------------------------------------------------
7 
8 // System Includes -------------------------------------------------------------
9 #include <Looper.h>
10 #include <Message.h>
11 #include <Messenger.h>
12 
13 // Project Includes ------------------------------------------------------------
14 
15 // Local Includes --------------------------------------------------------------
16 #include "MessageDestructTest.h"
17 
18 // Local Defines ---------------------------------------------------------------
19 
20 // Globals ---------------------------------------------------------------------
21 
22 //------------------------------------------------------------------------------
23 /**
24 	~BMessage
25 	@case			no reply to sent message
26 	@results		B_NO_REPLY reply is received
27  */
28 class Looper1 : public BLooper
29 {
30 	public:
Looper1(const char * name)31 		Looper1(const char* name) : BLooper(name) {;}
32 
MessageReceived(BMessage * msg)33 		void MessageReceived(BMessage* msg)
34 		{
35 			switch (msg->what)
36 			{
37 				case '1234':
38 					break;
39 				case '2345':
40 					msg->SendReply('3456');
41 					break;
42 				default:
43 					BLooper::MessageReceived(msg);
44 			}
45 		}
46 };
47 
MessageDestructTest1()48 void TMessageDestructTest::MessageDestructTest1()
49 {
50 	BLooper* looper1 = new Looper1("looper1");
51 
52 	looper1->Run();
53 
54 	BMessenger msgr(NULL, looper1);
55 	BMessage reply;
56 	CPPUNIT_ASSERT(msgr.SendMessage('1234', &reply) == B_OK);
57 	CPPUNIT_ASSERT(reply.what == B_NO_REPLY);
58 
59 	looper1->Lock();
60 	looper1->Quit();
61 }
62 //------------------------------------------------------------------------------
63 /**
64 	~BMessage
65 	@case			Reply is sent to message
66 	@result			No B_NO_REPLY reply is sent
67  */
MessageDestructTest2()68 void TMessageDestructTest::MessageDestructTest2()
69 {
70 	BLooper* looper1 = new Looper1("looper1");
71 	looper1->Run();
72 
73 	BMessenger msgr(NULL, looper1);
74 	BMessage reply;
75 	CPPUNIT_ASSERT(msgr.SendMessage('2345', &reply) == B_OK);
76 	CPPUNIT_ASSERT(reply.what == '3456');
77 
78 	looper1->Lock();
79 	looper1->Quit();
80 }
81 //------------------------------------------------------------------------------
Suite()82 TestSuite* TMessageDestructTest::Suite()
83 {
84 	TestSuite* suite = new TestSuite("BMessage::~BMessage()");
85 
86 	ADD_TEST4(BMessage, suite, TMessageDestructTest, MessageDestructTest1);
87 	ADD_TEST4(BMessage, suite, TMessageDestructTest, MessageDestructTest2);
88 
89 	return suite;
90 }
91 //------------------------------------------------------------------------------
92 
93 
94 /*
95  * $Log $
96  *
97  * $Id  $
98  *
99  */
100 
101