Changeset 27303
- Timestamp:
- Mar 16, 2010, 3:04:24 PM (16 years ago)
- Location:
- trunk/psLib
- Files:
-
- 6 edited
- 3 moved
-
src/pslib_strict.h (modified) (1 diff)
-
src/sys/psType.c (modified) (2 diffs)
-
src/sys/psType.h (modified) (1 diff)
-
src/types/Makefile.am (modified) (2 diffs)
-
src/types/psBits.c (moved) (moved from trunk/psLib/src/types/psBitSet.c ) (6 diffs)
-
src/types/psBits.h (moved) (moved from trunk/psLib/src/types/psBitSet.h ) (8 diffs)
-
src/types/psMetadata.c (modified) (1 diff)
-
test/types/Makefile.am (modified) (1 diff)
-
test/types/tap_psBits_all.c (moved) (moved from trunk/psLib/test/types/tap_psBitSet_all.c ) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/pslib_strict.h
r23149 r27303 102 102 #include "psType.h" 103 103 #include "psArray.h" 104 #include "psBit Set.h"104 #include "psBits.h" 105 105 #include "psHash.h" 106 106 #include "psList.h" -
trunk/psLib/src/sys/psType.c
r11617 r27303 20 20 21 21 #include "psType.h" 22 #include "psBit Set.h"22 #include "psBits.h" 23 23 #include "psFits.h" 24 24 #include "psPixels.h" … … 45 45 } 46 46 break; 47 case PS_DATA_BITS ET:48 if (psMemCheckBit Set(ptr)) {47 case PS_DATA_BITS: 48 if (psMemCheckBits(ptr)) { 49 49 return true; 50 50 } -
trunk/psLib/src/sys/psType.h
r25256 r27303 107 107 PS_DATA_STRING = 0x10000, ///< psString (char *) 108 108 PS_DATA_ARRAY, ///< psArray 109 PS_DATA_BITS ET, ///< psBitSet109 PS_DATA_BITS, ///< psBits 110 110 PS_DATA_CUBE, ///< psCube 111 111 PS_DATA_FITS, ///< psFits -
trunk/psLib/src/types/Makefile.am
r23148 r27303 6 6 libpslibtypes_la_SOURCES = \ 7 7 psArray.c \ 8 psBit Set.c \8 psBits.c \ 9 9 psHash.c \ 10 10 psList.c \ … … 23 23 pkginclude_HEADERS = \ 24 24 psArray.h \ 25 psBit Set.h \25 psBits.h \ 26 26 psHash.h \ 27 27 psList.h \ -
trunk/psLib/src/types/psBits.c
r27302 r27303 1 /** @file psBit Set.c1 /** @file psBits.c 2 2 * 3 3 * @brief Creates an array of bytes of arbitrary length for storing individual bits. … … 26 26 #include <math.h> 27 27 28 #include "psBit Set.h"28 #include "psBits.h" 29 29 #include "psMemory.h" 30 30 #include "psError.h" … … 34 34 35 35 36 37 enum { 38 UNKNOWN_OP, 39 AND_OP, 40 OR_OP, 41 XOR_OP, 42 NOT_OP 43 }; 44 45 static void bitSetFree(psBitSet* inBitSet); 36 static void bitsFree(psBits *inBits); 46 37 47 38 /** Private function to create a mask. … … 52 43 * @return char*: Pointer to byte in which bit is contained. 53 44 */ 54 PS_ATTR_PURE static char mask(psS32 bit) 55 { 56 char mask = (char)0x01; 57 58 // Ignore splint warning about negative bit shifts 59 /* @i@ */ 60 mask = mask << (bit % 8); 61 62 return mask; 63 } 64 65 static void bitSetFree(psBitSet* inBitSet) 66 { 67 psFree(inBitSet->bits); 68 } 69 70 bool psMemCheckBitSet(psPtr ptr) 45 PS_ATTR_PURE static inline char mask(long bit) 46 { 47 psAssert(bit < 8, "Bad bit: %ld", bit); 48 return (char)0x01 << (bit % 8); 49 } 50 51 // Return the byte with the bit of interest 52 static inline psU8 *bitsGetByte(const psBits *bits, long bit) 53 { 54 return bits->bits + bit / 8; 55 } 56 57 58 static void bitsFree(psBits *inBits) 59 { 60 psFree(inBits->bits); 61 } 62 63 bool psMemCheckBits(psPtr ptr) 71 64 { 72 65 PS_ASSERT_PTR(ptr, false); 73 return ( psMemGetDeallocator(ptr) == (psFreeFunc)bitSetFree ); 74 } 75 76 77 psBitSet* p_psBitSetAlloc(const char *file, 78 unsigned int lineno, 79 const char *func, 80 long nalloc) 81 { 82 if (nalloc < 0) { 83 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 84 _("The number of bit in a psBitSet (%ld) must be greater than zero."), 85 nalloc); 86 return NULL; 87 } 88 89 psS32 numBytes = 0; 90 psBitSet* newObj = NULL; 91 92 numBytes = ceil(nalloc / 8.0); 93 newObj = p_psAlloc(file, lineno, func, sizeof(psBitSet)); 94 psMemSetDeallocator(newObj, (psFreeFunc) bitSetFree); 95 newObj->n = numBytes; 96 97 // Ignore splint warning about releasing pointer members, since they've not been allocated yet 98 /* @i@ */ 99 newObj->bits = psAlloc(sizeof(char) * numBytes); 100 101 memset(newObj->bits, 0, numBytes); 102 103 return newObj; 104 } 105 106 107 bool psBitSetSet(psBitSet* bitSet, 108 long bit) 109 { 110 unsigned char *byte = NULL; 111 112 if (bitSet == NULL) { 113 psError(PS_ERR_BAD_PARAMETER_NULL, true, 114 _("Can not operate on a NULL psBitSet.")); 115 return false; 116 } else if ( (bit < 0) || 117 (bit > bitSet->n * 8 - 1) ) { 118 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 119 _("The specified bit position (%ld) is invalid. Position must be between 0 and %ld."), 120 bit, bitSet->n * 8 - 1); 121 return false; 122 } 123 // Variable byte is the byte in the array that contains the bit to be set 124 byte = bitSet->bits + bit / 8; 66 return (psMemGetDeallocator(ptr) == (psFreeFunc)bitsFree); 67 } 68 69 70 psBits *p_psBitsAlloc(const char *file, unsigned int lineno, const char *func, long nalloc) 71 { 72 psAssert(nalloc >= 0, "The number of bits in a psBits (%ld) must be greater than zero.", nalloc); 73 74 int numBytes = ceil((float)nalloc / 8.0); // Number of bytes to use 75 psBits *bits = p_psAlloc(file, lineno, func, sizeof(psBits)); 76 psMemSetDeallocator(bits, (psFreeFunc)bitsFree); 77 bits->n = nalloc; 78 79 bits->bits = p_psAlloc(file, lineno, func, numBytes); 80 memset(bits->bits, 0, numBytes); 81 82 return bits; 83 } 84 85 86 bool psBitsSet(psBits *bits, long bit) 87 { 88 PS_ASSERT_BITS_NON_NULL(bits, false); 89 PS_ASSERT_BITS_VALID_BIT(bits, bit, false); 90 91 psU8 *byte = bitsGetByte(bits, bit); // Byte with the bit of interest 125 92 *byte |= mask(bit); 126 93 … … 128 95 } 129 96 130 bool psBitSetClear(psBitSet* bitSet, 131 long bit) 132 { 133 unsigned char *byte = NULL; 134 135 if (bitSet == NULL) { 136 psError(PS_ERR_BAD_PARAMETER_NULL, true, 137 _("Can not operate on a NULL psBitSet.")); 138 return false; 139 } else if ( (bit < 0) || 140 (bit > bitSet->n * 8 - 1) ) { 141 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 142 _("The specified bit position (%ld) is invalid. Position must be between 0 and %ld."), 143 bit, bitSet->n * 8 - 1); 144 return false; 145 } 146 // Variable byte is the byte in the array that contains the bit to be set 147 byte = bitSet->bits + bit / 8; 148 *byte &= ! mask(bit); 97 bool psBitsClear(psBits *bits, long bit) 98 { 99 PS_ASSERT_BITS_NON_NULL(bits, false); 100 PS_ASSERT_BITS_VALID_BIT(bits, bit, false); 101 102 psU8 *byte = bitsGetByte(bits, bit); // Byte with the bit of interest 103 *byte &= !mask(bit); 149 104 150 105 return true; 151 106 } 152 107 153 bool psBitSetTest(const psBitSet* bitSet, 154 long bit) 155 { 156 unsigned char *byte = NULL; 157 158 if (bitSet == NULL) { 159 psError(PS_ERR_BAD_PARAMETER_NULL, true, 160 _("Can not operate on a NULL psBitSet.")); 161 return false; 162 } else if ( (bit < 0) || 163 (bit > bitSet->n * 8 - 1) ) { 164 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 165 _("The specified bit position (%ld) is invalid. Position must be between 0 and %ld."), 166 bit,bitSet->n * 8 - 1); 167 return false; 168 } 169 170 // Variable byte is the byte in the array that contains the bit to be tested 171 byte = bitSet->bits + bit / 8; 108 109 bool psBitsTest(const psBits *bits, long bit) 110 { 111 // XXX These errors probably cannot be caught 112 PS_ASSERT_BITS_NON_NULL(bits, false); 113 PS_ASSERT_BITS_VALID_BIT(bits, bit, false); 114 115 psU8 *byte = bitsGetByte(bits, bit); // Byte with the bit of interest 172 116 return ((*byte & mask(bit)) != 0); 173 117 } 174 118 175 psBitSet* psBitSetOp(psBitSet* outBitSet, 176 const psBitSet* inBitSet1, 177 const char *operator, 178 const psBitSet* inBitSet2) 179 { 180 if (inBitSet1 == NULL) { 181 psError(PS_ERR_BAD_PARAMETER_NULL, true, 182 _("First psBitSet operand can not be NULL.")); 183 psFree(outBitSet); 184 return NULL; 185 } 186 if (operator == NULL) { 187 psError(PS_ERR_BAD_PARAMETER_NULL, true, 188 _("Specified operator is NULL. Must specify desired operator.")); 189 psFree(outBitSet); 190 return NULL; 191 } 192 psS32 i = 0; 193 psS32 n = 0; 194 unsigned char* outBits = NULL; 195 unsigned char* inBits1 = NULL; 196 unsigned char* inBits2 = NULL; 197 psS32 op = UNKNOWN_OP; 198 199 inBits1 = inBitSet1->bits; 200 201 202 // parse the operator 203 if (strcmp(operator,"AND")==0) { 119 psBits *psBitsOp(psBits *outBits, const psBits *bits1, const char *operator, const psBits *bits2) 120 { 121 PS_ASSERT_BITS_NON_NULL(bits1, NULL); 122 PS_ASSERT_STRING_NON_EMPTY(operator, NULL); 123 124 enum { 125 UNKNOWN_OP, 126 AND_OP, 127 OR_OP, 128 XOR_OP, 129 NOT_OP 130 } op = UNKNOWN_OP; 131 132 // Parse the operator 133 if (strcmp(operator, "AND") == 0) { 204 134 op = AND_OP; 205 } else if (strcmp(operator, "OR")==0) {135 } else if (strcmp(operator, "OR") == 0) { 206 136 op = OR_OP; 207 } else if (strcmp(operator, "XOR")==0) {137 } else if (strcmp(operator, "XOR") == 0) { 208 138 op = XOR_OP; 209 } else if (strcmp(operator, "NOT")==0) {139 } else if (strcmp(operator, "NOT") == 0) { 210 140 op = NOT_OP; 211 141 } else { 212 psFree(outBitSet);213 142 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 214 _("Specified operator, %s, is invalid. Valid operators are AND, OR, and XOR."),143 _("Specified operator, %s, is invalid. Valid operators are AND, OR, XOR, NOT."), 215 144 operator); 216 145 return NULL; … … 218 147 219 148 if (op != NOT_OP) { 220 if (inBitSet2 == NULL) { 221 psError(PS_ERR_BAD_PARAMETER_NULL, true, 222 _("Second psBitSet operand can not be NULL.")); 223 psFree(outBitSet); 149 PS_ASSERT_BITS_NON_NULL(bits2, false); 150 if (bits1->n != bits2->n) { 151 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 152 "The psBits operands must be the same size: %ld vs %ld", 153 bits1->n, bits2->n); 224 154 return NULL; 225 155 } 226 227 if (inBitSet1->n != inBitSet2->n) { 228 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 229 _("The psBitSet operand must be the same size.")); 230 psFree(outBitSet); 231 return NULL; 232 } 233 inBits2 = inBitSet2->bits; 234 } 235 236 if (outBitSet == NULL) { 237 outBitSet = psBitSetAlloc(inBitSet1->n*8); 238 } else if (outBitSet->n != inBitSet1->n) { 239 outBitSet->n = inBitSet1->n; 240 outBitSet->bits = psRealloc(outBitSet->bits, inBitSet1->n); 241 } 242 243 n = outBitSet->n; 244 outBits = outBitSet->bits; 156 } 157 158 int numBits = bits1->n; // Number of bits 159 int numBytes = ceil((float)numBits / 8.0); // Number of bytes 160 161 if (!outBits) { 162 outBits = psBitsAlloc(numBits); 163 } else if (outBits->n != numBits) { 164 outBits->n = numBits; 165 outBits->bits = psRealloc(outBits->bits, numBytes); 166 } 167 168 psU8 *in1 = bits1->bits; // Bits for input 1 169 psU8 *in2 = (op == NOT_OP) ? NULL : bits2->bits; // Bits for input 2 170 psU8 *out = outBits->bits; // Bits for output 245 171 246 172 switch (op) { 247 173 case AND_OP: 248 for (i = 0; i < n; i++) {249 out Bits[i] = inBits1[i] & inBits2[i];174 for (int i = 0; i < numBytes; i++) { 175 out[i] = in1[i] & in2[i]; 250 176 } 251 177 break; 252 178 case OR_OP: 253 for (i = 0; i < n; i++) {254 out Bits[i] = inBits1[i] | inBits2[i];179 for (int i = 0; i < numBytes; i++) { 180 out[i] = in1[i] | in2[i]; 255 181 } 256 182 break; 257 183 case XOR_OP: 258 for (i = 0; i < n; i++) {259 out Bits[i] = inBits1[i] ^ inBits2[i];184 for (int i = 0; i < numBytes; i++) { 185 out[i] = in1[i] ^ in2[i]; 260 186 } 261 187 break; 262 188 case NOT_OP: 263 189 default: 264 for (i = 0; i < n; i++) { 265 outBits[i] = ~inBits1[i]; 266 } 267 break; 268 } 269 270 return outBitSet; 271 } 272 273 psBitSet* psBitSetNot(psBitSet* outBitSet, 274 const psBitSet* inBitSet) 275 { 276 if (inBitSet == NULL) { 277 psError(PS_ERR_BAD_PARAMETER_NULL, true, 278 _("Operand can not be NULL.")); 279 psFree(outBitSet); 280 return NULL; 281 } 282 283 outBitSet = psBitSetOp(outBitSet,inBitSet,"NOT",NULL); 284 285 return outBitSet; 286 } 287 288 psString psBitSetToString(const psBitSet* bitSet) 289 { 290 PS_ASSERT_PTR_NON_NULL(bitSet, NULL); 291 psS32 i = 0; 292 psS32 numBits = bitSet->n * 8; 293 // char *outString = psAlloc((size_t) numBits + 1); 294 psString outString = psStringAlloc(numBits + 1); 295 296 for (i = 0; i < numBits; i++) { 297 outString[numBits - i - 1] = psBitSetTest(bitSet, i) ? '1' : '0'; 298 } 299 300 outString[numBits] = 0; 301 302 return outString; 303 } 190 for (int i = 0; i < numBytes; i++) { 191 out[i] = ~in1[i]; 192 } 193 break; 194 } 195 196 return outBits; 197 } 198 199 psBits *psBitsNot(psBits *outBits, const psBits *inBits) 200 { 201 return psBitsOp(outBits, inBits, "NOT", NULL); 202 } 203 204 psString psBitsToString(const psBits *bits) 205 { 206 PS_ASSERT_BITS_NON_NULL(bits, NULL); 207 208 psS32 numBits = bits->n; 209 psString string = psStringAlloc(numBits + 1); 210 211 char *out = &string[numBits]; 212 *out = '\0'; 213 out--; 214 for (long i = 0; i < numBits; i++, out--) { 215 *out = psBitsTest(bits, i) ? '1' : '0'; 216 } 217 218 return string; 219 } -
trunk/psLib/src/types/psBits.h
r27302 r27303 1 /** @file psBit Set.h1 /** @file psBits.h 2 2 * 3 3 * @brief Creates an array of bytes of arbitrary length for storing individual bits. … … 17 17 */ 18 18 19 #ifndef PSBITS ET_H20 #define PSBITS ET_H19 #ifndef PSBITS_H 20 #define PSBITS_H 21 21 22 22 #include "psType.h" … … 38 38 typedef struct 39 39 { 40 long n; ///< Number of bytes in the array41 psU8 *bits; ///< Aray of bytes holding bits40 long n; ///< Number of bits in the array 41 psU8 *bits; ///< Aray of bytes holding bits 42 42 psMutex lock; ///< Optional lock for thread safety 43 } 44 psBitSet; 43 } psBits; 45 44 46 45 /*****************************************************************************/ … … 53 52 * datatype. 54 53 * 55 * @return bool: True if the pointer matches a psBit Setstructure, false otherwise.54 * @return bool: True if the pointer matches a psBits structure, false otherwise. 56 55 */ 57 bool psMemCheckBit Set(56 bool psMemCheckBits( 58 57 psPtr ptr ///< the pointer whose type to check 59 58 ); 60 59 61 60 62 /** Allocate a psBit Set.61 /** Allocate a psBits. 63 62 * 64 * Create a psBit Setwith the number of bits specified by the user. All bits63 * Create a psBits with the number of bits specified by the user. All bits 65 64 * are set to zero upon allocation. 66 65 * 67 * @return psBit Set* : Pointer to struct containing array of bits and size of array.66 * @return psBits* : Pointer to struct containing array of bits and size of array. 68 67 */ 69 68 #ifdef DOXYGEN 70 psBit Set* psBitSetAlloc(71 long nalloc ///< Number of bits in psBit Setarray69 psBits* psBitsAlloc( 70 long nalloc ///< Number of bits in psBits array 72 71 ); 73 72 #else // ifdef DOXYGEN 74 psBit Set* p_psBitSetAlloc(73 psBits* p_psBitsAlloc( 75 74 const char *file, ///< File of caller 76 75 unsigned int lineno, ///< Line number of caller 77 76 const char *func, ///< Function name of caller 78 long nalloc ///< Number of bits in psBit Setarray77 long nalloc ///< Number of bits in psBits array 79 78 ) PS_ATTR_MALLOC; 80 #define psBit SetAlloc(nalloc) \81 p_psBit SetAlloc(__FILE__, __LINE__, __func__, nalloc)79 #define psBitsAlloc(nalloc) \ 80 p_psBitsAlloc(__FILE__, __LINE__, __func__, nalloc) 82 81 #endif // ifdef DOXYGEN 83 82 … … 90 89 * with the first bit set in the zero bit slot of the zero element of the byte 91 90 * array. As an example, setting bit 3 in an array with two elements would 92 * result in an psBit Setthat looks like 00000000 00001000.91 * result in an psBits that looks like 00000000 00001000. 93 92 * 94 93 * @return bool : Successful operation? 95 94 */ 96 bool psBit SetSet(97 psBit Set* bitSet, ///< Pointer to psBitSetto be set.95 bool psBitsSet( 96 psBits* bits, ///< Pointer to psBits to be set. 98 97 long bit ///< Bit to be set. 99 98 ); … … 108 107 * @return bool : Successful operation? 109 108 */ 110 bool psBit SetClear(111 psBit Set* bitSet, ///< Pointer to psBitSetto be cleared.109 bool psBitsClear( 110 psBits* bits, ///< Pointer to psBits to be cleared. 112 111 long bit ///< Bit to be cleared. 113 112 ); … … 119 118 * resulting bit is based on a zero index format with the first bit set in the 120 119 * zero bit slot of the zero element of the byte array. As an example, 121 * testing bit 3 in a psBit Setwith two bytes that looks like 00000000120 * testing bit 3 in a psBits with two bytes that looks like 00000000 122 121 * 00001000 would return a value of one, since that is the value that was set. 123 122 * 124 123 * @return bool: True if successful, otherwise false 125 124 */ 126 bool psBit SetTest(127 const psBit Set* bitSet, ///< Pointer psBitSetto be tested.125 bool psBitsTest( 126 const psBits* bits, ///< Pointer psBits to be tested. 128 127 long bit ///< Bit to be tested. 129 128 ); 130 129 131 130 132 /** Perform a binary operation on two psBit Sets131 /** Perform a binary operation on two psBitss 133 132 * 134 * Perform an AND, OR, or XOR on two psBit Sets. If the BitMasks are not the133 * Perform an AND, OR, or XOR on two psBitss. If the BitMasks are not the 135 134 * same size, the operation will not be performed and an error message will be 136 135 * logged. 137 136 * 138 * @return psBit Set* : Pointer to struct containing result of binary operation.137 * @return psBits* : Pointer to struct containing result of binary operation. 139 138 */ 140 psBit Set* psBitSetOp(141 psBit Set* outBitSet, ///< Resulting psBitSetfrom binary operation142 const psBit Set* inBitSet1, ///< First psBitSeton which to operate139 psBits* psBitsOp( 140 psBits* outBits, ///< Resulting psBits from binary operation 141 const psBits* inBits1, ///< First psBits on which to operate 143 142 const char *operator, ///< Bit operation 144 const psBit Set* inBitSet2 ///< Second psBitSeton which to operate143 const psBits* inBits2 ///< Second psBits on which to operate 145 144 ); 146 145 147 146 148 /** Perform a not operation on a psBit Set147 /** Perform a not operation on a psBits 149 148 * 150 * Toggles bits in a psBits et. All zero bits are set to one and all one bits149 * Toggles bits in a psBits. All zero bits are set to one and all one bits 151 150 * are set to zero. 152 151 * 153 * @return psBit Set* : Pointer to struct containing result of operation.152 * @return psBits* : Pointer to struct containing result of operation. 154 153 */ 155 psBit Set* psBitSetNot(156 psBit Set* outBitSet, ///< Resulting psBitSetfrom operation157 const psBit Set* inBitSet ///< Input psBitSet154 psBits* psBitsNot( 155 psBits* outBits, ///< Resulting psBits from operation 156 const psBits* inBits ///< Input psBits 158 157 ); 159 158 160 159 161 /** Convert the psBit Setto a string of ones and zeros.160 /** Convert the psBits to a string of ones and zeros. 162 161 * 163 * Converts the contents of a psBit Setto a string representation of its162 * Converts the contents of a psBits to a string representation of its 164 163 * binary form of ones and zeros. The LSB is the right-most chracter. Each set 165 164 * of eight characters represents one byte. … … 167 166 * @return psString: Pointer to character array containing string data. 168 167 */ 169 psString psBit SetToString(170 const psBit Set* bitSet ///< psBitSetto convert168 psString psBitsToString( 169 const psBits* bits ///< psBits to convert 171 170 ); 171 172 #define PS_ASSERT_BITS_NON_NULL(NAME, RVAL) \ 173 if ((NAME) == NULL || (NAME)->bits == NULL || (NAME)->n < 0) { \ 174 psError(PS_ERR_BAD_PARAMETER_NULL, true, \ 175 "Unallowable operation: psBits %s or its data is NULL.", \ 176 #NAME); \ 177 return RVAL; \ 178 } \ 179 180 #define PS_ASSERT_BITS_VALID_BIT(NAME, BIT, RVAL) \ 181 if (BIT < 0 || BIT >= (NAME)->n) { \ 182 psError(PS_ERR_BAD_PARAMETER_VALUE, true, \ 183 "Unallowable operation: psBits %s or its data is NULL.", \ 184 #NAME); \ 185 return RVAL; \ 186 } \ 187 172 188 173 189 174 190 /// @} 175 #endif // #ifndef PSBITS ET_H191 #endif // #ifndef PSBITS_H -
trunk/psLib/src/types/psMetadata.c
r26892 r27303 280 280 } 281 281 case PS_DATA_ARRAY: // psArray 282 case PS_DATA_BITS ET: // psBitSet282 case PS_DATA_BITS: // psBits 283 283 case PS_DATA_CUBE: // psCube 284 284 case PS_DATA_FITS: // psFits -
trunk/psLib/test/types/Makefile.am
r18145 r27303 29 29 tap_psPixels_all \ 30 30 tap_psHash_all \ 31 tap_psBit Set_all \31 tap_psBits_all \ 32 32 tap_psList_all \ 33 33 tap_psLookupTable_all \ -
trunk/psLib/test/types/tap_psBits_all.c
r27302 r27303 1 1 /** 2 * C Implementation: tap_psBit Set_all3 * 4 * Description: Tests for psBit SetAlloc, psBitSetSet, psMemCheckBitSet, psBitSetClear,5 * psBit SetTest, psBitSetOp, psBitSetNot, psBitSetToString2 * C Implementation: tap_psBits_all 3 * 4 * Description: Tests for psBitsAlloc, psBitsSet, psMemCheckBits, psBitsClear, 5 * psBitsTest, psBitsOp, psBitsNot, psBitsToString 6 6 * 7 7 * Author: dRob <David.Robbins@mhpcc.hpc.mil>, (C) 2006 … … 20 20 psLogSetFormat("HLNM"); 21 21 psLogSetLevel(PS_LOG_INFO); 22 plan_tests(3 1);23 24 25 // testBit SetBasics()22 plan_tests(30); 23 24 25 // testBitsBasics() 26 26 { 27 27 psMemId id = psMemGetId(); 28 psBitSet *noBits = NULL; 29 psBitSet *bs = NULL; 30 31 //Return NULL for attempt to Allocate BitSet of negative size. 32 { 33 noBits = psBitSetAlloc(-1); 34 ok( noBits == NULL, 35 "psBitSetAlloc: return NULL for negative BitSet-size input."); 36 } 37 //Return properly allocated 0-size psBitSet 38 { 39 bs = psBitSetAlloc(0); 40 ok( bs != NULL && psMemCheckBitSet(bs) && bs->n == 0, 41 "psBitSetAlloc: return properly allocated psBitSet."); 42 } 43 //Return properly allocated psBitSet 28 psBits *noBits = NULL; 29 psBits *bs = NULL; 30 31 //Return properly allocated 0-size psBits 32 { 33 bs = psBitsAlloc(0); 34 ok( bs != NULL && psMemCheckBits(bs) && bs->n == 0, 35 "psBitsAlloc: return properly allocated psBits."); 36 } 37 //Return properly allocated psBits 44 38 { 45 39 psFree(bs); 46 bs = psBit SetAlloc(8);47 ok( bs != NULL && psMemCheckBit Set(bs) && bs->n == 1,48 "psBit SetAlloc: return properly allocated psBitSet.");49 } 50 //Make sure psMemCheckBit Setworks correctly - return false40 bs = psBitsAlloc(8); 41 ok( bs != NULL && psMemCheckBits(bs) && bs->n == 8, 42 "psBitsAlloc: return properly allocated psBits."); 43 } 44 //Make sure psMemCheckBits works correctly - return false 51 45 if (0) { 52 46 int j = 2; 53 ok( !psMemCheckBit Set(&j),54 "psMemCheckBit Set: return false for non-BitSetinput.");55 } 56 57 //Bit SetSet Tests58 //Return FALSE for NULL input psBit Set59 { 60 bool rc = psBit SetSet(NULL, 0);47 ok( !psMemCheckBits(&j), 48 "psMemCheckBits: return false for non-Bits input."); 49 } 50 51 //BitsSet Tests 52 //Return FALSE for NULL input psBits 53 { 54 bool rc = psBitsSet(NULL, 0); 61 55 ok(rc == false, 62 "psBit SetSet: return FALSE for NULL BitSetinput.");56 "psBitsSet: return FALSE for NULL Bits input."); 63 57 } 64 58 //Return FALSE for negative bit input 65 59 { 66 bool rc = psBit SetSet(bs, -1);67 ok( rc == false, 68 "psBit SetSet: return TRUE for negative bits input.");60 bool rc = psBitsSet(bs, -1); 61 ok( rc == false, 62 "psBitsSet: return TRUE for negative bits input."); 69 63 noBits = NULL; 70 64 } … … 72 66 { 73 67 psFree(bs); 74 bs = psBit SetAlloc(8);75 bool rc = psBit SetSet(bs, 8);76 ok( rc == false, 77 "psBit SetSet: return TRUE for out-of-range bits input.");78 noBits = NULL; 79 } 80 81 //Return set Bit Setfor valid inputs82 { 83 psBit SetSet(bs, 2);68 bs = psBitsAlloc(8); 69 bool rc = psBitsSet(bs, 8); 70 ok( rc == false, 71 "psBitsSet: return TRUE for out-of-range bits input."); 72 noBits = NULL; 73 } 74 75 //Return set Bits for valid inputs 76 { 77 psBitsSet(bs, 2); 84 78 ok( bs->bits[0] == 4, 85 "psBit SetSet: return properly set BitSetfor valid inputs.");86 } 87 88 //Bit SetClear Tests89 //Return FALSE for NULL input psBit Set90 { 91 bool rc = psBit SetClear(noBits, 0);92 ok( rc == false, 93 "psBit SetClear: return FALSE for NULL BitSetinput.");79 "psBitsSet: return properly set Bits for valid inputs."); 80 } 81 82 //BitsClear Tests 83 //Return FALSE for NULL input psBits 84 { 85 bool rc = psBitsClear(noBits, 0); 86 ok( rc == false, 87 "psBitsClear: return FALSE for NULL Bits input."); 94 88 } 95 89 //Return FALSE for negative bit input 96 90 { 97 bool rc = psBit SetClear(bs, -1);98 ok( rc == false, 99 "psBit SetClear: return TRUE for negative bits input.");91 bool rc = psBitsClear(bs, -1); 92 ok( rc == false, 93 "psBitsClear: return TRUE for negative bits input."); 100 94 noBits = NULL; 101 95 } 102 96 //Return FALSE for out-of-range bits 103 97 { 104 bool rc = psBit SetClear(bs, 8);105 ok( rc == false, 106 "psBit SetClear: return FALSE for out-of-range bits input.");107 noBits = NULL; 108 } 109 110 //Return cleared Bit Setfor valid inputs111 { 112 psBit SetClear(bs, 2);98 bool rc = psBitsClear(bs, 8); 99 ok( rc == false, 100 "psBitsClear: return FALSE for out-of-range bits input."); 101 noBits = NULL; 102 } 103 104 //Return cleared Bits for valid inputs 105 { 106 psBitsClear(bs, 2); 113 107 ok( bs->bits[0] == 0, 114 "psBit SetClear: return properly cleared BitSetfor valid inputs.");115 } 116 117 //Bit SetTest Tests118 //Return false for NULL input psBit Set119 { 120 ok( !psBit SetTest(noBits, 0),121 "psBit SetTest: return false for NULL BitSetinput.");108 "psBitsClear: return properly cleared Bits for valid inputs."); 109 } 110 111 //BitsTest Tests 112 //Return false for NULL input psBits 113 { 114 ok( !psBitsTest(noBits, 0), 115 "psBitsTest: return false for NULL Bits input."); 122 116 } 123 117 //Return false for negative bit input 124 118 { 125 ok( !psBit SetTest(bs, -1),126 "psBit SetTest: return false for negative bits input.");119 ok( !psBitsTest(bs, -1), 120 "psBitsTest: return false for negative bits input."); 127 121 } 128 122 //Return false for out-of-range bits 129 123 { 130 ok( !psBit SetTest(bs, 8),131 "psBit SetTest: return false for out-of-range bits input.");132 } 133 //Return false for non-matching bit in Bit Set134 { 135 ok( !psBit SetTest(bs, 2),136 "psBit SetTest: return false for non-matching bit in BitSet.");137 } 138 //Return false for non-matching bit in Bit Set139 { 140 psBit SetSet(bs, 2);141 ok( psBit SetTest(bs, 2),142 "psBit SetTest: return true for matching bit in BitSet.");124 ok( !psBitsTest(bs, 8), 125 "psBitsTest: return false for out-of-range bits input."); 126 } 127 //Return false for non-matching bit in Bits 128 { 129 ok( !psBitsTest(bs, 2), 130 "psBitsTest: return false for non-matching bit in Bits."); 131 } 132 //Return false for non-matching bit in Bits 133 { 134 psBitsSet(bs, 2); 135 ok( psBitsTest(bs, 2), 136 "psBitsTest: return true for matching bit in Bits."); 143 137 } 144 138 … … 148 142 149 143 150 // testBit SetOps()144 // testBitsOps() 151 145 { 152 146 psMemId id = psMemGetId(); 153 psBit Set*noBits = NULL;154 psBit Set*bs = NULL;155 bs = psBit SetAlloc(8);156 psBit SetSet(bs, 2); // 0000 0100 == 4157 psBit SetSet(bs, 3); // 0000 1100 == 12158 psBit SetSet(bs, 4); // 0001 1100 == 28159 psBit SetSet(bs, 5); // 0011 1100 == 60160 psBit SetSet(bs, 6); // 0111 1100 == 124161 psBit SetSet(bs, 7); // 1111 1100 == 252162 psBit Set*out = NULL;163 164 //psBit SetNot Tests165 //Return NULL for NULL Bit Setinput166 { 167 out = psBit SetNot(out, noBits);168 ok( out == NULL, 169 "psBit SetNot: return NULL for NULL BitSetinput.");170 } 171 //Return correct Bit Set for valid BitSetinput172 { 173 out = psBit SetNot(out, bs); //bs = 1111 1100 so out should = 0000 0011 = 3147 psBits *noBits = NULL; 148 psBits *bs = NULL; 149 bs = psBitsAlloc(8); 150 psBitsSet(bs, 2); // 0000 0100 == 4 151 psBitsSet(bs, 3); // 0000 1100 == 12 152 psBitsSet(bs, 4); // 0001 1100 == 28 153 psBitsSet(bs, 5); // 0011 1100 == 60 154 psBitsSet(bs, 6); // 0111 1100 == 124 155 psBitsSet(bs, 7); // 1111 1100 == 252 156 psBits *out = NULL; 157 158 //psBitsNot Tests 159 //Return NULL for NULL Bits input 160 { 161 out = psBitsNot(out, noBits); 162 ok( out == NULL, 163 "psBitsNot: return NULL for NULL Bits input."); 164 } 165 //Return correct Bits for valid Bits input 166 { 167 out = psBitsNot(out, bs); //bs = 1111 1100 so out should = 0000 0011 = 3 174 168 ok( out->bits[0] == 3, 175 "psBit SetNot: return correct BitSet for valid BitSetinput.");176 } 177 178 //psBit SetOp Tests out = psBitSetOp(out, bs1, "op", bs2);179 //Return NULL for NULL Bit Setinput169 "psBitsNot: return correct Bits for valid Bits input."); 170 } 171 172 //psBitsOp Tests out = psBitsOp(out, bs1, "op", bs2); 173 //Return NULL for NULL Bits input 180 174 { 181 175 psFree(out); 182 176 out = NULL; 183 out = psBit SetOp(out, noBits, "op", noBits);184 ok( out == NULL, 185 "psBit SetOp: return NULL for NULL BitSetinput.");177 out = psBitsOp(out, noBits, "op", noBits); 178 ok( out == NULL, 179 "psBitsOp: return NULL for NULL Bits input."); 186 180 } 187 181 //Return NULL for NULL operator input 188 182 { 189 out = psBit SetOp(out, bs, NULL, noBits);190 ok( out == NULL, 191 "psBit SetOp: return NULL for NULL operator input.");183 out = psBitsOp(out, bs, NULL, noBits); 184 ok( out == NULL, 185 "psBitsOp: return NULL for NULL operator input."); 192 186 } 193 187 //Return NULL for invalid operator input 194 188 { 195 out = psBit SetOp(out, bs, "XAND", noBits);196 ok( out == NULL, 197 "psBit SetOp: return NULL for invalid operator input.");198 } 199 //Return NULL for AND operator with NULL second Bit Setinput200 { 201 out = psBit SetOp(out, bs, "AND", noBits);202 ok( out == NULL, 203 "psBit SetOp: return NULL for AND operator with NULL second BitSetinput.");204 } 205 //Return NULL for AND operator with Bit Setinputs of differing size.206 psBit Set *bs2 = psBitSetAlloc(16);207 { 208 out = psBit SetOp(out, bs, "AND", bs2);209 ok( out == NULL, 210 "psBit SetOp: return NULL for AND operator with BitSetinputs of"189 out = psBitsOp(out, bs, "XAND", noBits); 190 ok( out == NULL, 191 "psBitsOp: return NULL for invalid operator input."); 192 } 193 //Return NULL for AND operator with NULL second Bits input 194 { 195 out = psBitsOp(out, bs, "AND", noBits); 196 ok( out == NULL, 197 "psBitsOp: return NULL for AND operator with NULL second Bits input."); 198 } 199 //Return NULL for AND operator with Bits inputs of differing size. 200 psBits *bs2 = psBitsAlloc(16); 201 { 202 out = psBitsOp(out, bs, "AND", bs2); 203 ok( out == NULL, 204 "psBitsOp: return NULL for AND operator with Bits inputs of" 211 205 " differing size."); 212 206 } 213 207 psFree(bs); 214 bs = psBit SetAlloc(16);215 psBit SetSet(bs, 1); // 0000 0010 == 2216 psBit SetSet(bs2, 2); // 0000 0100 == 4217 //Return correct psBit Setoutput for valid inputs with AND operator218 { 219 out = psBit SetOp(out, bs, "AND", bs2);208 bs = psBitsAlloc(16); 209 psBitsSet(bs, 1); // 0000 0010 == 2 210 psBitsSet(bs2, 2); // 0000 0100 == 4 211 //Return correct psBits output for valid inputs with AND operator 212 { 213 out = psBitsOp(out, bs, "AND", bs2); 220 214 ok( out->bits[0] == 0, 221 "psBit SetOp: return correct psBitSetoutput for valid inputs"215 "psBitsOp: return correct psBits output for valid inputs" 222 216 " with AND operator."); 223 217 } 224 //Return correct psBit Setoutput for valid inputs with OR operator225 { 226 out = psBit SetOp(out, bs, "OR", bs2);218 //Return correct psBits output for valid inputs with OR operator 219 { 220 out = psBitsOp(out, bs, "OR", bs2); 227 221 ok( out->bits[0] == 6, 228 "psBit SetOp: return correct psBitSetoutput for valid inputs"222 "psBitsOp: return correct psBits output for valid inputs" 229 223 " with OR operator."); 230 224 } 231 //Return correct psBit Setoutput for valid inputs with XOR operator232 psBit SetSet(bs2, 1); // 0000 0110 == 6233 { 234 out = psBit SetOp(out, bs, "XOR", bs2);225 //Return correct psBits output for valid inputs with XOR operator 226 psBitsSet(bs2, 1); // 0000 0110 == 6 227 { 228 out = psBitsOp(out, bs, "XOR", bs2); 235 229 ok( out->bits[0] == 4, 236 "psBit SetOp: return correct psBitSetoutput for valid inputs"230 "psBitsOp: return correct psBits output for valid inputs" 237 231 " with XOR operator."); 238 232 } 239 //Return correct psBit Setoutput for valid inputs with NOT operator233 //Return correct psBits output for valid inputs with NOT operator 240 234 { 241 235 psFree(out); 242 out = psBit SetAlloc(0);243 psBit SetSet(bs, 2); // 0000 0110 == 4244 psBit SetSet(bs, 3); // 0000 1110 == 12245 psBit SetSet(bs, 4); // 0001 1110 == 28246 psBit SetSet(bs, 5); // 0011 1110 == 60247 psBit SetSet(bs, 6); // 0111 1110 == 124248 psBit SetSet(bs, 7); // 1111 1110 == 252249 out = psBit SetOp(out, bs, "NOT", bs2);236 out = psBitsAlloc(0); 237 psBitsSet(bs, 2); // 0000 0110 == 4 238 psBitsSet(bs, 3); // 0000 1110 == 12 239 psBitsSet(bs, 4); // 0001 1110 == 28 240 psBitsSet(bs, 5); // 0011 1110 == 60 241 psBitsSet(bs, 6); // 0111 1110 == 124 242 psBitsSet(bs, 7); // 1111 1110 == 252 243 out = psBitsOp(out, bs, "NOT", bs2); 250 244 ok( out->bits[0] == 1, 251 "psBit SetOp: return correct psBitSetoutput for valid inputs"245 "psBitsOp: return correct psBits output for valid inputs" 252 246 " with NOT operator."); 253 247 } 254 248 255 //psBit SetToString Tests256 //Return NULL for NULL Bit Setinput249 //psBitsToString Tests 250 //Return NULL for NULL Bits input 257 251 psString bitStr = NULL; 258 252 { 259 bitStr = psBit SetToString(noBits);253 bitStr = psBitsToString(noBits); 260 254 ok( bitStr == NULL, 261 "psBit SetToString: return NULL for NULL BitSetinput.");262 } 263 //Return correct string for valid Bit Setinput255 "psBitsToString: return NULL for NULL Bits input."); 256 } 257 //Return correct string for valid Bits input 264 258 { 265 259 psFree(bs); 266 bs = psBit SetAlloc(8);267 psBit SetSet(bs, 2); // 0000 0100 == 4268 bitStr = psBit SetToString(bs);260 bs = psBitsAlloc(8); 261 psBitsSet(bs, 2); // 0000 0100 == 4 262 bitStr = psBitsToString(bs); 269 263 ok( !strncmp(bitStr, "00000100", 10), 270 "psBit SetToString: return correct string for valid BitSet input.");264 "psBitsToString: return correct string for valid Bits input (%s).", bitStr); 271 265 } 272 266
Note:
See TracChangeset
for help on using the changeset viewer.
