Tests.py

Go to the documentation of this file.
00001 # FreeCAD TemplatePyMod module  
00002 # (c) 2007 Juergen Riegel LGPL
00003 
00004 
00005 import FreeCAD, unittest
00006 
00007 
00008 #---------------------------------------------------------------------------
00009 # define the test cases for this module
00010 #---------------------------------------------------------------------------
00011 
00012 
00013 class ParameterTestCase(unittest.TestCase):
00014     def setUp(self):
00015         self.TestPar = FreeCAD.ParamGet("System parameter:Test")
00016         
00017     def testGroup(self):
00018         #FreeCAD.PrintLog("Base::ParameterTestCase::testGroup\n")
00019         # check on Group creation
00020         Temp = self.TestPar.GetGroup("44")
00021         self.failUnless(self.TestPar.HasGroup("44"),"Test on created group failed")
00022         # check on Deletion
00023         self.TestPar.RemGroup("44")
00024         self.failUnless(not self.TestPar.HasGroup("44"),"Test on delete group failed")
00025         Temp =0
00026 
00027         #check on special conditions
00028     def testInt(self):
00029         #FreeCAD.PrintLog("Base::ParameterTestCase::testInt\n")
00030         #Temp = FreeCAD.ParamGet("System parameter:Test/44")
00031         # check on Int
00032         self.TestPar.SetInt("44",4711)
00033         self.failUnless(self.TestPar.GetInt("44") == 4711,"In and out error at Int")
00034         # check on Deletion
00035         self.TestPar.RemInt("44")
00036         self.failUnless(self.TestPar.GetInt("44",1) == 1,"Deletion error at Int")
00037         
00038 
00039     def testBool(self):
00040         #FreeCAD.PrintLog("Base::ParameterTestCase::testBool\n")
00041         # check on Int
00042         self.TestPar.SetBool("44",1)
00043         self.failUnless(self.TestPar.GetBool("44") == 1,"In and out error at Bool")
00044         # check on Deletion
00045         self.TestPar.RemBool("44")
00046         self.failUnless(self.TestPar.GetBool("44",0) == 0,"Deletion error at Bool")
00047 
00048     def testFloat(self):
00049         #FreeCAD.PrintLog("Base::ParameterTestCase::testFloat\n")
00050         #Temp = FreeCAD.ParamGet("System parameter:Test/44")
00051         # check on Int
00052         self.TestPar.SetFloat("44",4711.4711)
00053         self.failUnless(self.TestPar.GetFloat("44") == 4711.4711,"In and out error at Float")
00054         # check on Deletion
00055         self.TestPar.RemFloat("44")
00056         self.failUnless(self.TestPar.GetFloat("44",1.1) == 1.1,"Deletion error at Float")
00057 
00058     def testString(self):
00059         #FreeCAD.PrintLog("Base::ParameterTestCase::testFloat\n")
00060         #Temp = FreeCAD.ParamGet("System parameter:Test/44")
00061         # check on Int
00062         self.TestPar.SetString("44","abcdefgh")
00063         self.failUnless(self.TestPar.GetString("44") == "abcdefgh","In and out error at String")
00064         # check on Deletion
00065         self.TestPar.RemString("44")
00066         self.failUnless(self.TestPar.GetString("44","hallo") == "hallo","Deletion error at String")
00067 
00068     def testNesting(self):
00069         # Parameter testing
00070         #FreeCAD.PrintLog("Base::ParameterTestCase::testNesting\n")
00071         for i in range(50):
00072             self.TestPar.SetFloat(`i`,4711.4711)
00073             self.TestPar.SetInt(`i`,4711)
00074             self.TestPar.SetBool(`i`,1)
00075             Temp = self.TestPar.GetGroup(`i`)
00076             for l in range(50):
00077                 Temp.SetFloat(`l`,4711.4711)
00078                 Temp.SetInt(`l`,4711)
00079                 Temp.SetBool(`l`,1)
00080         Temp = 0
00081         
00082     def testExportImport(self):
00083         # Parameter testing
00084         #FreeCAD.PrintLog("Base::ParameterTestCase::testNesting\n")
00085         self.TestPar.SetFloat("ExTest",4711.4711)
00086         self.TestPar.SetInt("ExTest",4711)
00087         self.TestPar.SetString("ExTest","4711")
00088         self.TestPar.SetBool("ExTest",1)
00089         Temp = self.TestPar.GetGroup("ExTest")
00090         Temp.SetFloat("ExTest",4711.4711)
00091         Temp.SetInt("ExTest",4711)
00092         Temp.SetString("ExTest","4711")
00093         Temp.SetBool("ExTest",1)
00094         self.TestPar.Export("ExportTest.FCExport")
00095         Temp = self.TestPar.GetGroup("ImportTest")
00096         Temp.Import("ExportTest.FCExport")
00097         self.failUnless(Temp.GetFloat("ExTest") == 4711.4711,"ExportImport error")
00098         Temp = 0
00099         
00100     def tearDown(self):
00101         #remove all
00102         TestPar = FreeCAD.ParamGet("System parameter:Test")
00103         TestPar.Clear()
00104 
00105 
00106 
00107     
00108 
00109 
00110         
00111 

Generated on Wed Nov 23 19:00:45 2011 for FreeCAD by  doxygen 1.6.1