BaseTests.py

Go to the documentation of this file.
00001 #***************************************************************************
00002 #*   (c) Juergen Riegel (juergen.riegel@web.de) 2004                       *   
00003 #*                                                                         *
00004 #*   This file is part of the FreeCAD CAx development system.              *
00005 #*                                                                         *
00006 #*   This program is free software; you can redistribute it and/or modify  *
00007 #*   it under the terms of the GNU Lesser General Public License (LGPL)    *
00008 #*   as published by the Free Software Foundation; either version 2 of     *
00009 #*   the License, or (at your option) any later version.                   *
00010 #*   for detail see the LICENCE text file.                                 *
00011 #*                                                                         *
00012 #*   FreeCAD is distributed in the hope that it will be useful,            *
00013 #*   but WITHOUT ANY WARRANTY; without even the implied warranty of        * 
00014 #*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015 #*   GNU Library General Public License for more details.                  *
00016 #*                                                                         *
00017 #*   You should have received a copy of the GNU Library General Public     *
00018 #*   License along with FreeCAD; if not, write to the Free Software        * 
00019 #*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
00020 #*   USA                                                                   *
00021 #*                                                                         *
00022 #*   Juergen Riegel 2004                                                   *
00023 #***************************************************************************/
00024 
00025 import FreeCAD, os, unittest, tempfile
00026 
00027 class ConsoleTestCase(unittest.TestCase):
00028     def setUp(self):
00029         self.count = 0
00030 
00031     def testPrint(self):
00032         FreeCAD.Console.PrintMessage("   Printing message\n")
00033         FreeCAD.Console.PrintError("   Printing error\n")
00034         FreeCAD.Console.PrintWarning("   Printing warning\n")
00035         FreeCAD.Console.PrintLog("   Printing Log\n")
00036 
00037     def testSynchronPrintFromThread(self):
00038         import thread, time
00039         def adder():
00040             lock.acquire()
00041             self.count=self.count+1
00042             # call of Console method is thread-safe
00043             FreeCAD.Console.PrintMessage("Call from Python thread: count="+str(self.count)+"\n")
00044             lock.release()
00045 
00046         lock=thread.allocate_lock()
00047         for i in range(10):
00048             thread.start_new(adder,())
00049 
00050         time.sleep(3)
00051         self.failUnless(self.count==10,"Synchronization of threads failed")
00052         FreeCAD.Console.PrintMessage(str(self.count)+"\n")
00053 
00054     def testAsynchronPrintFromThread(self):
00055         import thread, time
00056         def adder():
00057             self.count=self.count+1
00058             # call of Console method is thread-safe
00059             FreeCAD.Console.PrintMessage("Call from Python thread (not synchronized): count="+str(self.count)+"\n")
00060 
00061         lock=thread.allocate_lock()
00062         for i in range(10):
00063             thread.start_new(adder,())
00064 
00065         time.sleep(3)
00066         FreeCAD.Console.PrintMessage(str(self.count)+"\n")
00067 
00068 #    def testStatus(self):
00069 #        SLog = FreeCAD.GetStatus("Console","Log")
00070 #        SErr = FreeCAD.GetStatus("Console","Err")
00071 #        SWrn = FreeCAD.GetStatus("Console","Wrn")
00072 #        SMsg = FreeCAD.GetStatus("Console","Msg")
00073 #        FreeCAD.SetStatus("Console","Log",1)
00074 #        FreeCAD.SetStatus("Console","Err",1)
00075 #        FreeCAD.SetStatus("Console","Wrn",1)
00076 #        FreeCAD.SetStatus("Console","Msg",1)
00077 #        self.failUnless(FreeCAD.GetStatus("Console","Msg")==1,"Set and read status failed (Console,Msg)")
00078 #        self.failUnless(FreeCAD.GetStatus("Console","Err")==1,"Set and read status failed (Console,Err)")
00079 #        self.failUnless(FreeCAD.GetStatus("Console","Wrn")==1,"Set and read status failed (Console,Wrn)")
00080 #        self.failUnless(FreeCAD.GetStatus("Console","Log")==1,"Set and read status failed (Console,Log)")
00081 #        FreeCAD.SetStatus("Console","Log",0)
00082 #        FreeCAD.SetStatus("Console","Err",0)
00083 #        FreeCAD.SetStatus("Console","Wrn",0)
00084 #        FreeCAD.SetStatus("Console","Msg",0)
00085 #        self.failUnless(FreeCAD.GetStatus("Console","Msg")==0,"Set and read status failed (Console,Msg)")
00086 #        self.failUnless(FreeCAD.GetStatus("Console","Err")==0,"Set and read status failed (Console,Err)")
00087 #        self.failUnless(FreeCAD.GetStatus("Console","Wrn")==0,"Set and read status failed (Console,Wrn)")
00088 #        self.failUnless(FreeCAD.GetStatus("Console","Log")==0,"Set and read status failed (Console,Log)")
00089 #        FreeCAD.SetStatus("Console","Log",SLog)
00090 #        FreeCAD.SetStatus("Console","Err",SErr)
00091 #        FreeCAD.SetStatus("Console","Wrn",SWrn)
00092 #        FreeCAD.SetStatus("Console","Msg",SMsg)
00093 
00094     def tearDown(self):
00095         pass
00096 
00097 class ParameterTestCase(unittest.TestCase):
00098     def setUp(self):
00099         self.TestPar = FreeCAD.ParamGet("System parameter:Test")
00100         
00101     def testGroup(self):
00102         #FreeCAD.Console.PrintLog("Base::ParameterTestCase::testGroup\n")
00103         # check on Group creation
00104         Temp = self.TestPar.GetGroup("44")
00105         self.failUnless(self.TestPar.HasGroup("44"),"Test on created group failed")
00106         # check on Deletion
00107         self.TestPar.RemGroup("44")
00108         self.failUnless(not self.TestPar.HasGroup("44"),"Test on delete group failed")
00109         Temp =0
00110 
00111         #check on special conditions
00112     def testInt(self):
00113         #FreeCAD.Console.PrintLog("Base::ParameterTestCase::testInt\n")
00114         #Temp = FreeCAD.ParamGet("System parameter:Test/44")
00115         # check on Int
00116         self.TestPar.SetInt("44",4711)
00117         self.failUnless(self.TestPar.GetInt("44") == 4711,"In and out error at Int")
00118         # check on Deletion
00119         self.TestPar.RemInt("44")
00120         self.failUnless(self.TestPar.GetInt("44",1) == 1,"Deletion error at Int")
00121         
00122 
00123     def testBool(self):
00124         #FreeCAD.Console.PrintLog("Base::ParameterTestCase::testBool\n")
00125         # check on Int
00126         self.TestPar.SetBool("44",1)
00127         self.failUnless(self.TestPar.GetBool("44") == 1,"In and out error at Bool")
00128         # check on Deletion
00129         self.TestPar.RemBool("44")
00130         self.failUnless(self.TestPar.GetBool("44",0) == 0,"Deletion error at Bool")
00131 
00132     def testFloat(self):
00133         #FreeCAD.Console.PrintLog("Base::ParameterTestCase::testFloat\n")
00134         #Temp = FreeCAD.ParamGet("System parameter:Test/44")
00135         # check on Int
00136         self.TestPar.SetFloat("44",4711.4711)
00137         self.failUnless(self.TestPar.GetFloat("44") == 4711.4711,"In and out error at Float")
00138         # check on Deletion
00139         self.TestPar.RemFloat("44")
00140         self.failUnless(self.TestPar.GetFloat("44",1.1) == 1.1,"Deletion error at Float")
00141 
00142     def testString(self):
00143         #FreeCAD.Console.PrintLog("Base::ParameterTestCase::testFloat\n")
00144         #Temp = FreeCAD.ParamGet("System parameter:Test/44")
00145         # check on Int
00146         self.TestPar.SetString("44","abcdefgh")
00147         self.failUnless(self.TestPar.GetString("44") == "abcdefgh","In and out error at String")
00148         # check on Deletion
00149         self.TestPar.RemString("44")
00150         self.failUnless(self.TestPar.GetString("44","hallo") == "hallo","Deletion error at String")
00151 
00152     def testNesting(self):
00153         # Parameter testing
00154         #FreeCAD.Console.PrintLog("Base::ParameterTestCase::testNesting\n")
00155         for i in range(50):
00156             self.TestPar.SetFloat(`i`,4711.4711)
00157             self.TestPar.SetInt(`i`,4711)
00158             self.TestPar.SetBool(`i`,1)
00159             Temp = self.TestPar.GetGroup(`i`)
00160             for l in range(50):
00161                 Temp.SetFloat(`l`,4711.4711)
00162                 Temp.SetInt(`l`,4711)
00163                 Temp.SetBool(`l`,1)
00164         Temp = 0
00165         
00166     def testExportImport(self):
00167         # Parameter testing
00168         #FreeCAD.Console.PrintLog("Base::ParameterTestCase::testNesting\n")
00169         self.TestPar.SetFloat("ExTest",4711.4711)
00170         self.TestPar.SetInt("ExTest",4711)
00171         self.TestPar.SetString("ExTest","4711")
00172         self.TestPar.SetBool("ExTest",1)
00173         Temp = self.TestPar.GetGroup("ExTest")
00174         Temp.SetFloat("ExTest",4711.4711)
00175         Temp.SetInt("ExTest",4711)
00176         Temp.SetString("ExTest","4711")
00177         Temp.SetBool("ExTest",1)
00178         TempPath = tempfile.gettempdir() + os.sep + "ExportTest.FCExport"
00179 
00180         self.TestPar.Export(TempPath)
00181         Temp = self.TestPar.GetGroup("ImportTest")
00182         Temp.Import(TempPath)
00183         self.failUnless(Temp.GetFloat("ExTest") == 4711.4711,"ExportImport error")
00184         Temp = 0
00185         
00186     def tearDown(self):
00187         #remove all
00188         TestPar = FreeCAD.ParamGet("System parameter:Test")
00189         TestPar.Clear()

Generated on Wed Nov 23 18:59:57 2011 for FreeCAD by  doxygen 1.6.1