--- a/javauis/lcdui_qt/tsrc/src/com/nokia/openlcdui/mt/form/FormTest.java Mon May 03 12:27:20 2010 +0300
+++ b/javauis/lcdui_qt/tsrc/src/com/nokia/openlcdui/mt/form/FormTest.java Fri May 14 15:47:24 2010 +0300
@@ -11,7 +11,7 @@
*
* Contributors:
*
-* Description:
+* Description:
*
*/
package com.nokia.openlcdui.mt.form;
@@ -30,7 +30,8 @@
* <br>
* Created: 2008-07-10
*/
-public class FormTest extends SWTTestCase {
+public class FormTest extends SWTTestCase
+{
private static final int INVALID_APPEARANCE_MODE = 3;
private static final int INVALID_LAYOUT = 4;
@@ -38,7 +39,8 @@
/**
* Constructor.
*/
- public FormTest() {
+ public FormTest()
+ {
}
/**
@@ -47,7 +49,8 @@
* @param sTestName Test name.
* @param rTestMethod Test method.
*/
- public FormTest(String sTestName) {
+ public FormTest(String sTestName)
+ {
super(sTestName);
}
@@ -57,22 +60,25 @@
*
* @return New testsuite.
*/
- public static Test suite() {
- TestSuite suite = new TestSuite();
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite();
- java.util.Vector methodNames;
- java.util.Enumeration e;
+ java.util.Vector methodNames;
+ java.util.Enumeration e;
- // Add widget tests
- methodNames = FormTest.methodNames();
- e = methodNames.elements();
- while (e.hasMoreElements()) {
- suite.addTest(new FormTest((String)e.nextElement()));
- }
- return suite;
+ // Add widget tests
+ methodNames = FormTest.methodNames();
+ e = methodNames.elements();
+ while(e.hasMoreElements())
+ {
+ suite.addTest(new FormTest((String)e.nextElement()));
+ }
+ return suite;
}
- public static java.util.Vector methodNames() {
+ public static java.util.Vector methodNames()
+ {
java.util.Vector methodNames = new java.util.Vector();
methodNames.addElement("testFormException");
methodNames.addElement("testAppendException");
@@ -96,36 +102,38 @@
methodNames.addElement("testFormConstructor");
return methodNames;
}
-
- protected void runTest() throws Throwable {
- if (getName().equals("testFormException")) testFormException();
- else if (getName().equals("testAppendException")) testAppendException();
- else if (getName().equals("testInsertException")) testInsertException();
- else if (getName().equals("testDeleteException")) testDeleteException();
- else if (getName().equals("testSetException")) testSetException();
- else if (getName().equals("testGetException")) testGetException();
- else if (getName().equals("testSize")) testSize();
- else if (getName().equals("testDeleteAll")) testDeleteAll();
- else if (getName().equals("testGetWidthGetHeight")) testGetWidthGetHeight();
- else if (getName().equals("testFormSetIOOBExceptions")) testFormSetIOOBExceptions();
- else if (getName().equals("testFormSetNPExceptions")) testFormSetNPExceptions();
- else if (getName().equals("testFormSetISExceptions")) testFormSetISExceptions();
- else if (getName().equals("testFormInsertIOOBExceptions")) testFormInsertIOOBExceptions();
- else if (getName().equals("testFormInsertNPExceptions")) testFormInsertNPExceptions();
- else if (getName().equals("testFormInsertISExceptions")) testFormInsertISExceptions();
- else if (getName().equals("testFormGetIOOBExceptions")) testFormGetIOOBExceptions();
- else if (getName().equals("testFormDeleteIOOBExceptions")) testFormDeleteIOOBExceptions();
- else if (getName().equals("testFormAppend")) testFormAppend();
- else if (getName().equals("testFormAppendImage")) testFormAppendImage();
- else if (getName().equals("testFormConstructor")) testFormConstructor();
+
+ protected void runTest() throws Throwable
+ {
+ if(getName().equals("testFormException")) testFormException();
+ else if(getName().equals("testAppendException")) testAppendException();
+ else if(getName().equals("testInsertException")) testInsertException();
+ else if(getName().equals("testDeleteException")) testDeleteException();
+ else if(getName().equals("testSetException")) testSetException();
+ else if(getName().equals("testGetException")) testGetException();
+ else if(getName().equals("testSize")) testSize();
+ else if(getName().equals("testDeleteAll")) testDeleteAll();
+ else if(getName().equals("testGetWidthGetHeight")) testGetWidthGetHeight();
+ else if(getName().equals("testFormSetIOOBExceptions")) testFormSetIOOBExceptions();
+ else if(getName().equals("testFormSetNPExceptions")) testFormSetNPExceptions();
+ else if(getName().equals("testFormSetISExceptions")) testFormSetISExceptions();
+ else if(getName().equals("testFormInsertIOOBExceptions")) testFormInsertIOOBExceptions();
+ else if(getName().equals("testFormInsertNPExceptions")) testFormInsertNPExceptions();
+ else if(getName().equals("testFormInsertISExceptions")) testFormInsertISExceptions();
+ else if(getName().equals("testFormGetIOOBExceptions")) testFormGetIOOBExceptions();
+ else if(getName().equals("testFormDeleteIOOBExceptions")) testFormDeleteIOOBExceptions();
+ else if(getName().equals("testFormAppend")) testFormAppend();
+ else if(getName().equals("testFormAppendImage")) testFormAppendImage();
+ else if(getName().equals("testFormConstructor")) testFormConstructor();
else super.runTest();
}
-
-
+
+
/**
* Constructor Exception test.
*/
- public void testFormException() {
+ public void testFormException()
+ {
Form formContainer = new Form("Form Title");
StringItem itemOwned = new StringItem("label", "text", 0);
formContainer.append(itemOwned);
@@ -133,65 +141,78 @@
Item[] items1 = {new StringItem(null, "body", 0), itemOwned, };
Item[] items2 = {new StringItem(null, "body2", 0), null, };
- try {
+ try
+ {
Form formEx = new Form("header", items1);
fail("IllegalStateException not thrown");
}
- catch (IllegalStateException ise) {
- // Ok
+ catch(IllegalStateException ise)
+ {
+ // Ok
}
- try {
+ try
+ {
Form formEx = new Form("header", items2);
fail("NullPointerException not thrown");
}
- catch (NullPointerException npe) {
- // OK
+ catch(NullPointerException npe)
+ {
+ // OK
}
}
/**
* Tests that append throws correct exceptions in case of incorrect input.
*/
- public void testAppendException() {
+ public void testAppendException()
+ {
Form appendExForm = new Form("form title");
- Form container = new Form ("Form");
+ Form container = new Form("Form");
String appendString = null;
Image appendImage = null;
StringItem appendStringItem = null;
- try {
+ try
+ {
appendExForm.append(appendString);
fail("NullPointerException not thrown if string is null");
}
- catch (NullPointerException npe) {
- // Ok
+ catch(NullPointerException npe)
+ {
+ // Ok
}
- try {
+ try
+ {
appendExForm.append(appendImage);
fail("NullPointerException not thrown if image is null");
}
- catch (NullPointerException npe) {
- // Ok
+ catch(NullPointerException npe)
+ {
+ // Ok
}
- try {
+ try
+ {
appendExForm.append(appendStringItem);
fail("NullPointerException not thrown if item is null");
}
- catch (NullPointerException npe) {
- // Ok
+ catch(NullPointerException npe)
+ {
+ // Ok
}
appendStringItem = new StringItem("turur", "tururu", 0);
container.append(appendStringItem);
- try {
+ try
+ {
appendExForm.append(appendStringItem);
fail("IllegalStateException not thrown if item is already owned");
}
- catch (IllegalStateException npe) {
- // Ok
+ catch(IllegalStateException npe)
+ {
+ // Ok
}
}
@@ -200,7 +221,8 @@
* Tests that insert() throws correct exceptions
* in case of incorrect input.
*/
- public void testInsertException() {
+ public void testInsertException()
+ {
Form insertException = new Form("insertEx");
Form formContainer = new Form("Form Title");
StringItem itemOwned = new StringItem("label", "text", 0);
@@ -208,28 +230,34 @@
insertException.append("one item");
insertException.append("second item");
- try {
+ try
+ {
insertException.insert(3, new StringItem(null, "text", 0));
fail("IndexOutOfBoundsException not thrown");
}
- catch (IndexOutOfBoundsException iob) {
- // Ok
+ catch(IndexOutOfBoundsException iob)
+ {
+ // Ok
}
- try {
+ try
+ {
insertException.insert(1, itemOwned);
fail("IllegalStateException not thrown if Item is owned");
}
- catch (IllegalStateException ise) {
- // Ok
+ catch(IllegalStateException ise)
+ {
+ // Ok
}
- try {
+ try
+ {
insertException.insert(1, null);
fail("NullPointerException not thrown if Item is null");
}
- catch (NullPointerException npe) {
- // Ok
+ catch(NullPointerException npe)
+ {
+ // Ok
}
}
@@ -238,16 +266,19 @@
* Tests that delete() throws correct exception
* in case of incorrect input.
*/
- public void testDeleteException() {
+ public void testDeleteException()
+ {
Form deleteExForm = new Form("heder");
deleteExForm.append("string1");
deleteExForm.append("String2");
- try {
+ try
+ {
deleteExForm.delete(2);
fail("IndexOutOfBoundsException not thrown");
}
- catch (IndexOutOfBoundsException e) {
- // Ok
+ catch(IndexOutOfBoundsException e)
+ {
+ // Ok
}
}
@@ -256,36 +287,43 @@
* Tests that set() throws correct exceptions
* in case of incorrect input.
*/
- public void testSetException() {
- Form setForm = new Form ("set Form");
+ public void testSetException()
+ {
+ Form setForm = new Form("set Form");
setForm.append("string 1");
setForm.append("string 2");
Form formContainer = new Form("Form Title");
StringItem itemOwned = new StringItem("label", "text", 0);
formContainer.append(itemOwned);
- try {
+ try
+ {
setForm.set(3, new StringItem(null, "text", 0));
fail("IndexOutOfBoundsException not thrown");
}
- catch (IndexOutOfBoundsException e) {
- // Ok
+ catch(IndexOutOfBoundsException e)
+ {
+ // Ok
}
- try {
+ try
+ {
setForm.set(1, itemOwned);
fail("IllegalStateException not thrown if Item is owned");
}
- catch (IllegalStateException e) {
- // Ok
+ catch(IllegalStateException e)
+ {
+ // Ok
}
- try {
+ try
+ {
setForm.set(1, null);
fail("NullPointerException not thrown if Item is null");
}
- catch (NullPointerException npe) {
- // Ok
+ catch(NullPointerException npe)
+ {
+ // Ok
}
}
@@ -293,15 +331,18 @@
* Form.get() test.
* Tests that get() throws correct exceptions in case of incorrect input.
*/
- public void testGetException () {
+ public void testGetException()
+ {
Form getForm = new Form("getForm");
getForm.append("string1");
getForm.append("String2");
- try {
+ try
+ {
getForm.get(2);
fail("IndexOutOfBoundsException not thrown");
}
- catch (IndexOutOfBoundsException e) {
+ catch(IndexOutOfBoundsException e)
+ {
// Ok
}
}
@@ -310,63 +351,72 @@
*Form.size() test.
*Tests that size() returns correct result.
*/
- public void testSize() {
+ public void testSize()
+ {
Form formSize = new Form("form header");
formSize.append("String 1");
formSize.append("String 2");
assertTrue("Form.size(). Expected return 2 but returned"
- + formSize.size(), formSize.size() == 2);
+ + formSize.size(), formSize.size() == 2);
}
/**
* Form deleteAll() test.
* Tests that deleteAll() working properly
*/
- public void testDeleteAll() {
+ public void testDeleteAll()
+ {
Form formDeleteAll = new Form("deleteaAll");
formDeleteAll.append("String 1");
formDeleteAll.append("String 2");
formDeleteAll.deleteAll();
assertTrue("Form.deleteAll(). Expected size() returns 0 but returned"
- + formDeleteAll.size(), formDeleteAll.size() == 0);
+ + formDeleteAll.size(), formDeleteAll.size() == 0);
}
/**
*Form.getWidth(),Form.getHeight() test.
*
*/
- public void testGetWidthGetHeight () {
- Form formGetWidthHeight = new Form ("getWidth() getHeight()");
+ public void testGetWidthGetHeight()
+ {
+ Form formGetWidthHeight = new Form("getWidth() getHeight()");
int getWidth = 0;
int getHeight = 0;
getWidth = formGetWidthHeight.getWidth();
getHeight = formGetWidthHeight.getHeight();
assertTrue("Form.getWidth(),getHeight(). Expected return not 0 but"
- + " returned width " + getWidth + " and height " + getHeight,
- (getWidth != 0) && (getHeight != 0));
+ + " returned width " + getWidth + " and height " + getHeight,
+ (getWidth != 0) && (getHeight != 0));
}
/**
* Enhanced test for IndexOutOfBoundsExceptions for Form.set().
*/
- public void testFormSetIOOBExceptions () {
+ public void testFormSetIOOBExceptions()
+ {
int []positions = {Integer.MIN_VALUE, Integer.MIN_VALUE + 1, -256,
-255, -1, 1, 255, 256, Integer.MAX_VALUE - 1,
- Integer.MAX_VALUE, };
+ Integer.MAX_VALUE,
+ };
Form f = new Form("Test");
f.append("stub");
- for (int i = 0; i < positions.length; i++) {
- try {
- f.set(positions[i], new StringItem("0", "1"));
- fail("IndexOutOfBoundsException not thrown for value"
- + positions[i]);
- }
- catch (IndexOutOfBoundsException e1) {
- // Ok
+ for(int i = 0; i < positions.length; i++)
+ {
+ try
+ {
+ f.set(positions[i], new StringItem("0", "1"));
+ fail("IndexOutOfBoundsException not thrown for value"
+ + positions[i]);
}
- catch (Exception e) {
+ catch(IndexOutOfBoundsException e1)
+ {
+ // Ok
+ }
+ catch(Exception e)
+ {
fail("Unexpected " + e);
break;
}
@@ -376,17 +426,20 @@
/**
* Enhanced test for NullPointerException in Form.set().
*/
- public void testFormSetNPExceptions() {
+ public void testFormSetNPExceptions()
+ {
Item[] items = {new StringItem("label", "text") };
Form f1 = null;
f1 = new Form("Form 1", items); // Assign items to f1
- try {
+ try
+ {
f1.set(0, null);
fail("NullPointerException not thrown");
}
- catch (NullPointerException e1) {
+ catch(NullPointerException e1)
+ {
// Ok
}
}
@@ -394,7 +447,8 @@
/**
* enhanced test for IllegalStateException in Form.set().
*/
- public void testFormSetISExceptions () {
+ public void testFormSetISExceptions()
+ {
Item []items = {new StringItem("label", "text")};
Form f1 = null;
Form f2 = null;
@@ -403,11 +457,13 @@
f1 = new Form("Form 1");
f1.append("some");
- try {
+ try
+ {
f1.set(0, items[0]);
fail("IllegalStateException not thrown");
}
- catch (IllegalStateException e1) {
+ catch(IllegalStateException e1)
+ {
// Ok
}
}
@@ -415,24 +471,29 @@
/**
* Enhanced test for IndexOutOfBoundsException for Form.insert().
*/
- public void testFormInsertIOOBExceptions () {
+ public void testFormInsertIOOBExceptions()
+ {
int []positions = {Integer.MIN_VALUE, Integer.MIN_VALUE + 1, -256,
- -255, -1, 255, 256, Integer.MAX_VALUE - 1,
- Integer.MAX_VALUE,
- };
+ -255, -1, 255, 256, Integer.MAX_VALUE - 1,
+ Integer.MAX_VALUE,
+ };
Form f = new Form("Test");
f.append("stub");
- for (int i = 0; i < positions.length; i++) {
- try {
+ for(int i = 0; i < positions.length; i++)
+ {
+ try
+ {
f.insert(positions[i], new StringItem("0", "1"));
fail("IndexOutOfBoundsException not thrown for value"
- + positions[i]);
+ + positions[i]);
}
- catch (IndexOutOfBoundsException e1) {
- // Ok
+ catch(IndexOutOfBoundsException e1)
+ {
+ // Ok
}
- catch (Exception e) {
+ catch(Exception e)
+ {
fail("Unexpected " + e);
}
}
@@ -441,17 +502,20 @@
/**
* Enhanced test for NullPointerException for Form.insert().
*/
- public void testFormInsertNPExceptions () {
+ public void testFormInsertNPExceptions()
+ {
Item []items = {new StringItem("label", "text")};
Form f1 = null;
f1 = new Form("Form 1", items); // Assign items to f1
- try {
+ try
+ {
f1.insert(0, null);
fail("NullPointerException not thrown");
}
- catch (NullPointerException e1) {
+ catch(NullPointerException e1)
+ {
// Ok
}
}
@@ -459,7 +523,8 @@
/**
* Enhanced test for IllegalStateException for Form.insert().
*/
- public void testFormInsertISExceptions() {
+ public void testFormInsertISExceptions()
+ {
Item []items = {new StringItem("label", "text")};
Form f1 = null;
Form f2 = null;
@@ -468,11 +533,13 @@
f1 = new Form("Form 1");
f1.append("stub");
- try {
+ try
+ {
f1.insert(0, items[0]);
fail("IllegalStateException not thrown");
}
- catch (IllegalStateException e1) {
+ catch(IllegalStateException e1)
+ {
// Ok
}
}
@@ -480,24 +547,29 @@
/**
* Enhanced test for IndexOutOfBoundsException for Form.get().
*/
- public void testFormGetIOOBExceptions() {
+ public void testFormGetIOOBExceptions()
+ {
int []positions = {Integer.MIN_VALUE, Integer.MIN_VALUE + 1, -256,
- -255, -1, 1, 255, 256, Integer.MAX_VALUE - 1,
- Integer.MAX_VALUE,
- };
+ -255, -1, 1, 255, 256, Integer.MAX_VALUE - 1,
+ Integer.MAX_VALUE,
+ };
Form f = new Form("Test");
f.append("stub");
- for (int i = 0; i < positions.length; i++) {
- try {
+ for(int i = 0; i < positions.length; i++)
+ {
+ try
+ {
f.get(positions[i]);
fail("IndexOutOfBoundsException not thrown for value"
- + positions[i]);
+ + positions[i]);
}
- catch (IndexOutOfBoundsException e1) {
- // Ok
+ catch(IndexOutOfBoundsException e1)
+ {
+ // Ok
}
- catch (Exception e) {
+ catch(Exception e)
+ {
fail("Unexpected " + e);
}
}
@@ -506,24 +578,29 @@
/**
* Enhanced test for IndexOutOfboundsException for form.delete().
*/
- public void testFormDeleteIOOBExceptions () {
+ public void testFormDeleteIOOBExceptions()
+ {
int []positions = {Integer.MIN_VALUE, Integer.MIN_VALUE + 1, -256,
- -255, -1, 1, 255, 256, Integer.MAX_VALUE - 1,
- Integer.MAX_VALUE,
- };
+ -255, -1, 1, 255, 256, Integer.MAX_VALUE - 1,
+ Integer.MAX_VALUE,
+ };
Form form = new Form("Test");
form.append("stub");
- for (int i = 0; i < positions.length; i++) {
- try {
+ for(int i = 0; i < positions.length; i++)
+ {
+ try
+ {
form.delete(positions[i]);
fail("IndexOutOfBoundsException not thrown for value"
- + positions[i]);
+ + positions[i]);
}
- catch (IndexOutOfBoundsException e1) {
- // Ok
+ catch(IndexOutOfBoundsException e1)
+ {
+ // Ok
}
- catch (Exception e) {
+ catch(Exception e)
+ {
fail("Unexpected " + e);
}
}
@@ -532,7 +609,8 @@
/**
* Enhanced test for IllegalStateException for form.delete().
*/
- public void testFormAppendISExceptions () {
+ public void testFormAppendISExceptions()
+ {
Item []items = {new StringItem("label", "text")};
Form f1 = null;
Form f2 = null;
@@ -540,11 +618,13 @@
f1 = new Form("Form 1", items); // Assign items to f1
f2 = new Form("Form 2"); // Assign items to f1
- try {
+ try
+ {
f2.append(items[0]);
fail("IllegalStateException not thrown");
}
- catch (IllegalStateException e1) {
+ catch(IllegalStateException e1)
+ {
// Ok
}
}
@@ -552,15 +632,18 @@
/**
* Enhanced Form.append() test.
*/
- public void testFormAppend() {
+ public void testFormAppend()
+ {
String[] strings = {"string1", "string2", "string3" };
Form form = new Form("Title");
int ind = 0;
- for (int j = 0; j < strings.length; j++) {
+ for(int j = 0; j < strings.length; j++)
+ {
ind = form.append(strings[j]);
- if (!(((StringItem) form.get(ind)).getText().equals(strings[j]))) {
+ if(!(((StringItem) form.get(ind)).getText().equals(strings[j])))
+ {
fail("Failed at " + j);
}
}
@@ -570,18 +653,22 @@
* Enhanced test for Form.append().
* appending image to a form
*/
- public void testFormAppendImage() {
+ public void testFormAppendImage()
+ {
Image image = null;
- try {
+ try
+ {
image = Image.createImage("100x100.png");
}
- catch (Exception e) {
+ catch(Exception e)
+ {
e.printStackTrace();
}
Form form = new Form("Title");
int index = 0;
index = form.append(image);
- if (!(((ImageItem) form.get(index)).getImage() == image)) {
+ if(!(((ImageItem) form.get(index)).getImage() == image))
+ {
fail("Failed to append image");
}
}
@@ -589,20 +676,25 @@
/**
* Enhanced test for Form (String title, Item [] items.
*/
- public void testFormConstructor() {
+ public void testFormConstructor()
+ {
String title = "Title";
Item[][] items = {{}, null, };
Form form = null;
- for (int j = 0; j < items.length; j++) {
- try {
+ for(int j = 0; j < items.length; j++)
+ {
+ try
+ {
form = new Form(title, items[j]);
}
- catch (Exception e) {
+ catch(Exception e)
+ {
fail("Unexpected " + e);
}
- if (!(form.size() == 0)) {
+ if(!(form.size() == 0))
+ {
fail("Failed");
}
}