Skip to content

Commit

Permalink
Merge branch 'master' of github.com:FreeCAD/FreeCAD
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Aug 13, 2015
2 parents f64678a + 4dee066 commit 6170882
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/Base/Console.cpp
Expand Up @@ -42,9 +42,6 @@ using namespace Base;



char format[4024]; // global buffer
const unsigned int format_len = 4024;


//**************************************************************************
// Construction destruction
Expand Down Expand Up @@ -171,6 +168,9 @@ bool ConsoleSingleton::IsMsgTypeEnabled(const char* sObs, FreeCAD_ConsoleMsgType
*/
void ConsoleSingleton::Message( const char *pMsg, ... )
{
char format[4024];
const unsigned int format_len = 4024;

va_list namelessVars;
va_start(namelessVars, pMsg); // Get the "..." vars
vsnprintf(format, format_len, pMsg, namelessVars);
Expand All @@ -195,6 +195,9 @@ void ConsoleSingleton::Message( const char *pMsg, ... )
*/
void ConsoleSingleton::Warning( const char *pMsg, ... )
{
char format[4024];
const unsigned int format_len = 4024;

va_list namelessVars;
va_start(namelessVars, pMsg); // Get the "..." vars
vsnprintf(format, format_len, pMsg, namelessVars);
Expand All @@ -219,6 +222,9 @@ void ConsoleSingleton::Warning( const char *pMsg, ... )
*/
void ConsoleSingleton::Error( const char *pMsg, ... )
{
char format[4024];
const unsigned int format_len = 4024;

va_list namelessVars;
va_start(namelessVars, pMsg); // Get the "..." vars
vsnprintf(format, format_len, pMsg, namelessVars);
Expand Down Expand Up @@ -246,6 +252,9 @@ void ConsoleSingleton::Error( const char *pMsg, ... )

void ConsoleSingleton::Log( const char *pMsg, ... )
{
char format[4024];
const unsigned int format_len = 4024;

if (!_bVerbose)
{
va_list namelessVars;
Expand Down
107 changes: 107 additions & 0 deletions src/Gui/CommandTest.cpp
Expand Up @@ -33,6 +33,8 @@
# include <QMdiSubWindow>
# include <QWaitCondition>
# include <QTranslator>
# include <QRunnable>
# include <QThreadPool>
#endif

#include <Base/Console.h>
Expand Down Expand Up @@ -638,6 +640,110 @@ bool CmdTestMDI3::isActive(void)
return getMainWindow()->activeWindow();
}

DEF_STD_CMD(CmdTestConsoleOutput);

CmdTestConsoleOutput::CmdTestConsoleOutput()
: Command("Std_TestConsoleOutput")
{
sGroup = QT_TR_NOOP("Standard-Test");
sMenuText = QT_TR_NOOP("Test console output");
sToolTipText= QT_TR_NOOP("Test console output");
sStatusTip = QT_TR_NOOP("Test console output");
}

namespace Gui {
class TestConsoleObserver : public Base::ConsoleObserver
{
QMutex mutex;
public:
int matchMsg, matchWrn, matchErr, matchLog;
TestConsoleObserver() : matchMsg(0), matchWrn(0), matchErr(0), matchLog(0)
{
}
virtual void Warning(const char * msg)
{
mutex.lock();
matchWrn += strcmp(msg, "Write a warning to the console output.\n");
mutex.unlock();
}
virtual void Message(const char * msg)
{
mutex.lock();
matchMsg += strcmp(msg, "Write a message to the console output.\n");
mutex.unlock();
}
virtual void Error(const char * msg)
{
mutex.lock();
matchErr += strcmp(msg, "Write an error to the console output.\n");
mutex.unlock();
}
virtual void Log(const char * msg)
{
mutex.lock();
matchLog += strcmp(msg, "Write a log to the console output.\n");
mutex.unlock();
}
};

class ConsoleMessageTask : public QRunnable
{
public:
void run()
{
for (int i=0; i<10; i++)
Base::Console().Message("Write a message to the console output.\n");
}
};

class ConsoleWarningTask : public QRunnable
{
public:
void run()
{
for (int i=0; i<10; i++)
Base::Console().Warning("Write a warning to the console output.\n");
}
};

class ConsoleErrorTask : public QRunnable
{
public:
void run()
{
for (int i=0; i<10; i++)
Base::Console().Error("Write an error to the console output.\n");
}
};

class ConsoleLogTask : public QRunnable
{
public:
void run()
{
for (int i=0; i<10; i++)
Base::Console().Log("Write a log to the console output.\n");
}
};

}

void CmdTestConsoleOutput::activated(int iMsg)
{
TestConsoleObserver obs;
Base::Console().AttachObserver(&obs);
QThreadPool::globalInstance()->start(new ConsoleMessageTask);
QThreadPool::globalInstance()->start(new ConsoleWarningTask);
QThreadPool::globalInstance()->start(new ConsoleErrorTask);
QThreadPool::globalInstance()->start(new ConsoleLogTask);
QThreadPool::globalInstance()->waitForDone();
Base::Console().DetachObserver(&obs);

if (obs.matchMsg > 0 || obs.matchWrn > 0 || obs.matchErr > 0 || obs.matchLog > 0) {
Base::Console().Error("Race condition in Console class\n");
}
}


namespace Gui {

Expand All @@ -661,6 +767,7 @@ void CreateTestCommands(void)
rcCmdMgr.addCommand(new CmdTestMDI1());
rcCmdMgr.addCommand(new CmdTestMDI2());
rcCmdMgr.addCommand(new CmdTestMDI3());
rcCmdMgr.addCommand(new CmdTestConsoleOutput());
}

} // namespace Gui
4 changes: 3 additions & 1 deletion src/Gui/Qt4All.h
Expand Up @@ -37,12 +37,14 @@
#include <QProcess>
#include <qrect.h>
#include <qregexp.h>
#include <qrunnable.h>
#include <QSet>
#include <QSignalMapper>
#include <QTemporaryFile>
#include <qtextcodec.h>
#include <qtextstream.h>
#include <qthread.h>
#include <qthreadpool.h>
#include <qtimer.h>
#include <qtranslator.h>
#include <QUrl>
Expand Down Expand Up @@ -122,7 +124,7 @@
#include <QStylePainter>
#include <QSyntaxHighlighter>
#include <qtabbar.h>
#include <QTableView>
#include <QTableView>
#include <qtabwidget.h>
#include <QTextBrowser>
#include <QTextDocument>
Expand Down
4 changes: 4 additions & 0 deletions src/Mod/Test/InitGui.py
Expand Up @@ -86,6 +86,10 @@ def Initialize(self):
list = ["Std_TestProgress1", "Std_TestProgress2", "Std_TestProgress3", "Std_TestProgress4", "Std_TestProgress5"]
self.appendMenu(menu,list)

menu = ["Test &Commands","Console"]
list = ["Std_TestConsoleOutput"]
self.appendMenu(menu,list)

menu = ["Test &Commands","MDI"]
list = ["Std_MDITest1", "Std_MDITest2", "Std_MDITest3"]
self.appendMenu(menu,list)
Expand Down

0 comments on commit 6170882

Please sign in to comment.