public void ReadAMinimalDictionary(string fragment) { // 7.3.7 Dictionary Objects byte[] bytes = System.Text.UTF8Encoding.UTF8.GetBytes(fragment); Tokenizer feed = new Tokenizer(new MemoryStream(bytes)); var actual = new DictionaryObject(feed); actual.Childs <PdfObject>().Should().HaveCount(2); actual.Childs <PdfObject>()[0].Should().BeOfType <NameObject>(); Assert.Equal("Type", actual.Child <NameObject>(0).Value); Assert.Equal("Example", actual.Child <NameObject>(1).Value); }
[InlineData("<</Length 10>>stream\n0123456789endstream")] // is not completely valid, but some writers do public void ReadStreams(string fragment) { // 7.3.8 Stream Objects byte[] bytes = System.Text.UTF8Encoding.UTF8.GetBytes(fragment); Tokenizer feed = new Tokenizer(new MemoryStream(bytes)); Objectizer objectizer = new Objectizer(feed); DictionaryObject actual = (DictionaryObject)objectizer.NextObject(); Assert.Equal(2, actual.Childs <PdfObject>().Length); Assert.Equal("Length", actual.Child <NameObject>(0).Value); Assert.Equal(10, actual.Child <IntegerObject>(1).IntValue); Assert.Equal(System.Text.UTF8Encoding.UTF8.GetBytes("0123456789"), actual.Stream); }
public void ReadDictionary() { // 7.3.7 Dictionary Objects string fragment = @"<< /Type /Example /Subtype /DictionaryExample /Version 0.01 /IntegerItem 12 /StringItem (a string) /Subdictionary << /Item1 0.4 /Item2 true /LastItem (not!) /VeryLastItem (OK) >> >>"; byte[] bytes = System.Text.UTF8Encoding.UTF8.GetBytes(fragment); Tokenizer feed = new Tokenizer(new MemoryStream(bytes)); Objectizer objectizer = new Objectizer(feed); DictionaryObject actual = (DictionaryObject)objectizer.NextObject(); Assert.Equal(12, actual.Childs <PdfObject>().Length); Assert.Equal("Type", actual.Child <NameObject>(0).Value); Assert.Equal("Example", actual.Child <NameObject>(1).Value); Assert.Equal("Subtype", actual.Child <NameObject>(2).Value); Assert.Equal("DictionaryExample", actual.Child <NameObject>(3).Value); Assert.Equal("Version", actual.Child <NameObject>(4).Value); Assert.Equal(0.01f, actual.Child <RealObject>(5).Value); Assert.Equal("IntegerItem", actual.Child <NameObject>(6).Value); Assert.Equal(12, actual.Child <IntegerObject>(7).IntValue); Assert.Equal("StringItem", actual.Child <NameObject>(8).Value); Assert.Equal("a string", actual.Child <StringObject>(9).Value); Assert.Equal("Subdictionary", actual.Child <NameObject>(10).Value); Assert.Equal("Item1", actual.Child <DictionaryObject>(11).Child <NameObject>(0).Value); Assert.Equal(0.4f, actual.Child <DictionaryObject>(11).Child <RealObject>(1).Value); Assert.Equal("Item2", actual.Child <DictionaryObject>(11).Child <NameObject>(2).Value); Assert.True(actual.Child <DictionaryObject>(11).Child <BooleanObject>(3).Value); Assert.Equal("LastItem", actual.Child <DictionaryObject>(11).Child <NameObject>(4).Value); Assert.Equal("not!", actual.Child <DictionaryObject>(11).Child <StringObject>(5).Value); Assert.Equal("VeryLastItem", actual.Child <DictionaryObject>(11).Child <NameObject>(6).Value); Assert.Equal("OK", actual.Child <DictionaryObject>(11).Child <StringObject>(7).Value); }