/[alph]/alph/org/nongnu/alph/xml/serialization.test
ViewVC logotype

Diff of /alph/org/nongnu/alph/xml/serialization.test

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by tjl, Wed Apr 16 03:44:23 2003 UTC revision 1.7 by benja, Fri Apr 25 15:33:56 2003 UTC
# Line 1  Line 1 
1  from org.nongnu import alph  from org.nongnu import alph, storm
2  from org.nongnu.alph.xml import *  from org.nongnu.alph.xml import *
3    
4  import java  import java
# Line 30  class Sb(alph.TextScrollBlock): Line 30  class Sb(alph.TextScrollBlock):
30      def getID(self):      def getID(self):
31          return self.id          return self.id
32    
33  class Fact(SpanReader.ScrollBlockFactory):  class TestAlph(alph.Alph):
34        """
35        Partial implementation of Alph, for tests.
36        """
37      def getScrollBlock(self, id):      def getScrollBlock(self, id):
38          return Sb(id)          return Sb(id)
39    
# Line 48  def parseString(string, handler): Line 51  def parseString(string, handler):
51  # Actual tests  # Actual tests
52    
53  def testParseSpan():  def testParseSpan():
54      r = SpanReader()      r = SpanReader(TestAlph())
     r.scrollBlockFactory = Fact()  
55      str = """<ts b="X" s="5" e="10"/>"""      str = """<ts b="X" s="5" e="10"/>"""
56      parseString(str, r)      parseString(str, r)
57      sp = r.getSpans()[0]      sp = r.getSpans()[0]
# Line 62  def testParseSpan(): Line 64  def testParseSpan():
64  def testMultiple():  def testMultiple():
65      """See that multiple span readings work right.      """See that multiple span readings work right.
66      """      """
67      r = SpanReader()      r = SpanReader(TestAlph())
     r.scrollBlockFactory = Fact()  
68      str = """<alph><ts b="X" s="5" e="10"/><ts b="Y" s="7" e="8"/></alph>"""      str = """<alph><ts b="X" s="5" e="10"/><ts b="Y" s="7" e="8"/></alph>"""
69      parseString(str, r)      parseString(str, r)
70      list = r.getSpans()      list = r.getSpans()
# Line 89  def testMultiple(): Line 90  def testMultiple():
90  def testURN5():  def testURN5():
91      """See that reading and writing URN-5 spans works      """See that reading and writing URN-5 spans works
92      """      """
93      r = SpanReader()      r = SpanReader(TestAlph())
94      str = """<uts b="Q" o="5" t="foo&amp;bar"/>"""      str = """<uts b="Q" o="5" t="foo&amp;bar"/>"""
95      parseString(str, r)      parseString(str, r)
96      sp = r.getSpans()[0]      sp = r.getSpans()[0]
# Line 102  def testURN5(): Line 103  def testURN5():
103  def testFake():  def testFake():
104      """See that reading/writing fake spans works.      """See that reading/writing fake spans works.
105      """      """
106      r = SpanReader()      r = SpanReader(TestAlph())
107      str = """<fts t="foo&amp;bar"/>"""      str = """<fts t="foo&amp;bar"/>"""
108      parseString(str, r)      parseString(str, r)
109    
# Line 113  def testFake(): Line 114  def testFake():
114    
115      failUnlessEqual(SpanSerializer().span2xml(sp), str)      failUnlessEqual(SpanSerializer().span2xml(sp), str)
116    
117    def testPageImageSpan():
118        pool = storm.impl.TransientPool(java.util.HashSet())
119        salph = alph.impl.StormAlph(pool)
120        sb = salph.addFile(java.io.File('testdata/test1.pdf'),
121                           'application/pdf')
122        span = sb.getPage(1).subArea(70, 30, 40, 45)
123        s = SpanSerializer()
124        s.addSpan(span)
125        str = s.get()
126    
127        assert str == '<alph><pis b="urn:x-storm:1.0:application/pdf,6qrwyxinrkbr6znvopuo2rnqc7jjfpqg.ettfngwwbh4ore2hljm4soyipujr42gc7becvgq" p="1" x="70" y="30" w="40" h="45"/></alph>'
128    
129        r = SpanReader(salph)
130        
131        parseString(str, r)
132        sp = r.getSpans()[0]
133        assert sp.getPageIndex() == 1
134        assert sp.getLocation() == span.getLocation()
135        assert sp.getSize() == span.getSize()
136        

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26