コード例 #1
0
        public void Parse_Test()
        {
            string    value    = "102";
            long      expected = long.Parse(value);
            PDFNumber actual   = PDFNumber.Parse(value);

            Assert.AreEqual(expected, actual.Value);

            value = "NotANumber";

            try
            {
                actual = PDFNumber.Parse(value);
                Assert.Fail("Did not raise format exception");
            }
            catch (FormatException)
            {
                TestContext.WriteLine("Successfully caught the format exception for invalid number");
            }

            value = "102.1";

            try
            {
                actual = PDFNumber.Parse(value);
                Assert.Fail("Did not raise format exception");
            }
            catch (FormatException)
            {
                TestContext.WriteLine("Successfully caught the format exception for invalid number");
            }

            value = null;
            try
            {
                actual = PDFNumber.Parse(value);
                Assert.Fail("Did not raise a null exception");
            }
            catch (ArgumentNullException)
            {
                TestContext.WriteLine("Successfully caught the null exception for invalid number");
            }
        }
コード例 #2
0
        public void WriteData_Test()
        {
            PDFNumber expected = (PDFNumber)(-201);
            string    result;
            PDFNumber actual;

            using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
            {
                using (PDFWriter writer = new PDFWriter14(stream, new Scryber.Logging.DoNothingTraceLog(TraceRecordLevel.Diagnostic)))
                {
                    expected.WriteData(writer);
                    writer.InnerStream.Flush();
                }
                stream.Position = 0;

                using (System.IO.StreamReader sr = new System.IO.StreamReader(stream))
                {
                    result = sr.ReadToEnd();
                }
            }

            actual = PDFNumber.Parse(result.Trim());
            Assert.AreEqual(expected, actual);
        }