|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package com.nokia.mj.impl.rt.ui.qt; |
|
20 |
|
21 import com.nokia.mj.impl.installer.utils.InstallerMain; |
|
22 import com.nokia.mj.impl.utils.exception.ExceptionBase; |
|
23 import com.nokia.mj.impl.rt.ui.qt.RuntimeUiQt; |
|
24 import com.nokia.mj.impl.rt.ui.RuntimeUi; |
|
25 import com.nokia.mj.impl.rt.ui.ConfirmData; |
|
26 |
|
27 import j2meunit.framework.Test; |
|
28 import j2meunit.framework.TestCase; |
|
29 import j2meunit.framework.TestMethod; |
|
30 import j2meunit.framework.TestSuite; |
|
31 |
|
32 /** |
|
33 * RuntimeUiQt unit tests. |
|
34 */ |
|
35 public class RuntimeUiQtTests extends TestCase implements InstallerMain |
|
36 { |
|
37 |
|
38 // Begin j2meunit test framework setup |
|
39 public void installerMain(String[] args) |
|
40 { |
|
41 TestSuite suite = new TestSuite(this.getClass().getName()); |
|
42 |
|
43 suite.addTest(new RuntimeUiQtTests("testQt", new TestMethod() |
|
44 { |
|
45 public void run(TestCase tc) |
|
46 { |
|
47 ((RuntimeUiQtTests)tc).testQt(); |
|
48 } |
|
49 })); |
|
50 |
|
51 com.nokia.mj.impl.utils.OmjTestRunner.run(suite); |
|
52 } |
|
53 |
|
54 public RuntimeUiQtTests() |
|
55 { |
|
56 } |
|
57 |
|
58 public RuntimeUiQtTests(String aTestName, TestMethod aTestMethod) |
|
59 { |
|
60 super(aTestName, aTestMethod); |
|
61 } |
|
62 |
|
63 public void assertFalse(String aMsg, boolean aCondition) |
|
64 { |
|
65 assertTrue(aMsg, !aCondition); |
|
66 } |
|
67 |
|
68 // End j2meunit test framework setup |
|
69 |
|
70 protected void setUp() |
|
71 { |
|
72 } |
|
73 |
|
74 protected void tearDown() |
|
75 { |
|
76 } |
|
77 |
|
78 private void testQt() |
|
79 { |
|
80 doTest(new RuntimeUiQt()); |
|
81 } |
|
82 |
|
83 private void doTest(RuntimeUi runtimeUi) |
|
84 { |
|
85 // error message with details -> make sure both are available to the user |
|
86 ExceptionBase exc = new ExceptionBase( |
|
87 new ShortErrorMessage(), |
|
88 ShortErrorMessage.MSG_WITH_DETAILS_ID, |
|
89 null, /* no params for short msg */ |
|
90 new DetailedErrorMessage(), |
|
91 DetailedErrorMessage.MSG_ID, |
|
92 null /* no params for detailed msg */); |
|
93 |
|
94 |
|
95 runtimeUi.error("MyApplication", exc); |
|
96 |
|
97 // error message with short description only |
|
98 exc = new ExceptionBase( |
|
99 new ShortErrorMessage(), |
|
100 ShortErrorMessage.MSG_WITHOUT_DETAILS_ID, |
|
101 null, /* no params for short msg */ |
|
102 null, |
|
103 0, |
|
104 null /* no params for detailed msg */); |
|
105 |
|
106 boolean answerAvailable = false; |
|
107 |
|
108 // Test confirm |
|
109 ConfirmData confirmData = new ConfirmData("Confirm dialog. Select Allow", new String[] {"answerOpt1", "answerOpt2", "answerOption3"}, 1); |
|
110 answerAvailable = runtimeUi.confirm("MyFavouriteAplication", confirmData); |
|
111 assertTrue(answerAvailable && confirmData.getAnswer() == 1); |
|
112 |
|
113 confirmData = new ConfirmData("Confirm dialog. Select Deny", new String[] {"answerOpt1", "answerOpt2", "answerOption3"}, 1); |
|
114 answerAvailable = runtimeUi.confirm("MyFavouriteAplication", confirmData); |
|
115 assertTrue(answerAvailable && confirmData.getAnswer() == 0); |
|
116 |
|
117 confirmData = new ConfirmData("Null Answer options", null /*Not Supported*/, 1); |
|
118 answerAvailable = runtimeUi.confirm("Null answer options", confirmData); |
|
119 assertTrue(answerAvailable); |
|
120 |
|
121 ConfirmData nullConf = null; |
|
122 runtimeUi.confirm("Null Application", nullConf); |
|
123 |
|
124 runtimeUi.destroy(); |
|
125 } |
|
126 } |