incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fh...@apache.org
Subject svn commit: r1417744 - in /incubator/odf/trunk: odfdom/src/main/java/org/odftoolkit/odfdom/doc/table/ odfdom/src/test/java/org/odftoolkit/odfdom/doc/table/ simple/src/main/java/org/odftoolkit/simple/table/ simple/src/test/java/org/odftoolkit/simple/table/
Date Thu, 06 Dec 2012 06:25:07 GMT
Author: fhopf
Date: Thu Dec  6 06:25:05 2012
New Revision: 1417744

URL: http://svn.apache.org/viewvc?rev=1417744&view=rev
Log:
test and fix for ODFTOOLKIT-325 NPE in cell.getTimeValue()

Modified:
    incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/doc/table/OdfTableCell.java
    incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/doc/table/TableCellTest.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/table/Cell.java
    incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableCellTest.java

Modified: incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/doc/table/OdfTableCell.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/doc/table/OdfTableCell.java?rev=1417744&r1=1417743&r2=1417744&view=diff
==============================================================================
--- incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/doc/table/OdfTableCell.java
(original)
+++ incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/doc/table/OdfTableCell.java
Thu Dec  6 06:25:05 2012
@@ -883,6 +883,9 @@ public class OdfTableCell {
 	public Calendar getTimeValue() {
 		if (getTypeAttr() == OfficeValueTypeAttribute.Value.TIME) {
 			String timeStr = mCellElement.getOfficeTimeValueAttribute();
+                        if (timeStr == null) {
+                            return null;
+                        }
 			Date date = parseString(timeStr, DEFAULT_TIME_FORMAT);
 			Calendar calender = Calendar.getInstance();
 			calender.setTime(date);

Modified: incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/doc/table/TableCellTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/doc/table/TableCellTest.java?rev=1417744&r1=1417743&r2=1417744&view=diff
==============================================================================
--- incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/doc/table/TableCellTest.java
(original)
+++ incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/doc/table/TableCellTest.java
Thu Dec  6 06:25:05 2012
@@ -32,12 +32,12 @@ import java.util.logging.Logger;
 import junit.framework.Assert;
 
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.odftoolkit.odfdom.doc.OdfSpreadsheetDocument;
 import org.odftoolkit.odfdom.doc.OdfTextDocument;
 import org.odftoolkit.odfdom.dom.OdfContentDom;
 import org.odftoolkit.odfdom.dom.OdfStylesDom;
+import org.odftoolkit.odfdom.dom.attribute.office.OfficeValueTypeAttribute;
 import org.odftoolkit.odfdom.dom.element.draw.DrawFrameElement;
 import org.odftoolkit.odfdom.dom.element.draw.DrawImageElement;
 import org.odftoolkit.odfdom.dom.element.style.StyleParagraphPropertiesElement;
@@ -50,7 +50,6 @@ import org.odftoolkit.odfdom.incubator.d
 import org.odftoolkit.odfdom.type.Color;
 import org.odftoolkit.odfdom.utils.ResourceUtilities;
 
-@Ignore
 public class TableCellTest {
 
 	final static String SAMPLE_SPREADSHEET = "TestSpreadsheetTable";
@@ -1051,4 +1050,23 @@ public class TableCellTest {
 			Assert.fail();
 		}
 	}
+        
+        @Test
+        public void testGetFromEmptyDateValue() throws Exception {
+            OdfSpreadsheetDocument doc = OdfSpreadsheetDocument.newSpreadsheetDocument();
+            OdfTable table = OdfTable.newTable(doc);
+            OdfTableCell dateCell = table.appendRow().getCellByIndex(0);
+            dateCell.setValueType(OfficeValueTypeAttribute.Value.DATE.toString());
+            Assert.assertNull(dateCell.getDateValue());
+        }
+        
+        @Test
+        public void testGetFromEmptyTimeValue() throws Exception {
+            OdfSpreadsheetDocument doc = OdfSpreadsheetDocument.newSpreadsheetDocument();
+            OdfTable table = OdfTable.newTable(doc);
+            OdfTableCell timeCell = table.appendRow().getCellByIndex(0);
+            timeCell.setValueType(OfficeValueTypeAttribute.Value.TIME.toString());
+            Assert.assertNull(timeCell.getTimeValue());
+        }
+        
 }

Modified: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/table/Cell.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/table/Cell.java?rev=1417744&r1=1417743&r2=1417744&view=diff
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/table/Cell.java (original)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/table/Cell.java Thu Dec
 6 06:25:05 2012
@@ -1201,6 +1201,9 @@ public class Cell extends Component impl
 	public Calendar getTimeValue() {
 		if (getTypeAttr() == OfficeValueTypeAttribute.Value.TIME) {
 			String timeStr = mCellElement.getOfficeTimeValueAttribute();
+                        if (timeStr == null) {
+                            return null;
+                        }
 			Date date = parseString(timeStr, DEFAULT_TIME_FORMAT);
 			Calendar calender = Calendar.getInstance();
 			calender.setTime(date);

Modified: incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableCellTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableCellTest.java?rev=1417744&r1=1417743&r2=1417744&view=diff
==============================================================================
--- incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableCellTest.java
(original)
+++ incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableCellTest.java
Thu Dec  6 06:25:05 2012
@@ -35,6 +35,7 @@ import junit.framework.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.odftoolkit.odfdom.dom.OdfContentDom;
+import org.odftoolkit.odfdom.dom.attribute.office.OfficeValueTypeAttribute;
 import org.odftoolkit.odfdom.dom.element.draw.DrawFrameElement;
 import org.odftoolkit.odfdom.dom.element.style.StyleParagraphPropertiesElement;
 import org.odftoolkit.odfdom.dom.style.OdfStyleFamily;
@@ -581,6 +582,22 @@ public class TableCellTest {
 		Assert.assertEquals(0, fcell.getDateValue().compareTo(expectedCalendar));
 	}
 
+        @Test
+        public void testGetFromEmptyDateValue() throws Exception {
+            Table table = odsdoc.getTableByName("Sheet1");
+            Cell cell = table.appendRow().getCellByIndex(1);
+            cell.setValueType(OfficeValueTypeAttribute.Value.DATE.toString());
+            Assert.assertNull(cell.getDateValue());
+        }
+        
+        @Test
+        public void testGetFromEmptyTimeValue() throws Exception {
+            Table table = odsdoc.getTableByName("Sheet1");
+            Cell cell = table.appendRow().getCellByIndex(1);
+            cell.setValueType(OfficeValueTypeAttribute.Value.TIME.toString());
+            Assert.assertNull(cell.getTimeValue());
+        }
+
 	@Test
 	public void testGetSetStringValue() {
 		int rowindex = 6, columnindex = 0;



Mime
View raw message