[avida-cvs] avida CVS commits: /current/source/qt-viewer/exp/exp_cleanup2 avd_bool.hh avd_dbg_msgs.cc avd_dbg_msgs_t.cc avd_expectation_t.cc avd_message_class.cc avd_message_class.hh avd_message_class_base.hh avd_message_class_m.hh avd_message_class_t.cc avd_message_closure_base.hh avd_message_closure_m.hh avd_message_display_base.hh avd_message_display_m.hh avd_message_type.cc avd_message_type.hh avd_message_type_base.hh avd_message_type_m.hh avd_message_type_t.cc avd_verifiable.cc avd_verifiable.hh avd_verifiable_m.hh avd_verifiable_t.cc
kaben
avida-cvs at alife.org
Mon Dec 29 23:17:51 PST 2003
kaben Mon Dec 29 15:17:51 2003 EDT
Added files:
/avida/current/source/qt-viewer/exp/exp_cleanup2 avd_bool.hh
avd_dbg_msgs.cc
avd_dbg_msgs_t.cc
avd_expectation_t.cc
avd_message_class.cc
avd_message_class.hh
avd_message_class_base.hh
avd_message_class_m.hh
avd_message_class_t.cc
avd_message_closure_base.hh
avd_message_closure_m.hh
avd_message_display_base.hh
avd_message_display_m.hh
avd_message_type.cc
avd_message_type.hh
avd_message_type_base.hh
avd_message_type_m.hh
avd_message_type_t.cc
avd_verifiable.cc
avd_verifiable.hh
avd_verifiable_m.hh
avd_verifiable_t.cc
Log:
Several missing experimental files added from branch kaben.
-------------- next part --------------
Index: avida/current/source/qt-viewer/exp/exp_cleanup2/avd_bool.hh
+++ avida/current/source/qt-viewer/exp/exp_cleanup2/avd_bool.hh
#ifndef AVD_BOOL_HH
#define AVD_BOOL_HH
class avdBool {
protected:
bool m_is_true;
public:
bool isTrue(){ return m_is_true; }
void setTrue(bool is_true){ m_is_true = is_true; }
};
#endif
Index: avida/current/source/qt-viewer/exp/exp_cleanup2/avd_dbg_msgs.cc
+++ avida/current/source/qt-viewer/exp/exp_cleanup2/avd_dbg_msgs.cc
#ifndef AVD_DBG_MSGS_HH
#include "avd_dbg_msgs.hh"
#endif
#ifndef AVD_MESSAGE_CLASS_BASE_HH
#include "avd_message_class_base.hh"
#endif
#ifndef AVD_MESSAGE_TYPE_HH
#include "avd_message_type.hh"
#endif
#ifndef AVD_MESSAGE_TYPE_BASE_HH
#include "avd_message_type_base.hh"
#endif
static avdMessageType s_plain_message_type("General", avdMCPlain);
const avdMessageTypeBase &Plain_avdMsg(s_plain_message_type);
static avdMessageType s_info_message_type("General", avdMCInfo);
static avdMessageType s_debug_message_type("General", avdMCDebug);
static avdMessageType s_error_message_type("General", avdMCError);
static avdMessageType s_fatal_message_type("General", avdMCFatal);
const avdMessageTypeBase &Info_GEN_avdMsg(s_info_message_type);
const avdMessageTypeBase &Debug_GEN_avdMsg(s_debug_message_type);
const avdMessageTypeBase &Error_GEN_avdMsg(s_error_message_type);
const avdMessageTypeBase &Fatal_GEN_avdMsg(s_fatal_message_type);
Index: avida/current/source/qt-viewer/exp/exp_cleanup2/avd_dbg_msgs_t.cc
+++ avida/current/source/qt-viewer/exp/exp_cleanup2/avd_dbg_msgs_t.cc
#ifndef AVD_DBG_MSGS_HH
#include "avd_dbg_msgs.hh"
#endif
#ifndef AVD_MESSAGE_CLASS_HH
#include "avd_message_class.hh"
#endif
#ifndef AVD_MESSAGE_CLOSURE_M_HH
#include "avd_message_closure_m.hh"
#endif
#ifndef AVD_MESSAGE_DISPLAY_HH
#include "avd_message_display.hh"
#endif
#ifndef AVD_MESSAGE_TYPE_HH
#include "avd_message_type.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
#include <iostream>
using namespace std;
static avdMessageDisplay s_info_msg_dsp(&cerr);
static avdMessageDisplay s_debug_msg_dsp(&cerr);
static avdMessageDisplay s_error_msg_dsp(&cerr);
static avdMessageDisplay s_plain_msg_dsp(&cerr);
static avdMessageDisplayBase *s_info_msg_hdl(&s_info_msg_dsp);
static avdMessageDisplayBase *s_debug_msg_hdl(&s_debug_msg_dsp);
static avdMessageDisplayBase *s_error_msg_hdl(&s_error_msg_dsp);
static avdMessageDisplayBase *s_plain_msg_hdl(&s_plain_msg_dsp);
static avdMessageClass s_info_msg_class("Info:", &s_info_msg_hdl, false, false, false);
static avdMessageClass s_debug_msg_class("Debug:", &s_debug_msg_hdl, false, false, false);
static avdMessageClass s_error_msg_class("Error:", &s_error_msg_hdl, false, true, false);
static avdMessageClass s_plain_msg_class("Plain:", &s_plain_msg_hdl, false, true, true);
static avdMessageType Info_MOCK_avdMsg("Mock", s_info_msg_class);
static avdMessageType Debug_MOCK_avdMsg("Mock", s_debug_msg_class);
static avdMessageType Error_MOCK_avdMsg("Mock", s_error_msg_class);
static avdMessageType MOCK_avdMsg("Mock", s_plain_msg_class);
#define mockInfo AVD_INFO_MSG(mockMessageClosure, MOCK)
#define mockDebug AVD_DEBUG_MSG(mockMessageClosure, MOCK)
#define mockError AVD_ERROR_MSG(mockMessageClosure, MOCK)
#define mockMessage AVD_PLAIN_MSG(mockMessageClosure, MOCK)
class cInfoTest : public test_case {
public: virtual void test() {
mockInfo << "mockInfo.\n";
test_is_true(true);
} };
class cDebugTest : public test_case {
public: virtual void test() {
mockDebug << "mockDebug.\n";
test_is_true(true);
} };
class cErrorTest : public test_case {
public: virtual void test() {
mockError << "mockError.\n";
test_is_true(true);
} };
class cMessageTest : public test_case {
public: virtual void test() {
mockMessage << "mockMessage.\n";
test_is_true(true);
} };
class cTestSuite : public test_case {
public: cTestSuite() : test_case() {
adopt_test_case(new cInfoTest);
adopt_test_case(new cDebugTest);
adopt_test_case(new cErrorTest);
adopt_test_case(new cMessageTest);
} };
int main(int argc, char *argv[]){
cout << endl
<< "----------------------------------------" << endl
<< "Testing avdInfo, avdDebug, avdError, and Message." << endl;
cTestSuite t;
t.run_test();
cout << text_test_interpreter().interpretation(t.last_result());
return(t.last_result().success_count() != t.last_result().total_test_count());
}
Index: avida/current/source/qt-viewer/exp/exp_cleanup2/avd_expectation_t.cc
+++ avida/current/source/qt-viewer/exp/exp_cleanup2/avd_expectation_t.cc
#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
#include <iostream>
using namespace std;
namespace avd_expectation_t {
class test_ConstructorWithoutParent : public test_case {
public: virtual void test() {
//// Should record name and reference to stubExpectation::s_null. also
//// tests getName() and nullParent().
//const char name[] = "expectation";
//stubExpectation expectation(name);
//test_is_true(0 == strncmp(name, expectation.getName(), sizeof(name)));
//test_is_true(expectation.access_nullParent());
} };
class test_Constructor : public test_case {
public: virtual void test() {
//const char parent_name[] = "parent";
//const char name[] = "child";
//stubExpectation parent(parent_name);
//test_is_true(0 == parent.access_getChildList().GetSize());
//// Should record name and reference to parent. Also tests
//// getName(), operator==(), and getParent().
//stubExpectation child(name, parent);
//test_is_true(0 == strncmp(name, child.getName(), sizeof(name)));
//test_is_true(&parent == &child.access_getParent());
//// Should add self to parent list. Also tests getChildList().
//test_is_true(parent.access_getChildList().Find(&child));
} };
class test_clearActual : public test_case {
public: virtual void test() {
//// Should reset expectation's actual value(s).
} };
class test_ignoreActual : public test_case {
public: virtual void test() {
//// If setIgnoreActual(true) then ignoreActual() == true, and expectation should always succeed
//// on verify (even if actual fails).
} };
class test_setIgnoreActual : public test_case {
public: virtual void test() {
} };
class cTestSuite : public test_case {
public: cTestSuite() : test_case() {
adopt_test_case(new test_ConstructorWithoutParent);
adopt_test_case(new test_Constructor);
} };
}
int main(int argc, char *argv[]){
cout << endl
<< "----------------------------------------" << endl
<< "Testing avdExpectation via stubExpectation." << endl;
avd_expectation_t::cTestSuite t; t.run_test();
cout << text_test_interpreter().interpretation(t.last_result());
return(t.last_result().success_count() != t.last_result().total_test_count());
}
Index: avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_class.cc
+++ avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_class.cc
#ifndef AVD_MESSAGE_CLASS_HH
#include "avd_message_class.hh"
#endif
#ifndef AVD_MESSAGE_CLASS_BASE_HH
#include "avd_message_class_base.hh"
#endif
#ifndef AVD_MESSAGE_DISPLAY_BASE_HH
#include "avd_message_display_base.hh"
#endif
#ifndef STRING_HH
#include "string.hh"
#endif
#ifndef _CPP_IOSTREAM
#include <iostream>
#endif
using namespace std;
avdMessageClass::avdMessageClass(
const char *class_name,
avdMessageDisplayBase **msg_display,
bool is_fatal,
bool is_prefix,
bool no_prefix
):m_class_name(class_name)
, m_msg_display(msg_display)
, m_is_fatal(is_fatal)
, m_is_prefix(is_prefix)
, m_no_prefix(no_prefix)
{}
static avdMessageClass s_info_message_class("Info:", &s_avd_info_display, false, false, false);
static avdMessageClass s_debug_message_class("Debug:", &s_avd_debug_display, false, false, false);
static avdMessageClass s_error_message_class("Error:", &s_avd_error_display, false, true, false);
static avdMessageClass s_fatal_message_class("Fatal:", &s_avd_fatal_display, true, true, false);
static avdMessageClass s_plain_message_class("Plain:", &s_avd_plain_display, false, true, true);
avdMessageClassBase &avdMCInfo(s_info_message_class);
avdMessageClassBase &avdMCDebug(s_debug_message_class);
avdMessageClassBase &avdMCError(s_error_message_class);
avdMessageClassBase &avdMCFatal(s_fatal_message_class);
avdMessageClassBase &avdMCPlain(s_plain_message_class);
Index: avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_class.hh
+++ avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_class.hh
#ifndef AVD_MESSAGE_CLASS_HH
#define AVD_MESSAGE_CLASS_HH
#ifndef AVD_MESSAGE_CLASS_BASE_HH
#include "avd_message_class_base.hh"
#endif
class avdMessageClass : public avdMessageClassBase{
public:
avdMessageClass(
const char *class_name,
avdMessageDisplayBase **msg_display,
bool is_fatal,
bool is_prefix,
bool no_prefix
);
public:
virtual const char *const className() const { return m_class_name; }
virtual avdMessageDisplayBase **messageDisplay() const { return m_msg_display; }
virtual bool isFatal() const { return m_is_fatal; }
virtual bool isPrefix() const { return m_is_prefix; }
virtual bool noPrefix() const { return m_no_prefix; }
private:
const char *const m_class_name;
avdMessageDisplayBase **m_msg_display;
bool const m_is_fatal;
bool const m_is_prefix;
bool const m_no_prefix;
};
#endif
Index: avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_class_base.hh
+++ avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_class_base.hh
#ifndef AVD_MESSAGE_CLASS_BASE_HH
#define AVD_MESSAGE_CLASS_BASE_HH
class avdMessageDisplayBase;
class avdMessageTypeBase;
class avdMessageClassBase{
public:
virtual ~avdMessageClassBase(){};
virtual const char *const className() const = 0;
virtual avdMessageDisplayBase **messageDisplay() const = 0;
virtual bool isFatal() const = 0;
virtual bool isPrefix() const = 0;
virtual bool noPrefix() const = 0;
};
extern avdMessageClassBase &avdMCInfo;
extern avdMessageClassBase &avdMCDebug;
extern avdMessageClassBase &avdMCError;
extern avdMessageClassBase &avdMCFatal;
extern avdMessageClassBase &avdMCPlain;
#endif
Index: avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_class_m.hh
+++ avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_class_m.hh
#ifndef AVD_MESSAGE_CLASS_M_HH
#define AVD_MESSAGE_CLASS_M_HH
class mockMessageClass : public avdMessageClassBase{
public:
};
#endif
Index: avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_class_t.cc
+++ avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_class_t.cc
#ifndef AVD_MESSAGE_CLASS_HH
#include "avd_message_class.hh"
#endif
#ifndef AVD_MESSAGE_CLASS_M_HH
#include "avd_message_class_m.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
#include <iostream>
using namespace std;
class cTemplateTest : public test_case {
public: virtual void test() {
test_is_true(true);
} };
class cTestSuite : public test_case {
public: cTestSuite() : test_case() {
adopt_test_case(new cTemplateTest);
} };
int main(int argc, char *argv[]){
cout << endl
<< "----------------------------------------" << endl
<< "Testing Template." << endl;
cTestSuite t;
t.run_test();
cout << text_test_interpreter().interpretation(t.last_result());
return(t.last_result().success_count() != t.last_result().total_test_count());
}
Index: avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_closure_base.hh
+++ avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_closure_base.hh
#ifndef AVD_MESSAGE_CLOSURE_BASE_HH
#define AVD_MESSAGE_CLOSURE_BASE_HH
class QString;
class avdMessageClosureBase{
public:
virtual ~avdMessageClosureBase(void){}
virtual avdMessageClosureBase &operator<<(char c) = 0;
virtual avdMessageClosureBase &operator<<(unsigned char c) = 0;
virtual avdMessageClosureBase &operator<<(const char *s) = 0;
virtual avdMessageClosureBase &operator<<(int i) = 0;
virtual avdMessageClosureBase &operator<<(unsigned int i) = 0;
virtual avdMessageClosureBase &operator<<(long i) = 0;
virtual avdMessageClosureBase &operator<<(unsigned long i) = 0;
virtual avdMessageClosureBase &operator<<(float f) = 0;
virtual avdMessageClosureBase &operator<<(double f) = 0;
virtual avdMessageClosureBase &operator<<(const void *p) = 0;
virtual avdMessageClosureBase &operator<<(const QString &s) = 0;
avdMessageClosureBase &operator()(char c){ return operator<<(c); }
avdMessageClosureBase &operator()(unsigned char c){ return operator<<(c); }
avdMessageClosureBase &operator()(const char *s){ return operator<<(s); }
avdMessageClosureBase &operator()(int i){ return operator<<(i); }
avdMessageClosureBase &operator()(unsigned int i){ return operator<<(i); }
avdMessageClosureBase &operator()(long i){ return operator<<(i); }
avdMessageClosureBase &operator()(unsigned long i){ return operator<<(i); }
avdMessageClosureBase &operator()(float f){ return operator<<(f); }
avdMessageClosureBase &operator()(double f){ return operator<<(f); }
avdMessageClosureBase &operator()(const void *p){ return operator<<(p); }
avdMessageClosureBase &operator()(const QString &s){ return operator<<(s); }
virtual avdMessageClosureBase &va(const char *fmt, ...) = 0;
virtual void prefix(void) = 0;
};
#define AVD_MSG_CLOSURE_FL(closure, x)\
closure(\
x,\
__PRETTY_FUNCTION__,\
__FILE__,\
__LINE__\
)
#define AVD_INFO_MSG(closure, type)\
if (Info_ ## type ## _avdMsg.isActive())\
AVD_MSG_CLOSURE_FL(closure, Info_ ## type ## _avdMsg)
#define AVD_DEBUG_MSG(closure, type)\
if (Debug_ ## type ## _avdMsg.isActive())\
AVD_MSG_CLOSURE_FL(closure, Debug_ ## type ## _avdMsg)
#define AVD_ERROR_MSG(closure, type)\
if (Error_ ## type ## _avdMsg.isActive())\
AVD_MSG_CLOSURE_FL(closure, Error_ ## type ## _avdMsg)
#define AVD_FATAL_MSG(closure, type)\
if (Fatal_ ## type ## _avdMsg.isActive())\
AVD_MSG_CLOSURE_FL(closure, Fatal_ ## type ## _avdMsg)
#define AVD_PLAIN_MSG(closure, type)\
if (type ## _avdMsg.isActive())\
AVD_MSG_CLOSURE_FL(closure, type ## _avdMsg)
#endif
Index: avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_closure_m.hh
+++ avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_closure_m.hh
#ifndef AVD_MESSAGE_CLOSURE_M_HH
#define AVD_MESSAGE_CLOSURE_M_HH
#ifndef AVD_MESSAGE_CLOSURE_BASE_HH
#include "avd_message_closure_base.hh"
#endif
#ifndef AVD_MESSAGE_TYPE_BASE_HH
#include "avd_message_type_base.hh"
#endif
class mockMessageClosure : public avdMessageClosureBase{
public:
mockMessageClosure(
avdMessageTypeBase &type,
const char *function_name,
const char *file_name,
int line_number
)
{}
virtual avdMessageClosureBase &operator<<(char c){ return *this; }
virtual avdMessageClosureBase &operator<<(unsigned char c){ return *this; }
virtual avdMessageClosureBase &operator<<(const char *s){ return *this; }
virtual avdMessageClosureBase &operator<<(int i){ return *this; }
virtual avdMessageClosureBase &operator<<(unsigned int i){ return *this; }
virtual avdMessageClosureBase &operator<<(long i){ return *this; }
virtual avdMessageClosureBase &operator<<(unsigned long i){ return *this; }
virtual avdMessageClosureBase &operator<<(float f){ return *this; }
virtual avdMessageClosureBase &operator<<(double f){ return *this; }
virtual avdMessageClosureBase &operator<<(const void *p){ return *this; }
virtual avdMessageClosureBase &operator<<(const QString &s){ return *this; }
virtual avdMessageClosureBase &va(const char *fmt, ...){ return *this; }
virtual void prefix(void){}
};
#endif
Index: avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_display_base.hh
+++ avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_display_base.hh
#ifndef AVD_MESSAGE_DISPLAY_BASE_HH
#define AVD_MESSAGE_DISPLAY_BASE_HH
class cString;
class avdMessageDisplayBase{
public:
virtual ~avdMessageDisplayBase(){}
virtual void out(const cString &) const = 0;
virtual void abort() const { abort(); }
};
extern avdMessageDisplayBase *s_avd_info_display;
extern avdMessageDisplayBase *s_avd_debug_display;
extern avdMessageDisplayBase *s_avd_error_display;
extern avdMessageDisplayBase *s_avd_fatal_display;
extern avdMessageDisplayBase *s_avd_plain_display;
void setAvdInfoDisplay(avdMessageDisplayBase &info);
void setAvdDebugDisplay(avdMessageDisplayBase &md);
void setAvdErrorDisplay(avdMessageDisplayBase &md);
void setAvdFatalDisplay(avdMessageDisplayBase &md);
void setAvdPlainDisplay(avdMessageDisplayBase &md);
#endif
Index: avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_display_m.hh
+++ avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_display_m.hh
#ifndef AVD_MESSAGE_DISPLAY_M_HH
#define AVD_MESSAGE_DISPLAY_M_HH
#ifndef AVD_MESSAGE_DISPLAY_BASE_HH
#include "avd_message_display_base.hh"
#endif
#ifndef STRING_HH
#include "string.hh"
#endif
class cString;
class mockMessageDisplay : public avdMessageDisplayBase{
public:
mockMessageDisplay()
{}
virtual void out(const cString &) const {}
virtual void abort() const {}
};
#endif
Index: avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_type.cc
+++ avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_type.cc
#ifndef AVD_MESSAGE_TYPE_HH
#include "avd_message_type.hh"
#endif
#ifndef AVD_MESSAGE_CLASS_BASE_HH
#include "avd_message_class_base.hh"
#endif
avdMessageType::avdMessageType(
const char *type_name,
avdMessageClassBase &message_class
):m_type_name(type_name)
, m_class_name(message_class.className())
, m_is_fatal(message_class.isFatal())
, m_is_prefix(message_class.isPrefix())
, m_no_prefix(message_class.noPrefix())
, m_msg_display(message_class.messageDisplay())
{
setIsActive(true);
setShowWhere(true);
setShowFunction(true);
}
Index: avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_type.hh
+++ avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_type.hh
#ifndef AVD_MESSAGE_TYPE_HH
#define AVD_MESSAGE_TYPE_HH
#ifndef AVD_MESSAGE_TYPE_BASE_HH
#include "avd_message_type_base.hh"
#endif
class avdMessageClassBase;
class avdMessageDisplayBase;
class avdMessageType : public avdMessageTypeBase{
public:
avdMessageType(const char *type_name, avdMessageClassBase &message_class);
virtual const char *const typeName() const { return m_type_name; }
virtual const char *const className() const { return m_class_name; }
virtual bool isFatal() const { return m_is_fatal; }
virtual bool isPrefix() const { return m_is_prefix; }
virtual bool noPrefix() const { return m_no_prefix; }
virtual bool isActive() const { return m_is_active; }
virtual bool showWhere() const { return m_show_where; }
virtual bool showFunction() const { return m_show_function; }
virtual avdMessageDisplayBase **messageDisplay() const { return m_msg_display; }
virtual void setIsActive(bool is_active){ m_is_active = is_active; }
virtual void setShowWhere(bool show_where){ m_show_where = show_where; }
virtual void setShowFunction(bool show_function){ m_show_function = show_function; }
private:
const char *const m_type_name;
const char *const m_class_name;
bool const m_is_fatal;
bool const m_is_prefix;
bool const m_no_prefix;
bool m_is_active;
bool m_show_where;
bool m_show_function;
avdMessageDisplayBase **m_msg_display;
};
#endif
Index: avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_type_base.hh
+++ avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_type_base.hh
#ifndef AVD_MESSAGE_TYPE_BASE_HH
#define AVD_MESSAGE_TYPE_BASE_HH
class avdMessageDisplayBase;
class avdMessageTypeBase{
public:
virtual ~avdMessageTypeBase(){}
virtual const char *const typeName() const = 0;
virtual const char *const className() const = 0;
virtual bool isFatal() const = 0;
virtual bool isPrefix() const = 0;
virtual bool noPrefix() const = 0;
virtual bool isActive() const = 0;
virtual bool showWhere() const = 0;
virtual bool showFunction() const = 0;
virtual avdMessageDisplayBase **messageDisplay() const = 0;
virtual void setIsActive(bool is_active) = 0;
virtual void setShowWhere(bool show_where) = 0;
virtual void setShowFunction(bool show_function) = 0;
};
#endif
Index: avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_type_m.hh
+++ avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_type_m.hh
#ifndef AVD_MESSAGE_TYPE_M_HH
#define AVD_MESSAGE_TYPE_M_HH
#ifndef AVD_MESSAGE_TYPE_BASE_HH
#include "avd_message_type_base.hh"
#endif
class avdMessageClassBase;
class mockMessageType : public avdMessageTypeBase{
public:
mockMessageType()
{}
virtual const char *typeName(){ return 0; }
virtual const avdMessageClassBase &messageClass();
virtual bool isActive(){ return false; }
virtual bool showWhere(){ return false; }
virtual bool showFunction(){ return false; }
virtual void setIsActive(bool is_active){}
virtual void setShowWhere(bool show_where){}
virtual void setShowFunction(bool show_function){}
};
#endif
Index: avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_type_t.cc
+++ avida/current/source/qt-viewer/exp/exp_cleanup2/avd_message_type_t.cc
#ifndef AVD_MESSAGE_TYPE_M_HH
#include "avd_message_type_m.hh"
#endif
#ifndef AVD_MESSAGE_TYPE_HH
#include "avd_message_type.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
#include <iostream>
using namespace std;
class cTemplateTest : public test_case {
public: virtual void test() {
test_is_true(true);
} };
class cTestSuite : public test_case {
public: cTestSuite() : test_case() {
adopt_test_case(new cTemplateTest);
} };
int main(int argc, char *argv[]){
cout << endl
<< "----------------------------------------" << endl
<< "Testing Template." << endl;
cTestSuite t;
t.run_test();
cout << text_test_interpreter().interpretation(t.last_result());
return(t.last_result().success_count() != t.last_result().total_test_count());
}
Index: avida/current/source/qt-viewer/exp/exp_cleanup2/avd_verifiable.cc
+++ avida/current/source/qt-viewer/exp/exp_cleanup2/avd_verifiable.cc
#ifndef AVD_VERIFIABLE_HH
#include "avd_verifiable.hh"
#endif
avdVerifiable avdVerifiable::s_null("<avdVerifiable::s_null>");
avdVerifiable::avdVerifiable(const char *name, avdVerifiable &parent)
: m_name(name) , m_parent(parent)
{ if(!nullParent()) getParent().addVerifiable(*this); }
void avdVerifiable::addVerifiable(avdVerifiable &child) { getChildList().PushRear(&child); }
bool avdVerifiable::nullParent() { return avdVerifiable::s_null == getParent(); }
bool avdVerifiable::operator==(const avdVerifiable &in) { return (this == &in); }
bool avdVerifiable::verify()
{
tListIterator<avdVerifiable> it(getChildList());
while(avdVerifiable *v = it.Next()) if(!v->verify()) return false;
return true;
}
Index: avida/current/source/qt-viewer/exp/exp_cleanup2/avd_verifiable.hh
+++ avida/current/source/qt-viewer/exp/exp_cleanup2/avd_verifiable.hh
#ifndef AVD_VERIFIABLE_HH
#define AVD_VERIFIABLE_HH
#ifndef TLIST_HH
#include "tList.hh"
#endif
class avdVerifiable {
protected:
const char *m_name;
avdVerifiable &m_parent;
tList<avdVerifiable> m_child_list;
protected:
avdVerifiable(const char *name, avdVerifiable &parent = avdVerifiable::s_null);
virtual ~avdVerifiable(){}
void addVerifiable(avdVerifiable &child);
avdVerifiable &getParent(){ return m_parent; }
tList<avdVerifiable> &getChildList(){ return m_child_list; }
bool nullParent();
public:
static avdVerifiable s_null;
public:
bool operator==(const avdVerifiable &in);
const char *getName() const { return m_name; }
virtual bool verify();
};
#endif
Index: avida/current/source/qt-viewer/exp/exp_cleanup2/avd_verifiable_m.hh
+++ avida/current/source/qt-viewer/exp/exp_cleanup2/avd_verifiable_m.hh
#ifndef AVD_VERIFIABLE_M_HH
#define AVD_VERIFIABLE_M_HH
#ifndef AVD_VERIFIABLE_HH
#include "avd_verifiable.hh"
#endif
class stubVerifiable : public avdVerifiable {
bool m_should_fail;
public:
stubVerifiable(const char *name, avdVerifiable &parent = avdVerifiable::s_null)
: avdVerifiable(name, parent)
{}
virtual bool verify(){ return ((!m_should_fail) && avdVerifiable::verify()); }
public:
void access_addVerifiable(avdVerifiable &child){ addVerifiable(child); }
avdVerifiable &access_getParent() { return getParent(); }
tList<avdVerifiable> &access_getChildList(){ return getChildList(); }
bool access_nullParent(){ return nullParent(); }
void shouldFail(bool should_fail){ m_should_fail = should_fail; }
};
#endif
Index: avida/current/source/qt-viewer/exp/exp_cleanup2/avd_verifiable_t.cc
+++ avida/current/source/qt-viewer/exp/exp_cleanup2/avd_verifiable_t.cc
#ifndef AVD_VERIFIABLE_M_HH
#include "avd_verifiable_m.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
#include <iostream>
#include <string.h>
using namespace std;
namespace avd_verifiable_t {
class test_ConstructorWithoutParent : public test_case {
public: virtual void test() {
// Should record name and reference to stubVerifiable::s_null. also
// tests getName() and nullParent().
const char name[] = "verifiable";
stubVerifiable verifiable(name);
test_is_true(0 == strncmp(name, verifiable.getName(), sizeof(name)));
test_is_true(verifiable.access_nullParent());
} };
class test_Constructor : public test_case {
public: virtual void test() {
// Parent's child list should initially be empty.
const char parent_name[] = "parent";
const char name[] = "child";
stubVerifiable parent(parent_name);
test_is_true(0 == parent.access_getChildList().GetSize());
// Should record name and reference to parent. Also tests
// getName(), operator==(), and getParent().
stubVerifiable child(name, parent);
test_is_true(0 == strncmp(name, child.getName(), sizeof(name)));
test_is_true(&parent == &child.access_getParent());
// Should add self to parent list. Also tests getChildList().
test_is_true(parent.access_getChildList().Find(&child));
} };
class test_addVerifiable : public test_case {
public: virtual void test() {
// Should add a verifiable child to child list. Also tests getChildList().
stubVerifiable v1("v1");
stubVerifiable v2("v2");
v1.access_addVerifiable(v2);
test_is_true(v1.access_getChildList().Find(&v2));
} };
class test_nullParent : public test_case {
public: virtual void test() {
// Should be a static class member who can substitute for no-parent
// condition. Also tests getParent() and operator==().
stubVerifiable verifiable("verifiable");
test_is_true(&stubVerifiable::s_null == &verifiable.access_getParent());
} };
class test_verify : public test_case {
public: virtual void test() {
// Should recursively verify children.
stubVerifiable parent("parent");
stubVerifiable child1("child1", parent);
stubVerifiable child2("child2", parent);
stubVerifiable child3("child3", child2);
for(int i=0; i<=1; i++)
for(int j=0; j<=1; j++)
for(int k=0; k<=1; k++)
for(int l=0; l<=1; l++){
parent.shouldFail(i);
child1.shouldFail(j);
child2.shouldFail(k);
child3.shouldFail(l);
// parent.verify() should be true if and only if all of parent and children don't fail,
// i.e., when i==j==k==l==0.
test_is_true(((i+j+k+l)==0)==parent.verify());
}
} };
class cTestSuite : public test_case {
public: cTestSuite() : test_case() {
adopt_test_case(new test_ConstructorWithoutParent);
adopt_test_case(new test_Constructor);
adopt_test_case(new test_addVerifiable);
adopt_test_case(new test_nullParent);
adopt_test_case(new test_verify);
} };
}
int main(int argc, char *argv[]){
cout << endl
<< "----------------------------------------" << endl
<< "Testing avdVerifiable via stubVerifiable." << endl;
avd_verifiable_t::cTestSuite t; t.run_test();
cout << text_test_interpreter().interpretation(t.last_result());
return(t.last_result().success_count() != t.last_result().total_test_count());
}
More information about the Avida-cvs
mailing list