Source Code Cross Referenced for TestEventQueue.java in  » 6.0-JDK-Modules » j2me » com » sun » midp » events » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » com.sun.midp.events 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * 	
003:         *
004:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation.
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt).
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions.
025:         */
026:
027:        package com.sun.midp.events;
028:
029:        import com.sun.midp.i3test.*;
030:
031:        /**
032:         * Unit tests for the EventQueue class.
033:         */
034:        public class TestEventQueue extends TestCase {
035:
036:            /**
037:             * Test simple creation of an event queue.
038:             */
039:            void testCreate() {
040:                EventQueue eq = new EventQueue();
041:
042:                assertFalse(eq.alive);
043:                assertNotNull(eq.dispatchTable);
044:                assertTrue(eq.dispatchTable.length > 0);
045:                assertNotNull(eq.pool);
046:                assertEquals(-1, eq.nativeEventQueueHandle);
047:                assertNotNull(eq.eventQueueThread);
048:                assertNotNull(eq.eventMonitorThread);
049:                assertFalse(eq.eventQueueThread.isAlive());
050:                assertFalse(eq.eventMonitorThread.isAlive());
051:            }
052:
053:            /**
054:             * Tests the ability to register an event.
055:             */
056:            void testRegister() {
057:                final int EVENT_TYPE = 7;
058:                EventQueue eq = new EventQueue();
059:                InstrumentedEventListener iel = new InstrumentedEventListener();
060:                eq.registerEventListener(EVENT_TYPE, iel);
061:
062:                DispatchData dd = eq.dispatchTable[EVENT_TYPE - 1];
063:                assertNotNull(dd);
064:                assertEquals(iel, dd.listener);
065:            }
066:
067:            /**
068:             * Tests whether the dispatch table is grown properly.
069:             */
070:            void testGrowDispatchTable() {
071:                final int EVENT_TYPE_A = 4;
072:                final int EVENT_TYPE_B = 97;
073:                // must be larger than the dispatch table default size
074:
075:                EventQueue eq = new EventQueue();
076:
077:                assertTrue(EVENT_TYPE_B > eq.dispatchTable.length);
078:
079:                InstrumentedEventListener iela = new InstrumentedEventListener();
080:                InstrumentedEventListener ielb = new InstrumentedEventListener();
081:
082:                eq.registerEventListener(EVENT_TYPE_A, iela);
083:                eq.registerEventListener(EVENT_TYPE_B, ielb);
084:
085:                DispatchData dda = eq.dispatchTable[EVENT_TYPE_A - 1];
086:                assertNotNull(dda);
087:                assertEquals(iela, dda.listener);
088:
089:                DispatchData ddb = eq.dispatchTable[EVENT_TYPE_B - 1];
090:                assertNotNull(ddb);
091:                assertEquals(ielb, ddb.listener);
092:            }
093:
094:            /**
095:             * Tests posting of an event.
096:             */
097:            void testPost1() {
098:                final int EVENT_TYPE = 14;
099:                EventQueue eq = new EventQueue();
100:
101:                InstrumentedEventListener iel = new InstrumentedEventListener();
102:                eq.registerEventListener(EVENT_TYPE, iel);
103:
104:                Event ev = new Event(EVENT_TYPE);
105:                eq.post(ev);
106:
107:                // assertions on the event queue
108:
109:                assertSame("nextEvent should be ev", ev, eq.nextEvent);
110:                assertSame("lastEvent should be ev", ev, eq.lastEvent);
111:
112:                // assertions from the event listener
113:
114:                Event[] arr;
115:
116:                arr = iel.getProcessedEvents();
117:                assertEquals("processed should be length 0", 0, arr.length);
118:
119:                arr = iel.getPreprocessedEvents();
120:                assertEquals("preprocessed should be length 1", 1, arr.length);
121:                assertSame("preprocessed[0] should be ev", ev, arr[0]);
122:
123:                arr = iel.getWaitingEvents();
124:                assertEquals("waiting should be length 1", 1, arr.length);
125:                assertNull("waiting[0] should be null", arr[0]);
126:            }
127:
128:            /**
129:             * Tests posting of three events.
130:             */
131:            void testPost3() {
132:                final int EVENT_TYPE_A = 5;
133:                final int EVENT_TYPE_B = 7;
134:
135:                EventQueue eq = new EventQueue();
136:
137:                InstrumentedEventListener iel = new InstrumentedEventListener();
138:                eq.registerEventListener(EVENT_TYPE_A, iel);
139:                eq.registerEventListener(EVENT_TYPE_B, iel);
140:
141:                Event ev0 = new Event(EVENT_TYPE_A);
142:                Event ev1 = new Event(EVENT_TYPE_B);
143:                Event ev2 = new Event(EVENT_TYPE_A);
144:                eq.post(ev0);
145:                eq.post(ev1);
146:                eq.post(ev2);
147:
148:                // assertions on the event queue
149:
150:                assertSame("nextEvent should be ev0", ev0, eq.nextEvent);
151:                assertSame("lastEvent should be ev2", ev2, eq.lastEvent);
152:                assertSame("ev0.next should be ev1", ev1, ev0.next);
153:                assertSame("ev1.next should be ev2", ev2, ev1.next);
154:                assertNull("ev2.next should be null", ev2.next);
155:
156:                // assertions from the event listener
157:
158:                Event[] arr;
159:
160:                arr = iel.getProcessedEvents();
161:                assertEquals("processed should be length 0", 0, arr.length);
162:
163:                arr = iel.getPreprocessedEvents();
164:                assertEquals("preprocessed should be length 3", 3, arr.length);
165:                assertSame("preprocessed[0] should be ev0", ev0, arr[0]);
166:                assertSame("preprocessed[1] should be ev1", ev1, arr[1]);
167:                assertSame("preprocessed[2] should be ev2", ev2, arr[2]);
168:
169:                arr = iel.getWaitingEvents();
170:                assertEquals("waiting should be length 3", 3, arr.length);
171:                assertNull("waiting[0] should be null", arr[0]);
172:                assertNull("waiting[1] should be null", arr[1]);
173:                assertEquals("waiting[2] should be ev0", ev0, arr[2]);
174:            }
175:
176:            /**
177:             * Tests preprocessing of events.
178:             */
179:            void testPreprocess() {
180:                EventQueue eq = new EventQueue();
181:                InstrumentedEventListener iel = new InstrumentedEventListener(
182:                        true);
183:                final int EVENT_TYPE = 10;
184:
185:                eq.registerEventListener(EVENT_TYPE, iel);
186:
187:                Event ev0 = new Event(EVENT_TYPE);
188:                Event ev1 = new Event(EVENT_TYPE);
189:                eq.post(ev0);
190:                iel.setPreprocess(false);
191:                eq.post(ev1);
192:
193:                // assertions on the event queue
194:
195:                assertSame("nextEvent should be ev0", ev0, eq.nextEvent);
196:                assertSame("lastEvent should be ev0", ev0, eq.lastEvent);
197:                assertNull("ev0.next should be null", ev0.next);
198:
199:                // assertions from the event listener
200:
201:                Event[] arr;
202:
203:                arr = iel.getProcessedEvents();
204:                assertEquals("processed should be length 0", 0, arr.length);
205:
206:                arr = iel.getPreprocessedEvents();
207:                assertEquals("preprocessed should be length 2", 2, arr.length);
208:                assertSame("preprocessed[0] should be ev0", ev0, arr[0]);
209:                assertSame("preprocessed[1] should be ev1", ev1, arr[1]);
210:
211:                arr = iel.getWaitingEvents();
212:                assertEquals("waiting should be length 2", 2, arr.length);
213:                assertNull("waiting[0] should be null", arr[0]);
214:                assertEquals("waiting[1] should be ev0", ev0, arr[1]);
215:            }
216:
217:            /**
218:             * Runs all tests.
219:             */
220:            public void runTests() throws Throwable {
221:                declare("testCreate");
222:                testCreate();
223:                declare("testRegister");
224:                testRegister();
225:                declare("testGrowDispatchTable");
226:                testGrowDispatchTable();
227:                declare("testPost1");
228:                testPost1();
229:                declare("testPost3");
230:                testPost3();
231:                declare("testPreprocess");
232:                testPreprocess();
233:            }
234:
235:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.