incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From liud...@apache.org
Subject svn commit: r1411080 [3/3] - in /incubator/odf/trunk/simple/src: main/java/org/odftoolkit/simple/ main/java/org/odftoolkit/simple/draw/ main/java/org/odftoolkit/simple/form/ main/java/org/odftoolkit/simple/text/ test/java/org/odftoolkit/simple/form/
Date Mon, 19 Nov 2012 06:51:46 GMT
Added: incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/ButtonTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/ButtonTest.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/ButtonTest.java (added)
+++ incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/ButtonTest.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,204 @@
+package org.odftoolkit.simple.form;
+
+import java.util.Iterator;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import junit.framework.Assert;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.odftoolkit.simple.TextDocument;
+import org.odftoolkit.simple.draw.ControlStyleHandler;
+import org.odftoolkit.simple.draw.FrameRectangle;
+import org.odftoolkit.simple.style.GraphicProperties;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.AnchorType;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.FrameVerticalPosition;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.SupportedLinearMeasure;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.VerticalRelative;
+import org.odftoolkit.simple.table.Cell;
+import org.odftoolkit.simple.table.Table;
+import org.odftoolkit.simple.text.Paragraph;
+import org.odftoolkit.simple.utils.ResourceUtilities;
+
+public class ButtonTest {
+	private static final FrameRectangle btnRtg = new FrameRectangle(0.5, 2,
+			2.9433, 0.5567, SupportedLinearMeasure.IN);;
+
+	@BeforeClass
+	public static void createForm() {
+		try {
+			TextDocument doc = TextDocument.newTextDocument();
+			Form form = doc.createForm("Test Form");
+			form.createButton(doc, btnRtg, "Button1", "Push Button 1");
+			form.createButton(doc, btnRtg, "Button2", "Push Button 2");
+
+			Paragraph para = doc.addParagraph("Insert a button here.");
+			form.createButton(para, btnRtg, "Button3", "Push Button 3");
+
+			Table table1 = Table.newTable(doc, 2, 2);
+			Cell cell = table1.getCellByPosition("A1");
+			para = cell.addParagraph("Insert a button here:");
+			form.createButton(para, btnRtg, "Button4", "Push Button 4");
+
+			doc.save(ResourceUtilities
+					.newTestOutputFile("TestCreateButton.odt"));
+
+		} catch (Exception e) {
+			Logger.getLogger(ButtonTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testCreateButton() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateButton.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = Button.getSimpleIterator(form);
+			int count = 0;
+			while (iterator.hasNext()) {
+				Button btn = (Button) iterator.next();
+				Assert.assertNotNull(btn);
+				Assert.assertEquals("Button" + (++count), btn.getName());
+				Assert.assertEquals("Push Button " + (count), btn.getLabel());
+			}
+		} catch (Exception e) {
+			Logger.getLogger(ButtonTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+
+	}
+
+	@Test
+	public void testRemoveButton() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateButton.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = Button.getSimpleIterator(form);
+			while (iterator.hasNext()) {
+				Button btn = (Button) iterator.next();
+				if (btn.getName().equals("Button2")) {
+					iterator.remove();
+					break;
+				}
+			}
+			Button find = null;
+			while (iterator.hasNext()) {
+				Button btn = (Button) iterator.next();
+				if (btn.getName().equals("Button2")) {
+					find = btn;
+					break;
+				}
+			}
+			Assert.assertNull(find);
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestRemoveButton.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(ButtonTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testSetButtonRectangle() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateButton.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = Button.getSimpleIterator(form);
+			Button find = null;
+			while (iterator.hasNext()) {
+				Button btn = (Button) iterator.next();
+				if (btn.getName().equals("Button2")) {
+					find = btn;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// change the bounding box
+			find.setRectangle(new FrameRectangle(2.25455, 5, 3, 0.5,
+					SupportedLinearMeasure.IN));
+			Assert.assertEquals(3.0, find.getRectangle().getWidth());
+			Assert.assertEquals(0.5, find.getRectangle().getHeight());
+			Assert.assertEquals(5.0, find.getRectangle().getY());
+			Assert.assertEquals(2.2546, find.getRectangle().getX());
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetButtonRectangle.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(ButtonTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testSetAnchorType() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateButton.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = Button.getSimpleIterator(form);
+			Button find = null;
+			while (iterator.hasNext()) {
+				Button btn = (Button) iterator.next();
+				if (btn.getName().equals("Button3")) {
+					find = btn;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// change the bounding box
+			find.setAnchorType(AnchorType.AS_CHARACTER);
+			// validate
+			ControlStyleHandler frameStyleHandler = find.getDrawControl()
+					.getStyleHandler();
+			GraphicProperties graphicPropertiesForWrite = frameStyleHandler
+					.getGraphicPropertiesForWrite();
+			Assert.assertEquals(VerticalRelative.BASELINE,
+					graphicPropertiesForWrite.getVerticalRelative());
+			Assert.assertEquals(FrameVerticalPosition.TOP,
+					graphicPropertiesForWrite.getVerticalPosition());
+
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetButtonAnchorType.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(ButtonTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testSetLabel() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateButton.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = Button.getSimpleIterator(form);
+			Button find = null;
+			while (iterator.hasNext()) {
+				Button btn = (Button) iterator.next();
+				if (btn.getName().equals("Button4")) {
+					find = btn;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// set new label
+			String newLabel = "Change the content of button 4.";
+			find.setLabel(newLabel);
+			Assert.assertEquals(newLabel, find.getLabel());
+			// set null value
+			find.setLabel(null);
+			Assert.assertEquals("", find.getLabel());
+
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetButtonLabel.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(ButtonTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+}

Added: incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/CheckBoxTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/CheckBoxTest.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/CheckBoxTest.java (added)
+++ incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/CheckBoxTest.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,285 @@
+package org.odftoolkit.simple.form;
+
+import java.util.Iterator;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import junit.framework.Assert;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.odftoolkit.simple.TextDocument;
+import org.odftoolkit.simple.draw.ControlStyleHandler;
+import org.odftoolkit.simple.draw.FrameRectangle;
+import org.odftoolkit.simple.form.FormTypeDefinition.FormCheckboxState;
+import org.odftoolkit.simple.style.GraphicProperties;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.AnchorType;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.FrameHorizontalPosition;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.FrameVerticalPosition;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.HorizontalRelative;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.SupportedLinearMeasure;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.VerticalRelative;
+import org.odftoolkit.simple.table.Cell;
+import org.odftoolkit.simple.table.Table;
+import org.odftoolkit.simple.text.Paragraph;
+import org.odftoolkit.simple.utils.ResourceUtilities;
+
+public class CheckBoxTest {
+	private static final FrameRectangle checkBoxRtg = new FrameRectangle(
+			0.7972, 1.2862, 2.4441, 0.2669, SupportedLinearMeasure.IN);
+
+	@BeforeClass
+	public static void createForm() {
+		try {
+			TextDocument doc = TextDocument.newTextDocument();
+			Form form = doc.createForm("Test Form");
+
+			// checkbox 1
+			CheckBox checkbox = (CheckBox) form.createCheckBox(doc,
+					checkBoxRtg, "CheckBox 1", "CheckBox 1", "1");
+
+			// checkbox 2
+			Paragraph para = doc.addParagraph("CheckBox2 anchor to heading.");
+			para.applyHeading();
+			form.createCheckBox(para, checkBoxRtg, "CheckBox 2", "CheckBox 2",
+					"2");
+
+			// checkbox 3
+			para = doc.addParagraph("Insert checkbox3 here, as_char.");
+			checkbox = (CheckBox) form.createCheckBox(para, checkBoxRtg,
+					"CheckBox 3", "CheckBox 3", "3");
+			checkbox.setCurrentState(FormCheckboxState.CHECKED);
+			checkbox.setAnchorType(AnchorType.AS_CHARACTER);
+
+			Table table1 = Table.newTable(doc, 2, 2);
+			Cell cell = table1.getCellByPosition("B1");
+			para = cell.addParagraph("Insert a check box here.");
+			form.createCheckBox(para, checkBoxRtg, "CheckBox 4", "CheckBox 4",
+					"4");
+			doc.save(ResourceUtilities
+					.newTestOutputFile("TestCreateCheckbox.odt"));
+
+		} catch (Exception e) {
+			Logger.getLogger(CheckBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testCreateCheckBox() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateCheckbox.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = CheckBox.getSimpleIterator(form);
+			int count = 0;
+			while (iterator.hasNext()) {
+				CheckBox btn = (CheckBox) iterator.next();
+				Assert.assertNotNull(btn);
+				Assert.assertEquals("CheckBox " + (++count), btn.getName());
+				Assert.assertEquals("CheckBox " + (count), btn.getLabel());
+			}
+		} catch (Exception e) {
+			Logger.getLogger(CheckBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+
+	}
+
+	@Test
+	public void testRemoveCheckBox() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateCheckBox.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = CheckBox.getSimpleIterator(form);
+			while (iterator.hasNext()) {
+				CheckBox btn = (CheckBox) iterator.next();
+				if (btn.getName().equals("CheckBox 2")) {
+					iterator.remove();
+					break;
+				}
+			}
+			CheckBox find = null;
+			while (iterator.hasNext()) {
+				CheckBox btn = (CheckBox) iterator.next();
+				if (btn.getName().equals("CheckBox 2")) {
+					find = btn;
+					break;
+				}
+			}
+			Assert.assertNull(find);
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestRemoveCheckBox.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(CheckBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testSetCheckBoxRectangle() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateCheckBox.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = CheckBox.getSimpleIterator(form);
+			CheckBox find = null;
+			while (iterator.hasNext()) {
+				CheckBox btn = (CheckBox) iterator.next();
+				if (btn.getName().equals("CheckBox 2")) {
+					find = btn;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// change the bounding box
+			find.setRectangle(new FrameRectangle(2.25455, 5, 3, 0.5,
+					SupportedLinearMeasure.IN));
+			Assert.assertEquals(3.0, find.getRectangle().getWidth());
+			Assert.assertEquals(0.5, find.getRectangle().getHeight());
+			Assert.assertEquals(5.0, find.getRectangle().getY());
+			Assert.assertEquals(2.2546, find.getRectangle().getX());
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetCheckBoxRectangle.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(CheckBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testSetAnchorType() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateCheckBox.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = CheckBox.getSimpleIterator(form);
+			CheckBox find = null;
+			while (iterator.hasNext()) {
+				CheckBox btn = (CheckBox) iterator.next();
+				if (btn.getName().equals("CheckBox 3")) {
+					find = btn;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// change the bounding box
+			find.setAnchorType(AnchorType.TO_CHARACTER);
+			// validate
+			ControlStyleHandler frameStyleHandler = find.getDrawControl()
+					.getStyleHandler();
+			GraphicProperties graphicPropertiesForWrite = frameStyleHandler
+					.getGraphicPropertiesForWrite();
+			Assert.assertEquals(VerticalRelative.PARAGRAPH,
+					graphicPropertiesForWrite.getVerticalRelative());
+			Assert.assertEquals(FrameVerticalPosition.TOP,
+					graphicPropertiesForWrite.getVerticalPosition());
+			Assert.assertEquals(HorizontalRelative.PARAGRAPH,
+					graphicPropertiesForWrite.getHorizontalRelative());
+			Assert.assertEquals(FrameHorizontalPosition.CENTER,
+					graphicPropertiesForWrite.getHorizontalPosition());
+
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetCheckBoxAnchorType.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(CheckBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testSetLabel() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateCheckBox.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = CheckBox.getSimpleIterator(form);
+			CheckBox find = null;
+			while (iterator.hasNext()) {
+				CheckBox btn = (CheckBox) iterator.next();
+				if (btn.getName().equals("CheckBox 4")) {
+					find = btn;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// set new label
+			String newLabel = "Change the content of CheckBox 4.";
+			find.setLabel(newLabel);
+			Assert.assertEquals(newLabel, find.getLabel());
+			// set null value
+			find.setLabel(null);
+			Assert.assertEquals("", find.getLabel());
+
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetCheckBoxLabel.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(CheckBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testCheckedState() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateCheckBox.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = CheckBox.getSimpleIterator(form);
+			CheckBox find = null;
+			while (iterator.hasNext()) {
+				CheckBox btn = (CheckBox) iterator.next();
+				if (btn.getName().equals("CheckBox 3")) {
+					find = btn;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// validate
+			Assert.assertEquals(FormCheckboxState.CHECKED, find
+					.getCurrentState());
+
+			find.setCurrentState(FormCheckboxState.UNKNOWN);
+			Assert.assertEquals(FormCheckboxState.UNKNOWN, find
+					.getCurrentState());
+
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetCheckBoxState.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(CheckBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testSetValue() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateCheckBox.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = CheckBox.getSimpleIterator(form);
+			CheckBox find = null;
+			while (iterator.hasNext()) {
+				CheckBox btn = (CheckBox) iterator.next();
+				if (btn.getName().equals("CheckBox 1")) {
+					find = btn;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// validate
+			Assert.assertEquals("1", find.getValue());
+
+			find.setValue("15");
+			Assert.assertEquals("15", find.getValue());
+
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetCheckBoxValue.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(CheckBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+}

Added: incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/ComboBoxTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/ComboBoxTest.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/ComboBoxTest.java (added)
+++ incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/ComboBoxTest.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,254 @@
+package org.odftoolkit.simple.form;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import junit.framework.Assert;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.odftoolkit.simple.TextDocument;
+import org.odftoolkit.simple.draw.ControlStyleHandler;
+import org.odftoolkit.simple.draw.FrameRectangle;
+import org.odftoolkit.simple.form.FormTypeDefinition.FormCommandType;
+import org.odftoolkit.simple.form.FormTypeDefinition.FormListSourceType;
+import org.odftoolkit.simple.style.GraphicProperties;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.AnchorType;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.FrameVerticalPosition;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.SupportedLinearMeasure;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.VerticalRelative;
+import org.odftoolkit.simple.table.Cell;
+import org.odftoolkit.simple.table.Table;
+import org.odftoolkit.simple.text.Paragraph;
+import org.odftoolkit.simple.utils.ResourceUtilities;
+
+public class ComboBoxTest {
+	private static final FrameRectangle comboRtg = new FrameRectangle(0.7972,
+			1.2862, 2.4441, 0.2669, SupportedLinearMeasure.IN);
+
+	@BeforeClass
+	public static void createForm() {
+		try {
+			TextDocument doc = TextDocument.newTextDocument();
+			Form form = doc.createForm("Test Form");
+
+			FormControl comboBox = form.createComboBox(doc, new FrameRectangle(
+					0.7972, 1.2862, 2.4441, 0.2669, SupportedLinearMeasure.IN),
+					"combo1", "dd", true);
+			String[] items = { "aa", "bb", "cc", "dd", "ee", "ff", "gg", "hh",
+					"ii", "jj" };
+			((ComboBox) comboBox).addItems(items);
+
+			Paragraph para = doc.addParagraph("Insert a combo box here.");
+			comboBox = form.createComboBox(para, comboRtg, "combo2",
+					"default text", true);
+			form.setDataSource("Bibliography");
+			form.setCommandType(FormCommandType.TABLE);
+			form.setCommand("biblio");
+			((ComboBox) comboBox).setListSourceType(FormListSourceType.SQL);
+			((ComboBox) comboBox)
+					.setListSource("SELECT \"Publisher\", \"Identifier\" FROM \"biblio\"");
+			((ComboBox) comboBox).setDataField("Author");
+			comboBox.setAnchorType(AnchorType.AS_CHARACTER);
+
+			Table table = Table.newTable(doc, 2, 2);
+			table.setTableName("Table");
+			Cell cell = table.getCellByPosition("B1");
+			para = cell.addParagraph("Insert a combo box here.");
+			form.createComboBox(para, comboRtg, "combo3", "default text", true);
+
+			doc.save(ResourceUtilities
+					.newTestOutputFile("TestCreateComboBox.odt"));
+
+		} catch (Exception e) {
+			Logger.getLogger(ComboBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testCreateComboBox() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateComboBox.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = ComboBox.getSimpleIterator(form);
+			int count = 0;
+			
+			// combo1
+			ComboBox comboBox = (ComboBox) iterator.next();
+			Assert.assertNotNull(comboBox);
+			Assert.assertEquals("combo" + (++count), comboBox.getName());
+			Assert.assertEquals("dd", comboBox.getValue());
+			ArrayList<String> entries = comboBox.getEntries();
+			Assert.assertEquals("aa", entries.get(0));
+			Assert.assertEquals("jj", entries.get(entries.size() - 1));
+			
+			// combo2
+			comboBox = (ComboBox) iterator.next();
+			Assert.assertNotNull(comboBox);
+			Assert.assertEquals("combo" + (++count), comboBox.getName());
+			Assert.assertEquals(
+					"SELECT \"Publisher\", \"Identifier\" FROM \"biblio\"",
+					comboBox.getListSource());
+			Assert.assertEquals(FormListSourceType.SQL, comboBox
+					.getListSourceType());
+			Assert.assertEquals("Author", comboBox.getDataField());
+		
+			// combo3
+			comboBox = (ComboBox) iterator.next();
+			Assert.assertNotNull(comboBox);
+			Assert.assertEquals("combo" + (++count), comboBox.getName());
+			Assert.assertEquals("default text", comboBox.getValue());
+			Assert.assertEquals(textDoc.getTableByName("Table")
+					.getCellByPosition("B1").getParagraphByIndex(0, true)
+					.getOdfElement(), comboBox.getDrawControl()
+					.getContainerElement());
+
+		} catch (Exception e) {
+			Logger.getLogger(ComboBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+
+	}
+
+	@Test
+	public void testRemoveComboBox() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateComboBox.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = ComboBox.getSimpleIterator(form);
+			while (iterator.hasNext()) {
+				ComboBox combo = (ComboBox) iterator.next();
+				if (combo.getName().equals("ComboBox2")) {
+					iterator.remove();
+					break;
+				}
+			}
+			ComboBox find = null;
+			while (iterator.hasNext()) {
+				ComboBox btn = (ComboBox) iterator.next();
+				if (btn.getName().equals("ComboBox2")) {
+					find = btn;
+					break;
+				}
+			}
+			Assert.assertNull(find);
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestRemoveComboBox.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(ComboBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testSetComboBoxRectangle() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateComboBox.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = ComboBox.getSimpleIterator(form);
+			ComboBox find = null;
+			while (iterator.hasNext()) {
+				ComboBox btn = (ComboBox) iterator.next();
+				if (btn.getName().equals("combo2")) {
+					find = btn;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// change the bounding box
+			find.setRectangle(new FrameRectangle(2.25455, 5, 3, 0.5,
+					SupportedLinearMeasure.IN));
+			Assert.assertEquals(3.0, find.getRectangle().getWidth());
+			Assert.assertEquals(0.5, find.getRectangle().getHeight());
+			Assert.assertEquals(5.0, find.getRectangle().getY());
+			Assert.assertEquals(2.2546, find.getRectangle().getX());
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetComboBoxRectangle.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(ComboBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testSetAnchorType() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateComboBox.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = ComboBox.getSimpleIterator(form);
+			ComboBox find = null;
+			while (iterator.hasNext()) {
+				ComboBox btn = (ComboBox) iterator.next();
+				if (btn.getName().equals("combo3")) {
+					find = btn;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// change the bounding box
+			find.setAnchorType(AnchorType.AS_CHARACTER);
+			// validate
+			ControlStyleHandler frameStyleHandler = find.getDrawControl()
+					.getStyleHandler();
+			GraphicProperties graphicPropertiesForWrite = frameStyleHandler
+					.getGraphicPropertiesForWrite();
+			Assert.assertEquals(VerticalRelative.BASELINE,
+					graphicPropertiesForWrite.getVerticalRelative());
+			Assert.assertEquals(FrameVerticalPosition.TOP,
+					graphicPropertiesForWrite.getVerticalPosition());
+
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetComboBoxAnchorType.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(ComboBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testSetProperties() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateComboBox.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = ComboBox.getSimpleIterator(form);
+			ComboBox find = null;
+			while (iterator.hasNext()) {
+				ComboBox btn = (ComboBox) iterator.next();
+				if (btn.getName().equals("combo3")) {
+					find = btn;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// set new name
+			String newName = "combo4";
+			find.setName(newName);
+			Assert.assertEquals(newName, find.getName());
+			// set new text value
+			find.setCurrentValue(newName);
+			Assert.assertEquals(newName, find.getCurrentValue());
+			// set drop-down visibility
+			find.setFormDropdown(false);
+			Assert.assertEquals(newName, find.getCurrentValue());
+			// set list source
+			String sql = "SELECT DISTINCT \"ISBN\" FROM \"biblio\" ";
+			find.setListSource(sql);
+			Assert.assertEquals(sql, find.getListSource());
+
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetComboBoxProperties.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(ComboBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+}

Added: incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/FieldTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/FieldTest.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/FieldTest.java (added)
+++ incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/FieldTest.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,280 @@
+package org.odftoolkit.simple.form;
+
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import junit.framework.Assert;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.odftoolkit.simple.TextDocument;
+import org.odftoolkit.simple.draw.ControlStyleHandler;
+import org.odftoolkit.simple.draw.FrameRectangle;
+import org.odftoolkit.simple.style.GraphicProperties;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.AnchorType;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.FrameVerticalPosition;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.SupportedLinearMeasure;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.VerticalRelative;
+import org.odftoolkit.simple.text.Paragraph;
+import org.odftoolkit.simple.utils.ResourceUtilities;
+
+public class FieldTest {
+	private static final FrameRectangle fieldRtg = new FrameRectangle(0.5, 2.0,
+			2.9433, 0.5567, SupportedLinearMeasure.IN);
+
+	@BeforeClass
+	public static void createForm() {
+		try {
+			TextDocument doc = TextDocument.newTextDocument();
+			Form form = doc.createForm("Test Form");
+
+			Paragraph.newParagraph(doc);
+			Paragraph.newParagraph(doc);
+			Paragraph.newParagraph(doc);
+			Paragraph para = Paragraph.newParagraph(doc);
+			FormControl dateField = form.createDateField(para, fieldRtg,
+					"DateField", "20120715");
+			((DateField) dateField).setSpinButonVisible(true);
+			((DateField) dateField).setDropDownVisible(true);
+			((DateField) dateField).formatDate("yy/MM/dd", Locale.US);
+
+			Paragraph.newParagraph(doc);
+			Paragraph.newParagraph(doc);
+			Paragraph.newParagraph(doc);
+			para = Paragraph.newParagraph(doc);
+			FormControl timeField = form.createTimeField(para, fieldRtg,
+					"TimeField", "15234000");
+			((TimeField) timeField).setSpinButonVisible(true);
+			((TimeField) timeField).formatTime("HH:mm a", Locale.US);
+
+			Paragraph.newParagraph(doc);
+			Paragraph.newParagraph(doc);
+			Paragraph.newParagraph(doc);
+			para = Paragraph.newParagraph(doc);
+			FormControl numericField = form.createNumericField(para, fieldRtg,
+					"NumericField", "-154.3567");
+			((NumericField) numericField).setDecimalAccuracy(3);
+			((NumericField) numericField).setSpinButonVisible(true);
+
+			Paragraph.newParagraph(doc);
+			Paragraph.newParagraph(doc);
+			Paragraph.newParagraph(doc);
+			para = Paragraph.newParagraph(doc);
+			FormControl patternField = form.createPatternField(para, fieldRtg,
+					"PatternField", "12345");
+			((PatternField) patternField).setLiteralMask("###");
+			((PatternField) patternField).setEditMask("abc");
+			((PatternField) patternField).setSpinButonVisible(true);
+
+			Paragraph.newParagraph(doc);
+			Paragraph.newParagraph(doc);
+			Paragraph.newParagraph(doc);
+			para = Paragraph.newParagraph(doc);
+			para.appendTextContent("insert currency field here:");
+			FormControl currencyField = form.createCurrencyField(para,
+					fieldRtg, "CurrencyField", "135.467");
+			((CurrencyField) currencyField).setCurrencySymbol("CNY");
+			((CurrencyField) currencyField).setDecimalAccuracy(4);
+			((CurrencyField) currencyField).setSpinButonVisible(true);
+
+			doc
+					.save(ResourceUtilities
+							.newTestOutputFile("TestCreateField.odt"));
+
+		} catch (Exception e) {
+			Logger.getLogger(FieldTest.class.getName()).log(Level.SEVERE, null,
+					e);
+		}
+	}
+
+	@Test
+	public void testCreateField() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateField.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = Field.getSimpleIterator(form);
+			if (iterator.hasNext()) {
+				Field field = (Field) iterator.next();
+				Assert.assertNotNull(field);
+				Assert.assertEquals("DateField", field.getName());
+				Assert.assertEquals("20120715", field.getCurrentValue());
+			}
+			if (iterator.hasNext()) {
+				Field field = (Field) iterator.next();
+				Assert.assertNotNull(field);
+				Assert.assertEquals("TimeField", field.getName());
+				Assert.assertEquals("15234000", field.getCurrentValue());
+			}
+			if (iterator.hasNext()) {
+				Field field = (Field) iterator.next();
+				Assert.assertNotNull(field);
+				Assert.assertEquals("NumericField", field.getName());
+				Assert.assertEquals("-154.3567", field.getCurrentValue());
+			}
+			if (iterator.hasNext()) {
+				Field field = (Field) iterator.next();
+				Assert.assertNotNull(field);
+				Assert.assertEquals("PatternField", field.getName());
+				Assert.assertEquals("12345", field.getCurrentValue());
+			}
+			if (iterator.hasNext()) {
+				Field field = (Field) iterator.next();
+				Assert.assertNotNull(field);
+				Assert.assertEquals("CurrencyField", field.getName());
+				Assert.assertEquals("135.467", field.getCurrentValue());
+			}
+		} catch (Exception e) {
+			Logger.getLogger(FieldTest.class.getName()).log(Level.SEVERE, null,
+					e);
+		}
+
+	}
+
+	@Test
+	public void testRemoveField() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateField.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = Field.getSimpleIterator(form);
+			while (iterator.hasNext()) {
+				Field field = (Field) iterator.next();
+				if (field.getName().equals("PatternField")) {
+					iterator.remove();
+					break;
+				}
+			}
+			Field find = null;
+			while (iterator.hasNext()) {
+				Field field = (Field) iterator.next();
+				if (field.getName().equals("PatternField")) {
+					find = field;
+					break;
+				}
+			}
+			Assert.assertNull(find);
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestRemoveField.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(FieldTest.class.getName()).log(Level.SEVERE, null,
+					e);
+		}
+	}
+
+	@Test
+	public void testSetFieldRectangle() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateField.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = Field.getSimpleIterator(form);
+			Field find = null;
+			while (iterator.hasNext()) {
+				Field field = (Field) iterator.next();
+				if (field.getName().equals("TimeField")) {
+					find = field;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// change the bounding box
+			find.setRectangle(new FrameRectangle(2.25455, 0.2, 6, 2.5,
+					SupportedLinearMeasure.IN));
+			Assert.assertEquals(6.0, find.getRectangle().getWidth());
+			Assert.assertEquals(2.5, find.getRectangle().getHeight());
+			Assert.assertEquals(0.2, find.getRectangle().getY());
+			Assert.assertEquals(2.2546, find.getRectangle().getX());
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetFieldRectangle.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(FieldTest.class.getName()).log(Level.SEVERE, null,
+					e);
+		}
+	}
+
+	@Test
+	public void testSetAnchorType() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateField.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = Field.getSimpleIterator(form);
+			Field find = null;
+			while (iterator.hasNext()) {
+				Field field = (Field) iterator.next();
+				if (field.getName().equals("CurrencyField")) {
+					find = field;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// change the bounding box
+			find.setAnchorType(AnchorType.AS_CHARACTER);
+			// validate
+			ControlStyleHandler frameStyleHandler = find.getDrawControl()
+					.getStyleHandler();
+			GraphicProperties graphicPropertiesForWrite = frameStyleHandler
+					.getGraphicPropertiesForWrite();
+			Assert.assertEquals(VerticalRelative.BASELINE,
+					graphicPropertiesForWrite.getVerticalRelative());
+			Assert.assertEquals(FrameVerticalPosition.TOP,
+					graphicPropertiesForWrite.getVerticalPosition());
+
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetFieldAnchorType.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(FieldTest.class.getName()).log(Level.SEVERE, null,
+					e);
+		}
+	}
+
+	@Test
+	public void testSetFormat() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateField.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = Field.getSimpleIterator(form);
+			Field find = null;
+			while (iterator.hasNext()) {
+				Field field = (Field) iterator.next();
+				if (field.getName().equals("DateField")) {
+					find = field;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+
+			// set date format
+			String date = "19840605";
+			String format = "yy-MM-dd";
+			find.setCurrentValue(date);
+			((DateField) find).formatDate(format, Locale.GERMANY);
+			Assert.assertEquals(date, find.getCurrentValue());
+			Assert.assertEquals(format, ((DateField) find).getDateFormat());
+			find.setCurrentValue(null);
+			Assert.assertEquals("", find.getCurrentValue());
+			try {
+				((DateField) find).formatDate(null, Locale.US);
+			} catch (IllegalArgumentException e) {
+				Assert.assertTrue(true);
+			}
+			while (iterator.hasNext()) {
+				Field field = (Field) iterator.next();
+				if (field.getName().equals("TimeField")) {
+					find = field;
+					break;
+				}
+			}
+			
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetFormatValue.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(FieldTest.class.getName()).log(Level.SEVERE, null,
+					e);
+		}
+	}
+}

Added: incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/LabelTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/LabelTest.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/LabelTest.java (added)
+++ incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/LabelTest.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,208 @@
+package org.odftoolkit.simple.form;
+
+import java.util.Iterator;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import junit.framework.Assert;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.odftoolkit.simple.TextDocument;
+import org.odftoolkit.simple.draw.ControlStyleHandler;
+import org.odftoolkit.simple.draw.FrameRectangle;
+import org.odftoolkit.simple.style.GraphicProperties;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.AnchorType;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.FrameVerticalPosition;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.SupportedLinearMeasure;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.VerticalRelative;
+import org.odftoolkit.simple.table.Cell;
+import org.odftoolkit.simple.table.Table;
+import org.odftoolkit.simple.text.Paragraph;
+import org.odftoolkit.simple.utils.ResourceUtilities;
+
+public class LabelTest {
+	private static final FrameRectangle labelRtg = new FrameRectangle(0.5, 1.2553,
+			1.2, 0.5, SupportedLinearMeasure.IN);
+
+	@BeforeClass
+	public static void createForm() {
+		try {
+			TextDocument doc = TextDocument.newTextDocument();
+			Form form = doc.createForm("Test Form");
+			// label1
+			form.createLabel(doc, labelRtg, "Label1", "Label1");
+			// label2
+			Label label = (Label) form.createLabel(doc, labelRtg, "Label2",
+					"Label2");
+			label.setAnchorType(AnchorType.TO_CHARACTER);
+			// label3
+			Paragraph para = doc.addParagraph("Insert a Label here.");
+			form.createLabel(para, labelRtg, "Label3", "Label3");
+			// label4
+			Table table1 = Table.newTable(doc, 2, 2);
+			Cell cell = table1.getCellByPosition("B1");
+			para = cell.addParagraph("Insert a Label here.");
+			form.createLabel(para, labelRtg, "Label4", "Label4");
+			doc
+					.save(ResourceUtilities
+							.newTestOutputFile("TestCreateLabel.odt"));
+
+		} catch (Exception e) {
+			Logger.getLogger(LabelTest.class.getName()).log(Level.SEVERE, null,
+					e);
+		}
+	}
+
+	@Test
+	public void testCreateLabel() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateLabel.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = Label.getSimpleIterator(form);
+			int count = 0;
+			while (iterator.hasNext()) {
+				Label label = (Label) iterator.next();
+				Assert.assertNotNull(label);
+				Assert.assertEquals("Label" + (++count), label.getName());
+				Assert.assertEquals("Label" + (count), label.getLabel());
+			}
+		} catch (Exception e) {
+			Logger.getLogger(LabelTest.class.getName()).log(Level.SEVERE, null,
+					e);
+		}
+
+	}
+
+	@Test
+	public void testRemoveLabel() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateLabel.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = Label.getSimpleIterator(form);
+			while (iterator.hasNext()) {
+				Label label = (Label) iterator.next();
+				if (label.getName().equals("Label2")) {
+					iterator.remove();
+					break;
+				}
+			}
+			Label find = null;
+			while (iterator.hasNext()) {
+				Label label = (Label) iterator.next();
+				if (label.getName().equals("Label2")) {
+					find = label;
+					break;
+				}
+			}
+			Assert.assertNull(find);
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestRemoveLabel.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(LabelTest.class.getName()).log(Level.SEVERE, null,
+					e);
+		}
+	}
+
+	@Test
+	public void testSetLabelRectangle() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateLabel.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = Label.getSimpleIterator(form);
+			Label find = null;
+			while (iterator.hasNext()) {
+				Label label = (Label) iterator.next();
+				if (label.getName().equals("Label2")) {
+					find = label;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// change the bounding box
+			find.setRectangle(new FrameRectangle(2.25455, 5, 3, 0.5,
+					SupportedLinearMeasure.IN));
+			Assert.assertEquals(3.0, find.getRectangle().getWidth());
+			Assert.assertEquals(0.5, find.getRectangle().getHeight());
+			Assert.assertEquals(5.0, find.getRectangle().getY());
+			Assert.assertEquals(2.2546, find.getRectangle().getX());
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetLabelRectangle.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(LabelTest.class.getName()).log(Level.SEVERE, null,
+					e);
+		}
+	}
+
+	@Test
+	public void testSetAnchorType() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateLabel.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = Label.getSimpleIterator(form);
+			Label find = null;
+			while (iterator.hasNext()) {
+				Label label = (Label) iterator.next();
+				if (label.getName().equals("Label2")) {
+					find = label;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// change the bounding box
+			find.setAnchorType(AnchorType.AS_CHARACTER);
+			// validate
+			ControlStyleHandler frameStyleHandler = find.getDrawControl()
+					.getStyleHandler();
+			GraphicProperties graphicPropertiesForWrite = frameStyleHandler
+					.getGraphicPropertiesForWrite();
+			Assert.assertEquals(VerticalRelative.BASELINE,
+					graphicPropertiesForWrite.getVerticalRelative());
+			Assert.assertEquals(FrameVerticalPosition.TOP,
+					graphicPropertiesForWrite.getVerticalPosition());
+
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetLabelAnchorType.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(LabelTest.class.getName()).log(Level.SEVERE, null,
+					e);
+		}
+	}
+
+	@Test
+	public void testSetLabel() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateLabel.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = Label.getSimpleIterator(form);
+			Label find = null;
+			while (iterator.hasNext()) {
+				Label label = (Label) iterator.next();
+				if (label.getName().equals("Label3")) {
+					find = label;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// set new label
+			String newLabel = "Change the content of Label 4.";
+			find.setLabel(newLabel);
+			Assert.assertEquals(newLabel, find.getLabel());
+			// set null value
+			find.setLabel(null);
+			Assert.assertEquals("", find.getLabel());
+
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetLabelLabel.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(LabelTest.class.getName()).log(Level.SEVERE, null,
+					e);
+		}
+	}
+
+}

Added: incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/ListBoxTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/ListBoxTest.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/ListBoxTest.java (added)
+++ incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/ListBoxTest.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,254 @@
+package org.odftoolkit.simple.form;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import junit.framework.Assert;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.odftoolkit.simple.TextDocument;
+import org.odftoolkit.simple.draw.ControlStyleHandler;
+import org.odftoolkit.simple.draw.FrameRectangle;
+import org.odftoolkit.simple.form.FormTypeDefinition.FormCommandType;
+import org.odftoolkit.simple.form.FormTypeDefinition.FormListSourceType;
+import org.odftoolkit.simple.style.GraphicProperties;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.AnchorType;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.FrameVerticalPosition;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.SupportedLinearMeasure;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.VerticalRelative;
+import org.odftoolkit.simple.table.Cell;
+import org.odftoolkit.simple.table.Table;
+import org.odftoolkit.simple.text.Paragraph;
+import org.odftoolkit.simple.utils.ResourceUtilities;
+
+public class ListBoxTest {
+	private static final FrameRectangle listBoxRtg = new FrameRectangle(0.5752,
+			0.1429, 2.3307, 0.8398, SupportedLinearMeasure.IN);
+
+	@BeforeClass
+	public static void createForm() {
+		try {
+			TextDocument doc = TextDocument.newTextDocument();
+			Form form = doc.createForm("Test Form");
+
+			// list box1
+			FormControl listBox = form.createListBox(doc, listBoxRtg, "list1",
+					true, false);
+			String[] items = { "aa", "bb", "cc", "dd", "ee", "ff", "gg", "hh",
+					"ii", "jj" };
+			((ListBox) listBox).addItems(items);
+
+			// list box2
+			Paragraph para = doc.addParagraph("Insert a list box here.");
+			listBox = form
+					.createListBox(para, listBoxRtg, "list2", false, true);
+			form.setDataSource("Bibliography");
+			form.setCommandType(FormCommandType.TABLE);
+			form.setCommand("biblio");
+			((ListBox) listBox).setListSourceType(FormListSourceType.SQL);
+			((ListBox) listBox)
+					.setListSource("SELECT \"Publisher\", \"Identifier\" FROM \"biblio\"");
+			((ListBox) listBox).setDataField("Author");
+			listBox.setAnchorType(AnchorType.AS_CHARACTER);
+
+			// list box3
+			Table table = Table.newTable(doc, 2, 2);
+			table.setTableName("Table");
+			Cell cell = table.getCellByPosition("B1");
+			para = cell.addParagraph("Insert a list box here.");
+			form.createListBox(para, listBoxRtg, "list3", false, true);
+
+			doc.save(ResourceUtilities
+					.newTestOutputFile("TestCreateListBox.odt"));
+
+		} catch (Exception e) {
+			Logger.getLogger(ListBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testCreateListBox() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateListBox.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = ListBox.getSimpleIterator(form);
+			int count = 0;
+
+			// list1
+			ListBox listBox = (ListBox) iterator.next();
+			Assert.assertNotNull(listBox);
+			Assert.assertEquals("list" + (++count), listBox.getName());
+			ArrayList<String> entries = listBox.getEntries();
+			Assert.assertEquals("aa", entries.get(0));
+			Assert.assertEquals("jj", entries.get(entries.size() - 1));
+
+			// list2
+			listBox = (ListBox) iterator.next();
+			Assert.assertNotNull(listBox);
+			Assert.assertEquals("list" + (++count), listBox.getName());
+			Assert.assertEquals(
+					"SELECT \"Publisher\", \"Identifier\" FROM \"biblio\"",
+					listBox.getListSource());
+			Assert.assertEquals(FormListSourceType.SQL, listBox
+					.getListSourceType());
+			Assert.assertEquals("Author", listBox.getDataField());
+
+			// list3
+			listBox = (ListBox) iterator.next();
+			Assert.assertNotNull(listBox);
+			Assert.assertEquals("list" + (++count), listBox.getName());
+			Assert.assertEquals(textDoc.getTableByName("Table")
+					.getCellByPosition("B1").getParagraphByIndex(0, true)
+					.getOdfElement(), listBox.getDrawControl()
+					.getContainerElement());
+
+		} catch (Exception e) {
+			Logger.getLogger(ListBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+
+	}
+
+	@Test
+	public void testRemoveListBox() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateListBox.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = ListBox.getSimpleIterator(form);
+			while (iterator.hasNext()) {
+				ListBox list = (ListBox) iterator.next();
+				if (list.getName().equals("list2")) {
+					iterator.remove();
+					break;
+				}
+			}
+			ListBox find = null;
+			while (iterator.hasNext()) {
+				ListBox listbox = (ListBox) iterator.next();
+				if (listbox.getName().equals("list2")) {
+					find = listbox;
+					break;
+				}
+			}
+			Assert.assertNull(find);
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestRemoveListBox.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(ListBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testSetListBoxRectangle() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateListBox.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = ListBox.getSimpleIterator(form);
+			ListBox find = null;
+			while (iterator.hasNext()) {
+				ListBox listbox = (ListBox) iterator.next();
+				if (listbox.getName().equals("list2")) {
+					find = listbox;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// change the bounding box
+			find.setRectangle(new FrameRectangle(2.25455, 5, 3, 0.5,
+					SupportedLinearMeasure.IN));
+			Assert.assertEquals(3.0, find.getRectangle().getWidth());
+			Assert.assertEquals(0.5, find.getRectangle().getHeight());
+			Assert.assertEquals(5.0, find.getRectangle().getY());
+			Assert.assertEquals(2.2546, find.getRectangle().getX());
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetListBoxRectangle.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(ListBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testSetAnchorType() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateListBox.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = ListBox.getSimpleIterator(form);
+			ListBox find = null;
+			while (iterator.hasNext()) {
+				ListBox listbox = (ListBox) iterator.next();
+				if (listbox.getName().equals("list3")) {
+					find = listbox;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// change the bounding box
+			find.setAnchorType(AnchorType.AS_CHARACTER);
+			// validate
+			ControlStyleHandler frameStyleHandler = find.getDrawControl()
+					.getStyleHandler();
+			GraphicProperties graphicPropertiesForWrite = frameStyleHandler
+					.getGraphicPropertiesForWrite();
+			Assert.assertEquals(VerticalRelative.BASELINE,
+					graphicPropertiesForWrite.getVerticalRelative());
+			Assert.assertEquals(FrameVerticalPosition.TOP,
+					graphicPropertiesForWrite.getVerticalPosition());
+
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetListBoxAnchorType.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(ListBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testSetProperties() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateListBox.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = ListBox.getSimpleIterator(form);
+			ListBox find = null;
+			while (iterator.hasNext()) {
+				ListBox listbox = (ListBox) iterator.next();
+				if (listbox.getName().equals("list2")) {
+					find = listbox;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// set new name
+			String newName = "list4";
+			find.setName(newName);
+			Assert.assertEquals(newName, find.getName());
+			// set drop-down visibility
+			find.setFormDropdown(false);
+			Assert.assertEquals(false, find.getFormDropdown());
+			// set multi-selection
+			find.setFormMultiSelection(true);
+			Assert.assertEquals(true, find.getFormMultiSelection());
+			// set list source
+			String sql = "SELECT DISTINCT \"ISBN\" FROM \"biblio\" ";
+			find.setListSource(sql);
+			Assert.assertEquals(sql, find.getListSource());
+
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetListBoxProperties.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(ListBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+}

Added: incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/RadioButtonTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/RadioButtonTest.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/RadioButtonTest.java (added)
+++ incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/RadioButtonTest.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,290 @@
+package org.odftoolkit.simple.form;
+
+import java.util.Iterator;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import junit.framework.Assert;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.odftoolkit.simple.TextDocument;
+import org.odftoolkit.simple.draw.ControlStyleHandler;
+import org.odftoolkit.simple.draw.FrameRectangle;
+import org.odftoolkit.simple.style.GraphicProperties;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.AnchorType;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.FrameHorizontalPosition;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.FrameVerticalPosition;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.HorizontalRelative;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.SupportedLinearMeasure;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.VerticalRelative;
+import org.odftoolkit.simple.table.Cell;
+import org.odftoolkit.simple.table.Table;
+import org.odftoolkit.simple.text.Paragraph;
+import org.odftoolkit.simple.utils.ResourceUtilities;
+
+public class RadioButtonTest {
+	private final static FrameRectangle radioRtg = new FrameRectangle(0.7972,
+			1.2862, 2.4441, 0.2669, SupportedLinearMeasure.IN);
+
+	@BeforeClass
+	public static void createForm() {
+		try {
+			TextDocument doc = TextDocument.newTextDocument();
+			Form form = doc.createForm("Test Form");
+
+			// radiobox 1
+			RadioButton radiobutton = (RadioButton) form.createRadioButton(doc,
+					radioRtg, "RadioGroup1", "RadioButton 1", "1");
+
+			// radiobutton 2
+			Paragraph para = doc
+					.addParagraph("RadioButton2 anchor to heading.");
+			para.applyHeading();
+			form.createRadioButton(para, radioRtg, "RadioGroup1",
+					"RadioButton 2", "2");
+
+			// radiobutton 3
+			para = doc.addParagraph("Insert radiobutton3 here, as_char.");
+			radiobutton = (RadioButton) form.createRadioButton(para, radioRtg,
+					"RadioGroup1", "RadioButton 3", "3");
+			radiobutton.setCurrentSelected(true);
+			radiobutton.setAnchorType(AnchorType.AS_CHARACTER);
+
+			Table table1 = Table.newTable(doc, 2, 2);
+			Cell cell = table1.getCellByPosition("B1");
+			para = cell.addParagraph("Insert a check box here.");
+			form.createRadioButton(para, radioRtg, "RadioGroup1",
+					"RadioButton 4", "4");
+			doc.save(ResourceUtilities
+					.newTestOutputFile("TestCreateRadioButton.odt"));
+
+		} catch (Exception e) {
+			Logger.getLogger(RadioButtonTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testCreateRadioButton() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateRadioButton.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = RadioButton
+					.getSimpleIterator(form);
+			int count = 0;
+			while (iterator.hasNext()) {
+				RadioButton radio = (RadioButton) iterator.next();
+				Assert.assertNotNull(radio);
+				Assert.assertEquals("RadioGroup1", radio.getName());
+				Assert.assertEquals("RadioButton " + (++count), radio
+						.getLabel());
+			}
+		} catch (Exception e) {
+			Logger.getLogger(RadioButtonTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+
+	}
+
+	@Test
+	public void testRemoveRadioButton() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateRadioButton.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = RadioButton
+					.getSimpleIterator(form);
+			while (iterator.hasNext()) {
+				RadioButton radio = (RadioButton) iterator.next();
+				if (radio.getLabel().equals("RadioButton 2")) {
+					iterator.remove();
+					break;
+				}
+			}
+			RadioButton find = null;
+			while (iterator.hasNext()) {
+				RadioButton radio = (RadioButton) iterator.next();
+				if (radio.getLabel().equals("RadioButton 2")) {
+					find = radio;
+					break;
+				}
+			}
+			Assert.assertNull(find);
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestRemoveRadioButton.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(RadioButtonTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testSetRadioButtonRectangle() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateRadioButton.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = RadioButton
+					.getSimpleIterator(form);
+			RadioButton find = null;
+			while (iterator.hasNext()) {
+				RadioButton radio = (RadioButton) iterator.next();
+				if (radio.getLabel().equals("RadioButton 2")) {
+					find = radio;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// change the bounding box
+			find.setRectangle(new FrameRectangle(2.25455, 5, 3, 0.5,
+					SupportedLinearMeasure.IN));
+			Assert.assertEquals(3.0, find.getRectangle().getWidth());
+			Assert.assertEquals(0.5, find.getRectangle().getHeight());
+			Assert.assertEquals(5.0, find.getRectangle().getY());
+			Assert.assertEquals(2.2546, find.getRectangle().getX());
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetRadioButtonRectangle.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(RadioButtonTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testSetAnchorType() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateRadioButton.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = RadioButton
+					.getSimpleIterator(form);
+			RadioButton find = null;
+			while (iterator.hasNext()) {
+				RadioButton radio = (RadioButton) iterator.next();
+				if (radio.getLabel().equals("RadioButton 3")) {
+					find = radio;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// change the bounding box
+			find.setAnchorType(AnchorType.TO_CHARACTER);
+			// validate
+			ControlStyleHandler frameStyleHandler = find.getDrawControl()
+					.getStyleHandler();
+			GraphicProperties graphicPropertiesForWrite = frameStyleHandler
+					.getGraphicPropertiesForWrite();
+			Assert.assertEquals(VerticalRelative.PARAGRAPH,
+					graphicPropertiesForWrite.getVerticalRelative());
+			Assert.assertEquals(FrameVerticalPosition.TOP,
+					graphicPropertiesForWrite.getVerticalPosition());
+			Assert.assertEquals(HorizontalRelative.PARAGRAPH,
+					graphicPropertiesForWrite.getHorizontalRelative());
+			Assert.assertEquals(FrameHorizontalPosition.CENTER,
+					graphicPropertiesForWrite.getHorizontalPosition());
+
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetRadioButtonAnchorType.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(RadioButtonTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testSetLabel() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateRadioButton.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = RadioButton
+					.getSimpleIterator(form);
+			RadioButton find = null;
+			while (iterator.hasNext()) {
+				RadioButton radio = (RadioButton) iterator.next();
+				if (radio.getLabel().equals("RadioButton 4")) {
+					find = radio;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// set new label
+			String newLabel = "Change the content of RadioButton 4.";
+			find.setLabel(newLabel);
+			Assert.assertEquals(newLabel, find.getLabel());
+			// set null value
+			find.setLabel(null);
+			Assert.assertEquals("", find.getLabel());
+
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetRadioButtonLabel.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(RadioButtonTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testCheckedState() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateRadioButton.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = RadioButton
+					.getSimpleIterator(form);
+			RadioButton find = null;
+			while (iterator.hasNext()) {
+				RadioButton radio = (RadioButton) iterator.next();
+				if (radio.getLabel().equals("RadioButton 3")) {
+					find = radio;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// validate
+			Assert.assertEquals(true, find.getCurrentSelected());
+
+			find.setCurrentSelected(false);
+			Assert.assertEquals(false, find.getCurrentSelected());
+
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetRadioButtonState.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(RadioButtonTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testSetValue() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateRadioButton.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = RadioButton
+					.getSimpleIterator(form);
+			RadioButton find = null;
+			while (iterator.hasNext()) {
+				RadioButton radio = (RadioButton) iterator.next();
+				if (radio.getLabel().equals("RadioButton 1")) {
+					find = radio;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// validate
+			Assert.assertEquals("1", find.getValue());
+
+			find.setValue("15");
+			Assert.assertEquals("15", find.getValue());
+
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetRadioButtonValue.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(RadioButtonTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+}

Added: incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/TextBoxTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/TextBoxTest.java?rev=1411080&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/TextBoxTest.java (added)
+++ incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/form/TextBoxTest.java Mon Nov 19 06:51:44 2012
@@ -0,0 +1,221 @@
+package org.odftoolkit.simple.form;
+
+import java.util.Iterator;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import junit.framework.Assert;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.odftoolkit.simple.TextDocument;
+import org.odftoolkit.simple.draw.ControlStyleHandler;
+import org.odftoolkit.simple.draw.FrameRectangle;
+import org.odftoolkit.simple.style.GraphicProperties;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.AnchorType;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.FrameVerticalPosition;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.SupportedLinearMeasure;
+import org.odftoolkit.simple.style.StyleTypeDefinitions.VerticalRelative;
+import org.odftoolkit.simple.table.Cell;
+import org.odftoolkit.simple.table.Table;
+import org.odftoolkit.simple.text.Paragraph;
+import org.odftoolkit.simple.utils.ResourceUtilities;
+
+public class TextBoxTest {
+	private static final FrameRectangle textBoxRtg = new FrameRectangle(0.5,
+			0.2846, 2.9432, 0.8567, SupportedLinearMeasure.IN);
+
+	@BeforeClass
+	public static void createForm() {
+		try {
+			TextDocument doc = TextDocument.newTextDocument();
+			Form form = doc.createForm("Test Form");
+			// textbox1
+			form.createTextBox(doc, textBoxRtg, "TextBox1", "TextBox1", true);
+
+			// textbox2
+			Paragraph para = doc.addParagraph("Insert a text box here.");
+			FormControl textBox = form.createTextBox(para, textBoxRtg,
+					"TextBox2", "TextBox2", false);
+			textBox.setAnchorType(AnchorType.TO_CHARACTER);
+
+			// textbox3
+			Table table = Table.newTable(doc, 2, 2);
+			Cell cell = table.getCellByPosition("B1");
+			para = cell.addParagraph("Insert a text box here.");
+			form.createTextBox(para, textBoxRtg, "TextBox3", "TextBox3", false);
+			
+			doc.save(ResourceUtilities
+					.newTestOutputFile("TestCreateTextBox.odt"));
+
+		} catch (Exception e) {
+			Logger.getLogger(TextBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testCreateCheckBox() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateTextBox.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = CheckBox.getSimpleIterator(form);
+			int count = 0;
+			while (iterator.hasNext()) {
+				TextBox textBox = (TextBox) iterator.next();
+				Assert.assertNotNull(textBox);
+				Assert.assertEquals("TextBox" + (++count), textBox.getName());
+				Assert.assertEquals("TextBox" + (count), textBox
+						.getCurrentValue());
+			}
+		} catch (Exception e) {
+			Logger.getLogger(TextBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+
+	}
+
+	@Test
+	public void testRemoveCheckBox() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateTextBox.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = TextBox.getSimpleIterator(form);
+			while (iterator.hasNext()) {
+				TextBox textBox = (TextBox) iterator.next();
+				if (textBox.getName().equals("TextBox2")) {
+					iterator.remove();
+					break;
+				}
+			}
+			CheckBox find = null;
+			while (iterator.hasNext()) {
+				CheckBox textBox = (CheckBox) iterator.next();
+				if (textBox.getName().equals("TextBox2")) {
+					find = textBox;
+					break;
+				}
+			}
+			Assert.assertNull(find);
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestRemoveTextBox.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(TextBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testSetTextBoxRectangle() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateTextBox.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = TextBox.getSimpleIterator(form);
+			TextBox find = null;
+			while (iterator.hasNext()) {
+				TextBox textBox = (TextBox) iterator.next();
+				if (textBox.getName().equals("TextBox2")) {
+					find = textBox;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// change the bounding box
+			find.setRectangle(new FrameRectangle(2.25455, 5, 3, 0.5,
+					SupportedLinearMeasure.IN));
+			Assert.assertEquals(3.0, find.getRectangle().getWidth());
+			Assert.assertEquals(0.5, find.getRectangle().getHeight());
+			Assert.assertEquals(5.0, find.getRectangle().getY());
+			Assert.assertEquals(2.2546, find.getRectangle().getX());
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetTextBoxRectangle.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(TextBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testSetAnchorType() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateTextBox.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = TextBox.getSimpleIterator(form);
+			TextBox find = null;
+			while (iterator.hasNext()) {
+				TextBox textBox = (TextBox) iterator.next();
+				if (textBox.getName().equals("TextBox3")) {
+					find = textBox;
+					break;
+				}
+			}
+			Assert.assertNotNull(find);
+			// change the bounding box
+			find.setAnchorType(AnchorType.AS_CHARACTER);
+			// validate
+			ControlStyleHandler frameStyleHandler = find.getDrawControl()
+					.getStyleHandler();
+			GraphicProperties graphicPropertiesForWrite = frameStyleHandler
+					.getGraphicPropertiesForWrite();
+			Assert.assertEquals(VerticalRelative.BASELINE,
+					graphicPropertiesForWrite.getVerticalRelative());
+			Assert.assertEquals(FrameVerticalPosition.TOP,
+					graphicPropertiesForWrite.getVerticalPosition());
+
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetTextBoxAnchorType.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(TextBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+
+	@Test
+	public void testSetTextContent() {
+		try {
+			TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities
+					.getTestResourceAsStream("TestCreateTextBox.odt"));
+			Form form = textDoc.getFormByName("Test Form");
+			Iterator<FormControl> iterator = TextBox.getSimpleIterator(form);
+			TextBox textbox1 = null;
+			while (iterator.hasNext()) {
+				TextBox textBox = (TextBox) iterator.next();
+				if (textBox.getName().equals("TextBox1")) {
+					textbox1 = textBox;
+					break;
+				}
+			}
+			TextBox textbox3 = null;
+			while (iterator.hasNext()) {
+				TextBox textBox = (TextBox) iterator.next();
+				if (textBox.getName().equals("TextBox3")) {
+					textbox3 = textBox;
+					break;
+				}
+			}
+			Assert.assertNotNull(textbox3);
+			Assert.assertNotNull(textbox1);
+			// set one-line text
+			String textOneLine = "Input text content into this text box.";
+			textbox3.setCurrentValue(textOneLine);
+			Assert.assertEquals(textOneLine, textbox3.getCurrentValue());
+			// set multi-line textString
+			String textMultiLine = "This text box allow input multi-line content.\n This is the second line.";
+			textbox1.setCurrentValue(textMultiLine);
+			Assert.assertEquals(textMultiLine, textbox1.getCurrentValue());
+			// set null value
+			textbox3.setCurrentValue(null);
+			Assert.assertEquals("", textbox3.getCurrentValue());
+
+			textDoc.save(ResourceUtilities
+					.newTestOutputFile("TestSetTextBoxContent.odt"));
+		} catch (Exception e) {
+			Logger.getLogger(TextBoxTest.class.getName()).log(Level.SEVERE,
+					null, e);
+		}
+	}
+}



Mime
View raw message