Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sw / qa / python / load_save_test.py
bloba79bc3285af0b0892a0c00f097ca2e7b8a730ba9
1 '''
2 This file is part of the LibreOffice project.
4 This Source Code Form is subject to the terms of the Mozilla Public
5 License, v. 2.0. If a copy of the MPL was not distributed with this
6 file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 This file incorporates work covered by the following license notice:
10 Licensed to the Apache Software Foundation (ASF) under one or more
11 contributor license agreements. See the NOTICE file distributed
12 with this work for additional information regarding copyright
13 ownership. The ASF licenses this file to you under the Apache
14 License, Version 2.0 (the "License"); you may not use this file
15 except in compliance with the License. You may obtain a copy of
16 the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 '''
19 import unittest
20 import unohelper
21 import os
22 import os.path
23 import time
24 import uno
25 from com.sun.star.lang import EventObject
26 from com.sun.star.lang import XMultiServiceFactory
27 from com.sun.star.lang import XComponent
28 from com.sun.star.beans import PropertyValue
29 from com.sun.star.frame import XGlobalEventBroadcaster
30 from com.sun.star.frame import XStorable
31 from com.sun.star.document import DocumentEvent
32 from com.sun.star.document import XDocumentEventListener
33 from org.libreoffice.unotest import UnoInProcess
34 from urllib.parse import quote
37 class LoadSaveTest(unittest.TestCase):
39 def mkPropertyValue(self, name, value):
40 return uno.createUnoStruct("com.sun.star.beans.PropertyValue", name, 0, value, 0)
42 @classmethod
43 def setUpClass(cls):
44 cls._uno = UnoInProcess()
45 cls._uno.setUp()
46 cls.xDoc = cls._uno.openEmptyWriterDoc()
47 cls.xContext = cls._uno.getContext()
49 cls.m_fileURL = "file:/"
50 cls.m_SourceDir = "FIXME"
51 cls.m_TargetDir = "/tmp/out/"
52 cls.dirs = []
53 cls.files = []
54 cls.file_name = ""
56 @classmethod
57 def tearDownClass(cls):
58 cls._uno.tearDown()
60 def testLoadStore(self):
61 self.dirs, self.files = self.getDirAndFile(self.m_SourceDir)
62 self.makeDirs(self.m_TargetDir)
63 for self.file_name in self.files:
64 self.tstDoc()
66 def tstDoc(self):
67 try:
68 props = [("ReadOnly", True)]
69 load_props = tuple([self.mkPropertyValue(name, value) for (name, value) in props])
71 m_xMSF = self.xContext.ServiceManager
72 desktop = m_xMSF.createInstanceWithContext('com.sun.star.frame.Desktop', self.xContext)
74 filepath = os.path.abspath("FIXME")
75 if os.name == "nt":
76 source_file = ''.join(("file:///", filepath, "/", quote(self.file_name)))
77 else:
78 source_file = ''.join(("file://", quote(filepath), "/", quote(self.file_name)))
80 self.xDoc = desktop.loadComponentFromURL(source_file, "_blank", 0, load_props)
81 assert(self.xDoc)
83 if os.name == "nt":
84 target_file = ''.join(("file:///", self.m_TargetDir, quote(self.m_SourceDir), "/", quote(self.file_name)))
85 else:
86 target_file = ''.join(("file://", quote(self.m_TargetDir), quote(self.m_SourceDir), "/", quote(self.fileName)))
88 p1 = PropertyValue()
89 PropValue = uno.Any("[]com.sun.star.beans.PropertyValue", (p1,))
90 uno.invoke(self.xDoc, "storeToURL", (target_file, PropValue))
92 except Exception:
93 raise
95 def getDirAndFile(self, dir):
97 root2 = os.mkdir(dir)
98 root_path = ''.join((dir, "/", dir, ".odt"))
99 root = open(root_path, 'a')
101 self.getDirAndFileNames(dir)
102 return self.dirs, self.files
104 def getDirAndFileNames(self, fdName):
106 if os.path.isdir(fdName):
107 self.dirs.append(fdName)
108 subfiles = os.listdir(fdName)
110 if not fdName[-1] == "/":
111 fdName += "/"
113 for subfile in subfiles:
114 subfile_name = fdName + subfile
115 self.getDirAndFileNames(subfile_name)
117 if os.path.isfile(fdName):
118 self.files.append(fdName.split('/')[-1])
120 def makeDirs(self, target):
121 if not os.path.exists(target):
122 os.mkdir(target)
123 self.assertTrue(os.path.exists(target))
125 for dir in self.dirs:
126 if not os.path.exists(target + dir):
127 f = os.mkdir(target + dir)
128 self.assertTrue(os.path.exists(target + dir))
130 target_path = ''.join((target, dir, "/", self.m_SourceDir, ".odt"))
131 root = open(target_path, 'a')
132 filepath = os.path.abspath(target_path)