xref: /haiku/src/tests/kits/app/bmessage/MessageConstructTest.cpp (revision 1dc215ba9b242118ed56f4d557b28d768d8fe4dd)
1 //------------------------------------------------------------------------------
2 //	MessageConstructTest.cpp
3 //
4 //------------------------------------------------------------------------------
5 
6 // Standard Includes -----------------------------------------------------------
7 #include <stdio.h>
8 
9 // System Includes -------------------------------------------------------------
10 #include <Message.h>
11 // Project Includes ------------------------------------------------------------
12 
13 // Local Includes --------------------------------------------------------------
14 #include "../common.h"
15 #include "MessageConstructTest.h"
16 
17 // Local Defines ---------------------------------------------------------------
18 
19 // Globals ---------------------------------------------------------------------
20 
21 //------------------------------------------------------------------------------
22 /**
23 	BMessage()
24 	@case		Default construction
25 	@params		none
26 	@results	BMessage::what == 0
27  */
MessageConstructTest1()28 void TMessageConstructTest::MessageConstructTest1()
29 {
30 	BMessage msg;
31 	CPPUNIT_ASSERT(msg.what == 0);
32 	ConfirmNullConstruction(msg);
33 }
34 //------------------------------------------------------------------------------
35 /**
36 	BMessage(uint32 what)
37 	@case			what initialization constructor
38 	@params	what	a uint32 message ID code
39 	@results		BMessage::what == what param
40  */
MessageConstructTest2()41 void TMessageConstructTest::MessageConstructTest2()
42 {
43 	BMessage msg(1234);
44 	CPPUNIT_ASSERT(msg.what == 1234);
45 	ConfirmNullConstruction(msg);
46 }
47 //------------------------------------------------------------------------------
48 /**
49 	BMessage(const BMessage& msg)
50 	@case			copy of default constructed
51 	@params	msg		a default constructed BMessage instance
52 	@results		what == msg.what and ConfirmNullConstruction is good
53  */
MessageConstructTest3()54 void TMessageConstructTest::MessageConstructTest3()
55 {
56 	BMessage msg1(1234);
57 	CPPUNIT_ASSERT(msg1.what == 1234);
58 	ConfirmNullConstruction(msg1);
59 
60 	BMessage msg2(msg1);
61 	CPPUNIT_ASSERT(msg2.what == msg1.what);
62 	ConfirmNullConstruction(msg2);
63 }
64 //------------------------------------------------------------------------------
Suite()65 TestSuite* TMessageConstructTest::Suite()
66 {
67 	TestSuite* suite = new TestSuite("BMessage::BMessage()");
68 
69 	ADD_TEST4(BMessage, suite, TMessageConstructTest, MessageConstructTest1);
70 	ADD_TEST4(BMessage, suite, TMessageConstructTest, MessageConstructTest2);
71 
72 	return suite;
73 }
74 //------------------------------------------------------------------------------
ConfirmNullConstruction(BMessage & msg)75 void TMessageConstructTest::ConfirmNullConstruction(BMessage& msg)
76 {
77 	CPPUNIT_ASSERT(msg.CountNames(B_ANY_TYPE) == 0);
78 	CPPUNIT_ASSERT(msg.IsEmpty());
79 	CPPUNIT_ASSERT(!msg.IsSystem());
80 	CPPUNIT_ASSERT(!msg.IsReply());
81 	CPPUNIT_ASSERT(!msg.WasDelivered());
82 	CPPUNIT_ASSERT(!msg.IsSourceWaiting());
83 	CPPUNIT_ASSERT(!msg.IsSourceRemote());
84 }
85 //------------------------------------------------------------------------------
86 
87 /*
88  * $Log $
89  *
90  * $Id  $
91  *
92  */
93 
94