Source Code Cross Referenced for TestCommandSorting.java in  » 6.0-JDK-Modules » j2me » javax » microedition » lcdui » 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 » javax.microedition.lcdui 
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 javax.microedition.lcdui;
028:
029:        import com.sun.midp.chameleon.*;
030:        import com.sun.midp.chameleon.layers.*;
031:        import com.sun.midp.i3test.TestCase;
032:        import com.sun.midp.util.LcduiTestCanvas;
033:        import com.sun.midp.util.LcduiTestMIDlet;
034:
035:        /**
036:         * This test case does extensive testing on command sorting in chameleon. 
037:         * It validates the rules specified in the spec for sorting commands
038:         * in a particular order along with taking their priorities into 
039:         * consideration. For example, it tests the decision on what goes into the 
040:         * left soft button and what goes into the right soft button as the system 
041:         * menu list of commands.
042:         */
043:        public class TestCommandSorting extends TestCase {
044:
045:            /** Name of the test */
046:            static final String testName = "CommandSorting";
047:
048:            /** The Display to use to view our test canvases */
049:            protected Display display;
050:
051:            /** Reference to MIDPWindow, to help us gain access into 
052:             * SoftButtonLayer's attributes used in this test.
053:             */
054:            protected MIDPWindow window;
055:
056:            /**
057:             * Simple constructor.
058:             */
059:            public TestCommandSorting() {
060:            }
061:
062:            /**
063:             * Utility method that checks that the left soft button is indeed the
064:             * intended one as passed in via parameter cmd, after making the canvas 
065:             * current.
066:             *
067:             * @param canvas the canvas being used to test the commands
068:             * @param cmd the command under test
069:             */
070:            protected void checkLeftBtn(LcduiTestCanvas canvas, Command cmd) {
071:                display.setCurrent(canvas);
072:                if (!canvas.awaitPaint()) {
073:                    fail("test canvas not visible");
074:                    return;
075:                }
076:
077:                assertSame("Checking left button:", cmd, window.getSoftOne());
078:            }
079:
080:            /**
081:             * This test is for a canvas with just the STOP command added. The STOP 
082:             * command should be the left soft button. (only negative commands are 
083:             * being tested)
084:             */
085:            protected void testOne() {
086:                declare(testName + " 1: STOP command added to the screen.");
087:
088:                LcduiTestCanvas canvas = new LcduiTestCanvas();
089:
090:                Command stopCmd = new Command("Stop", Command.STOP, 0);
091:                canvas.addCommand(stopCmd);
092:
093:                checkLeftBtn(canvas, stopCmd);
094:            }
095:
096:            /**
097:             * This test is for a canvas with the CANCEL & STOP commands added. The 
098:             * CANCEL command should be the left soft button. (only negative 
099:             * commands are being tested)
100:             */
101:            protected void testTwo() {
102:                declare(testName
103:                        + " 2: CANCEL & STOP commands added to the screen.");
104:
105:                LcduiTestCanvas canvas = new LcduiTestCanvas();
106:
107:                Command cancelCmd = new Command("Cancel", Command.CANCEL, 0);
108:                Command stopCmd = new Command("Stop", Command.STOP, 0);
109:
110:                // we add the commands in reverse order so that we are
111:                // sure the button layer is sorting it correctly
112:                canvas.addCommand(stopCmd);
113:                canvas.addCommand(cancelCmd);
114:
115:                checkLeftBtn(canvas, cancelCmd);
116:            }
117:
118:            /**
119:             * This test is for a canvas with the EXIT, CANCEL & STOP commands added.
120:             * The EXIT command should be the left soft button. (only negative
121:             * commands are being tested)
122:             */
123:            protected void testThree() {
124:                declare(testName
125:                        + " 3: EXIT, CANCEL & STOP commands added to the screen.");
126:
127:                LcduiTestCanvas canvas = new LcduiTestCanvas();
128:
129:                Command exitCmd = new Command("Exit", Command.EXIT, 0);
130:                Command cancelCmd = new Command("Cancel", Command.CANCEL, 0);
131:                Command stopCmd = new Command("Stop", Command.STOP, 0);
132:
133:                // we add the commands in reverse order so that we are
134:                // sure the button layer is sorting it correctly
135:                canvas.addCommand(stopCmd);
136:                canvas.addCommand(cancelCmd);
137:                canvas.addCommand(exitCmd);
138:
139:                checkLeftBtn(canvas, exitCmd);
140:            }
141:
142:            /**
143:             * This test is for a canvas with the BACK, EXIT, CANCEL & STOP
144:             * commands added. The BACK command should be the left soft button. 
145:             * (only negative commands are being tested)
146:             */
147:            protected void testFour() {
148:                declare(testName
149:                        + " 4: BACK, EXIT, CANCEL & STOP commands added to the screen.");
150:
151:                LcduiTestCanvas canvas = new LcduiTestCanvas();
152:
153:                Command backCmd = new Command("Back", Command.BACK, 0);
154:                Command exitCmd = new Command("Exit", Command.EXIT, 0);
155:                Command cancelCmd = new Command("Cancel", Command.CANCEL, 0);
156:                Command stopCmd = new Command("Stop", Command.STOP, 0);
157:
158:                // we add the commands in reverse order so that we are
159:                // sure the button layer is sorting it correctly
160:                canvas.addCommand(stopCmd);
161:                canvas.addCommand(cancelCmd);
162:                canvas.addCommand(exitCmd);
163:                canvas.addCommand(backCmd);
164:                checkLeftBtn(canvas, backCmd);
165:            }
166:
167:            /**
168:             * This test is for a canvas with the BACK, STOP, CANCEL, EXIT, HELP, 
169:             * OK, SCREEN & ITEM commands added. The BACK command should be the 
170:             * left soft button. And all the other commands should be sorted 
171:             * correctly as defined in the spec on the right soft button as the 
172:             * system menu. (combination of positive & negative commands are
173:             * being tested)
174:             */
175:            protected void testFive() {
176:                declare(testName
177:                        + " 5: BACK, STOP, CANCEL, EXIT, HELP, OK, SCREEN & ITEM commands added to the screen.");
178:
179:                LcduiTestCanvas canvas = new LcduiTestCanvas();
180:
181:                // we add the commands in reverse order so that we are
182:                // sure the button layer is sorting it correctly
183:                for (int i = 0; i < 2; i++) {
184:                    canvas.addCommand(new Command("STOP" + i, Command.STOP, i));
185:                    canvas.addCommand(new Command("CANCEL" + i, Command.CANCEL,
186:                            i));
187:                    canvas.addCommand(new Command("EXIT" + i, Command.EXIT, i));
188:                    canvas.addCommand(new Command("HELP" + i, Command.HELP, i));
189:                    canvas.addCommand(new Command("OK" + i, Command.OK, i));
190:                    canvas.addCommand(new Command("SCREEN" + i, Command.SCREEN,
191:                            i));
192:                    canvas.addCommand(new Command("ITEM" + i, Command.ITEM, i));
193:                }
194:
195:                Command backCmd = new Command("Back", Command.BACK, 0);
196:                canvas.addCommand(backCmd);
197:
198:                checkLeftBtn(canvas, backCmd);
199:                Command[] cmds = window.getSoftTwo();
200:
201:                assertTrue("ITEM", cmds[0].getCommandType() == Command.ITEM);
202:                assertTrue("ITEM", cmds[1].getCommandType() == Command.ITEM);
203:                assertTrue("ITEM PRIORITY", cmds[0].getPriority() < cmds[1]
204:                        .getPriority());
205:
206:                assertTrue("SCREEN", cmds[2].getCommandType() == Command.SCREEN);
207:                assertTrue("SCREEN", cmds[3].getCommandType() == Command.SCREEN);
208:                assertTrue("SCREEN PRIORITY", cmds[2].getPriority() < cmds[3]
209:                        .getPriority());
210:
211:                assertTrue("OK", cmds[4].getCommandType() == Command.OK);
212:                assertTrue("OK", cmds[5].getCommandType() == Command.OK);
213:                assertTrue("OK PRIORITY", cmds[4].getPriority() < cmds[5]
214:                        .getPriority());
215:
216:                assertTrue("EXIT, ", cmds[6].getCommandType() == Command.EXIT);
217:                assertTrue("EXIT, ", cmds[7].getCommandType() == Command.EXIT);
218:                assertTrue("EXIT PRIORITY, ", cmds[6].getPriority() < cmds[7]
219:                        .getPriority());
220:
221:                assertTrue("CANCEL, ",
222:                        cmds[8].getCommandType() == Command.CANCEL);
223:                assertTrue("CANCEL, ",
224:                        cmds[9].getCommandType() == Command.CANCEL);
225:                assertTrue("CANCEL PRIORITY, ", cmds[8].getPriority() < cmds[9]
226:                        .getPriority());
227:
228:                assertTrue("STOP, ", cmds[10].getCommandType() == Command.STOP);
229:                assertTrue("STOP, ", cmds[11].getCommandType() == Command.STOP);
230:                assertTrue("STOP PRIORITY, ", cmds[10].getPriority() < cmds[11]
231:                        .getPriority());
232:
233:                assertTrue("HELP, ", cmds[12].getCommandType() == Command.HELP);
234:                assertTrue("HELP, ", cmds[13].getCommandType() == Command.HELP);
235:                assertTrue("HELP PRIORITY, ", cmds[12].getPriority() < cmds[13]
236:                        .getPriority());
237:            }
238:
239:            /**
240:             * This test is for a canvas with the HELP, OK, SCREEN & ITEM
241:             * commands added, without any negative commands and check to see
242:             * if the left soft button is mapped to the highest positive
243:             * command as expected. All the remaining positive
244:             * commands should be sorted correctly as defined in the spec on
245:             * the right soft button as the system menu. (only positive commands are
246:             * being tested)
247:             */
248:            protected void testSix() {
249:                declare(testName
250:                        + " 6: HELP, OK, SCREEN & ITEM commands added to the screen.");
251:
252:                LcduiTestCanvas canvas = new LcduiTestCanvas();
253:
254:                Command helpCmd = new Command("HELP", Command.HELP, 0);
255:                Command okCmd = new Command("OK", Command.OK, 1);
256:                Command screenCmd = new Command("SCREEN", Command.SCREEN, 2);
257:                Command itemCmd = new Command("ITEM", Command.ITEM, 3);
258:
259:                canvas.addCommand(helpCmd);
260:                canvas.addCommand(okCmd);
261:                canvas.addCommand(screenCmd);
262:                canvas.addCommand(itemCmd);
263:
264:                checkLeftBtn(canvas, itemCmd); // ITEM command has highest priority
265:            }
266:
267:            /**
268:             * Overridden from TestCase parent. This method will kick off each
269:             * individual test
270:             */
271:            public void runTests() throws Throwable {
272:
273:                if (!LcduiTestMIDlet.invoke()) {
274:                    throw new RuntimeException("can't start LcduiTestMIDlet");
275:                }
276:
277:                try {
278:                    display = LcduiTestMIDlet.getDisplay();
279:                    window = display.getWindow();
280:
281:                    testOne();
282:                    testTwo();
283:                    testThree();
284:                    testFour();
285:                    testFive();
286:                    testSix();
287:                } finally {
288:                    LcduiTestMIDlet.cleanup();
289:                }
290:            }
291:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.