Skip to content

Commit

Permalink
+ clean-up, fix and new methods added in unit test module
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Oct 19, 2015
1 parent 28abf35 commit 169b2e3
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 327 deletions.
39 changes: 0 additions & 39 deletions src/Mod/Test/Gui/AppTestGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,41 +79,6 @@ class UnitTestModule : public Py::ExtensionModule<UnitTestModule>
return Py::None();
}
};
/*
static PyObject* addTest(PyObject *self, PyObject *args)
{
char *pstr=0;
if (!PyArg_ParseTuple(args, "|s", &pstr)) // convert args: Python->C
return NULL; // NULL triggers exception
TestGui::UnitTestDialog* dlg = TestGui::UnitTestDialog::instance();
if (pstr)
dlg->addUnitTest(QString::fromLatin1(pstr));
dlg->show();
dlg->raise();
Py_Return;
}
static PyObject* setTest(PyObject *self, PyObject *args)
{
char *pstr=0;
if (!PyArg_ParseTuple(args, "|s", &pstr)) // convert args: Python->C
return NULL; // NULL triggers exception
TestGui::UnitTestDialog* dlg = TestGui::UnitTestDialog::instance();
if (pstr)
dlg->setUnitTest(QString::fromLatin1(pstr));
dlg->show();
dlg->raise();
Py_Return;
}
*/
/* registration table */
//static struct PyMethodDef TestGui_methods[] = {
// {"addTest", addTest, 1},
// {"setTest", setTest, 1},
// {NULL, NULL} /* end of table marker */
//};

void loadTestResource()
{
Expand All @@ -130,10 +95,6 @@ void AppTestGuiExport initQtUnitGui()
// with the Python runtime system
(void)new UnitTestModule;

//if(PyType_Ready(&TestGui::UnitTestPy::Type) < 0) return;
//PyObject* pyModule = Py_InitModule("QtUnitGui", TestGui_methods); /* mod name, table ptr */
//union PyType_Object pyDlgType = {&TestGui::UnitTestPy::Type};
//PyModule_AddObject(pyModule, "UnitTest", pyDlgType.o);
Base::Console().Log("Loading GUI of Test module... done\n");

// add resources and reloads the translators
Expand Down
8 changes: 8 additions & 0 deletions src/Mod/Test/Gui/UnitTestImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ void UnitTestDialog::setUnitTest(const QString& unit)
}
}

/**
* Clears the unit tests.
*/
void UnitTestDialog::clearUnitTests()
{
this->comboTests->clear();
}

/**
* Returns the unit test.
*/
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Test/Gui/UnitTestImp.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class UnitTestDialog : public QDialog, public Ui_UnitTest
void showErrorDialog(const char* title, const char* message);
void addUnitTest(const QString& unit);
void setUnitTest(const QString& unit);
void clearUnitTests();
QString getUnitTest() const;
void setStatusText(const QString& text);
void setProgressFraction(float fraction, const QString& = QString::null);
Expand Down
265 changes: 15 additions & 250 deletions src/Mod/Test/Gui/UnitTestPy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ void UnitTestDialogPy::init_type()
add_varargs_method("setErrorCount",&UnitTestDialogPy::setErrorCount,"setErrorCount");
add_varargs_method("setRemainCount",&UnitTestDialogPy::setRemainCount,"setRemainCount");
add_varargs_method("updateGUI",&UnitTestDialogPy::updateGUI,"updateGUI");
add_varargs_method("addUnitTest",&UnitTestDialogPy::addUnitTest,"addUnitTest");
add_varargs_method("clearUnitTests",&UnitTestDialogPy::clearUnitTests,"clearUnitTests");
}

UnitTestDialogPy::UnitTestDialogPy()
Expand Down Expand Up @@ -191,262 +193,25 @@ Py::Object UnitTestDialogPy::updateGUI(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))
throw Py::Exception();
qApp->processEvents();
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
return Py::None();
}

//--------------------------------------------------------------------------
// Type structure
//--------------------------------------------------------------------------

PyTypeObject TestGui::UnitTestPy::Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*ob_size*/
"TestGui.UnitTest", /*tp_name*/
sizeof(UnitTestPy), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
PyDestructor, /*tp_dealloc*/
0, /*tp_print*/
__getattr, /*tp_getattr*/
__setattr, /*tp_setattr*/
0, /*tp_compare*/
__repr, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash*/
0, /*tp_call */
0, /*tp_str */
0, /*tp_getattro*/
0, /*tp_setattro*/
/* --- Functions to access object as input/output buffer ---------*/
0, /* tp_as_buffer */
/* --- Flags to define presence of optional/expanded features */
Py_TPFLAGS_HAVE_CLASS, /*tp_flags */
"About TestGui.UnitTest", /*tp_doc */
0, /*tp_traverse */
0, /*tp_clear */
0, /*tp_richcompare */
0, /*tp_weaklistoffset */
0, /*tp_iter */
0, /*tp_iternext */
0, /*tp_methods */
0, /*tp_members */
0, /*tp_getset */
&Base::PyObjectBase::Type, /*tp_base */
0, /*tp_dict */
0, /*tp_descr_get */
0, /*tp_descr_set */
0, /*tp_dictoffset */
0, /*tp_init */
0, /*tp_alloc */
UnitTestPy::PyMake, /*tp_new */
0, /*tp_free Low-level free-memory routine */
0, /*tp_is_gc For PyObject_IS_GC */
0, /*tp_bases */
0, /*tp_mro method resolution order */
0, /*tp_cache */
0, /*tp_subclasses */
0 /*tp_weaklist */

};

//--------------------------------------------------------------------------
// Methods structure
//--------------------------------------------------------------------------
PyMethodDef TestGui::UnitTestPy::Methods[] = {
PYMETHODEDEF(clearErrorList)
PYMETHODEDEF(insertError)
PYMETHODEDEF(setUnitTest)
PYMETHODEDEF(getUnitTest)
PYMETHODEDEF(setStatusText)
PYMETHODEDEF(setProgressFraction)
PYMETHODEDEF(errorDialog)
PYMETHODEDEF(setRunCount)
PYMETHODEDEF(setFailCount)
PYMETHODEDEF(setErrorCount)
PYMETHODEDEF(setRemainCount)
PYMETHODEDEF(updateGUI)
{NULL, NULL} /* Sentinel */
};

//--------------------------------------------------------------------------
// Constructor
//--------------------------------------------------------------------------
TestGui::UnitTestPy::UnitTestPy(PyTypeObject *T)
: PyObjectBase(0, T)
Py::Object UnitTestDialogPy::addUnitTest(const Py::Tuple& args)
{
}

PyObject *UnitTestPy::PyMake(PyTypeObject *ignored, PyObject *args, PyObject *kwds) // Python wrapper
{
return new UnitTestPy();
}

//--------------------------------------------------------------------------
// destructor
//--------------------------------------------------------------------------
UnitTestPy::~UnitTestPy() // Everything handled in parent
{
}


//--------------------------------------------------------------------------
// UnitTestPy representation
//--------------------------------------------------------------------------
PyObject *UnitTestPy::_repr(void)
{
return Py_BuildValue("s", "UnitTest");
}

//--------------------------------------------------------------------------
// UnitTestPy Attributes
//--------------------------------------------------------------------------
PyObject *UnitTestPy::_getattr(char *attr) // __getattr__ function: note only need to handle new state
{
_getattr_up(PyObjectBase);
}

int UnitTestPy::_setattr(char *attr, PyObject *value) // __setattr__ function: note only need to handle new state
{
return PyObjectBase::_setattr(attr, value);
}


//--------------------------------------------------------------------------
// Python wrappers
//--------------------------------------------------------------------------

PYFUNCIMP_D(UnitTestPy,clearErrorList)
{
PY_TRY {
UnitTestDialog::instance()->clearErrorList();
Py_Return;
}PY_CATCH;
}

PYFUNCIMP_D(UnitTestPy,insertError)
{
char *failure=0;
char *details=0;
if (!PyArg_ParseTuple(args, "ss", &failure,&details)) // convert args: Python->C
return NULL; // NULL triggers exception
PY_TRY {
UnitTestDialog::instance()->insertError(QString::fromLatin1(failure),
QString::fromLatin1(details));
Py_Return;
}PY_CATCH;
}

PYFUNCIMP_D(UnitTestPy,setUnitTest)
{
char *pstr=0;
if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C
return NULL; // NULL triggers exception
PY_TRY {
UnitTestDialog::instance()->setUnitTest(QString::fromLatin1(pstr));
Py_Return;
}PY_CATCH;
}

PYFUNCIMP_D(UnitTestPy,getUnitTest)
{
if (!PyArg_ParseTuple(args, "")) // convert args: Python->C
return NULL; // NULL triggers exception
PY_TRY {
return Py_BuildValue("s", (const char*)UnitTestDialog::instance()->getUnitTest().toAscii());
}PY_CATCH;
}

PYFUNCIMP_D(UnitTestPy,setStatusText)
{
char *pstr=0;
if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C
return NULL; // NULL triggers exception
PY_TRY {
UnitTestDialog::instance()->setStatusText(QString::fromLatin1(pstr));
Py_Return;
}PY_CATCH;
}

PYFUNCIMP_D(UnitTestPy,setProgressFraction)
{
float fraction;
char* pColor=0;
if (!PyArg_ParseTuple(args, "f|s",&fraction, &pColor)) // convert args: Python->C
return NULL; // NULL triggers exception

PY_TRY {
if (pColor)
UnitTestDialog::instance()->setProgressFraction(fraction,QString::fromLatin1(pColor));
else
UnitTestDialog::instance()->setProgressFraction(fraction);
Py_Return;
}PY_CATCH;
}

PYFUNCIMP_D(UnitTestPy,errorDialog)
{
char *title=0;
char *message=0;
if (!PyArg_ParseTuple(args, "ss", &title, &message)) // convert args: Python->C
return NULL; // NULL triggers exception
PY_TRY {
UnitTestDialog::instance()->showErrorDialog(title,message);
Py_Return;
}PY_CATCH;
}

PYFUNCIMP_D(UnitTestPy,setRunCount)
{
int count;
if (!PyArg_ParseTuple(args, "i", &count)) // convert args: Python->C
return NULL; // NULL triggers exception
PY_TRY {
UnitTestDialog::instance()->setRunCount(count);
Py_Return;
}PY_CATCH;
}

PYFUNCIMP_D(UnitTestPy,setFailCount)
{
int count;
if (!PyArg_ParseTuple(args, "i", &count)) // convert args: Python->C
return NULL; // NULL triggers exception
PY_TRY {
UnitTestDialog::instance()->setFailCount(count);
Py_Return;
}PY_CATCH;
}

PYFUNCIMP_D(UnitTestPy,setErrorCount)
{
int count;
if (!PyArg_ParseTuple(args, "i", &count)) // convert args: Python->C
return NULL; // NULL triggers exception
PY_TRY {
UnitTestDialog::instance()->setErrorCount(count);
Py_Return;
}PY_CATCH;
}
char *pstr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr))
throw Py::Exception();

PYFUNCIMP_D(UnitTestPy,setRemainCount)
{
int count;
if (!PyArg_ParseTuple(args, "i", &count)) // convert args: Python->C
return NULL; // NULL triggers exception
PY_TRY {
UnitTestDialog::instance()->setRemainCount(count);
Py_Return;
}PY_CATCH;
TestGui::UnitTestDialog* dlg = TestGui::UnitTestDialog::instance();
dlg->addUnitTest(QString::fromLatin1(pstr));
return Py::None();
}

PYFUNCIMP_D(UnitTestPy,updateGUI)
Py::Object UnitTestDialogPy::clearUnitTests(const Py::Tuple& args)
{
PY_TRY {
qApp->processEvents();
Py_Return;
}PY_CATCH;
if (!PyArg_ParseTuple(args.ptr(), ""))
throw Py::Exception();
UnitTestDialog::instance()->clearUnitTests();
return Py::None();
}

Loading

0 comments on commit 169b2e3

Please sign in to comment.