Changeset 9082
- Timestamp:
- Sep 30, 2006, 2:40:35 PM (20 years ago)
- Location:
- trunk/psLib
- Files:
-
- 7 edited
-
src/types/psBitSet.c (modified) (9 diffs)
-
src/types/psBitSet.h (modified) (8 diffs)
-
test/types/Makefile.am (modified) (3 diffs)
-
test/types/execute_tap (modified) (1 diff)
-
test/types/tap_psBitSet_all.c (modified) (5 diffs)
-
test/types/tap_psHash_all.c (modified) (1 diff)
-
test/types/tap_psList_all.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/types/psBitSet.c
r8973 r9082 11 11 * @author Robert DeSonia, MHPCC 12 12 * 13 * @version $Revision: 1.3 6$ $Name: not supported by cvs2svn $14 * @date $Date: 2006- 09-26 02:55:34$13 * @version $Revision: 1.37 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2006-10-01 00:40:35 $ 15 15 * 16 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 27 27 #include "psAbort.h" 28 28 #include "psString.h" 29 #include "psAssert.h" 29 30 30 31 … … 60 61 static void bitSetFree(psBitSet* inBitSet) 61 62 { 62 if (inBitSet == NULL) {63 return;64 }65 63 psFree(inBitSet->bits); 66 64 } … … 77 75 psBitSet* psBitSetAlloc(long nalloc) 78 76 { 77 if (nalloc < 0) { 78 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 79 _("The number of bit in a psBitSet (%ld) must be greater than zero."), 80 nalloc); 81 return NULL; 82 } 83 79 84 psS32 numBytes = 0; 80 85 psBitSet* newObj = NULL; 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 86 89 87 numBytes = ceil(nalloc / 8.0); … … 174 172 const psBitSet* inBitSet2) 175 173 { 174 if (inBitSet1 == NULL) { 175 psError(PS_ERR_BAD_PARAMETER_NULL, true, 176 _("First psBitSet operand can not be NULL.")); 177 psFree(outBitSet); 178 return NULL; 179 } 180 if (operator == NULL) { 181 psError(PS_ERR_BAD_PARAMETER_NULL, true, 182 _("Specified operator is NULL. Must specify desired operator.")); 183 psFree(outBitSet); 184 return NULL; 185 } 176 186 psS32 i = 0; 177 187 psS32 n = 0; … … 181 191 psS32 op = UNKNOWN_OP; 182 192 183 if (inBitSet1 == NULL) {184 psError(PS_ERR_BAD_PARAMETER_NULL, true,185 _("First psBitSet operand can not be NULL."));186 psFree(outBitSet);187 return NULL;188 }189 193 inBits1 = inBitSet1->bits; 190 194 191 if (operator == NULL) {192 psError(PS_ERR_BAD_PARAMETER_NULL, true,193 _("Specified operator is NULL. Must specify desired operator."));194 psFree(outBitSet);195 return NULL;196 }197 195 198 196 // parse the operator … … 257 255 break; 258 256 case NOT_OP: 257 default: 259 258 for (i = 0; i < n; i++) { 260 259 outBits[i] = ~inBits1[i]; 261 260 } 262 261 break; 263 default:264 psAbort("psBitSetOp",265 "Unexpected error - operator parsed successfully but not valid?");266 262 } 267 263 … … 281 277 outBitSet = psBitSetOp(outBitSet,inBitSet,"NOT",NULL); 282 278 283 if (outBitSet == NULL) {284 psError(PS_ERR_UNKNOWN, false,285 _("Could not perform NOT operation."));286 }287 288 279 return outBitSet; 289 280 } … … 291 282 psString psBitSetToString(const psBitSet* bitSet) 292 283 { 284 PS_ASSERT_PTR_NON_NULL(bitSet, NULL); 293 285 psS32 i = 0; 294 286 psS32 numBits = bitSet->n * 8; 295 char *outString = psAlloc((size_t) numBits + 1); 287 // char *outString = psAlloc((size_t) numBits + 1); 288 psString outString = psStringAlloc(numBits + 1); 296 289 297 290 for (i = 0; i < numBits; i++) { -
trunk/psLib/src/types/psBitSet.h
r8973 r9082 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1.2 6$ $Name: not supported by cvs2svn $15 * @date $Date: 2006- 09-26 02:55:34$14 * @version $Revision: 1.27 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2006-10-01 00:40:35 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 32 32 /** Struct containing array of bytes to hold bit data and corresponding array length. 33 33 * 34 * The bits in the struct are assembled in as an array of bytes with eight bits per byte. The bits are 35 * arranged with the LSB in first (right most) position of the first array element. 34 * The bits in the struct are assembled in as an array of bytes with eight bits per 35 * byte. The bits are arranged with the LSB in first (right most) position of the 36 * first array element. 36 37 */ 37 38 typedef struct … … 51 52 * Uses the appropriate deallocation function in psMemBlock to check the ptr datatype. 52 53 * 53 * @return bool: True if the pointer matches a psBitSet structure, false otherwise.54 * @return bool: True if the pointer matches a psBitSet structure, false otherwise. 54 55 */ 55 56 bool psMemCheckBitSet( … … 60 61 /** Allocate a psBitSet. 61 62 * 62 * Create a psBitSet with the number of bits specified by the user. All bits are set to zero upon63 * allocation.63 * Create a psBitSet with the number of bits specified by the user. All bits are set 64 * to zero upon allocation. 64 65 * 65 66 * @return psBitSet* : Pointer to struct containing array of bits and size of array. 66 67 */ 67 68 psBitSet* psBitSetAlloc( 68 long nalloc ///< Number of bits in psBitSet array69 long nalloc ///< Number of bits in psBitSet array 69 70 ); 70 71 … … 72 73 * 73 74 * Sets a bit at a given bit location. The bit is set based on a zero index with the 74 * first bit set in the zero bit slot of the zero element of the byte array. As an example, setting bit 3 in 75 * an array with two elements would result in an psBitSet that looks like 00000000 00001000. 75 * first bit set in the zero bit slot of the zero element of the byte array. As an 76 * example, setting bit 3 in an array with two elements would result in an psBitSet 77 * that looks like 00000000 00001000. 76 78 * 77 79 * @return psBitSet* : Pointer to struct containing psBitSet. … … 97 99 /** Test the value of a bit. 98 100 * 99 * Prints the value of a bit at a given bit location, either one or zero. The resulting bit is based on a 100 * zero index format with the first bit set in the zero bit slot of the zero element of the byte array 101 * As an example, testing bit 3 in a psBitSet with two bytes that looks like 00000000 00001000 would return a 102 * value of one, since that is the value that was set. 101 * Prints the value of a bit at a given bit location, either one or zero. The resulting 102 * bit is based on a zero index format with the first bit set in the zero bit slot of 103 * the zero element of the byte array. As an example, testing bit 3 in a psBitSet with 104 * two bytes that looks like 00000000 00001000 would return a value of one, since that 105 * is the value that was set. 103 106 * 104 107 * @return bool: True if successful, otherwise false 105 108 */ 106 107 109 bool psBitSetTest( 108 110 const psBitSet* bitSet, ///< Pointer psBitSet to be tested. … … 112 114 /** Perform a binary operation on two psBitSets 113 115 * 114 * Perform an AND, OR, or XOR on two psBitSets. If the BitMasks are not the same size, the operation will not115 * be performed and an error message will be logged.116 * Perform an AND, OR, or XOR on two psBitSets. If the BitMasks are not the same size, 117 * the operation will not be performed and an error message will be logged. 116 118 * 117 119 * @return psBitSet* : Pointer to struct containing result of binary operation. 118 120 */ 119 121 psBitSet* psBitSetOp( 120 psBitSet* outBitSet, ///< Resulting psBitSet from binary operation121 const psBitSet* inBitSet1, ///< First psBitSet on which to operate122 const char *operator, ///< Bit operation123 const psBitSet* inBitSet2 ///< FirstpsBitSet on which to operate122 psBitSet* outBitSet, ///< Resulting psBitSet from binary operation 123 const psBitSet* inBitSet1, ///< First psBitSet on which to operate 124 const char *operator, ///< Bit operation 125 const psBitSet* inBitSet2 ///< Second psBitSet on which to operate 124 126 ); 125 127 126 128 /** Perform a not operation on a psBitSet 127 129 * 128 * Toggles bits in a psBitset. All zero bits are set to one and all one bits are set to zero. 130 * Toggles bits in a psBitset. All zero bits are set to one and all one bits are set 131 * to zero. 129 132 * 130 133 * @return psBitSet* : Pointer to struct containing result of operation. 131 134 */ 132 133 135 psBitSet* psBitSetNot( 134 136 psBitSet* outBitSet, ///< Resulting psBitSet from operation … … 138 140 /** Convert the psBitSet to a string of ones and zeros. 139 141 * 140 * Converts the contents of a psBitSet to a string representation of its binary form of ones and zeros. The 141 * LSB is the right-most chracter. Each set of eight characters represents one byte. 142 * Converts the contents of a psBitSet to a string representation of its binary form of 143 * ones and zeros. The LSB is the right-most chracter. Each set of eight characters 144 * represents one byte. 142 145 * 143 * @return char*:Pointer to character array containing string data.146 * @return psString: Pointer to character array containing string data. 144 147 */ 145 146 148 psString psBitSetToString( 147 const psBitSet* bitSet ///< psBitSet to convert */149 const psBitSet* bitSet ///< psBitSet to convert 148 150 ); 149 151 -
trunk/psLib/test/types/Makefile.am
r8960 r9082 24 24 tap_psMetadata_polynomials \ 25 25 tap_psArray_all \ 26 tap_psArguments_all 26 tap_psArguments_all \ 27 tap_psPixels_all \ 28 tap_psHash_all \ 29 tap_psBitSet_all \ 30 tap_psList_all 27 31 28 32 if BUILD_TESTS … … 42 46 data/test3.config \ 43 47 data/test4.config \ 44 data/test5.config 48 data/test5.config 45 49 46 50 tmp_files = \ … … 53 57 test3.config \ 54 58 test4.config \ 55 test5.config 59 test5.config 56 60 57 61 CLEANFILES = $(tmp_files) multi.fits table.fits temp/* MDCopy.in MDCopy.out mdcfgwrt.out \ -
trunk/psLib/test/types/execute_tap
r8966 r9082 15 15 ./tap_psPixels_all 16 16 ./tap_psHash_all 17 ./tap_psBitSet_all 18 ./tap_psList_all -
trunk/psLib/test/types/tap_psBitSet_all.c
r8930 r9082 12 12 13 13 #include <pslib.h> 14 #include <string.h> 14 15 15 16 #include "tap.h" … … 21 22 int main(void) 22 23 { 23 plan_tests( 5);24 plan_tests(31); 24 25 25 26 diag("Tests for psBitSet Functions"); … … 50 51 "psBitSetAlloc: return properly allocated psBitSet."); 51 52 } 53 //Return properly allocated psBitSet 54 { 55 psFree(bs); 56 bs = psBitSetAlloc(8); 57 ok( bs != NULL && psMemCheckBitSet(bs) && bs->n == 1, 58 "psBitSetAlloc: return properly allocated psBitSet."); 59 } 52 60 //Make sure psMemCheckBitSet works correctly - return false 53 61 { … … 56 64 "psMemCheckBitSet: return false for non-BitSet input."); 57 65 } 58 //Return properly allocated psBitSet 59 { 60 psFree(bs); 61 bs = psBitSetAlloc(8); 62 ok( bs != NULL && psMemCheckBitSet(bs) && bs->n == 1, 63 "psBitSetAlloc: return properly allocated psBitSet."); 64 } 66 67 //BitSetSet Tests 68 //Return NULL for NULL input psBitSet 69 { 70 noBits = psBitSetSet(noBits, 0); 71 ok( noBits == NULL, 72 "psBitSetSet: return NULL for NULL BitSet input."); 73 } 74 //Return input BitSet for negative bit input 75 { 76 noBits = psBitSetSet(bs, -1); 77 ok( noBits == bs, 78 "psBitSetSet: return input BitSet for negative bits input."); 79 noBits = NULL; 80 } 81 //Return input BitSet for out-of-range bits 82 { 83 noBits = psBitSetSet(bs, 8); 84 ok( noBits == bs, 85 "psBitSetSet: return input BitSet for out-of-range bits input."); 86 noBits = NULL; 87 } 88 //Return set BitSet for valid inputs 89 { 90 bs = psBitSetSet(bs, 2); 91 ok( bs->bits[0] == 4, 92 "psBitSetSet: return properly set BitSet for valid inputs."); 93 } 94 95 //BitSetClear Tests 96 //Return NULL for NULL input psBitSet 97 { 98 noBits = psBitSetClear(noBits, 0); 99 ok( noBits == NULL, 100 "psBitSetClear: return NULL for NULL BitSet input."); 101 } 102 //Return input BitSet for negative bit input 103 { 104 noBits = psBitSetClear(bs, -1); 105 ok( noBits == bs, 106 "psBitSetClear: return input BitSet for negative bits input."); 107 noBits = NULL; 108 } 109 //Return input BitSet for out-of-range bits 110 { 111 noBits = psBitSetClear(bs, 8); 112 ok( noBits == bs, 113 "psBitSetClear: return input BitSet for out-of-range bits input."); 114 noBits = NULL; 115 } 116 //Return cleared BitSet for valid inputs 117 { 118 bs = psBitSetClear(bs, 2); 119 ok( bs->bits[0] == 0, 120 "psBitSetClear: return properly cleared BitSet for valid inputs."); 121 } 122 123 //BitSetTest Tests 124 //Return false for NULL input psBitSet 125 { 126 ok( !psBitSetTest(noBits, 0), 127 "psBitSetTest: return false for NULL BitSet input."); 128 } 129 //Return false for negative bit input 130 { 131 ok( !psBitSetTest(bs, -1), 132 "psBitSetTest: return false for negative bits input."); 133 } 134 //Return false for out-of-range bits 135 { 136 ok( !psBitSetTest(bs, 8), 137 "psBitSetTest: return false for out-of-range bits input."); 138 } 139 //Return false for non-matching bit in BitSet 140 { 141 ok( !psBitSetTest(bs, 2), 142 "psBitSetTest: return false for non-matching bit in BitSet."); 143 } 144 //Return false for non-matching bit in BitSet 145 { 146 bs = psBitSetSet(bs, 2); 147 ok( psBitSetTest(bs, 2), 148 "psBitSetTest: return true for matching bit in BitSet."); 149 } 150 65 151 66 152 //Check for Memory leaks … … 74 160 { 75 161 diag(" >>>Test 2: psBitSet Operation Fxns"); 162 psBitSet *noBits = NULL; 163 psBitSet *bs = NULL; 164 bs = psBitSetAlloc(8); 165 bs = psBitSetSet(bs, 2); // 0000 0100 == 4 166 bs = psBitSetSet(bs, 3); // 0000 1100 == 12 167 bs = psBitSetSet(bs, 4); // 0001 1100 == 28 168 bs = psBitSetSet(bs, 5); // 0011 1100 == 60 169 bs = psBitSetSet(bs, 6); // 0111 1100 == 124 170 bs = psBitSetSet(bs, 7); // 1111 1100 == 252 171 psBitSet *out = NULL; 172 173 //psBitSetNot Tests 174 //Return NULL for NULL BitSet input 175 { 176 out = psBitSetNot(out, noBits); 177 ok( out == NULL, 178 "psBitSetNot: return NULL for NULL BitSet input."); 179 } 180 //Return correct BitSet for valid BitSet input 181 { 182 out = psBitSetNot(out, bs); //bs = 1111 1100 so out should = 0000 0011 = 3 183 ok( out->bits[0] == 3, 184 "psBitSetNot: return correct BitSet for valid BitSet input."); 185 } 186 187 //psBitSetOp Tests out = psBitSetOp(out, bs1, "op", bs2); 188 //Return NULL for NULL BitSet input 189 { 190 psFree(out); 191 out = NULL; 192 out = psBitSetOp(out, noBits, "op", noBits); 193 ok( out == NULL, 194 "psBitSetOp: return NULL for NULL BitSet input."); 195 } 196 //Return NULL for NULL operator input 197 { 198 out = psBitSetOp(out, bs, NULL, noBits); 199 ok( out == NULL, 200 "psBitSetOp: return NULL for NULL operator input."); 201 } 202 //Return NULL for invalid operator input 203 { 204 out = psBitSetOp(out, bs, "XAND", noBits); 205 ok( out == NULL, 206 "psBitSetOp: return NULL for invalid operator input."); 207 } 208 //Return NULL for AND operator with NULL second BitSet input 209 { 210 out = psBitSetOp(out, bs, "AND", noBits); 211 ok( out == NULL, 212 "psBitSetOp: return NULL for AND operator with NULL second BitSet input."); 213 } 214 //Return NULL for AND operator with BitSet inputs of differing size. 215 psBitSet *bs2 = psBitSetAlloc(16); 216 { 217 out = psBitSetOp(out, bs, "AND", bs2); 218 ok( out == NULL, 219 "psBitSetOp: return NULL for AND operator with BitSet inputs of" 220 " differing size."); 221 } 222 psFree(bs); 223 bs = psBitSetAlloc(16); 224 bs = psBitSetSet(bs, 1); // 0000 0010 == 2 225 bs2 = psBitSetSet(bs2, 2); // 0000 0100 == 4 226 //Return correct psBitSet output for valid inputs with AND operator 227 { 228 out = psBitSetOp(out, bs, "AND", bs2); 229 ok( out->bits[0] == 0, 230 "psBitSetOp: return correct psBitSet output for valid inputs" 231 " with AND operator."); 232 } 233 //Return correct psBitSet output for valid inputs with OR operator 234 { 235 out = psBitSetOp(out, bs, "OR", bs2); 236 ok( out->bits[0] == 6, 237 "psBitSetOp: return correct psBitSet output for valid inputs" 238 " with OR operator."); 239 } 240 //Return correct psBitSet output for valid inputs with XOR operator 241 bs2 = psBitSetSet(bs2, 1); // 0000 0110 == 6 242 { 243 out = psBitSetOp(out, bs, "XOR", bs2); 244 ok( out->bits[0] == 4, 245 "psBitSetOp: return correct psBitSet output for valid inputs" 246 " with XOR operator."); 247 } 248 //Return correct psBitSet output for valid inputs with NOT operator 249 { 250 psFree(out); 251 out = psBitSetAlloc(0); 252 bs = psBitSetSet(bs, 2); // 0000 0110 == 4 253 bs = psBitSetSet(bs, 3); // 0000 1110 == 12 254 bs = psBitSetSet(bs, 4); // 0001 1110 == 28 255 bs = psBitSetSet(bs, 5); // 0011 1110 == 60 256 bs = psBitSetSet(bs, 6); // 0111 1110 == 124 257 bs = psBitSetSet(bs, 7); // 1111 1110 == 252 258 out = psBitSetOp(out, bs, "NOT", bs2); 259 ok( out->bits[0] == 1, 260 "psBitSetOp: return correct psBitSet output for valid inputs" 261 " with NOT operator."); 262 } 263 264 //psBitSetToString Tests 265 //Return NULL for NULL BitSet input 266 psString bitStr = NULL; 267 { 268 bitStr = psBitSetToString(noBits); 269 ok( bitStr == NULL, 270 "psBitSetToString: return NULL for NULL BitSet input."); 271 } 272 //Return correct string for valid BitSet input 273 { 274 psFree(bs); 275 bs = psBitSetAlloc(8); 276 bs = psBitSetSet(bs, 2); // 0000 0100 == 4 277 bitStr = psBitSetToString(bs); 278 ok( !strncmp(bitStr, "00000100", 10), 279 "psBitSetToString: return correct string for valid BitSet input."); 280 } 76 281 77 282 78 283 //Check for Memory leaks 79 284 { 285 psFree(bitStr); 286 psFree(out); 287 psFree(bs); 288 psFree(bs2); 80 289 checkMem(); 81 290 } 82 291 } 83 84 /*85 //Attempt to reallocate the psArray - smaller86 {87 skip_start( !psArraySet(a, 0, s32) || !psArraySet(a, 1, s32), 1,88 "Skipping 1 tests because psArraySet failed");89 ok( a->n == 1 && a->nalloc == 1 && *s32_2 == 1,90 "psArrayRealloc: return properly reallocated psArray.");91 skip_end();92 }93 94 */95 -
trunk/psLib/test/types/tap_psHash_all.c
r8966 r9082 12 12 13 13 #include <pslib.h> 14 #include <string.h> 14 15 15 16 #include "tap.h" -
trunk/psLib/test/types/tap_psList_all.c
r8966 r9082 12 12 13 13 #include <pslib.h> 14 #include <string.h> 14 15 15 16 #include "tap.h"
Note:
See TracChangeset
for help on using the changeset viewer.
