示例#1
0
        public void OTFileFieldInitializationHandlingTest()
        {
            bool caughtExpectedException = false; // will set to true if expected exception is caught

            OTFile target = new OTFile();
            Assert.IsNull(target.GetFileInfo(), "Error: unexpected FileInfo");
            Assert.IsNull(target.GetMemoryStream(), "Error: unexpected FileStream");
            try
            {
                OTFont f = target.GetFont(0);
            }
            catch (NullReferenceException)
            {
                caughtExpectedException = true;
            }
            Assert.IsTrue(caughtExpectedException, "Error: expected exception not caught");
            Assert.IsFalse(target.IsCollection, "Error: unexpected value in unopened OTFile");
            Assert.IsFalse(target.IsSupportedFileType, "Error: unexpected value in unopened OTFile");
            Assert.IsTrue(target.Length == 0, "Error: unexpected value in unopened OTFile");
            Assert.IsTrue(target.NumFonts == 0, "Error: unexpected value in unopened OTFile");
            Assert.IsNull(target.SfntVersionTag, "Error: unexpected value in unopened OTFile");
            TtcHeader t = target.TtcHeader;
            Assert.IsTrue(t.FileOffset == 0, "Error: unexpected value in unconfigured TtcHeader");
            Assert.IsNull(t.TtcTag, "Error: unexpected value in unconfigured TtcHeader");
            Assert.IsTrue(t.MajorVersion == 0, "Error: unexpected value in unconfigured TtcHeader");
            Assert.IsTrue(t.MinorVersion == 0, "Error: unexpected value in unconfigured TtcHeader");
            Assert.IsTrue(t.NumFonts == 0, "Error: unexpected value in unconfigured TtcHeader");
            Assert.IsNull(t.OffsetTableOffsets, "Error: unexpected value in unconfigured TtcHeader");
            Assert.IsNull(t.DSIGTag, "Error: unexpected value in unconfigured TtcHeader");
            Assert.IsTrue(t.DSIGLength == 0, "Error: unexpected value in unconfigured TtcHeader");
            Assert.IsTrue(t.DSIGOffset == 0, "Error: unexpected value in unconfigured TtcHeader");
            Assert.IsFalse(t.HasDSIG, "Error: unexpected value in unconfigured TtcHeader");
        }
示例#2
0
        public void OTFile_ReadFromFileAndGetMemoryStream()
        {
            // construct OTFile and read from test font
            OTFile target = new OTFile();
            string FilePath = "TestData\\selawk.ttf";
            target.ReadFromFile(FilePath);

            // Get memory stream and take sample
            System.IO.MemoryStream ms = target.GetMemoryStream();
            ms.Seek(0, System.IO.SeekOrigin.Begin);
            byte[] data = new byte[32];
            int cb = ms.Read(data, 0, 32);
            Assert.IsTrue((cb == 32), "Error: Read from memory stream returned less data than expected");

            // Create comparison data and compare
            byte[] expectedData = { 0, 1, 0, 0, 0, 0x0F, 0, 0x80, 0, 3, 0, 0x70, 0x44, 0x53, 0x49, 0x47, 0xF0, 0x54, 0x3E, 0x26, 0, 0, 0x91, 0xE4, 0, 0, 0x1A, 0xDC, 0x47, 0x44, 0x45, 0x46 };
            bool match = true;
            for (int i = 0; i < data.Length; i++)
            {
                if (data[i] != expectedData[i])
                {
                    match = false;
                    break;
                }
            }
            Assert.IsTrue(match, "Error: Read from memory stream returned unexpected data");
        }
示例#3
0
        public void OTFileCalcTableChecksumTest()
        {
            // construct OTFile, read from test font and get memory stream
            OTFile target = new OTFile();
            string FilePath = "TestData\\selawk.ttf";
            target.ReadFromFile(FilePath);
            System.IO.MemoryStream ms = target.GetMemoryStream();

            // Selawik GPOS table has a checksum of 0x8969_4DB2
            UInt32 expected = 0x8969_4DB2;
            // GPOS offset: 0x7BC4; length: 0x114C;
            UInt32 actual = OTFile.CalcTableCheckSum(ms, 0x7BC4, 0x114C);
            Assert.AreEqual(actual, expected);
        }