aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org
diff options
context:
space:
mode:
authorYegor Kozlov <yegor@apache.org>2009-07-12 07:21:04 +0000
committerYegor Kozlov <yegor@apache.org>2009-07-12 07:21:04 +0000
commit35c4438666b32e4a6579c2e525df66e24818fb81 (patch)
treea790a921a7c23ebc3e59fb0fac2deb2f209c8b43 /src/testcases/org
parent3601f7f8c60b971f77ef80f51c2e91bc28be59b0 (diff)
downloadpoi-35c4438666b32e4a6579c2e525df66e24818fb81.tar.gz
poi-35c4438666b32e4a6579c2e525df66e24818fb81.zip
Fixed HyperlinkRecord to properly handle URL monikers, see Bugzilla 47498
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@793281 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org')
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java39
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java4
-rwxr-xr-xsrc/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java22
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java6
4 files changed, 65 insertions, 6 deletions
diff --git a/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java b/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java
index 4232af7c78..3383bccbbf 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java
@@ -243,7 +243,24 @@ public final class TestHyperlinkRecord extends TestCase {
"43 00 32 00 00 00");
- private void confirmGUID(GUID expectedGuid, GUID actualGuid) {
+ /**
+ * From Bugzilla 47498
+ */
+ private static byte[] data_47498 = {
+ 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, (byte)0xD0, (byte)0xC9,
+ (byte)0xEA, 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, 0x11, (byte)0x8C,
+ (byte)0x82, 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B, 0x02, 0x00,
+ 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x50, 0x00,
+ 0x44, 0x00, 0x46, 0x00, 0x00, 0x00, (byte)0xE0, (byte)0xC9, (byte)0xEA,
+ 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, (byte)0x11, (byte)0x8C, (byte)0x82,
+ 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B, 0x28, 0x00, 0x00, 0x00,
+ 0x74, 0x00, 0x65, 0x00, 0x73, 0x00, 0x74, 0x00, 0x66, 0x00, 0x6F, 0x00,
+ 0x6C, 0x00, 0x64, 0x00, 0x65, 0x00, 0x72, 0x00, 0x2F, 0x00, 0x74, 0x00,
+ 0x65, 0x00, 0x73, 0x00, 0x74, 0x00, 0x2E, 0x00, 0x50, 0x00, 0x44, 0x00,
+ 0x46, 0x00, 0x00, 0x00};
+
+
+ private void confirmGUID(GUID expectedGuid, GUID actualGuid) {
assertEquals(expectedGuid, actualGuid);
}
public void testReadURLLink(){
@@ -479,4 +496,24 @@ public final class TestHyperlinkRecord extends TestCase {
assertEquals(new String(HexDump.longToHex(d4)), new String(HexDump.longToHex(g.getD4())));
}
+ public void test47498(){
+ RecordInputStream is = TestcaseRecordInputStream.create(HyperlinkRecord.sid, data_47498);
+ HyperlinkRecord link = new HyperlinkRecord(is);
+ assertEquals(2, link.getFirstRow());
+ assertEquals(2, link.getLastRow());
+ assertEquals(0, link.getFirstColumn());
+ assertEquals(0, link.getLastColumn());
+ confirmGUID(HyperlinkRecord.STD_MONIKER, link.getGuid());
+ confirmGUID(HyperlinkRecord.URL_MONIKER, link.getMoniker());
+ assertEquals(2, link.getLabelOptions());
+ int opts = HyperlinkRecord.HLINK_URL | HyperlinkRecord.HLINK_LABEL;
+ assertEquals(opts, link.getLinkOptions());
+ assertEquals(0, link.getFileOptions());
+
+ assertEquals("PDF", link.getLabel());
+ assertEquals("testfolder/test.PDF", link.getAddress());
+
+ byte[] ser = link.serialize();
+ TestcaseRecordInputStream.confirmRecordEncoding(HyperlinkRecord.sid, data_47498, ser);
+ }
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java
index 3281b5115a..98ccbf0394 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java
@@ -860,7 +860,7 @@ public final class TestFormulas extends TestCase {
HSSFWorkbook wb = openSample("27272_1.xls");
wb.getSheetAt(0);
assertEquals("Reference for named range ", "Compliance!#REF!",wb.getNameAt(0).getRefersToFormula());
- File outF = File.createTempFile("bug27272_1",".xls");
+ File outF = TempFile.createTempFile("bug27272_1",".xls");
wb.write(new FileOutputStream(outF));
System.out.println("Open "+outF.getAbsolutePath()+" in Excel");
}
@@ -868,7 +868,7 @@ public final class TestFormulas extends TestCase {
public void test27272_2() throws Exception {
HSSFWorkbook wb = openSample("27272_2.xls");
assertEquals("Reference for named range ", "LOAD.POD_HISTORIES!#REF!",wb.getNameAt(0).getRefersToFormula());
- File outF = File.createTempFile("bug27272_2",".xls");
+ File outF = TempFile.createTempFile("bug27272_2",".xls");
wb.write(new FileOutputStream(outF));
System.out.println("Open "+outF.getAbsolutePath()+" in Excel");
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java
index 2d56482173..454a297105 100755
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java
@@ -166,6 +166,28 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
assertEquals("http://poi.apache.org/hssf/", link.getAddress());
}
+ public void testCreate() throws Exception {
+ HSSFWorkbook wb = getTestDataProvider().createWorkbook();
+
+ HSSFHyperlink link;
+ HSSFCell cell;
+ HSSFSheet sheet = wb.createSheet("Hyperlinks");
+
+ cell = sheet.createRow(1).createCell(0);
+ cell.setCellValue("File Link");
+ link = new HSSFHyperlink(HSSFHyperlink.LINK_FILE);
+ link.setAddress("testfolder\\test.PDF");
+ cell.setHyperlink(link);
+
+ wb = getTestDataProvider().writeOutAndReadBack(wb);
+ sheet = wb.getSheet("Hyperlinks");
+
+ cell = sheet.getRow(1).getCell(0);
+ link = cell.getHyperlink();
+ assertNotNull(link);
+ assertEquals("testfolder\\test.PDF", link.getAddress());
+ }
+
/**
* Test that HSSFSheet#shiftRows moves hyperlinks,
* see bugs #46445 and #29957
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
index 2f944c5fd7..ee8e0e8245 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
@@ -34,6 +34,7 @@ import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.ss.usermodel.BaseTestSheet;
import org.apache.poi.ddf.EscherDgRecord;
+import org.apache.poi.util.TempFile;
/**
* Tests HSSFSheet. This test case is very incomplete at the moment.
@@ -572,8 +573,7 @@ public final class TestHSSFSheet extends BaseTestSheet {
assertFalse(sheet2.getForceFormulaRecalculation());
// Save and manually verify that on column C we have 0, value in template
- File tempFile = new File(System.getProperty("java.io.tmpdir")+"/uncalced_err.xls" );
- tempFile.delete();
+ File tempFile = TempFile.createTempFile("uncalced_err", ".xls" );
FileOutputStream fout = new FileOutputStream( tempFile );
workbook.write( fout );
fout.close();
@@ -581,7 +581,7 @@ public final class TestHSSFSheet extends BaseTestSheet {
assertTrue(sheet.getForceFormulaRecalculation());
// Save and manually verify that on column C we have now 13, calculated value
- tempFile = new File(System.getProperty("java.io.tmpdir")+"/uncalced_succ.xls" );
+ tempFile = TempFile.createTempFile("uncalced_succ", ".xls");
tempFile.delete();
fout = new FileOutputStream( tempFile );
workbook.write( fout );