1//------------------------------------------------------------------------------
2//	HandlerAtTest.cpp
3//
4//------------------------------------------------------------------------------
5
6// Standard Includes -----------------------------------------------------------
7
8// System Includes -------------------------------------------------------------
9#include <Handler.h>
10#include <Looper.h>
11
12// Project Includes ------------------------------------------------------------
13
14// Local Includes --------------------------------------------------------------
15#include "HandlerAtTest.h"
16
17// Local Defines ---------------------------------------------------------------
18
19// Globals ---------------------------------------------------------------------
20
21//------------------------------------------------------------------------------
22/**
23	HandlerAt(int32 index)
24	@case		No handlers added, check for looper itself
25	@param		index	0
26	@results	HandlerAt() returns pointer to Looper.
27 */
28void THandlerAtTest::HandlerAtTest1()
29{
30	BLooper Looper;
31	CPPUNIT_ASSERT(Looper.HandlerAt(0) == &Looper);
32}
33//------------------------------------------------------------------------------
34/**
35	HandlerAt(int32 index)
36	@case		Index out of range (CountHandlers() + 1)
37	@param		index	1 & -1
38	@results	HandlerAt() returns NULL
39 */
40void THandlerAtTest::HandlerAtTest2()
41{
42	BLooper Looper;
43	CPPUNIT_ASSERT(Looper.HandlerAt(1) == NULL);
44	CPPUNIT_ASSERT(Looper.HandlerAt(-1) == NULL);
45}
46//------------------------------------------------------------------------------
47/**
48	HandlerAt(int32 index)
49	@case		Several handlers added, checked against expected indices
50	@param		index	Various
51	@results
52 */
53#define CREATE_AND_ADD(XHANDLER)	\
54	BHandler XHANDLER;				\
55	Looper.AddHandler(&XHANDLER);
56void THandlerAtTest::HandlerAtTest3()
57{
58	BLooper Looper;
59	CREATE_AND_ADD(Handler1);
60	CREATE_AND_ADD(Handler2);
61	CREATE_AND_ADD(Handler3);
62
63	CPPUNIT_ASSERT(Looper.HandlerAt(0) == &Looper);
64	CPPUNIT_ASSERT(Looper.HandlerAt(1) == &Handler1);
65	CPPUNIT_ASSERT(Looper.HandlerAt(2) == &Handler2);
66	CPPUNIT_ASSERT(Looper.HandlerAt(3) == &Handler3);
67}
68//------------------------------------------------------------------------------
69/**
70	HandlerAt(int32 index)
71	@case		Looper is not locked
72	@param		index	0
73	@results
74 */
75void THandlerAtTest::HandlerAtTest4()
76{
77	DEBUGGER_ESCAPE;
78
79	BLooper Looper;
80	Looper.Unlock();
81	CPPUNIT_ASSERT(Looper.HandlerAt(0) == &Looper);
82}
83//------------------------------------------------------------------------------
84TestSuite* THandlerAtTest::Suite()
85{
86	TestSuite* suite = new TestSuite("BLooper::HandlerAt(int32)");
87
88	ADD_TEST4(BLooper, suite, THandlerAtTest, HandlerAtTest1);
89	ADD_TEST4(BLooper, suite, THandlerAtTest, HandlerAtTest2);
90	ADD_TEST4(BLooper, suite, THandlerAtTest, HandlerAtTest3);
91	ADD_TEST4(BLooper, suite, THandlerAtTest, HandlerAtTest4);
92
93	return suite;
94}
95//------------------------------------------------------------------------------
96
97/*
98 * $Log $
99 *
100 * $Id  $
101 *
102 */
103
104
105