IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 9082


Ignore:
Timestamp:
Sep 30, 2006, 2:40:35 PM (20 years ago)
Author:
drobbin
Message:

Fixed BitSet test and corresponding small fixes to src/psBitSet's. Updated Makefile in test/types and execute tap. Added <string.h> to tap tests missing it.

Location:
trunk/psLib
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/types/psBitSet.c

    r8973 r9082  
    1111 *  @author Robert DeSonia, MHPCC
    1212 *
    13  *  @version $Revision: 1.36 $ $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 $
    1515 *
    1616 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2727#include "psAbort.h"
    2828#include "psString.h"
     29#include "psAssert.h"
    2930
    3031
     
    6061static void bitSetFree(psBitSet* inBitSet)
    6162{
    62     if (inBitSet == NULL) {
    63         return;
    64     }
    6563    psFree(inBitSet->bits);
    6664}
     
    7775psBitSet* psBitSetAlloc(long nalloc)
    7876{
     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
    7984    psS32 numBytes = 0;
    8085    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     }
    8886
    8987    numBytes = ceil(nalloc / 8.0);
     
    174172                     const psBitSet* inBitSet2)
    175173{
     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    }
    176186    psS32 i = 0;
    177187    psS32 n = 0;
     
    181191    psS32 op = UNKNOWN_OP;
    182192
    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     }
    189193    inBits1 = inBitSet1->bits;
    190194
    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     }
    197195
    198196    // parse the operator
     
    257255        break;
    258256    case NOT_OP:
     257    default:
    259258        for (i = 0; i < n; i++) {
    260259            outBits[i] = ~inBits1[i];
    261260        }
    262261        break;
    263     default:
    264         psAbort("psBitSetOp",
    265                 "Unexpected error - operator parsed successfully but not valid?");
    266262    }
    267263
     
    281277    outBitSet = psBitSetOp(outBitSet,inBitSet,"NOT",NULL);
    282278
    283     if (outBitSet == NULL) {
    284         psError(PS_ERR_UNKNOWN, false,
    285                 _("Could not perform NOT operation."));
    286     }
    287 
    288279    return outBitSet;
    289280}
     
    291282psString psBitSetToString(const psBitSet* bitSet)
    292283{
     284    PS_ASSERT_PTR_NON_NULL(bitSet, NULL);
    293285    psS32 i = 0;
    294286    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);
    296289
    297290    for (i = 0; i < numBits; i++) {
  • trunk/psLib/src/types/psBitSet.h

    r8973 r9082  
    1212 *  @author Ross Harman, MHPCC
    1313 *
    14  *  @version $Revision: 1.26 $ $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 $
    1616 *
    1717 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3232/** Struct containing array of bytes to hold bit data and corresponding array length.
    3333 *
    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.
    3637 */
    3738typedef struct
     
    5152 *  Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.
    5253 *
    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.
    5455 */
    5556bool psMemCheckBitSet(
     
    6061/** Allocate a psBitSet.
    6162 *
    62  *  Create a psBitSet with the number of bits specified by the user. All bits are set to zero upon
    63  *  allocation.
     63 *  Create a psBitSet with the number of bits specified by the user. All bits are set
     64 *  to zero upon allocation.
    6465 *
    6566 *  @return  psBitSet* : Pointer to struct containing array of bits and size of array.
    6667 */
    6768psBitSet* psBitSetAlloc(
    68     long nalloc                            ///< Number of bits in psBitSet array
     69    long nalloc                        ///< Number of bits in psBitSet array
    6970);
    7071
     
    7273 *
    7374 *  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.
    7678 *
    7779 *  @return  psBitSet* : Pointer to struct containing psBitSet.
     
    9799/** Test the value of a bit.
    98100 *
    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.
    103106 *
    104107 *  @return  bool:      True if successful, otherwise false
    105108 */
    106 
    107109bool psBitSetTest(
    108110    const psBitSet* bitSet,            ///< Pointer psBitSet to be tested.
     
    112114/** Perform a binary operation on two psBitSets
    113115 *
    114  *  Perform an AND, OR, or XOR on two psBitSets. If the BitMasks are not the same size, the operation will not
    115  *  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.
    116118 *
    117119 *  @return  psBitSet* : Pointer to struct containing result of binary operation.
    118120 */
    119121psBitSet* psBitSetOp(
    120     psBitSet* outBitSet,                 ///< Resulting psBitSet from binary operation
    121     const psBitSet* inBitSet1,           ///< First psBitSet on which to operate
    122     const char *operator,                    ///< Bit operation
    123     const psBitSet* inBitSet2            ///< First psBitSet on which to operate
     122    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
    124126);
    125127
    126128/** Perform a not operation on a psBitSet
    127129 *
    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.
    129132 *
    130133 *  @return  psBitSet* : Pointer to struct containing result of operation.
    131134 */
    132 
    133135psBitSet* psBitSetNot(
    134136    psBitSet* outBitSet,               ///< Resulting psBitSet from operation
     
    138140/** Convert the psBitSet to a string of ones and zeros.
    139141 *
    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.
    142145 *
    143  *  @return  char*: Pointer to character array containing string data.
     146 *  @return  psString:      Pointer to character array containing string data.
    144147 */
    145 
    146148psString psBitSetToString(
    147     const psBitSet* bitSet             ///< psBitSet to convert */
     149    const psBitSet* bitSet             ///< psBitSet to convert
    148150);
    149151
  • trunk/psLib/test/types/Makefile.am

    r8960 r9082  
    2424        tap_psMetadata_polynomials \
    2525        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
    2731
    2832if BUILD_TESTS
     
    4246        data/test3.config \
    4347        data/test4.config \
    44         data/test5.config 
     48        data/test5.config
    4549
    4650tmp_files = \
     
    5357        test3.config \
    5458        test4.config \
    55         test5.config 
     59        test5.config
    5660
    5761CLEANFILES = $(tmp_files) multi.fits table.fits temp/* MDCopy.in MDCopy.out mdcfgwrt.out \
  • trunk/psLib/test/types/execute_tap

    r8966 r9082  
    1515./tap_psPixels_all
    1616./tap_psHash_all
     17./tap_psBitSet_all
     18./tap_psList_all
  • trunk/psLib/test/types/tap_psBitSet_all.c

    r8930 r9082  
    1212
    1313#include <pslib.h>
     14#include <string.h>
    1415
    1516#include "tap.h"
     
    2122int main(void)
    2223{
    23     plan_tests(5);
     24    plan_tests(31);
    2425
    2526    diag("Tests for psBitSet Functions");
     
    5051            "psBitSetAlloc:         return properly allocated psBitSet.");
    5152    }
     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    }
    5260    //Make sure psMemCheckBitSet works correctly - return false
    5361    {
     
    5664            "psMemCheckBitSet:      return false for non-BitSet input.");
    5765    }
    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
    65151
    66152    //Check for Memory leaks
     
    74160{
    75161    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    }
    76281
    77282
    78283    //Check for Memory leaks
    79284    {
     285        psFree(bitStr);
     286        psFree(out);
     287        psFree(bs);
     288        psFree(bs2);
    80289        checkMem();
    81290    }
    82291}
    83 
    84 /*
    85     //Attempt to reallocate the psArray - smaller
    86 {
    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  
    1212
    1313#include <pslib.h>
     14#include <string.h>
    1415
    1516#include "tap.h"
  • trunk/psLib/test/types/tap_psList_all.c

    r8966 r9082  
    1212
    1313#include <pslib.h>
     14#include <string.h>
    1415
    1516#include "tap.h"
Note: See TracChangeset for help on using the changeset viewer.