[Libreoffice-commits] .: src/docrecord.py test/comment.rtf test/doc test/fonts.rtf test/hello.rtf test/parprops.rtf test/parstyles.rtf test/unicode.rtf
Miklos Vajna
vmiklos at kemper.freedesktop.org
Mon Nov 26 00:26:43 PST 2012
src/docrecord.py | 4 +-
test/comment.rtf | 16 --------
test/doc/comment.doc |binary
test/doc/comment.rtf | 31 +++++++++++++++++
test/doc/fonts.doc |binary
test/doc/fonts.rtf | 7 +++
test/doc/hello.doc |binary
test/doc/hello.rtf | 3 +
test/doc/parprops.doc |binary
test/doc/parprops.rtf | 4 ++
test/doc/parstyles.doc |binary
test/doc/parstyles.rtf | 10 +++++
test/doc/test.py | 88 +++++++++++++++++++++++++++++++++++++++++++++----
test/doc/unicode.doc |binary
test/doc/unicode.rtf | 5 ++
test/fonts.rtf | 7 ---
test/hello.rtf | 3 -
test/parprops.rtf | 4 --
test/parstyles.rtf | 10 -----
test/unicode.rtf | 5 --
20 files changed, 143 insertions(+), 54 deletions(-)
New commits:
commit f519bfa92deef99f314d17b242af1edbe7c72a89
Author: Miklos Vajna <vmiklos at suse.cz>
Date: Sun Nov 25 14:52:17 2012 +0100
more doc tests
diff --git a/src/docrecord.py b/src/docrecord.py
index 4b17907..7cd9df9 100755
--- a/src/docrecord.py
+++ b/src/docrecord.py
@@ -975,9 +975,9 @@ class SttbfAtnBkmk(DOCDirStream):
self.pos += 2
for i in range(self.cData):
cchData = self.getuInt16()
- print '<cchData index="%d" offset="%d", size="%d bytes"/>' % (i, self.pos, cchData)
+ print '<cchData index="%d" offset="%d" size="%d bytes"/>' % (i, self.pos, cchData)
self.pos += 2
- print '<extraData index="%d" offset="%d", size="%d bytes">' % (i, self.pos, ATNBE.size)
+ print '<extraData index="%d" offset="%d" size="%d bytes">' % (i, self.pos, ATNBE.size)
atnbe = ATNBE(self)
atnbe.dump()
self.pos += ATNBE.size
diff --git a/test/comment.rtf b/test/comment.rtf
deleted file mode 100755
index 434ca47..0000000
--- a/test/comment.rtf
+++ /dev/null
@@ -1,16 +0,0 @@
-{\rtf1
-\pard\plain
-{\*\atrfstart 341185741}
-Hello
-{\*\atrfend 341185741}
-{\*\atnid v}
-{\*\atnauthor vmiklos}
-\chatn
-{\*\annotation
-{\*\atnref 341185741}
-{\*\atndate 1191945128}
-This is a comment.
-}
-world!
-\par
-}
diff --git a/test/doc/comment.doc b/test/doc/comment.doc
new file mode 100644
index 0000000..d581d73
Binary files /dev/null and b/test/doc/comment.doc differ
diff --git a/test/doc/comment.rtf b/test/doc/comment.rtf
new file mode 100644
index 0000000..fc48810
--- /dev/null
+++ b/test/doc/comment.rtf
@@ -0,0 +1,31 @@
+{\rtf1
+{
+{\*\atrfstart 341626352}
+Hello
+{\*\atrfend 341626352}
+{\*\atnid v}
+{\*\atnauthor vmiklos}
+\chatn
+{\*\annotation
+{\*\atnref 341626352}
+{\*\atndate 1191945128}
+{This is a comment.}
+}
+ world!}
+\par
+{\*\atrfstart 341626364}
+This
+{
+{\*\atrfend 341626364}
+{\*\atnid v}
+{\*\atnauthor vmiklos}
+\chatn
+{\*\annotation
+{\*\atnref 341626364}
+{\*\atndate 118213700}
+This is also commented.
+}
+}
+{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24 \hich\af0\dbch\loch\f0 \hich\af0\dbch\loch\f0 is also commented.
+\par }
+}
diff --git a/test/doc/fonts.doc b/test/doc/fonts.doc
new file mode 100644
index 0000000..bf4db37
Binary files /dev/null and b/test/doc/fonts.doc differ
diff --git a/test/doc/fonts.rtf b/test/doc/fonts.rtf
new file mode 100644
index 0000000..c3d6f1e
--- /dev/null
+++ b/test/doc/fonts.rtf
@@ -0,0 +1,7 @@
+{\rtf1
+{\fonttbl
+{\f0 Times New Roman;}
+{\f1 Arial;}
+}
+\f0 This is Times New Roman \f1 this is arial.\par
+}
diff --git a/test/doc/hello.doc b/test/doc/hello.doc
new file mode 100644
index 0000000..514caa8
Binary files /dev/null and b/test/doc/hello.doc differ
diff --git a/test/doc/hello.rtf b/test/doc/hello.rtf
new file mode 100644
index 0000000..af7104a
--- /dev/null
+++ b/test/doc/hello.rtf
@@ -0,0 +1,3 @@
+{\rtf1
+Hello world!\par
+}
diff --git a/test/doc/parprops.doc b/test/doc/parprops.doc
new file mode 100644
index 0000000..b4a734e
Binary files /dev/null and b/test/doc/parprops.doc differ
diff --git a/test/doc/parprops.rtf b/test/doc/parprops.rtf
new file mode 100644
index 0000000..149e819
--- /dev/null
+++ b/test/doc/parprops.rtf
@@ -0,0 +1,4 @@
+{\rtf1
+Hello world!\par
+\qc Second para.\par
+}
diff --git a/test/doc/parstyles.doc b/test/doc/parstyles.doc
new file mode 100644
index 0000000..e729238
Binary files /dev/null and b/test/doc/parstyles.doc differ
diff --git a/test/doc/parstyles.rtf b/test/doc/parstyles.rtf
new file mode 100644
index 0000000..93e3201
--- /dev/null
+++ b/test/doc/parstyles.rtf
@@ -0,0 +1,10 @@
+{\rtf1
+{\fonttbl
+{\f0 Times New Roman;}
+}
+{\stylesheet
+{\s15\qc\sbasedon0\snext15 Center;}
+}
+{Hello world!\par }
+{\s15\qc This is centered.\par }
+}
diff --git a/test/doc/test.py b/test/doc/test.py
index 52874cc..a0356d0 100755
--- a/test/doc/test.py
+++ b/test/doc/test.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+# -*- encoding: UTF-8 -*-
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -26,19 +27,92 @@ class Test(unittest.TestCase):
sys.stdout = saved
sock.close()
tree = ElementTree.parse('%s.doc.xml' % name)
- return tree.getroot()
+ self.root = tree.getroot()
+
+ def getFontId(self, name):
+ fonts = self.root.findall('stream[@name="WordDocument"]/fib/fibRgFcLcbBlob/lcbSttbfFfn/sttbfFfn/cchData')
+ for i in fonts:
+ if len (i.findall('ffn/xszFfn[@value="%s"]' % name)) == 1:
+ return int(i.attrib['index'])
+
+ def getRuns(self):
+ return self.root.findall('stream[@name="WordDocument"]/fib/fibRgFcLcbBlob/lcbPlcfBteChpx/plcBteChpx/aFC/aPnBteChpx/chpxFkp/rgfc')
+
+ def getParas(self):
+ return self.root.findall('stream[@name="WordDocument"]/fib/fibRgFcLcbBlob/lcbPlcfBtePapx/plcBtePapx/aFC/aPnBtePapx/papxFkp/rgfc')
+
+ def getHex(self, num):
+ return int(num, 16)
+
+ def test_hello(self):
+ self.dump('hello')
+
+ runs = self.getRuns()
+ self.assertEqual(1, len(runs))
+
+ self.assertEqual('Hello world!\\x0D', runs[0].findall('transformed')[0].attrib['value'])
+
+ def test_unicode(self):
+ self.dump('unicode')
+
+ uni = self.root.findall('stream[@name="WordDocument"]/fib/fibRgFcLcbBlob/lcbClx/clx/pcdt/plcPcd/aCP/transformed')
+ self.assertEqual('Hello world! éáÅű\\x0D', uni[0].attrib['value'])
def test_charprops(self):
- root = self.dump('charprops')
+ self.dump('charprops')
+
+ runs = self.getRuns()
+ self.assertEqual(2, len(runs))
+
+ self.assertEqual('Hello ', runs[0].findall('transformed')[0].attrib['value'])
+ self.assertEqual(0, len(runs[0].findall('chpx/prl/sprm[@name="sprmCFBold"]')))
+
+ self.assertEqual('world!\\x0D', runs[1].findall('transformed')[0].attrib['value'])
+ self.assertEqual(1, len(runs[1].findall('chpx/prl/sprm[@name="sprmCFBold"]')))
- runs = root.findall('./stream[@name="WordDocument"]/fib/fibRgFcLcbBlob/lcbPlcfBteChpx/plcBteChpx/aFC/aPnBteChpx/chpxFkp/rgfc')
+ def test_fonts(self):
+ self.dump('fonts')
+ runs = self.getRuns()
self.assertEqual(2, len(runs))
- self.assertEqual('Hello ', runs[0].findall('./transformed')[0].attrib['value'])
- self.assertEqual(0, len(runs[0].findall("./chpx/prl/sprm[@name='sprmCFBold']")))
+ self.assertEqual('This is Times New Roman ', runs[0].findall('transformed')[0].attrib['value'])
+ self.assertEqual(self.getFontId("Times New Roman"), self.getHex(runs[0].findall('chpx/prl/sprm[@name="sprmCRgFtc0"]')[0].attrib['operand']))
+
+ self.assertEqual('this is arial.\\x0D', runs[1].findall('transformed')[0].attrib['value'])
+ self.assertEqual(self.getFontId("Arial"), self.getHex(runs[1].findall('chpx/prl/sprm[@name="sprmCRgFtc0"]')[0].attrib['operand']))
+
+ def test_parprops(self):
+ self.dump('parprops')
+ paras = self.getParas()
+ self.assertEqual(2, len(paras))
+
+ self.assertEqual('Second para.\\x0D', paras[1].findall('transformed')[0].attrib['value'])
+ self.assertEqual('0x1', paras[1].findall('bxPap/papxInFkp/grpPrlAndIstd/prl/sprm[@name="sprmPJc"]')[0].attrib['operand'])
+
+ def test_parstyles(self):
+ self.dump('parstyles')
+ styles = self.root.findall('stream[@name="WordDocument"]/fib/fibRgFcLcbBlob/lcbStshf/stsh/rglpstd')
+ self.assertEqual('Center', styles[15].findall('std/xstz/xst/rgtchar')[0].attrib['value'])
+
+ paras = self.getParas()
+ self.assertEqual(15, self.getHex(paras[1].findall('bxPap/papxInFkp/grpPrlAndIstd/istd')[0].attrib['value']))
+
+ def test_comment(self):
+ self.dump('comment')
+ comments = self.root.findall('stream[@name="WordDocument"]/fib/fibRgFcLcbBlob/lcbPlcfandTxt/plcfandTxt/aCP')
+ self.assertEqual(2, len(comments))
+
+ self.assertEqual('This is a comment.\\x0D', comments[0].findall('transformed')[0].attrib['value'])
+ self.assertEqual('This is also commented.\\x0D', comments[1].findall('transformed')[0].attrib['value'])
+
+ commentStarts = self.root.findall('stream[@name="WordDocument"]/fib/fibRgFcLcbBlob/lcbPlcfAtnBkf/plcfBkf/aCP')
+ commentEnds = self.root.findall('stream[@name="WordDocument"]/fib/fibRgFcLcbBlob/lcbPlcfAtnBkl/plcfBkl/aCP')
- self.assertEqual('world!\\x0D', runs[1].findall('./transformed')[0].attrib['value'])
- self.assertEqual(1, len(runs[1].findall("./chpx/prl/sprm[@name='sprmCFBold']")))
+ # The first comment covers Hello\x05, the second covers This\x05.
+ self.assertEqual('H', commentStarts[0].findall('transformed')[0].attrib['value'])
+ self.assertEqual('\\x05', commentEnds[0].findall('transformed')[0].attrib['value'])
+ self.assertEqual('T', commentStarts[1].findall('transformed')[0].attrib['value'])
+ self.assertEqual('\\x05', commentEnds[1].findall('transformed')[0].attrib['value'])
if __name__ == '__main__':
unittest.main()
diff --git a/test/doc/unicode.doc b/test/doc/unicode.doc
new file mode 100644
index 0000000..a94e2df
Binary files /dev/null and b/test/doc/unicode.doc differ
diff --git a/test/doc/unicode.rtf b/test/doc/unicode.rtf
new file mode 100644
index 0000000..f1334dd
--- /dev/null
+++ b/test/doc/unicode.rtf
@@ -0,0 +1,5 @@
+{\rtf1
+\pard\plain
+Hello world! \uc2 \u233\'c3\'a9\u225\'c3\'a1\u337\'c5\'91\u369\'c5\'b1\uc1
+\par
+}
diff --git a/test/fonts.rtf b/test/fonts.rtf
deleted file mode 100644
index c3d6f1e..0000000
--- a/test/fonts.rtf
+++ /dev/null
@@ -1,7 +0,0 @@
-{\rtf1
-{\fonttbl
-{\f0 Times New Roman;}
-{\f1 Arial;}
-}
-\f0 This is Times New Roman \f1 this is arial.\par
-}
diff --git a/test/hello.rtf b/test/hello.rtf
deleted file mode 100644
index af7104a..0000000
--- a/test/hello.rtf
+++ /dev/null
@@ -1,3 +0,0 @@
-{\rtf1
-Hello world!\par
-}
diff --git a/test/parprops.rtf b/test/parprops.rtf
deleted file mode 100644
index 149e819..0000000
--- a/test/parprops.rtf
+++ /dev/null
@@ -1,4 +0,0 @@
-{\rtf1
-Hello world!\par
-\qc Second para.\par
-}
diff --git a/test/parstyles.rtf b/test/parstyles.rtf
deleted file mode 100755
index 93e3201..0000000
--- a/test/parstyles.rtf
+++ /dev/null
@@ -1,10 +0,0 @@
-{\rtf1
-{\fonttbl
-{\f0 Times New Roman;}
-}
-{\stylesheet
-{\s15\qc\sbasedon0\snext15 Center;}
-}
-{Hello world!\par }
-{\s15\qc This is centered.\par }
-}
diff --git a/test/unicode.rtf b/test/unicode.rtf
deleted file mode 100755
index f1334dd..0000000
--- a/test/unicode.rtf
+++ /dev/null
@@ -1,5 +0,0 @@
-{\rtf1
-\pard\plain
-Hello world! \uc2 \u233\'c3\'a9\u225\'c3\'a1\u337\'c5\'91\u369\'c5\'b1\uc1
-\par
-}
More information about the Libreoffice-commits
mailing list