00001
00007 #include <stdlib.h>
00008 #include <stdio.h>
00009 #include <errno.h>
00010 #include <math.h>
00011 #include <complex.h>
00012
00013 #include "assert.h"
00014
00015 EXPORT_CREATE_C(assert,g_assert);
00016 EXPORT_INIT_C(assert,g_assert);
00017 EXPORT_COMMIT_C(assert,g_assert);
00018 EXPORT_NOTIFY_C(assert,g_assert);
00019
00020 CLASS *g_assert::oclass = NULL;
00021 g_assert *g_assert::defaults = NULL;
00022
00023 g_assert::g_assert(MODULE *module)
00024 {
00025 if (oclass==NULL)
00026 {
00027
00028 oclass = gld_class::create(module,"assert",sizeof(g_assert),PC_AUTOLOCK|PC_OBSERVER);
00029 if (oclass==NULL)
00030 throw "unable to register class assert";
00031 else
00032 oclass->trl = TRL_PROVEN;
00033
00034 defaults = this;
00035 if (gl_publish_variable(oclass,
00036 PT_enumeration,"status",get_status_offset(),PT_DESCRIPTION,"desired outcome of assert test",
00037 PT_KEYWORD,"INIT",(enumeration)AS_INIT,
00038 PT_KEYWORD,"TRUE",(enumeration)AS_TRUE,
00039 PT_KEYWORD,"FALSE",(enumeration)AS_FALSE,
00040 PT_KEYWORD,"NONE",(enumeration)AS_NONE,
00041 PT_char1024, "target", get_target_offset(),PT_DESCRIPTION,"the target property to test",
00042 PT_char32, "part", get_part_offset(),PT_DESCRIPTION,"the target property part to test",
00043 PT_enumeration,"relation",get_relation_offset(),PT_DESCRIPTION,"the relation to use for the test",
00044 PT_KEYWORD,"==",(enumeration)TCOP_EQ,
00045 PT_KEYWORD,"<",(enumeration)TCOP_LT,
00046 PT_KEYWORD,"<=",(enumeration)TCOP_LE,
00047 PT_KEYWORD,">",(enumeration)TCOP_GT,
00048 PT_KEYWORD,">=",(enumeration)TCOP_GE,
00049 PT_KEYWORD,"!=",(enumeration)TCOP_NE,
00050 PT_KEYWORD,"inside",(enumeration)TCOP_IN,
00051 PT_KEYWORD,"outside",(enumeration)TCOP_NI,
00052 PT_char1024, "value", get_value_offset(),PT_DESCRIPTION,"the value to compare with for binary tests",
00053 PT_char1024, "within", get_value2_offset(),PT_DESCRIPTION,"the bounds within which the value must bed compared",
00054 PT_char1024, "lower", get_value_offset(),PT_DESCRIPTION,"the lower bound to compare with for interval tests",
00055 PT_char1024, "upper", get_value2_offset(),PT_DESCRIPTION,"the upper bound to compare with for interval tests",
00056 NULL)<1){
00057 char msg[256];
00058 sprintf(msg, "unable to publish properties in %s",__FILE__);
00059 throw msg;
00060 }
00061
00062 memset(this,0,sizeof(g_assert));
00063 status = AS_INIT;
00064 relation=TCOP_EQ;
00065 }
00066 }
00067
00068 int g_assert::create(void)
00069 {
00070 memcpy(this,defaults,sizeof(*this));
00071
00072 return 1;
00073 }
00074
00075 int g_assert::init(OBJECT *parent)
00076 {
00077 gld_property target(get_parent(),get_target());
00078 if ( !target.is_valid() )
00079 exception("target '%s' property '%s' does not exist", get_parent()?get_parent()->get_name():"global",get_target());
00080
00081 set_status(AS_TRUE);
00082 return 1;
00083 }
00084
00085 TIMESTAMP g_assert::commit(TIMESTAMP t1, TIMESTAMP t2)
00086 {
00087
00088 gld_property target_prop(get_parent(),get_target());
00089 if ( !target_prop.is_valid() )
00090 {
00091 gl_error("%s: target %s is not valid",get_target(),get_name());
00092
00093
00094
00095
00096
00097
00098 return 0;
00099 }
00100
00101
00102 if ( status==AS_NONE )
00103 {
00104 gl_verbose("%s: test is not being run on %s", get_name(), get_parent()->get_name());
00105 return TS_NEVER;
00106 }
00107 else
00108 {
00109 if ( evaluate_status() != get_status() )
00110 {
00111 gld_property relation_prop(my(),"relation");
00112 gld_keyword *pKeyword = relation_prop.find_keyword(relation);
00113 char buf[1024];
00114 char *p = get_part();
00115 gl_error("%s: assert failed on %s %s.%s.%s %s %s %s %s", get_name(), status==AS_TRUE?"":"NOT",
00116 get_parent()?get_parent()->get_name():"global variable", get_target(), get_part(), target_prop.to_string(buf,sizeof(buf))?buf:"(void)", pKeyword->get_name(), get_value(), get_value2());
00117 return 0;
00118 }
00119 else
00120 {
00121 gl_verbose("%s: assert passed on %s", get_name(), get_parent()?get_parent()->get_name():"global variable");
00122 return TS_NEVER;
00123 }
00124 }
00125
00126 }
00127
00128 g_assert::ASSERTSTATUS g_assert::evaluate_status(void)
00129 {
00130 gld_property target_prop(get_parent(),get_target());
00131 if ( strcmp(get_part(),"")==0 )
00132 return target_prop.compare(relation,get_value(),get_value2()) ? AS_TRUE : AS_FALSE ;
00133 else
00134 return target_prop.compare(relation,get_value(),get_value2(),get_part()) ? AS_TRUE : AS_FALSE ;
00135 }
00136
00137 int g_assert::postnotify(PROPERTY *prop, char *value)
00138 {
00139
00140 return 1;
00141 }