test.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. #!/usr/bin/python
  2. import regression as test
  3. import os
  4. import sys
  5. import getopt
  6. def opc_zipread_test(path):
  7. test.call(test.build("opc_zipread"), [], ["--verify", test.docs(path)], test.tmp(path+".opc_zipread"), [], {})
  8. test.regr(test.docs(path+".opc_zipread"), test.tmp(path+".opc_zipread"), True)
  9. def opc_dump_test(path):
  10. test.call(test.build("opc_dump"), [], [test.docs(path)], test.tmp(path+".opc_dump"), [], {})
  11. test.regr(test.docs(path+".opc_dump"), test.tmp(path+".opc_dump"), True)
  12. def opc_extract_test(path, part):
  13. out_ext=".opc_extract."+part.replace("/", "-")
  14. test.call(test.build("opc_extract"), [], [test.docs(path), part], test.tmp(path)+out_ext, [], {})
  15. test.regr(test.docs(path)+out_ext, test.tmp(path)+out_ext, False)
  16. def opc_mem_test(path):
  17. test.call(test.build("opc_mem"), [], [test.docs(path)], test.tmp(path+".opc_mem"), [], {})
  18. test.regr(test.docs(path+".opc_dump"), test.tmp(path+".opc_mem"), True)
  19. def opc_type_test(path):
  20. test.call(test.build("opc_type"), [], [test.docs(path)], test.tmp(path+".opc_type"), [], {})
  21. test.regr(test.docs(path+".opc_type"), test.tmp(path+".opc_type"), True)
  22. def opc_relation_test(path):
  23. test.call(test.build("opc_relation"), [], [test.docs(path)], test.tmp(path+".opc_relation"), [], {})
  24. test.regr(test.docs(path+".opc_relation"), test.tmp(path+".opc_relation"), True)
  25. test.call(test.build("opc_relation"), [], [test.docs(path), "rId1"], test.tmp(path+".opc_relation.rId1"), [], {})
  26. test.regr(test.docs(path+".opc_relation.rId1"), test.tmp(path+".opc_relation.rId1"), True)
  27. test.call(test.build("opc_relation"), [], [test.docs(path), "word/document.xml", "rId1"], test.tmp(path+".opc_relation.word-document.rId1"), [], {})
  28. test.regr(test.docs(path+".opc_relation.word-document.rId1"), test.tmp(path+".opc_relation.word-document.rId1"), True)
  29. def opc_image_test(path):
  30. test.call(test.build("opc_image"), [], [test.docs(path), test.tmp("")], test.tmp(path+".opc_image"), [], {})
  31. test.regr(test.docs(path+".opc_image"), test.tmp(path+".opc_image"), True)
  32. def opc_text_test(path):
  33. test.call(test.build("opc_text"), [], [test.docs(path)], test.tmp(path+".opc_text.html"), [], {})
  34. test.regr(test.docs(path+".opc_text.html"), test.tmp(path+".opc_text.html"), True)
  35. def opc_part_test(path):
  36. test.call(test.build("opc_part"), [], [test.docs(path), "word/document.xml"], test.tmp(path+".opc_part"), [], {})
  37. test.regr(test.docs(path+".opc_part"), test.tmp(path+".opc_part"), True)
  38. def opc_xml_test(path):
  39. test.call(test.build("opc_xml"), [], [test.docs(path), "word/document.xml"], test.tmp(path+".opc_xml"), [], {})
  40. test.regr(test.docs(path+".opc_xml"), test.tmp(path+".opc_xml"), True)
  41. def opc_xml2_test(path):
  42. test.call(test.build("opc_xml2"), [], [test.docs(path)], test.tmp(path+".opc_xml2"), [], {})
  43. test.regr(test.docs(path+".opc_xml2"), test.tmp(path+".opc_xml2"), True)
  44. def opc_zipextract_test(path):
  45. test.call(test.build("opc_zipextract"), [], [test.docs(path), "word/document.xml"], test.tmp(path+".opc_zipextract"), [], {})
  46. test.regr(test.docs(path+".opc_zipextract"), test.tmp(path+".opc_zipextract"), True)
  47. def opc_zipwrite_test(path):
  48. test.rm(test.tmp(path))
  49. test.call(test.build("opc_zipwrite"), [], [test.tmp(path), "--import", "--delete", "--add", "--commit"], test.tmp("stdout.txt"), [], {})
  50. test.call(test.build("opc_zipread"), [], ["--verify", test.tmp(path)], test.tmp(path+"_1.opc_zipread"), [], {})
  51. test.regr(test.docs(path+"_1.opc_zipread"), test.tmp(path+"_1.opc_zipread"), True)
  52. test.call(test.build("opc_zipwrite"), [], [test.tmp(path), "--import", "--commit"], test.tmp("stdout.txt"), [], {})
  53. test.call(test.build("opc_zipread"), [], ["--verify", test.tmp(path)], test.tmp(path+"_2.opc_zipread"), [], {})
  54. test.regr(test.tmp(path+"_1.opc_zipread"), test.tmp(path+"_2.opc_zipread"), True)
  55. test.call(test.build("opc_zipwrite"), [], [test.tmp(path), "--import", "--trim"], test.tmp("stdout.txt"), [], {})
  56. test.call(test.build("opc_zipread"), [], ["--verify", test.tmp(path)], test.tmp(path+"_3.opc_zipread"), [], {})
  57. test.regr(test.docs(path+"_3.opc_zipread"), test.tmp(path+"_3.opc_zipread"), True)
  58. test.call(test.build("opc_zipwrite"), [], [test.tmp(path), "--delete", "--commit"], test.tmp("stdout.txt"), [], {})
  59. test.call(test.build("opc_zipread"), [], ["--verify", test.tmp(path)], test.tmp(path+"_4.opc_zipread"), [], {})
  60. test.regr(test.docs(path+"_4.opc_zipread"), test.tmp(path+"_4.opc_zipread"), True)
  61. test.call(test.build("opc_zipwrite"), [], [test.tmp(path), "--delete", "--trim"], test.tmp("stdout.txt"), [], {})
  62. test.call(test.build("opc_zipread"), [], ["--verify", test.tmp(path)], test.tmp(path+"_5.opc_zipread"), [], {})
  63. test.regr(test.docs(path+"_5.opc_zipread"), test.tmp(path+"_5.opc_zipread"), True)
  64. def opc_trim_test(path):
  65. test.rm(test.tmp(path))
  66. test.cp(test.docs(path), test.tmp(path))
  67. test.call(test.build("opc_dump"), [], [test.docs(path)], test.tmp(path+"_1.opc_trim.opc_dump"), [], {})
  68. test.regr(test.docs(path+".opc_dump"), test.tmp(path+"_1.opc_trim.opc_dump"), True)
  69. test.call(test.build("opc_trim"), [], [test.tmp(path)], test.tmp("stdout.txt"), [], {})
  70. test.call(test.build("opc_dump"), [], [test.docs(path)], test.tmp(path+"_2.opc_trim.opc_dump"), [], {})
  71. test.regr(test.tmp(path+"_1.opc_trim.opc_dump"), test.tmp(path+"_2.opc_trim.opc_dump"), True)
  72. test.call(test.build("opc_trim"), [], [test.tmp(path)], test.tmp("stdout.txt"), [], {})
  73. test.call(test.build("opc_dump"), [], [test.docs(path)], test.tmp(path+"_3.opc_trim.opc_dump"), [], {})
  74. test.regr(test.tmp(path+"_2.opc_trim.opc_dump"), test.tmp(path+"_3.opc_trim.opc_dump"), True)
  75. test.call(test.build("opc_trim"), [], [test.tmp(path)], test.tmp("stdout.txt"), [], {})
  76. test.call(test.build("opc_dump"), [], [test.docs(path)], test.tmp(path+"_4.opc_trim.opc_dump"), [], {})
  77. test.regr(test.tmp(path+"_3.opc_trim.opc_dump"), test.tmp(path+"_4.opc_trim.opc_dump"), True)
  78. def mce_extract_test(path, part, namespaces, returncode):
  79. _part_="."+part.replace('.', '_')
  80. args=[test.docs(path), part]
  81. for namespace in namespaces:
  82. args.append("--understands"); args.append(namespace[1])
  83. _part_=_part_+"."+namespace[0]
  84. test.call(test.build("mce_extract"), [], args, test.tmp(path+_part_+".mce_extract"), [], {"return": returncode})
  85. test.regr(test.docs(path+_part_+".mce_extract"), test.tmp(path+_part_+".mce_extract"), True)
  86. def mce_write_test(path):
  87. test.rm(test.tmp(path))
  88. test.call(test.build("mce_write"), [], [test.tmp(path)], test.tmp("stdout.txt"), [], {})
  89. test.call(test.build("mce_extract"), [], [test.tmp(path), "sample.xml"], test.tmp(path+".mce_write.mce_extract"), [], {})
  90. test.regr(test.docs(path+".mce_write.mce_extract"), test.tmp(path+".mce_write.mce_extract"), False)
  91. test.call(test.build("mce_extract"), [], [test.tmp(path), "--understands", "http://schemas.openxmlformats.org/Circles/v2", "sample.xml"], test.tmp(path+".mce_write.v2.mce_extract"), [], {})
  92. test.regr(test.docs(path+".mce_write.v2.mce_extract"), test.tmp(path+".mce_write.v2.mce_extract"), False)
  93. def mcepp_test(path):
  94. test.rm(test.tmp(path))
  95. test.call(test.build("mcepp"), [], [test.docs(path)], test.tmp(path+".mcepp"), [], {})
  96. test.regr(test.docs(path+".mcepp"), test.tmp(path+".mcepp"), True)
  97. def opc_generate_test(basepath, path):
  98. dest=os.path.join(os.path.split(path)[0], os.path.splitext(os.path.split(path)[1])[0]+".c")
  99. test.ensureDir(test.tmp(os.path.dirname(dest)))
  100. test.call(test.build("opc_dump"), [], [os.path.join(basepath, path)], test.tmp(path+"_1.opc_generate.opc_dump"), [], {})
  101. test.call(test.build("opc_generate"), [], [os.path.join(basepath, path), test.tmp(dest)], test.tmp("stdout.txt"), [], {})
  102. exe=test.compile(test.tmp(dest))
  103. test.call(exe, [], [test.tmp(path)], test.tmp("stdout.txt"), [], {})
  104. test.call(test.build("opc_dump"), [], [test.tmp(path)], test.tmp(path+"_2.opc_generate.opc_dump"), [], {})
  105. test.regr(test.tmp(path+"_1.opc_generate.opc_dump"), test.tmp(path+"_2.opc_generate.opc_dump"), False)
  106. def opc_proc_test(path, args, cmd):
  107. test.rm(test.tmp(path))
  108. test.cp(test.docs(path), test.tmp(path))
  109. call_args=[test.tmp(path)]
  110. call_args.extend(args)
  111. out=path+".opc_proc."+cmd+".txt"
  112. test.call(test.build("opc_proc"), [], call_args, test.tmp(out), [], {})
  113. test.regr(test.docs(out), test.tmp(out), True)
  114. def usage():
  115. print("usage:")
  116. print(" test [--target=mode \"debug|release\"]")
  117. print(" [--generate \"test_docs/\"] [--skip]")
  118. if __name__ == "__main__":
  119. target_mode=None
  120. target_type="static"
  121. generate_path=None
  122. generate_skip=False
  123. try:
  124. opts, args = getopt.getopt(sys.argv[1:], "h", ["help", "target=", "generate=", "skip", "type="])
  125. except getopt.GetoptError, err:
  126. # print help information and exit:
  127. print str(err) # will print something like "option -a not recognized"
  128. usage()
  129. sys.exit(2)
  130. for o, a in opts:
  131. if o in ("-h", "--help"):
  132. usage()
  133. sys.exit(0)
  134. elif o in ("--target"):
  135. target_mode=a
  136. elif o in ("--generate"):
  137. generate_path=a
  138. elif o in ("--skip"):
  139. generate_skip=True
  140. elif o in ("--type"):
  141. target_type=a
  142. if None==target_type and "nt"==os.name:
  143. target_type=""
  144. if None==target_type:
  145. print "please specify target type , e.g. --type=static or --type=shared"
  146. if None==target_mode:
  147. print "please specify target mode, e.g. --target=debug"
  148. sys.exit(2)
  149. else:
  150. test.init(target_mode, target_type)
  151. # sys.exit(0)
  152. if None==generate_path:
  153. # sys.exit(0)
  154. opc_zipread_test("stream.zip") # fails --- streaming mode is not yet implemented.
  155. opc_zipread_test("OOXMLI1.docx")
  156. opc_zipread_test("OOXMLI4.docx")
  157. opc_zipextract_test("OOXMLI1.docx")
  158. opc_zipextract_test("OOXMLI4.docx")
  159. opc_zipwrite_test("out.zipwrite")
  160. opc_dump_test("OOXMLI1.docx")
  161. opc_dump_test("OOXMLI4.docx")
  162. opc_extract_test("OOXMLI1.docx", "word/document.xml")
  163. opc_mem_test("OOXMLI1.docx")
  164. opc_mem_test("OOXMLI4.docx")
  165. opc_type_test("OOXMLI1.docx")
  166. opc_type_test("OOXMLI4.docx")
  167. opc_relation_test("OOXMLI1.docx")
  168. opc_relation_test("OOXMLI4.docx")
  169. opc_image_test("OOXMLI1.docx")
  170. opc_image_test("OOXMLI4.docx")
  171. opc_text_test("OOXMLI1.docx")
  172. opc_text_test("OOXMLI4.docx")
  173. opc_part_test("OOXMLI1.docx")
  174. opc_xml_test("OOXMLI1.docx")
  175. opc_xml2_test("OOXMLI1.docx")
  176. opc_xml2_test("OOXMLI4.docx")
  177. opc_trim_test("OOXMLI1.docx")
  178. opc_trim_test("OOXMLI4.docx")
  179. mce_extract_test("mce.zip", "circles-ignorable.xml", [], 0)
  180. mce_extract_test("mce.zip", "circles-ignorable.xml", [["v2", "http://schemas.openxmlformats.org/Circles/v2"]], 0)
  181. mce_extract_test("mce.zip", "circles-ignorable.xml", [["v2", "http://schemas.openxmlformats.org/Circles/v2"], ["v3", "http://schemas.openxmlformats.org/Circles/v3"]], 0)
  182. mce_extract_test("mce.zip", "circles-ignorable-ns.xml", [], 0)
  183. mce_extract_test("mce.zip", "circles-ignorable-ns.xml", [["v1", "http://schemas.openxmlformats.org/MyExtension/v1"]], 0)
  184. mce_extract_test("mce.zip", "circles-plugin.xml", [], 0)
  185. mce_extract_test("mce.zip", "circles-plugin.xml", [["v2", "http://schemas.openxmlformats.org/Circles/v2"]], 0)
  186. mce_extract_test("mce.zip", "circles-alternatecontent.xml", [], 0)
  187. mce_extract_test("mce.zip", "circles-alternatecontent.xml", [["v2", "http://schemas.openxmlformats.org/Circles/v2"]], 0)
  188. mce_extract_test("mce.zip", "circles-alternatecontent.xml", [["v2", "http://schemas.openxmlformats.org/Circles/v2"], ["v3", "http://schemas.openxmlformats.org/Circles/v3"]], 0)
  189. mce_extract_test("mce.zip", "circles-alternatecontent2.xml", [], 0)
  190. mce_extract_test("mce.zip", "circles-alternatecontent2.xml", [["v1", "http://schemas.openxmlformats.org/metallicfinishes/v1"]], 0)
  191. mce_extract_test("mce.zip", "circles-processcontent.xml", [], 0)
  192. mce_extract_test("mce.zip", "circles-processcontent.xml", [["v2", "http://schemas.openxmlformats.org/Circles/v2"]], 0)
  193. mce_extract_test("mce.zip", "circles-processcontent-ns.xml", [], 0)
  194. mce_extract_test("mce.zip", "circles-processcontent-ns.xml", [["ext", "http://schemas.openxmlformats.org/Circles/extension"]], 0)
  195. mce_extract_test("mce.zip", "circles-mustunderstand.xml", [], 2)
  196. mce_extract_test("mce.zip", "circles-mustunderstand.xml", [["v2", "http://schemas.openxmlformats.org/Circles/v2"]], 0)
  197. mce_write_test("mce_write.zip")
  198. mcepp_test("extLst.xml")
  199. mcepp_test("mce-test-1.xml")
  200. mcepp_test("mce-test-2.xml")
  201. opc_proc_test("OOXMLI1.docx", ["--delete", "customXml/item1.xml", "--dump"], "delete")
  202. opc_proc_test("OOXMLI1.docx", ["--create", "readme.txt", "text/plain", "0", test.docs("Readme.txt"), "--delete", "readme.txt", "--dump"], "create_delete")
  203. else:
  204. ignore_list = { }
  205. skip_list = { }
  206. ignore_file = os.path.join(generate_path, "opc_generate.ignore")
  207. skip_file = os.path.join(generate_path, "opc_generate.skip")
  208. if os.path.exists(ignore_file):
  209. f=open(ignore_file, "r")
  210. ignore_list=eval(f.read())
  211. f.close()
  212. # print "ignore_list="+str(ignore_list)
  213. if os.path.exists(skip_file):
  214. f=open(skip_file, "r")
  215. for line in f.readlines():
  216. line=line.strip()
  217. if ""!=line:
  218. skip_list[line]=True
  219. f.close()
  220. # print "skip_list="+str(skip_list)
  221. skip_f=open(skip_file, "w")
  222. for item in skip_list:
  223. skip_f.write(item+"\n")
  224. skip_f.flush()
  225. suitename=os.path.split(generate_path)[1]
  226. basedir=os.path.split(generate_path)[0]
  227. for root, dirs, files in os.walk(generate_path):
  228. for name in files:
  229. src=os.path.relpath(os.path.join(root, name), basedir)
  230. f=os.path.relpath(src, suitename).replace(os.sep, "/")
  231. dst=os.path.join(suitename, f)
  232. ext=os.path.splitext(src)[1]
  233. ignore=f in ignore_list and ignore_list[f]
  234. if generate_skip:
  235. skip=f in skip_list and skip_list[f]
  236. else:
  237. skip=False
  238. # print f+" "+str(ignore)
  239. if not(ignore) and not(skip) and (".docx"==ext or ".xlsx"==ext or ".pptx"==ext or ".xps"==ext):
  240. print "opc_generate_test("+basedir+", "+src+")"
  241. opc_generate_test(basedir, src)
  242. skip_f.write(f+"\n")
  243. skip_f.flush()
  244. skip_f.close()
  245. # opc_generate_test(test.docs(""), "helloworld.pptx")
  246. # opc_generate_test(test.docs(""), "OOXMLI1.docx")
  247. # opc_generate_test(test.docs(""), "OOXMLI4.docx") ## this is toooo much for the compiler: "fatal error C1060: compiler is out of heap space"