00001
00008 #ifndef ctl_declarations
00009 #error The 'ctl_declarations' template parameter was not defined. It should be a string to pass to #include.
00010 #endif
00011
00012
00013
00014
00015 #define UNDEF_ALL
00016 #include "ctl/dg/blank.h"
00017
00018 #ifdef MAKE_RANDOMIZE
00019
00020
00021
00022
00023
00024
00025
00026 #define protocol_begin( label )
00027
00028
00029
00030
00031
00032 #define enum_begin( label )
00033 #define enum_item( label )
00034 #define enum_end( label )
00035
00036
00037
00038
00039 #define record_begin(label) void ppConcat(label,_randomize)( label* self ) \
00040 {\
00041 assertobjptr(self);
00042 #define record_var(label,type,val) self->label = type_rand(type);
00043 #define record_varok(label,type,val,min,max) self->label = rand_between(type,min,max);
00044 #define record_array(label,type,alen,val) { array_foreach(type,self->label, curr ) *curr = type_rand(type); }
00045 #define record_arrayok(label,type,alen,val,min,max) { array_foreach(type,self->label, curr ) *curr = rand_between(type,min,max); }
00046 #define record_objarray(label,type,alen) { array_foreach(type,self->label, curr ) ppConcat(type,_randomize)(curr); }
00047 #define record_achar(label,type,alen,val) { const type* const szz[] = {szconst(type,""), szconst(type,"egg"),szconst(type,"bacon"),szconst(type,"spam"),szconst(type,"sausage"),szconst(type,"baked beans")}; cstrncpy(type)(self->label,szz[rand()%5],alen); }
00048 #define record_string(label,type) { const type* const szz[] = {szconst(type,""), szconst(type,"<Ungah>"),szconst(type,"bunga"),szconst(type,"binga"),szconst(type,"booga"),szconst(type,"smurf")}; ctl_gstring_strcpy(type, &self->label, szz[rand()%5] ); }
00049 #define record_obj(label,type) ppConcat(type,_randomize)(&self->label);
00050 #define record_container(label,type) record_obj(label,type)
00051 #define record_ref(label,type) { \
00052 ctl_delete(self->label);\
00053 ctl_new(self->label,type);\
00054 ppConcat(type,_randomize)(self->label); \
00055 }
00056 #define record_preref(label,type) record_ref(label,type)
00057 #define record_enum(label,enum,val) self->label = rand()%enum_count(enum);
00058 #define record_serial(label) ctl_serial_alloc( &self->label, 1+type_rand(uint8) );\
00059 { \
00060 uint8* p = (uint8*)self->label.begin; \
00061 while( p < self->label.end ) \
00062 *p++ = (uint8)rand(); \
00063 }
00064 #define record_serialref(label) record_serial(label)
00065 #define record_member(stuff)
00066 #define record_atinit(stuff)
00067 #define record_atdestroy(stuff)
00068 #define record_end(label) }
00069
00070 #define record_alias(label,type)
00071
00072
00073
00074
00075 #define union_begin(label,etype) void ppConcat(label,_randomize)( label* self ) \
00076 {\
00077 self->type = rand()%enum_count(etype);\
00078 switch( self->type )\
00079 {
00080 #define union_alias(type,enum) case enum:
00081 #define union_member(label,type,enum) case enum:\
00082 ppConcat(type,_randomize)(&self->obj.label);\
00083 break;
00084 #define union_end(label,etype) default:\
00085 \
00086 throwassert(ppTokStr(ppConcat(label,_randomize)) ":Unknown type");\
00087 break;\
00088 }\
00089 }
00090
00091
00092
00093
00094 #define container_array(label,type,size)\
00095 void ppConcat(label,_randomize)( label* self ) \
00096 { \
00097 int count = 1+(rand()%size); \
00098 while( count-- ) \
00099 ppConcat(type,_randomize)(ppConcat(label,_push_back)(self)); \
00100 }
00101 #define container_vector(label,type)\
00102 void ppConcat(label,_randomize)( label* self ) \
00103 { \
00104 int count = 1+(rand()&0xf); \
00105 while( count-- ) \
00106 ppConcat(type,_randomize)(ppConcat(label,_push_back)(self)); \
00107 }
00108 #define container_list(label,type) \
00109 void ppConcat(label,_randomize)( label* self ) \
00110 {\
00111 int count = 1+(rand()&0xf);\
00112 while( count-- ) \
00113 ppConcat(type,_randomize)(ppConcat(label,_push_back)(self)); \
00114 }
00115 #define container_map(label,keytype,type) \
00116 void ppConcat(label,_randomize)( label* self ) \
00117 { \
00118 int count = 1+(rand()&0xf); \
00119 while( count-- ) \
00120 { \
00121 keytype key;\
00122 ppConcat(keytype,_init)(&key);\
00123 ppConcat(keytype,_randomize)(&key);\
00124 ppConcat(type,_randomize)(ppConcat(label,_insert)(self,&key)); \
00125 ppConcat(keytype,_destroy)(&key);\
00126 } \
00127 }
00128 #define container_multimap(label,keytype,type) \
00129 void ppConcat(label,_randomize)( label* self ) \
00130 { \
00131 int count = 1+(rand()&0xf); \
00132 while( count-- ) \
00133 { \
00134 keytype key;\
00135 ppConcat(keytype,_init)(&key);\
00136 ppConcat(keytype,_randomize)(&key);\
00137 ppConcat(type,_randomize)(ppConcat(label,_insert)(self,&key)); \
00138 ppConcat(keytype,_destroy)(&key);\
00139 } \
00140 }
00141 #define container_set(label,type) \
00142 void ppConcat(label,_randomize)( label* self ) \
00143 { \
00144 int count = 1+(rand()&0xf); \
00145 while( count-- ) \
00146 { \
00147 type key;\
00148 ppConcat(type,_init)(&key);\
00149 ppConcat(type,_randomize)(&key);\
00150 ppConcat(label,_insert)(self,&key); \
00151 ppConcat(type,_destroy)(&key);\
00152 } \
00153 }
00154 #define container_multiset(label,type) \
00155 void ppConcat(label,_randomize)( label* self ) \
00156 { \
00157 int count = 1+(rand()&0xf); \
00158 while( count-- ) \
00159 { \
00160 type key;\
00161 ppConcat(type,_init)(&key);\
00162 ppConcat(type,_randomize)(&key);\
00163 ppConcat(label,_insert)(self,&key); \
00164 ppConcat(type,_destroy)(&key);\
00165 } \
00166 }
00167
00168 #define bool_randomize( p ) ((*p) = type_rand(bool))
00169 #define int8_randomize( p ) ((*p) = type_rand(int8))
00170 #define uint8_randomize( p ) ((*p) = type_rand(uint8))
00171 #define int16_randomize( p ) ((*p) = type_rand(int16))
00172 #define uint16_randomize( p ) ((*p) = type_rand(uint16))
00173 #define int32_randomize( p ) ((*p) = type_rand(int32))
00174 #define uint32_randomize( p ) ((*p) = type_rand(uint32))
00175 #define int64_randomize( p ) ((*p) = type_rand(int64))
00176 #define uint64_randomize( p ) ((*p) = type_rand(uint64))
00177 #define float32_randomize( p ) ((*p) = type_rand(float32))
00178 #define float64_randomize( p ) ((*p) = type_rand(float64))
00179 #define tag_randomize( p )
00180
00181
00182
00183
00184 #define protocol_end( label )
00185
00186
00187 #include ctl_declarations
00188
00189
00190
00191
00192 #define UNDEF_ALL
00193 #include "ctl/dg/blank.h"
00194
00195 #endif
00196
00197 #undef ctl_declarations