IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6218


Ignore:
Timestamp:
Jan 26, 2006, 3:49:05 PM (20 years ago)
Author:
drobbin
Message:

Updated psStringSplit and created/finished corresponding test.

Location:
trunk/psLib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sys/psString.c

    r6201 r6218  
    1313 *  @author David Robbins, MHPCC
    1414 *
    15  *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
    16  *  @date $Date: 2006-01-26 05:31:54 $
     15 *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
     16 *  @date $Date: 2006-01-27 01:49:05 $
    1717 *
    1818 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2525#include "psMemory.h"
    2626#include "psError.h"
     27#include "psConstants.h"
    2728
    2829#include "psErrorText.h"
     
    168169                      const char *splitters)
    169170{
     171    PS_ASSERT_PTR_NON_NULL(string, NULL);
     172    PS_ASSERT_PTR_NON_NULL(splitters, NULL);
     173
    170174    psList *values = psListAlloc(NULL); // The list of values to return
    171175    unsigned int length = strlen(string); // The length of the string
  • trunk/psLib/test/sys/tst_psString.c

    r6211 r6218  
    2020 *  @author  Eric Van Alst, MHPCC
    2121 *
    22  *  @version $Revision: 1.2 $  $Name: not supported by cvs2svn $
    23  *  @date  $Date: 2006-01-26 23:31:22 $
     22 *  @version $Revision: 1.3 $  $Name: not supported by cvs2svn $
     23 *  @date  $Date: 2006-01-27 01:49:05 $
    2424 *
    2525 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    442442{
    443443    psList *strList = NULL;
    444     char str[30];
     444    char str[35];
    445445    char split[5];
    446     strncpy(str, "This is, a, test case, to check.", 30);
     446    strncpy(str, "This is, a, test case, to check.", 35);
    447447    strncpy(split, ",", 2);
    448448    psString psStr;
     
    456456    if (strList != NULL) {
    457457        psFree(strList);
     458        return 1;
    458459    }
    459460    //Return NULL for NULL string input
     
    462463    if (strList != NULL) {
    463464        psFree(strList);
     465        return 2;
    464466    }
    465467    //Return NULL for NULL splitter input
     
    468470    if (strList != NULL) {
    469471        psFree(strList);
    470     }
    471 
    472 
    473     /*
    474         strList = psStringSplit(str, split);
    475      
    476         strList = psStringSplit(psStr, split);
    477      
    478         strList = psStringSplit(str, psSplit);
    479      
    480         strList = psStringSplit(psStr, psSplit);
    481     */
    482     //    psFree(strList);
    483     return 0;
    484 }
    485 
     472        return 3;
     473    }
     474    //Return a psList* of psStrings
     475    strList = psStringSplit(str, split);
     476    if (strList->n != 4) {
     477        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     478                "psStringSplit failed to return the correct number of strings.\n");
     479        return 4;
     480    }
     481    if ( strncmp((psString)(strList->head->data), "This is", 10) ) {
     482        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     483                "psStringSplit failed to return expected strings.");
     484        return 5;
     485    }
     486    if ( strncmp((psString)(strList->head->next->data), " a", 10) ) {
     487        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     488                "psStringSplit failed to return expected strings.");
     489        return 6;
     490    }
     491    if ( strncmp((psString)(strList->head->next->next->data), " test case", 10) ) {
     492        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     493                "psStringSplit failed to return expected strings.");
     494        return 7;
     495    }
     496    if ( strncmp((psString)(strList->head->next->next->next->data), " to check.", 10) ) {
     497        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     498                "psStringSplit failed to return expected strings.");
     499        return 8;
     500    }
     501    psFree(strList);
     502    //Return correct psList when using (psString, char*)
     503    strList = psStringSplit(psStr, split);
     504    if (strList->n != 4) {
     505        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     506                "psStringSplit failed to return the correct number of strings.\n");
     507        return 9;
     508    }
     509    if ( strncmp((psString)(strList->head->data), "This is", 10) ) {
     510        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     511                "psStringSplit failed to return expected strings.");
     512        return 10;
     513    }
     514    if ( strncmp((psString)(strList->head->next->data), " a", 10) ) {
     515        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     516                "psStringSplit failed to return expected strings.");
     517        return 11;
     518    }
     519    if ( strncmp((psString)(strList->head->next->next->data), " test case", 10) ) {
     520        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     521                "psStringSplit failed to return expected strings.");
     522        return 12;
     523    }
     524    if ( strncmp((psString)(strList->head->next->next->next->data), " to check.", 10) ) {
     525        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     526                "psStringSplit failed to return expected strings.");
     527        return 13;
     528    }
     529    psFree(strList);
     530    //Return correct psList when using (char*, psString)
     531    strList = psStringSplit(str, psSplit);
     532    if (strList->n != 4) {
     533        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     534                "psStringSplit failed to return the correct number of strings.\n");
     535        return 14;
     536    }
     537    if ( strncmp((psString)(strList->head->data), "This is", 10) ) {
     538        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     539                "psStringSplit failed to return expected strings.");
     540        return 15;
     541    }
     542    if ( strncmp((psString)(strList->head->next->data), " a", 10) ) {
     543        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     544                "psStringSplit failed to return expected strings.");
     545        return 16;
     546    }
     547    if ( strncmp((psString)(strList->head->next->next->data), " test case", 10) ) {
     548        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     549                "psStringSplit failed to return expected strings.");
     550        return 17;
     551    }
     552    if ( strncmp((psString)(strList->head->next->next->next->data), " to check.", 10) ) {
     553        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     554                "psStringSplit failed to return expected strings.");
     555        return 18;
     556    }
     557    psFree(strList);
     558    //Return correct psList when using (psString, psString)
     559    strList = psStringSplit(psStr, psSplit);
     560    if (strList->n != 4) {
     561        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     562                "psStringSplit failed to return the correct number of strings.\n");
     563        return 19;
     564    }
     565    if ( strncmp((psString)(strList->head->data), "This is", 10) ) {
     566        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     567                "psStringSplit failed to return expected strings.");
     568        return 20;
     569    }
     570    if ( strncmp((psString)(strList->head->next->data), " a", 10) ) {
     571        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     572                "psStringSplit failed to return expected strings.");
     573        return 21;
     574    }
     575    if ( strncmp((psString)(strList->head->next->next->data), " test case", 10) ) {
     576        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     577                "psStringSplit failed to return expected strings.");
     578        return 22;
     579    }
     580    if ( strncmp((psString)(strList->head->next->next->next->data), " to check.", 10) ) {
     581        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     582                "psStringSplit failed to return expected strings.");
     583        return 23;
     584    }
     585    psFree(strList);
     586    //Return correct psList output for string of zero length case
     587    strncpy(str, "This is,, a,, test case,, to check.", 35);
     588    strList = psStringSplit(str, split);
     589    if (strList->n != 4) {
     590        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     591                "psStringSplit failed to return the correct number of strings.\n");
     592        return 24;
     593    }
     594    if ( strncmp((psString)(strList->head->data), "This is", 10) ) {
     595        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     596                "psStringSplit failed to return expected strings.");
     597        return 25;
     598    }
     599    if ( strncmp((psString)(strList->head->next->data), " a", 10) ) {
     600        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     601                "psStringSplit failed to return expected strings.");
     602        return 26;
     603    }
     604    if ( strncmp((psString)(strList->head->next->next->data), " test case", 10) ) {
     605        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     606                "psStringSplit failed to return expected strings.");
     607        return 27;
     608    }
     609    if ( strncmp((psString)(strList->head->next->next->next->data), " to check.", 10) ) {
     610        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     611                "psStringSplit failed to return expected strings.");
     612        return 28;
     613    }
     614
     615    psFree(strList);
     616    psFree(psStr);
     617    psFree(psSplit);
     618    return 0;
     619}
     620
  • trunk/psLib/test/sys/verified/tst_psString.stderr

    r4547 r6218  
    125125---> TESTPOINT PASSED (psString{Test prepend null-op} | tst_psString.c)
    126126
     127/***************************** TESTPOINT ******************************************\
     128*             TestFile: tst_psString.c                                             *
     129*            TestPoint: psString{Test String Splitting}                            *
     130*             TestType: Positive                                                   *
     131\**********************************************************************************/
     132
     133<DATE><TIME>|<HOST>|I|testStrSplit00
     134    Following should generate error message
     135<DATE><TIME>|<HOST>|E|psStringSplit (FILE:LINENO)
     136    Unallowable operation: string is NULL.
     137<DATE><TIME>|<HOST>|I|testStrSplit00
     138    Following should generate error message
     139<DATE><TIME>|<HOST>|E|psStringSplit (FILE:LINENO)
     140    Unallowable operation: string is NULL.
     141<DATE><TIME>|<HOST>|I|testStrSplit00
     142    Following should generate error message
     143<DATE><TIME>|<HOST>|E|psStringSplit (FILE:LINENO)
     144    Unallowable operation: splitters is NULL.
     145
     146---> TESTPOINT PASSED (psString{Test String Splitting} | tst_psString.c)
     147
Note: See TracChangeset for help on using the changeset viewer.