You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TestFeatRecord.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hssf.record;
  16. import org.apache.poi.hssf.HSSFTestDataSamples;
  17. import org.apache.poi.hssf.model.InternalWorkbook;
  18. import org.apache.poi.hssf.usermodel.HSSFTestHelper;
  19. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  20. import junit.framework.TestCase;
  21. /**
  22. * Tests for <tt>FeatRecord</tt>
  23. *
  24. * @author Josh Micich
  25. */
  26. public final class TestFeatRecord extends TestCase {
  27. public void testWithoutFeatRecord() throws Exception {
  28. HSSFWorkbook hssf =
  29. HSSFTestDataSamples.openSampleWorkbook("46136-WithWarnings.xls");
  30. InternalWorkbook wb = HSSFTestHelper.getWorkbookForTest(hssf);
  31. int countFR = 0;
  32. int countFRH = 0;
  33. for(Record r : wb.getRecords()) {
  34. if(r instanceof FeatRecord) {
  35. countFR++;
  36. } else if (r.getSid() == FeatRecord.sid) {
  37. countFR++;
  38. }
  39. if(r instanceof FeatHdrRecord) {
  40. countFRH++;
  41. } else if (r.getSid() == FeatHdrRecord.sid) {
  42. countFRH++;
  43. }
  44. }
  45. assertEquals(0, countFR);
  46. assertEquals(0, countFRH);
  47. }
  48. /**
  49. * TODO - make this work!
  50. * (Need to have the Internal Workbook capture it or something)
  51. */
  52. public void DISABLEDtestReadFeatRecord() throws Exception {
  53. HSSFWorkbook hssf =
  54. HSSFTestDataSamples.openSampleWorkbook("46136-NoWarnings.xls");
  55. InternalWorkbook wb = HSSFTestHelper.getWorkbookForTest(hssf);
  56. FeatRecord fr = null;
  57. int countFR = 0;
  58. int countFRH = 0;
  59. for(Record r : wb.getRecords()) {
  60. if(r instanceof FeatRecord) {
  61. fr = (FeatRecord)r;
  62. countFR++;
  63. } else if (r.getSid() == FeatRecord.sid) {
  64. fail("FeatRecord SID found but not created correctly!");
  65. }
  66. if(r instanceof FeatHdrRecord) {
  67. countFRH++;
  68. } else if (r.getSid() == FeatHdrRecord.sid) {
  69. fail("FeatHdrRecord SID found but not created correctly!");
  70. }
  71. }
  72. assertEquals(1, countFR);
  73. assertEquals(1, countFRH);
  74. assertNotNull(fr);
  75. // Now check the contents are as expected
  76. }
  77. }