00001 #ifndef PS_ASSERT_H
00002 #define PS_ASSERT_H
00003
00004 #include "psError.h"
00005 #include "psLogMsg.h"
00006
00007 #define PS_ASSERT_INT_UNEQUAL(NAME1, NAME2, RVAL) \
00008 if ((NAME1) == (NAME2)) { \
00009 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00010 "Error: %s and %s are equal.", \
00011 #NAME1, #NAME2); \
00012 return(RVAL); \
00013 }
00014
00015 #define PS_ASSERT_INT_EQUAL(NAME1, NAME2, RVAL) \
00016 if ((NAME1) != (NAME2)) { \
00017 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00018 "Error: %s and %s are not equal.", \
00019 #NAME1, #NAME2); \
00020 return(RVAL); \
00021 }
00022
00023 #define PS_ASSERT_INT_NONNEGATIVE(NAME, RVAL) \
00024 if ((NAME) < 0) { \
00025 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: %s is less than 0.", #NAME); \
00026 return(RVAL); \
00027 }
00028
00029 #define PS_ASSERT_INT_POSITIVE(NAME, RVAL) \
00030 if ((NAME) < 1) { \
00031 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00032 "Error: %s is 0 or less.", #NAME); \
00033 return(RVAL); \
00034 }
00035
00036 #define PS_ASSERT_INT_ZERO(NAME, RVAL) \
00037 if ((NAME) != 0) { \
00038 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00039 "Error: %s is 0.", #NAME); \
00040 return(RVAL); \
00041 }
00042
00043 #define PS_ASSERT_INT_NONZERO(NAME, RVAL) \
00044 if ((NAME) == 0) { \
00045 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00046 "Error: %s is 0.", #NAME); \
00047 return(RVAL); \
00048 }
00049
00050
00051 #define PS_ASSERT_INT_WITHIN_RANGE(NAME, LOWER, UPPER, RVAL) \
00052 if ((int)(NAME) < LOWER || (int)(NAME) > UPPER) { \
00053 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00054 "Error: %s, %d, is out of range. Must be between %d and %d.", \
00055 #NAME,(int)NAME,LOWER,UPPER); \
00056 return RVAL; \
00057 }
00058
00059 #define PS_ASSERT_INT_LESS_THAN(VAR1, VAR2, RVAL) \
00060 if (!(VAR1 < VAR2)) { \
00061 psError(PS_ERR_UNKNOWN, true, \
00062 "Error: %s is not less than %s (%d, %d)", #VAR1, #VAR2, VAR1, VAR2); \
00063 return(RVAL); \
00064 }
00065
00066 #define PS_ASSERT_INT_LESS_THAN_OR_EQUAL(VAR1, VAR2, RVAL) \
00067 if (!(VAR1 <= VAR2)) { \
00068 psError(PS_ERR_UNKNOWN, true, \
00069 "Error: %s is not less than %s (%d, %d)", #VAR1, #VAR2, VAR1, VAR2); \
00070 return(RVAL); \
00071 }
00072
00073 #define PS_ASSERT_INT_LARGER_THAN(NAME1, NAME2, RVAL) \
00074 if (!((NAME1) > (NAME2))) { \
00075 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00076 "Error: !(%s > %s) (%d %d).", \
00077 #NAME1, #NAME2, NAME1, NAME2); \
00078 return(RVAL); \
00079 }
00080
00081 #define PS_ASSERT_INT_LARGER_THAN_OR_EQUAL(NAME1, NAME2, RVAL) \
00082 if (!((NAME1) >= (NAME2))) { \
00083 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00084 "Error: !(%s >= %s) (%d %d).", \
00085 #NAME1, #NAME2, NAME1, NAME2); \
00086 return(RVAL); \
00087 }
00088 #define PS_ASSERT_FLOAT_LARGER_THAN(NAME1, NAME2, RVAL) \
00089 if (!((NAME1) > (NAME2))) { \
00090 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00091 "Error: !(%s > %s) (%f %f).", \
00092 #NAME1, #NAME2, NAME1, NAME2); \
00093 return(RVAL); \
00094 }
00095
00096 #define PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(NAME1, NAME2, RVAL) \
00097 if (!((NAME1) >= (NAME2))) { \
00098 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00099 "Error: !(%s >= %s) (%f %f).", \
00100 #NAME1, #NAME2, NAME1, NAME2); \
00101 return(RVAL); \
00102 }
00103
00104 #define PS_ASSERT_FLOAT_LESS_THAN(NAME1, NAME2, RVAL) \
00105 if (!((NAME1) < (NAME2))) { \
00106 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00107 "Error: !(%s < %s) (%f %f).", \
00108 #NAME1, #NAME2, NAME1, NAME2); \
00109 return(RVAL); \
00110 }
00111
00112 #define PS_ASSERT_FLOAT_LESS_THAN_OR_EQUAL(NAME1, NAME2, RVAL) \
00113 if (!((NAME1) <= (NAME2))) { \
00114 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00115 "Error: !(%s <= %s) (%f %f).", \
00116 #NAME1, #NAME2, NAME1, NAME2); \
00117 return(RVAL); \
00118 }
00119
00120 #define PS_ASSERT_FLOAT_NON_EQUAL(NAME1, NAME2, RVAL) \
00121 if (fabs((NAME2) - (NAME1)) < FLT_EPSILON) { \
00122 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00123 "Error: %s and %s are equal.", \
00124 #NAME1, #NAME2); \
00125 return(RVAL); \
00126 }
00127
00128 #define PS_ASSERT_FLOAT_EQUAL(NAME1, NAME2, RVAL) \
00129 if (fabs((NAME2) - (NAME1)) > FLT_EPSILON) { \
00130 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00131 "Error: %s and %s are not equal.", \
00132 #NAME1, #NAME2); \
00133 return(RVAL); \
00134 }
00135
00136
00137 #define PS_ASSERT_FLOAT_WITHIN_RANGE(NAME, LOWER, UPPER, RVAL) \
00138 if ((NAME) < (LOWER) || (NAME) > (UPPER)) { \
00139 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00140 "Error: %s, %f, is out of range. Must be between %f and %f.", \
00141 #NAME, NAME, LOWER, UPPER); \
00142 return RVAL; \
00143 }
00144
00145 #define PS_ASSERT_DOUBLE_WITHIN_RANGE(NAME, LOWER, UPPER, RVAL) \
00146 if ((NAME) < (LOWER) || (NAME) > (UPPER)) { \
00147 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00148 "Error: %s, %lf, is out of range. Must be between %lf and %lf.", \
00149 #NAME, NAME, LOWER, UPPER); \
00150 return RVAL; \
00151 }
00152
00153 #define PS_ASSERT_LONG_WITHIN_RANGE(NAME, LOWER, UPPER, RVAL) \
00154 if ((NAME) < (LOWER) || (NAME) > (UPPER)) { \
00155 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00156 "Error: %s, %lld, is out of range.", \
00157 #NAME, NAME, LOWER, UPPER); \
00158 return RVAL; \
00159 }
00160
00161
00162
00163
00164
00165 #define PS_WARN_PTR_NON_NULL(NAME) \
00166 if ((NAME) == NULL) { \
00167 psLogMsg(__func__, PS_LOG_WARN, "WARNING: %s is NULL.", #NAME); \
00168 } \
00169
00170 #define PS_ASSERT_PTR_NON_NULL(NAME, RVAL) PS_ASSERT_GENERAL_PTR_NON_NULL(NAME, return RVAL)
00171 #define PS_ASSERT_GENERAL_PTR_NON_NULL(NAME, CLEANUP) \
00172 if ((NAME) == NULL) { \
00173 psError(PS_ERR_BAD_PARAMETER_NULL, true, \
00174 "Unallowable operation: %s is NULL.", \
00175 #NAME); \
00176 CLEANUP; \
00177 }
00178
00179 #define PS_ASSERT_PTR_TYPE(NAME, TYPE, RVAL) \
00180 if ((NAME)->type.type != TYPE) { \
00181 psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
00182 "Unallowable operation: %s has incorrect type.", \
00183 #NAME); \
00184 return(RVAL); \
00185 }
00186
00187 #define PS_ASSERT_PTR_DIMEN(NAME, DIMEN, RVAL) PS_ASSERT_GENERAL_PTR_DIMEN(NAME, DIMEN, return RVAL)
00188 #define PS_ASSERT_GENERAL_PTR_DIMEN(NAME, DIMEN, CLEANUP) \
00189 if ((NAME)->type.dimen != DIMEN) { \
00190 psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
00191 "Unallowable operation: %s has incorrect dimensionality.", \
00192 #NAME); \
00193 CLEANUP; \
00194 }
00195
00196 #define PS_ASSERT_PTR_DIMEN_GENERAL_NOT(NAME, DIMEN, CLEANUP) \
00197 if ((NAME)->type.dimen == DIMEN) { \
00198 psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
00199 "Unallowable operation: %s has incorrect dimensionality.", \
00200 #NAME); \
00201 CLEANUP; \
00202 }
00203
00204
00205 #define PS_ASSERT_PTRS_SIZE_EQUAL(PTR1, PTR2, RVAL) \
00206 if (PTR1->n != PTR2->n) { \
00207 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
00208 "ptr %s has size %d, ptr %s has size %d.", \
00209 #PTR1, PTR1->n, #PTR2, PTR2->n); \
00210 return(RVAL); \
00211 }
00212
00213 #define PS_ASSERT_PTR_TYPE_EQUAL(PTR1, PTR2, RVAL) PS_ASSERT_PTRS_TYPE_EQUAL_GENERAL(PTR1, PTR2, return RVAL)
00214 #define PS_ASSERT_PTRS_TYPE_EQUAL_GENERAL(PTR1, PTR2, CLEANUP) \
00215 if (PTR1->type.type != PTR2->type.type) { \
00216 psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
00217 "ptr %s has type %d, ptr %s has type %d.", \
00218 #PTR1, PTR1->type.type, #PTR2, PTR2->type.type); \
00219 CLEANUP; \
00220 }
00221
00222
00223 #endif