public void TestShortConstructor() { // Get the logger to be used DummyPOILogger logger = (DummyPOILogger)POILogFactory.GetLogger( typeof(RawDataBlock) ); logger.Reset(); // the logger may have been used before Assert.AreEqual(0, logger.logged.Count); // Test for various short sizes for (int k = 2049; k < 2560; k++) { byte[] data = new byte[k]; for (int j = 0; j < k; j++) { data[j] = (byte)j; } // Check we logged the error logger.Reset(); new RawDataBlockList(new MemoryStream(data), POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS); Assert.AreEqual(1, logger.logged.Count); } }
public void TestVariousLogTypes() { //NKB Testing only that logging classes use gives no exception // Since logging can be disabled, no checking of logging // output is done. POILogger log = POILogFactory.GetLogger("foo"); log.Log(POILogger.WARN, "Test = ", 1); }
public void TestShortConstructor() { //// Get the logger to be used DummyPOILogger logger = (DummyPOILogger)POILogFactory.GetLogger(typeof(RawDataBlock)); logger.Reset(); // the logger may have been used before Assert.AreEqual(0, logger.logged.Count); // Test for various data sizes for (int k = 1; k <= 512; k++) { byte[] data = new byte[k]; for (int j = 0; j < k; j++) { data[j] = (byte)j; } RawDataBlock block = null; logger.Reset(); Assert.AreEqual(0, logger.logged.Count); // Have it created block = new RawDataBlock(new MemoryStream(data)); Assert.IsNotNull(block); // Check for the warning Is there for <512 if (k < 512) { Assert.AreEqual( 1, logger.logged.Count, "Warning on " + k + " byte short block" ); // Build the expected warning message, and check String bts = k + " byte"; if (k > 1) { bts += "s"; } Assert.AreEqual( (String)logger.logged[0], "7 - Unable to read entire block; " + bts + " read before EOF; expected 512 bytes. Your document was either written by software that ignores the spec, or has been truncated!" ); } else { Assert.AreEqual(0, logger.logged.Count); } } }
public void TestVariousLogTypes() { //NKB Testing only that logging classes use gives no exception // Since logging can be disabled, no checking of logging // output is done. POILogger log = POILogFactory.GetLogger("foo"); log.Log(POILogger.WARN, "Test = ", 1); log.LogFormatted(POILogger.ERROR, "Test param 1 = %, param 2 = %", "2", 3); log.LogFormatted(POILogger.ERROR, "Test param 1 = %, param 2 = %", new int[] { 4, 5 }); log.LogFormatted(POILogger.ERROR, "Test param 1 = %1.1, param 2 = %0.1", new double[] { 4, 5.23 }); }
public void TestSlowInputStream() { // Get the logger to be used DummyPOILogger logger = (DummyPOILogger)POILogFactory.GetLogger(typeof(RawDataBlock)); logger.Reset(); // the logger may have been used before Assert.AreEqual(0, logger.logged.Count); // Test for various ok data sizes for (int k = 1; k < 512; k++) { byte[] data = new byte[512]; for (int j = 0; j < data.Length; j++) { data[j] = (byte)j; } // Shouldn't complain, as there Is enough data, // even if it dribbles through RawDataBlock block = new RawDataBlock(new SlowInputStream(data, 512)); //k is changed to 512 Assert.IsFalse(block.EOF); } // But if there wasn't enough data available, will // complain for (int k = 1; k < 512; k++) { byte[] data = new byte[511]; for (int j = 0; j < data.Length; j++) { data[j] = (byte)j; } logger.Reset(); Assert.AreEqual(0, logger.logged.Count); // Should complain, as there Isn't enough data RawDataBlock block = new RawDataBlock(new SlowInputStream(data, k)); Assert.IsNotNull(block); Assert.AreEqual( 1, logger.logged.Count, "Warning on " + k + " byte short block" ); } }
public void TestLog() { //NKB Testing only that logging classes use gives no exception // Since logging can be disabled, no checking of logging // output is done. POILogger l1 = POILogFactory.GetLogger("org.apache.poi.hssf.test"); POILogger l2 = POILogFactory.GetLogger("org.apache.poi.hdf.test"); l1.Log(POILogger.FATAL, "testing cat org.apache.poi.hssf.*:FATAL"); l1.Log(POILogger.ERROR, "testing cat org.apache.poi.hssf.*:ERROR"); l1.Log(POILogger.WARN, "testing cat org.apache.poi.hssf.*:WARN"); l1.Log(POILogger.INFO, "testing cat org.apache.poi.hssf.*:INFO"); l1.Log(POILogger.DEBUG, "testing cat org.apache.poi.hssf.*:DEBUG"); l2.Log(POILogger.FATAL, "testing cat org.apache.poi.hdf.*:FATAL"); l2.Log(POILogger.ERROR, "testing cat org.apache.poi.hdf.*:ERROR"); l2.Log(POILogger.WARN, "testing cat org.apache.poi.hdf.*:WARN"); l2.Log(POILogger.INFO, "testing cat org.apache.poi.hdf.*:INFO"); l2.Log(POILogger.DEBUG, "testing cat org.apache.poi.hdf.*:DEBUG"); }
/// <summary> /// Reads the dictionary. /// </summary> /// <param name="src">The byte array containing the bytes making out the dictionary.</param> /// <param name="offset">At this offset within src the dictionary starts.</param> /// <param name="Length">The dictionary Contains at most this many bytes.</param> /// <param name="codepage">The codepage of the string values.</param> /// <returns>The dictonary</returns> protected IDictionary ReadDictionary(byte[] src, long offset, int Length, int codepage) { /* Check whether "offset" points into the "src" array". */ if (offset < 0 || offset > src.Length) { throw new HPSFRuntimeException ("Illegal offset " + offset + " while HPSF stream Contains " + Length + " bytes."); } int o = (int)offset; /* * Read the number of dictionary entries. */ long nrEntries = LittleEndian.GetUInt(src, o); o += LittleEndianConsts.INT_SIZE; Hashtable m = new Hashtable((int)nrEntries, (float)1.0); try { for (int i = 0; i < nrEntries; i++) { /* The key. */ long id = LittleEndian.GetUInt(src, o); o += LittleEndianConsts.INT_SIZE; /* The value (a string). The Length is the either the * number of (two-byte) characters if the character Set is Unicode * or the number of bytes if the character Set is not Unicode. * The Length includes terminating 0x00 bytes which we have To strip * off To Create a Java string. */ long sLength = LittleEndian.GetUInt(src, o); o += LittleEndianConsts.INT_SIZE; /* Read the string. */ StringBuilder b = new StringBuilder(); switch (codepage) { case -1: { /* Without a codepage the Length is equal To the number of * bytes. */ b.Append(Encoding.UTF8.GetString(src, o, (int)sLength)); break; } case (int)Constants.CP_UNICODE: { /* The Length is the number of characters, i.e. the number * of bytes is twice the number of the characters. */ int nrBytes = (int)(sLength * 2); byte[] h = new byte[nrBytes]; for (int i2 = 0; i2 < nrBytes; i2 += 2) { h[i2] = src[o + i2 + 1]; h[i2 + 1] = src[o + i2]; } b.Append(Encoding.GetEncoding(codepage).GetString(h, 0, nrBytes)); break; } default: { /* For encodings other than Unicode the Length is the number * of bytes. */ b.Append(Encoding.GetEncoding(codepage).GetString(src, o, (int)sLength)); break; } } /* Strip 0x00 characters from the end of the string: */ while (b.Length > 0 && b[b.Length - 1] == 0x00) { b.Length = b.Length - 1; } if (codepage == (int)Constants.CP_UNICODE) { if (sLength % 2 == 1) { sLength++; } o += (int)(sLength + sLength); } else { o += (int)sLength; } m[id] = b.ToString(); } } catch (Exception ex) { POILogger l = POILogFactory.GetLogger(typeof(Property)); l.Log(POILogger.WARN, "The property Set's dictionary Contains bogus data. " + "All dictionary entries starting with the one with ID " + id + " will be ignored.", ex); } return(m); }