[avida-cvs] avida CVS commits: /current/source modules.pri /current/source/qt-viewer Makefile.am qt_test_case.cc qt_test_case.hh template.t.cc /current/source/third-party Makefile.am

kaben avida-cvs at alife.org
Tue Nov 25 19:43:48 PST 2003


kaben		Tue Nov 25 11:43:48 2003 EDT

  Added files:                 
    /avida/current/source/qt-viewer	qt_test_case.cc qt_test_case.hh 
                                   	template.t.cc 

  Modified files:              
    /avida/current/source	modules.pri 
    /avida/current/source/qt-viewer	Makefile.am 
    /avida/current/source/third-party	Makefile.am 
  Log:
  
  Makefile and qmake .pri modules fixups;
  
  Added missing support code for unit test of qt classes (but those tests
  don't yet work).
  
  
  
Index: avida/current/source/modules.pri
diff -u avida/current/source/modules.pri:1.5 avida/current/source/modules.pri:1.6
--- avida/current/source/modules.pri:1.5	Wed Oct 15 21:33:04 2003
+++ avida/current/source/modules.pri	Tue Nov 25 11:43:47 2003
@@ -2,7 +2,7 @@
 CPU_CC    = $$AVIDA_SRC_DIR/cpu
 EVENT_CC  = $$AVIDA_SRC_DIR/event
 MAIN_CC   = $$AVIDA_SRC_DIR/main
-TRIO_C    = $$AVIDA_SRC_DIR/third-party/trio-1.9
+TRIO_C    = $$AVIDA_SRC_DIR/third-party/trio
 TOOLS_CC  = $$AVIDA_SRC_DIR/tools
 SUPPORT_CC= $$AVIDA_SRC_DIR/support
 DOC_CC	  = $$AVIDA_SRC_DIR/../doc
Index: avida/current/source/qt-viewer/Makefile.am
diff -u avida/current/source/qt-viewer/Makefile.am:1.50 avida/current/source/qt-viewer/Makefile.am:1.51
--- avida/current/source/qt-viewer/Makefile.am:1.50	Tue Nov 25 10:20:44 2003
+++ avida/current/source/qt-viewer/Makefile.am	Tue Nov 25 11:43:48 2003
@@ -7,6 +7,7 @@
 
 if QMAKE_DEBUG
 QMAKE_OPTIONS+="CONFIG*=debug"
+QMAKE_OPTIONS+="DEFINES+=DEBUG"
 else
 QMAKE_OPTIONS+="DEFINES+=NDEBUG"
 endif
@@ -23,7 +24,6 @@
 #QMAKE_OPTIONS+="AT_HTMLDIR=$(HTMLDIR)"
 QMAKE_OPTIONS+="AT_DATADIR=$(datadir)"
 QMAKE_OPTIONS+="AT_PWD=`pwd`"
-QMAKE_OPTIONS+="DEFINES+=DEBUG"
 
 SUFFIXES = .cc
 
@@ -46,10 +46,8 @@
 
 avida: avida.qmakefile cPopulation_enums_auto.ci FORCE
 	${MAKE} -f avida.qmakefile
-qt-viewer: qt-viewer.qmakefile cPopulation_enums_auto.ci FORCE
-	${MAKE} -f qt-viewer.qmakefile
 
-bin_PROGRAMS = qt-viewer avida
+bin_PROGRAMS = avida
 
 CLEANFILES = cPopulation_enums_auto.ci 		\
 	cPopulation_name2enum_auto.ci  		\
@@ -208,10 +206,11 @@
 .cc.o:
 	$(QTDIR)/bin/moc $< -o $(<:%.cc=%.moc)
 	$(CXXCOMPILE) -c $<
-template_t_SOURCES = template.t.cc
+#template_t_SOURCES = template.t.cc
+
+#check_PROGRAMS = $(TESTSUITES)
+#TESTS = $(TESTSUITES)
 
-check_PROGRAMS = $(TESTSUITES)
-TESTS = $(TESTSUITES)
+#TESTSUITES = \
+#  template.t
 
-TESTSUITES = \
-  template.t
Index: avida/current/source/third-party/Makefile.am
diff -u avida/current/source/third-party/Makefile.am:1.2 avida/current/source/third-party/Makefile.am:1.3
--- avida/current/source/third-party/Makefile.am:1.2	Thu May 22 11:58:53 2003
+++ avida/current/source/third-party/Makefile.am	Tue Nov 25 11:43:48 2003
@@ -1,3 +1 @@
-
-
-SUBDIRS = trio-1.9
+SUBDIRS = mockpp trio yaktest

Index: avida/current/source/qt-viewer/qt_test_case.cc
+++ avida/current/source/qt-viewer/qt_test_case.cc
#ifndef QT_TEST_CASE_HH
#include "qt_test_case.hh"
#endif

#ifndef QAPPLICATION_H
#include <qapplication.h>
#endif
#ifndef QTIMER_H
#include <qtimer.h>
#endif

cQtTestCase::cQtTestCase(int argc, char **argv)
: QObject(0, "<cQtTestCase>")
, m_a(0)
, m_t(0)
, m_deadman(0)
, m_argc(argc)
, m_argv(argv)
{
  m_a = new QApplication(m_argc, m_argv);
  m_t = new QTimer(this);
  connect(m_t, SIGNAL(timeout()), this, SLOT(testDriver()));
  m_deadman = new QTimer(this);
  connect(m_deadman, SIGNAL(timeout()), this, SLOT(timeOut()));
}
cQtTestCase::~cQtTestCase(){
  if(m_deadman){ delete m_deadman; m_deadman = 0; }
  if(m_t){ delete m_t; m_t = 0; }
  if(m_a){ delete m_a; m_a = 0; }
}
void cQtTestCase::restartTimer(int milliseconds, bool one_shot){
  if(m_t) m_t->start(milliseconds, one_shot);
}
void cQtTestCase::resetDeadMan(int milliseconds){
  if(m_deadman) m_deadman->changeInterval(milliseconds);
}
int cQtTestCase::execApp(){
  return (m_a != 0)?(m_a->exec()):(1);
}
void cQtTestCase::exitApp(int retval){
  if (m_a != 0) m_a->exit(retval);
}
void cQtTestCase::pushFunctor(tFunctor &functor){
  m_functor_list.PushRear(&functor);
}
tFunctor *popFunctor(){
  return m_functor_list.Pop();
}
void cQtTestCase::twiddle(){
  restartTimer();
  qDebug("twiddling my thumbs...");
  resetDeadMan();
}
void cQtTestCase::timeOut(){
  qWarning("ERROR: timed out while waiting for event to be triggered...");
  test_non_error(false);
  twiddle();
}
void cQtTestCase::testDriver(){
  if(tFunctor *functor = popFunctor()){ (*functor)(); }
  else exitApp();
}

Index: avida/current/source/qt-viewer/qt_test_case.hh
+++ avida/current/source/qt-viewer/qt_test_case.hh
#ifndef QT_TEST_CASE_HH
#define QT_TEST_CASE_HH

#ifndef TLIST_HH
#include "tList.hh"
#endif

#ifndef TEST_CASE_H
#include "third-party/yaktest/test_case.h"
#endif
#ifndef TEST_RESULT_H
#include "third-party/yaktest/test_result.h"
#endif

/* XXX disables the Loki small-object allocator; it crashes under OSX10. */
#ifndef MAX_SMALL_OBJECT_SIZE
#define MAX_SMALL_OBJECT_SIZE 0
#endif
#ifndef FUNCTOR_INC
#include "third-party/Loki/Functor.h"
#endif

#ifndef QOBJECT_H
#include <qobject.h>
#endif

class QApplication;
class QTimer;
class cQtTestCase : public QObject, public test_case {
Q_OBJECT
protected: // variables
  typedef Loki::Functor<void> tFunctor;
  tList<tFunctor> m_functor_list;
  QApplication *m_a;
  QTimer *m_t;
  QTimer *m_deadman;
  int m_argc;
  char **m_argv;
protected: // constructors/destructors
  cQtTestCase(int argc, char **argv);
  ~cQtTestCase();
protected: // manipulators
  void restartTimer(int milliseconds = 0, bool one_shot = true);
  void resetDeadMan(int milliseconds = 5000);
  int execApp();
  void exitApp(int retval = 0);
  void pushFunctor(tFunctor &functor);
  tFunctor *popFunctor();
protected slots:
  virtual void twiddle();
  virtual void timeOut();
  virtual void testDriver();
};

#endif

Index: avida/current/source/qt-viewer/template.t.cc
+++ avida/current/source/qt-viewer/template.t.cc
#ifndef QT_TEST_CASE_HH
#include "qt_test_case.hh"
#endif

#ifndef TEST_CASE_H
#include "third-party/yaktest/test_case.h"
#endif
#ifndef TEXT_TEST_INTERPRETER_H
#include "third-party/yaktest/text_test_interpreter.h"
#endif
#ifndef TEST_RESULT_H
#include "third-party/yaktest/test_result.h"
#endif

#ifndef QLAYOUT_H
#include <qlayout.h>
#endif
#ifndef QPUSHBUTTON_H
#include <qpushbutton.h>
#endif
#ifndef QWIDGET_H
#include <qwidget.h>
#endif

#include <iostream>

using namespace std;

class myWidget : public QWidget {
Q_OBJECT
public:
  QPushButton *m_pb;
  explicit myWidget(QWidget *parent = 0, const char *name = 0, WFlags f = 0)
  : QWidget(parent, name, f), m_pb(0)
  {
    QVBoxLayout *layout = new QVBoxLayout(this, 10, -1, "<myWidget(layout)>");
    m_pb = new QPushButton("foo", this, "<myWidget::m_pb>");
    layout->addWidget(m_pb);
    connect(m_pb, SIGNAL(clicked()), this, SIGNAL(clicked()));
  }
signals:
  void clicked();
};

class cTemplateTest : public cQtTestCase {
Q_OBJECT
protected:
  myWidget *m_w;
public:
  cTemplateTest(int argc, char **argv) : cQtTestCase(argc, argv) { }
public slots:
  void buttonClicked(){
    resetDeadMan();
    std::cout << "buttonClicked..." << std::endl;
    test_is_true(true);
    restartTimer();
  }
public:
  virtual void test() {
    m_w = new myWidget(0, "<cTemplateTest::(myWidget *)m_w>", 0);
    m_w->show(); m_w->raise();
    connect(m_w, SIGNAL(clicked()), this, SLOT(buttonClicked()));

    tFunctor twiddle_functor(this, &cQtTestCase::twiddle);
    tFunctor click_functor(m_w->m_pb, &QPushButton::animateClick);
    pushFunctor(twiddle_functor);
    pushFunctor(twiddle_functor);
    pushFunctor(click_functor);

    restartTimer();
    resetDeadMan();
    execApp();

    if(m_w){ delete m_w; m_w = 0; }
  }
};

class cTestSuite : public test_case {
public: cTestSuite(int argc, char **argv) : test_case() {
  adopt_test_case(new cTemplateTest(argc, argv)); 
} };

int main(int argc, char *argv[]){
  cout << endl 
  << "----------------------------------------" << endl
  << "Testing Template." << endl;
  cTestSuite t(argc, argv);
  t.run_test();
  cout << text_test_interpreter().interpretation(t.last_result());
  return(t.last_result().success_count() != t.last_result().total_test_count());
}

#include "template.t.moc"






More information about the Avida-cvs mailing list