~ubuntu-branches/ubuntu/wily/openmcdf/wily

« back to all changes in this revision

Viewing changes to src/OLECFSTest/CompoundFileTest.cs

  • Committer: Package Import Robot
  • Author(s): Mathieu Malaterre
  • Date: 2013-04-08 11:02:15 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: package-import@ubuntu.com-20130408110215-qji2rhvpx41kqpyj
Tags: upstream-1.5.4
ImportĀ upstreamĀ versionĀ 1.5.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
237
237
        public void Test_MULTIPLE_SAVE()
238
238
        {
239
239
            var file = new CompoundFile();
240
 
            
 
240
 
241
241
            file.Save("test.mdf");
242
242
 
243
243
            var meta = file.
260
260
        }
261
261
 
262
262
        [TestMethod]
 
263
        public void Test_COMPARE_DIR_ENTRY_NAME_BUG_FIX_ID_3487353()
 
264
        {
 
265
            var f = new CompoundFile("report_name_fix.xls", UpdateMode.Update, true, true);
 
266
            CFStream cfs = f.RootStorage.AddStream("Poorbook");
 
267
            cfs.AppendData(Helpers.GetBuffer(20));
 
268
            f.Commit();
 
269
            f.Close();
 
270
 
 
271
            f = new CompoundFile("report_name_fix.xls", UpdateMode.Update, true, true);
 
272
            cfs = f.RootStorage.GetStream("Workbook");
 
273
            Assert.IsTrue(cfs.Name == "Workbook");
 
274
            f.RootStorage.Delete("PoorBook");
 
275
            f.Commit();
 
276
            f.Close();
 
277
 
 
278
        }
 
279
 
 
280
        [TestMethod]
 
281
        public void Test_GET_COMPOUND_VERSION()
 
282
        {
 
283
            var f = new CompoundFile("report_name_fix.xls");
 
284
            CFSVersion ver = f.Version;
 
285
 
 
286
            Assert.IsTrue(ver == CFSVersion.Ver_3);
 
287
 
 
288
            f.Close();
 
289
        }
 
290
 
 
291
        [TestMethod]
263
292
        public void Test_FUNCTIONAL_BEHAVIOUR()
264
293
        {
265
294
            const int N_FACTOR = 1;
356
385
 
357
386
 
358
387
            File.Copy("8_Streams.cfs", "6_Streams.cfs", true);
 
388
            File.Delete("8_Streams.cfs");
359
389
 
360
390
            //###########
361
391
 
518
548
            cf.RootStorage.GetStorage("MiniStorage").GetStream("miniSt2").SetData(bA);
519
549
            cf.Commit();
520
550
            cf.Close();
521
 
           
 
551
 
522
552
 
523
553
            //Test Phase 7
524
554
 
526
556
            d2 = cf.RootStorage.GetStorage("MiniStorage").GetStream("miniSt2").GetData();
527
557
            Assert.IsNotNull(d2);
528
558
            Assert.IsTrue(d2.Length == bA.Length);
529
 
           
 
559
 
530
560
            cf.Close();
531
561
 
532
562
            //##############
533
 
          
 
563
 
534
564
            cf = new CompoundFile("6_Streams_Shrinked.cfs", UpdateMode.ReadOnly, true, false);
535
565
 
536
566
            var myStream = cf.RootStorage.GetStream("C");
547
577
            Console.WriteLine(sw.ElapsedMilliseconds);
548
578
 
549
579
        }
 
580
 
 
581
        [TestMethod]
 
582
        public void Test_RETRIVE_ALL_NAMED_ENTRIES()
 
583
        {
 
584
            var f = new CompoundFile("MultipleStorage4.cfs");
 
585
            IList<CFItem> result = f.GetAllNamedEntries("MyStream");
 
586
 
 
587
            Assert.IsTrue(result.Count == 3);
 
588
        }
 
589
 
 
590
 
 
591
        [TestMethod]
 
592
        public void Test_CORRUPTED_CYCLIC_FAT_CHECK()
 
593
        {
 
594
            CompoundFile f = null;
 
595
            try
 
596
            {
 
597
                f = new CompoundFile("CyclicFAT.cfs");
 
598
 
 
599
            }
 
600
            catch (Exception ex)
 
601
            {
 
602
                Assert.IsTrue(ex is CFCorruptedFileException);
 
603
            }
 
604
            finally
 
605
            {
 
606
                if (f != null)
 
607
                    f.Close();
 
608
            }
 
609
        }
 
610
 
 
611
        [TestMethod]
 
612
        public void Test_DIFAT_CHECK()
 
613
        {
 
614
            CompoundFile f = null;
 
615
            try
 
616
            {
 
617
                f = new CompoundFile();
 
618
                CFStream st = f.RootStorage.AddStream("LargeStream");
 
619
                st.AppendData(Helpers.GetBuffer(20000000, 0x0A)); //Forcing creation of two DIFAT sectors
 
620
                byte[] b1 = Helpers.GetBuffer(3, 0x0B);
 
621
                st.AppendData(b1); //Forcing creation of two DIFAT sectors
 
622
 
 
623
                f.Save("$OpenMcdf$LargeFile.cfs");
 
624
 
 
625
                f.Close();
 
626
 
 
627
                int cnt = 3;
 
628
                f = new CompoundFile("$OpenMcdf$LargeFile.cfs");
 
629
                byte[] b2 = f.RootStorage.GetStream("LargeStream").GetData(20000000, ref cnt);
 
630
                f.Close();
 
631
                Assert.IsTrue(Helpers.CompareBuffer(b1, b2));
 
632
            }
 
633
            finally
 
634
            {
 
635
                if (f != null)
 
636
                    f.Close();
 
637
 
 
638
                if (File.Exists("$OpenMcdf$LargeFile.cfs"))
 
639
                    File.Delete("$OpenMcdf$LargeFile.cfs");
 
640
            }
 
641
        }
 
642
 
 
643
        //[TestMethod]
 
644
        //public void Test_CORRUPTED_CYCLIC_DIFAT_VALIDATION_CHECK()
 
645
        //{
 
646
 
 
647
        //    CompoundFile cf = null;
 
648
        //    try
 
649
        //    {
 
650
        //        cf = new CompoundFile("CiclycDFAT.cfs");
 
651
        //        CFStorage s = cf.RootStorage.GetStorage("MyStorage");
 
652
        //        CFStream st = s.GetStream("MyStream");
 
653
        //        Assert.IsTrue(st.Size > 0);
 
654
        //    }
 
655
        //    catch (Exception ex)
 
656
        //    {
 
657
        //        Assert.IsTrue(ex is CFCorruptedFileException);
 
658
        //    }
 
659
        //    finally
 
660
        //    {
 
661
        //        if (cf != null)
 
662
        //        {
 
663
        //            cf.Close();
 
664
        //        }
 
665
        //    }
 
666
        //}
 
667
        //[TestMethod]
 
668
        //public void Test_REM()
 
669
        //{
 
670
        //    var f = new CompoundFile();
 
671
 
 
672
        //    byte[] bB = Helpers.GetBuffer(5 * 1024, 0x0B); 
 
673
        //    f.RootStorage.AddStream("Test").AppendData(bB);
 
674
        //    f.Save("Astorage.cfs");
 
675
        //}
 
676
 
550
677
    }
551
678
}