UnitTestPy.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2006 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 
00026 #include <Base/PyObjectBase.h>
00027 #include <Base/Exception.h>
00028 #include <Base/Console.h>
00029 
00030 #include "UnitTestPy.h"
00031 #include "UnitTestImp.h"
00032 
00033 
00034 using namespace TestGui;
00035 
00036 
00037 void UnitTestDialogPy::init_type()
00038 {
00039     behaviors().name("TestGui.UnitTest");
00040     behaviors().doc("About TestGui.UnitTest");
00041     // you must have overwritten the virtual functions
00042     behaviors().supportRepr();
00043     behaviors().supportGetattr();
00044     behaviors().supportSetattr();
00045 
00046     add_varargs_method("clearErrorList",&UnitTestDialogPy::clearErrorList,"clearErrorList");
00047     add_varargs_method("insertError",&UnitTestDialogPy::insertError,"insertError");
00048     add_varargs_method("setUnitTest",&UnitTestDialogPy::setUnitTest,"setUnitTest");
00049     add_varargs_method("getUnitTest",&UnitTestDialogPy::getUnitTest,"getUnitTest");
00050     add_varargs_method("setStatusText",&UnitTestDialogPy::setStatusText,"setStatusText");
00051     add_varargs_method("setProgressFraction",&UnitTestDialogPy::setProgressFrac,"setProgressFraction");
00052     add_varargs_method("errorDialog",&UnitTestDialogPy::errorDialog,"errorDialog");
00053     add_varargs_method("setRunCount",&UnitTestDialogPy::setRunCount,"setRunCount");
00054     add_varargs_method("setFailCount",&UnitTestDialogPy::setFailCount,"setFailCount");
00055     add_varargs_method("setErrorCount",&UnitTestDialogPy::setErrorCount,"setErrorCount");
00056     add_varargs_method("setRemainCount",&UnitTestDialogPy::setRemainCount,"setRemainCount");
00057     add_varargs_method("updateGUI",&UnitTestDialogPy::updateGUI,"updateGUI");
00058 }
00059 
00060 UnitTestDialogPy::UnitTestDialogPy()
00061 {
00062 }
00063 
00064 UnitTestDialogPy::~UnitTestDialogPy()
00065 {
00066 }
00067 
00068 Py::Object UnitTestDialogPy::repr()
00069 {
00070     return Py::String("UnitTest");
00071 }
00072 
00073 Py::Object UnitTestDialogPy::getattr(const char * attr)
00074 {
00075     return Py::PythonExtension<UnitTestDialogPy>::getattr(attr);
00076 }
00077 
00078 int UnitTestDialogPy::setattr(const char * attr, const Py::Object & value)
00079 {
00080     return Py::PythonExtension<UnitTestDialogPy>::setattr(attr, value);
00081 }
00082 
00083 Py::Object UnitTestDialogPy::clearErrorList(const Py::Tuple& args)
00084 {
00085     if (!PyArg_ParseTuple(args.ptr(), ""))
00086         throw Py::Exception();
00087     UnitTestDialog::instance()->clearErrorList();
00088     return Py::None();
00089 }
00090 
00091 Py::Object UnitTestDialogPy::insertError(const Py::Tuple& args)
00092 {
00093     char *failure=0;
00094     char *details=0;
00095     if (!PyArg_ParseTuple(args.ptr(), "ss", &failure,&details))
00096         throw Py::Exception();
00097 
00098     UnitTestDialog::instance()->insertError(QString::fromLatin1(failure),
00099                                             QString::fromLatin1(details));
00100     return Py::None();
00101 }
00102 
00103 Py::Object UnitTestDialogPy::setUnitTest(const Py::Tuple& args)
00104 {
00105     char *pstr=0;
00106     if (!PyArg_ParseTuple(args.ptr(), "s", &pstr))
00107         throw Py::Exception();
00108 
00109     UnitTestDialog::instance()->setUnitTest(QString::fromLatin1(pstr));
00110     return Py::None();
00111 }
00112 
00113 Py::Object UnitTestDialogPy::getUnitTest(const Py::Tuple& args)
00114 {
00115     if (!PyArg_ParseTuple(args.ptr(), ""))
00116         throw Py::Exception();
00117     return Py::String((const char*)UnitTestDialog::instance()->getUnitTest().toAscii());
00118 }
00119 
00120 Py::Object UnitTestDialogPy::setStatusText(const Py::Tuple& args)
00121 {
00122     char *pstr=0;
00123     if (!PyArg_ParseTuple(args.ptr(), "s", &pstr))
00124         throw Py::Exception();
00125 
00126     UnitTestDialog::instance()->setStatusText(QString::fromLatin1(pstr));
00127     return Py::None();
00128 }
00129 
00130 Py::Object UnitTestDialogPy::setProgressFrac(const Py::Tuple& args)
00131 {
00132     float fraction;
00133     char* pColor=0;
00134     if (!PyArg_ParseTuple(args.ptr(), "f|s",&fraction, &pColor))
00135         throw Py::Exception();
00136 
00137     if (pColor)
00138         UnitTestDialog::instance()->setProgressFraction(fraction,QString::fromLatin1(pColor));
00139     else
00140       UnitTestDialog::instance()->setProgressFraction(fraction);
00141     return Py::None();
00142 }
00143 
00144 Py::Object UnitTestDialogPy::errorDialog(const Py::Tuple& args)
00145 {
00146     char *title=0;
00147     char *message=0;
00148     if (!PyArg_ParseTuple(args.ptr(), "ss", &title, &message))
00149         throw Py::Exception();
00150     UnitTestDialog::instance()->showErrorDialog(title,message);
00151     return Py::None();
00152 }
00153 
00154 Py::Object UnitTestDialogPy::setRunCount(const Py::Tuple& args)
00155 {
00156     int count;
00157     if (!PyArg_ParseTuple(args.ptr(), "i", &count))
00158         throw Py::Exception();
00159     UnitTestDialog::instance()->setRunCount(count);
00160     return Py::None();
00161 }
00162 
00163 Py::Object UnitTestDialogPy::setFailCount(const Py::Tuple& args)
00164 {
00165     int count;
00166     if (!PyArg_ParseTuple(args.ptr(), "i", &count))
00167         throw Py::Exception();
00168     UnitTestDialog::instance()->setFailCount(count);
00169     return Py::None();
00170 }
00171 
00172 Py::Object UnitTestDialogPy::setErrorCount(const Py::Tuple& args)
00173 {
00174     int count;
00175     if (!PyArg_ParseTuple(args.ptr(), "i", &count))
00176         throw Py::Exception();
00177     UnitTestDialog::instance()->setErrorCount(count);
00178     return Py::None();
00179 }
00180 
00181 Py::Object UnitTestDialogPy::setRemainCount(const Py::Tuple& args)
00182 {
00183     int count;
00184     if (!PyArg_ParseTuple(args.ptr(), "i", &count))
00185         throw Py::Exception();
00186     UnitTestDialog::instance()->setRemainCount(count);
00187     return Py::None();
00188 }
00189 
00190 Py::Object UnitTestDialogPy::updateGUI(const Py::Tuple& args)
00191 {
00192     if (!PyArg_ParseTuple(args.ptr(), ""))
00193         throw Py::Exception();
00194     qApp->processEvents();
00195     return Py::None();
00196 }
00197 
00198 //--------------------------------------------------------------------------
00199 // Type structure
00200 //--------------------------------------------------------------------------
00201 
00202 PyTypeObject TestGui::UnitTestPy::Type = {
00203         PyObject_HEAD_INIT(&PyType_Type)
00204         0,                                              /*ob_size*/
00205         "TestGui.UnitTest",                             /*tp_name*/
00206         sizeof(UnitTestPy),                     /*tp_basicsize*/
00207         0,                                              /*tp_itemsize*/
00208         /* methods */
00209         PyDestructor,                   /*tp_dealloc*/
00210         0,                                              /*tp_print*/
00211         __getattr,                              /*tp_getattr*/
00212         __setattr,                              /*tp_setattr*/
00213         0,                                              /*tp_compare*/
00214         __repr,                                 /*tp_repr*/
00215         0,                                              /*tp_as_number*/
00216         0,                                              /*tp_as_sequence*/
00217         0,                                              /*tp_as_mapping*/
00218         0,                                              /*tp_hash*/
00219         0,                                              /*tp_call */
00220   0,                                                /*tp_str  */
00221   0,                                                /*tp_getattro*/
00222   0,                                                /*tp_setattro*/
00223   /* --- Functions to access object as input/output buffer ---------*/
00224   0,                                                /* tp_as_buffer */
00225   /* --- Flags to define presence of optional/expanded features */
00226   Py_TPFLAGS_HAVE_CLASS,                            /*tp_flags */
00227   "About TestGui.UnitTest",                         /*tp_doc */
00228   0,                                                /*tp_traverse */
00229   0,                                                /*tp_clear */
00230   0,                                                /*tp_richcompare */
00231   0,                                                /*tp_weaklistoffset */
00232   0,                                                /*tp_iter */
00233   0,                                                /*tp_iternext */
00234   0,                                                /*tp_methods */
00235   0,                                                /*tp_members */
00236   0,                                                /*tp_getset */
00237   &Base::PyObjectBase::Type,                        /*tp_base */
00238   0,                                                /*tp_dict */
00239   0,                                                /*tp_descr_get */
00240   0,                                                /*tp_descr_set */
00241   0,                                                /*tp_dictoffset */
00242   0,                                                /*tp_init */
00243   0,                                                /*tp_alloc */
00244   UnitTestPy::PyMake,                               /*tp_new */
00245   0,                                                /*tp_free   Low-level free-memory routine */
00246   0,                                                /*tp_is_gc  For PyObject_IS_GC */
00247   0,                                                /*tp_bases */
00248   0,                                                /*tp_mro    method resolution order */
00249   0,                                                /*tp_cache */
00250   0,                                                /*tp_subclasses */
00251   0                                                 /*tp_weaklist */
00252 
00253 };
00254 
00255 //--------------------------------------------------------------------------
00256 // Methods structure
00257 //--------------------------------------------------------------------------
00258 PyMethodDef TestGui::UnitTestPy::Methods[] = {
00259   PYMETHODEDEF(clearErrorList)
00260   PYMETHODEDEF(insertError)
00261   PYMETHODEDEF(setUnitTest)
00262   PYMETHODEDEF(getUnitTest)
00263   PYMETHODEDEF(setStatusText)
00264   PYMETHODEDEF(setProgressFraction)
00265   PYMETHODEDEF(errorDialog)
00266   PYMETHODEDEF(setRunCount)
00267   PYMETHODEDEF(setFailCount)
00268   PYMETHODEDEF(setErrorCount)
00269   PYMETHODEDEF(setRemainCount)
00270   PYMETHODEDEF(updateGUI)
00271   {NULL, NULL}          /* Sentinel */
00272 };
00273 
00274 //--------------------------------------------------------------------------
00275 // Parents structure
00276 //--------------------------------------------------------------------------
00277 PyParentObject TestGui::UnitTestPy::Parents[] = {&PyObjectBase::Type, NULL};
00278 
00279 //--------------------------------------------------------------------------
00280 // Constructor
00281 //--------------------------------------------------------------------------
00282 TestGui::UnitTestPy::UnitTestPy(PyTypeObject *T)
00283 : PyObjectBase(0, T)
00284 {
00285 }
00286 
00287 PyObject *UnitTestPy::PyMake(PyTypeObject *ignored, PyObject *args, PyObject *kwds)     // Python wrapper
00288 {
00289         return new UnitTestPy();
00290 }
00291 
00292 //--------------------------------------------------------------------------
00293 // destructor
00294 //--------------------------------------------------------------------------
00295 UnitTestPy::~UnitTestPy()                                               // Everything handled in parent
00296 {
00297 }
00298 
00299 
00300 //--------------------------------------------------------------------------
00301 // UnitTestPy representation
00302 //--------------------------------------------------------------------------
00303 PyObject *UnitTestPy::_repr(void)
00304 {
00305         return Py_BuildValue("s", "UnitTest");
00306 }
00307 
00308 //--------------------------------------------------------------------------
00309 // UnitTestPy Attributes
00310 //--------------------------------------------------------------------------
00311 PyObject *UnitTestPy::_getattr(char *attr)                              // __getattr__ function: note only need to handle new state
00312 { 
00313    _getattr_up(PyObjectBase);
00314 } 
00315 
00316 int UnitTestPy::_setattr(char *attr, PyObject *value)   // __setattr__ function: note only need to handle new state
00317 { 
00318   return PyObjectBase::_setattr(attr, value);                                           
00319 } 
00320 
00321 
00322 //--------------------------------------------------------------------------
00323 // Python wrappers
00324 //--------------------------------------------------------------------------
00325 
00326 PYFUNCIMP_D(UnitTestPy,clearErrorList)
00327 {
00328   PY_TRY {
00329     UnitTestDialog::instance()->clearErrorList();
00330     Py_Return;
00331   }PY_CATCH;
00332 }
00333 
00334 PYFUNCIMP_D(UnitTestPy,insertError)
00335 {
00336   char *failure=0;
00337   char *details=0;
00338   if (!PyArg_ParseTuple(args, "ss", &failure,&details))     // convert args: Python->C 
00339     return NULL;                             // NULL triggers exception
00340   PY_TRY {
00341       UnitTestDialog::instance()->insertError(QString::fromLatin1(failure),
00342                                               QString::fromLatin1(details));
00343     Py_Return;
00344   }PY_CATCH;
00345 }
00346 
00347 PYFUNCIMP_D(UnitTestPy,setUnitTest)
00348 {
00349   char *pstr=0;
00350   if (!PyArg_ParseTuple(args, "s", &pstr))     // convert args: Python->C 
00351     return NULL;                             // NULL triggers exception
00352   PY_TRY {
00353     UnitTestDialog::instance()->setUnitTest(QString::fromLatin1(pstr));
00354     Py_Return;
00355   }PY_CATCH;
00356 }
00357 
00358 PYFUNCIMP_D(UnitTestPy,getUnitTest)
00359 {
00360   if (!PyArg_ParseTuple(args, ""))     // convert args: Python->C 
00361     return NULL;                             // NULL triggers exception
00362   PY_TRY {
00363     return Py_BuildValue("s", (const char*)UnitTestDialog::instance()->getUnitTest().toAscii());
00364   }PY_CATCH;
00365 }
00366 
00367 PYFUNCIMP_D(UnitTestPy,setStatusText)
00368 {
00369   char *pstr=0;
00370   if (!PyArg_ParseTuple(args, "s", &pstr))     // convert args: Python->C 
00371     return NULL;                             // NULL triggers exception
00372   PY_TRY {
00373     UnitTestDialog::instance()->setStatusText(QString::fromLatin1(pstr));
00374     Py_Return;
00375   }PY_CATCH;
00376 }
00377 
00378 PYFUNCIMP_D(UnitTestPy,setProgressFraction)
00379 {
00380   float fraction;
00381   char* pColor=0;
00382   if (!PyArg_ParseTuple(args, "f|s",&fraction, &pColor))     // convert args: Python->C
00383     return NULL;                       // NULL triggers exception
00384 
00385   PY_TRY {
00386     if (pColor)
00387         UnitTestDialog::instance()->setProgressFraction(fraction,QString::fromLatin1(pColor));
00388     else
00389       UnitTestDialog::instance()->setProgressFraction(fraction);
00390     Py_Return;
00391   }PY_CATCH;
00392 }
00393 
00394 PYFUNCIMP_D(UnitTestPy,errorDialog)
00395 {
00396   char *title=0;
00397   char *message=0;
00398   if (!PyArg_ParseTuple(args, "ss", &title, &message))     // convert args: Python->C 
00399     return NULL;                             // NULL triggers exception
00400   PY_TRY {
00401     UnitTestDialog::instance()->showErrorDialog(title,message);
00402     Py_Return;
00403   }PY_CATCH;
00404 }
00405 
00406 PYFUNCIMP_D(UnitTestPy,setRunCount)
00407 {
00408   int count;
00409   if (!PyArg_ParseTuple(args, "i", &count))     // convert args: Python->C 
00410     return NULL;                             // NULL triggers exception
00411   PY_TRY {
00412     UnitTestDialog::instance()->setRunCount(count);
00413     Py_Return;
00414   }PY_CATCH;
00415 }
00416 
00417 PYFUNCIMP_D(UnitTestPy,setFailCount)
00418 {
00419   int count;
00420   if (!PyArg_ParseTuple(args, "i", &count))     // convert args: Python->C 
00421     return NULL;                             // NULL triggers exception
00422   PY_TRY {
00423     UnitTestDialog::instance()->setFailCount(count);
00424     Py_Return;
00425   }PY_CATCH;
00426 }
00427 
00428 PYFUNCIMP_D(UnitTestPy,setErrorCount)
00429 {
00430   int count;
00431   if (!PyArg_ParseTuple(args, "i", &count))     // convert args: Python->C 
00432     return NULL;                             // NULL triggers exception
00433   PY_TRY {
00434     UnitTestDialog::instance()->setErrorCount(count);
00435     Py_Return;
00436   }PY_CATCH;
00437 }
00438 
00439 PYFUNCIMP_D(UnitTestPy,setRemainCount)
00440 {
00441   int count;
00442   if (!PyArg_ParseTuple(args, "i", &count))     // convert args: Python->C 
00443     return NULL;                             // NULL triggers exception
00444   PY_TRY {
00445     UnitTestDialog::instance()->setRemainCount(count);
00446     Py_Return;
00447   }PY_CATCH;
00448 }
00449 
00450 PYFUNCIMP_D(UnitTestPy,updateGUI)
00451 {
00452   PY_TRY {
00453     qApp->processEvents();
00454           Py_Return;
00455   }PY_CATCH;
00456 }
00457 

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