xref: /haiku/src/tests/kits/app/bhandler/IsWatchedTest.cpp (revision b8a45b3a2df2379b4301bf3bd5949b9a105be4ba)
1 //------------------------------------------------------------------------------
2 //	IsWatchedTest.cpp
3 //
4 //------------------------------------------------------------------------------
5 
6 // Standard Includes -----------------------------------------------------------
7 
8 // System Includes -------------------------------------------------------------
9 
10 // Project Includes ------------------------------------------------------------
11 
12 // Local Includes --------------------------------------------------------------
13 #include "IsWatchedTest.h"
14 
15 // Local Defines ---------------------------------------------------------------
16 
17 // Globals ---------------------------------------------------------------------
18 
19 //------------------------------------------------------------------------------
20 /**
21 	IsWatched()
22 	@case		No added watchers
23 	@results	Returns false
24  */
25 void TIsWatchedTest::IsWatched1()
26 {
27 	CPPUNIT_ASSERT(!fHandler.IsWatched());
28 }
29 //------------------------------------------------------------------------------
30 /**
31 	IsWatched()
32 	@case		Add then remove watcher
33 	@results	Returns true after add, returns false after remove
34 	@note		Original implementation fails this test.  Either the removal
35 				doesn't happen (unlikely) or some list-within-a-list doesn't
36 				get removed when there's nothing in it anymore.
37  */
38 void TIsWatchedTest::IsWatched2()
39 {
40 	BHandler Watcher;
41 	fHandler.StartWatching(&Watcher, '1234');
42 	CPPUNIT_ASSERT(fHandler.IsWatched() == true);
43 
44 	fHandler.StopWatching(&Watcher, '1234');
45 #ifndef TEST_R5
46 	CPPUNIT_ASSERT(fHandler.IsWatched() == false);
47 #endif
48 }
49 //------------------------------------------------------------------------------
50 /**
51 	IsWatched()
52 	@case		Add watcher, send notice, then remove watcher
53 	@results	Returns true after add, returns false after remove
54  */
55 void TIsWatchedTest::IsWatched3()
56 {
57 	BHandler Watcher;
58 	fHandler.StartWatching(&Watcher, '1234');
59 	CPPUNIT_ASSERT(fHandler.IsWatched() == true);
60 
61 	fHandler.SendNotices('1234');
62 
63 	fHandler.StopWatching(&Watcher, '1234');
64 	CPPUNIT_ASSERT(fHandler.IsWatched() == false);
65 }
66 //------------------------------------------------------------------------------
67 /**
68 	IsWatched()
69 	@case		Remove inexistent watcher
70 	@results	Returns false
71  */
72 void TIsWatchedTest::IsWatched4()
73 {
74 	BHandler Watcher;
75 
76 	fHandler.StopWatching(&Watcher, '1234');
77 	CPPUNIT_ASSERT(fHandler.IsWatched() == false);
78 }
79 //------------------------------------------------------------------------------
80 /**
81 	IsWatched()
82 	@case		Send notices without watchers
83 	@results	Returns false
84  */
85 void TIsWatchedTest::IsWatched5()
86 {
87 	BHandler Watcher;
88 
89 	// Create handler's internal list
90 	fHandler.StartWatching(&Watcher, '1234');
91 	fHandler.StopWatching(&Watcher, '1234');
92 
93 	fHandler.SendNotices('1234');
94 	CPPUNIT_ASSERT(fHandler.IsWatched() == false);
95 }
96 //------------------------------------------------------------------------------
97 Test* TIsWatchedTest::Suite()
98 {
99 	TestSuite* SuiteOfTests = new TestSuite("BHandler::IsWatched");
100 
101 	ADD_TEST4(BHandler, SuiteOfTests, TIsWatchedTest, IsWatched1);
102 	ADD_TEST4(BHandler, SuiteOfTests, TIsWatchedTest, IsWatched2);
103 	ADD_TEST4(BHandler, SuiteOfTests, TIsWatchedTest, IsWatched3);
104 	ADD_TEST4(BHandler, SuiteOfTests, TIsWatchedTest, IsWatched4);
105 	ADD_TEST4(BHandler, SuiteOfTests, TIsWatchedTest, IsWatched5);
106 
107 	return SuiteOfTests;
108 }
109 //------------------------------------------------------------------------------
110 
111 /*
112  * $Log $
113  *
114  * $Id  $
115  *
116  */
117 
118 
119