IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 10, 2007, 11:09:31 AM (19 years ago)
Author:
gusciora
Message:

This is a fairly large checkin. Most of the files were modified so they have
the same basic structure and format for testing: reporting errors, checking
memory leaks etc. Several bug fixes are included as well.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/sys/tap_psString.c

    r12607 r12781  
    2020 *  @author  Eric Van Alst, MHPCC
    2121 *
    22  *  @version $Revision: 1.7 $  $Name: not supported by cvs2svn $
    23  *  @date  $Date: 2007-03-27 22:52:03 $
     22 *  @version $Revision: 1.8 $  $Name: not supported by cvs2svn $
     23 *  @date  $Date: 2007-04-10 21:09:31 $
    2424 *
    2525 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3535#define STR_0 "binky had a leeeetle lamb"
    3636
    37 psS32 testStringCopy00(void);
    38 psS32 testStringCopy01(void);
    39 psS32 testStringCopy02(void);
    40 psS32 testStringCopy03(void);
    41 psS32 testStringCopy04(void);
    42 //psS32 testStringCopy05(void);
    43 psS32 testStringCopy06(void);
    44 
    45 psS32 testStrAppend00(void);
    46 psS32 testStrAppend01(void);
    47 psS32 testStrAppend02(void);
    48 psS32 testStrAppend03(void);
    49 
    50 psS32 testStrPrepend00(void);
    51 psS32 testStrPrepend01(void);
    52 psS32 testStrPrepend02(void);
    53 psS32 testStrPrepend03(void);
    54 
    55 psS32 testStrSplit00(void);
    56 psS32 testNULLStrings(void);
    57 psS32 testStrCheck(void);
    58 
    5937
    6038psS32 main( psS32 argc, char* argv[] )
    6139{
    62     plan_tests(55);
    63 
    64     testStringCopy00();
    65     testStringCopy01();
    66     testStringCopy02();
    67     testStringCopy03();
    68     testStringCopy04();
    69     testStringCopy06();
    70 
    71     testStrAppend00();
    72     testStrAppend01();
    73     testStrAppend02();
    74     testStrAppend03();
    75 
    76     testStrPrepend00();
    77     testStrPrepend01();
    78     testStrPrepend02();
    79     testStrPrepend03();
    80 
    81     testStrSplit00();
    82     testNULLStrings();
    83     testStrCheck();
    84 }
    85 
    86 
    87 psS32 testStringCopy00(void)
    88 {
    89 //    diag("testStringCopy00");
    90 
    91     char  stringval[20] = "E R R O R";
    92     psS32   result = 0;
    93     psS32   result1 = 0;
    94     char  *strResult;
    95 
    96     // Test point #1 Verify string copy - psStringCopy
    97     strResult = psStringCopy(stringval);
    98     // Perform string compare
    99     result = strcmp(strResult, stringval);
    100     // Modify original string
    101     stringval[0]='G';
    102     result1 = strcmp(strResult, stringval);
    103     stringval[0]='E';
    104     ok ( ( result == 0 ) && ( result1 != 0),
    105          "Failed test point #1 strcmp result = %d expected 0\n",result);
    106 
    107     // Free memory allocated
    108     psFree(strResult);
    109 
    110     return 0;
    111 }
    112 
    113 
    114 psS32 testStringCopy01(void)
    115 {
    116 //    diag("testStringCopy01");
    117 
    118     char  *emptyval = "";
    119     psS32   result = 0;
    120     char  *strResult;
    121 
    122     // Test point #2 Verify empty string copy - psStringCopy
    123     strResult = psStringCopy(emptyval);
    124     // Perform string compare
    125     result = strcmp(strResult, emptyval);
    126     ok ( result == 0,
    127          "test point #2 strcmp result = %d expected 0\n",result);
    128 
    129     // Free memory allocated
    130     psFree(strResult);
    131 
    132     return 0;
    133 }
    134 
    135 
    136 psS32 testStringCopy02(void)
    137 {
    138 //    diag("testStringCopy02");
    139 
    140     psS32   result = 0;
    141     psS32   result1 = 0;
    142     char  *strResult;
    143     char  stringval1[20] = "e r r o r";
    144     psS32   substringlen = 5;
    145     char  *substringval = "e r r";
    146 
    147     // Test point #3 Verify string copy with length - psStringNCopy
    148     strResult = psStringNCopy(stringval1, substringlen);
    149     // Perform string compare and get string length
    150     result = strncmp(strResult, substringval, substringlen);
    151     // Change original string
    152     stringval1[0] = 'g';
    153     result1 = strncmp(strResult, substringval, substringlen);
    154     ok ( ( result == 0 ) && ( result1 == 0 ),
    155          "Failed test point #3 strcmp result = %d expected 0\n",result);
    156 
    157     // Free memory allocated
    158     psFree(strResult);
    159 
    160     return 0;
    161 }
    162 
    163 psS32 testStringCopy03(void)
    164 {
    165 //    diag("testStringCopy03");
    166 
    167     psS32   result = 0;
    168     psS32   result1 = 0;
    169     char  *strResult;
    170     char  *stringvalnocopy = "F A I L";
    171 
    172     // Test point #4 Verify empty string copy with length - psStringNCopy
    173     strResult = psStringNCopy(stringvalnocopy, 0);
    174     // Perform string compare and get sting length
    175     result = strcmp(strResult, stringvalnocopy);
    176     result1 = strlen(strResult);
    177     ok ( result != 0,
    178          "test point #4 strcmp result = %d didn't expected %d\n",result,0);
    179 
    180     // Free memory
    181     psFree(strResult);
    182 
    183     return 0;
    184 }
    185 
    186 psS32 testStringCopy04(void)
    187 {
    188 //    diag("testStringCopy04");
    189 
    190     psS32   result = 0;
    191     psS32   result1 = 0;
    192     char  *strResult;
    193     char  stringval[20] = "E R R O R";
    194     psS32   increaseSize = 5;
    195 
    196     // Test point #5 Copy string to larger string - psStringNCopy
    197     strResult = psStringNCopy(stringval, (strlen(stringval) + increaseSize));
    198     // Perform string compare and get string length
    199     result = strcmp(strResult, stringval);
    200     result1 = strlen(strResult);
    201     // The strings should still compare
    202     ok ( result == 0 && result1 == strlen(stringval),
    203          "test point #5 strcmp result = %d expected %d\n",result,0);
    204 
    205     // Free memory
    206     psFree(strResult);
    207 
    208     return 0;
    209 }
     40    psLogSetFormat("HLNM");
     41    psLogSetLevel(PS_LOG_INFO);
     42    plan_tests(72);
     43
     44
     45    //testStringCopy00()
     46    {
     47        psMemId id = psMemGetId();
     48        char  stringval[20] = "E R R O R";
     49        psS32   result = 0;
     50        psS32   result1 = 0;
     51        char  *strResult;
     52
     53        // Test point #1 Verify string copy - psStringCopy
     54        strResult = psStringCopy(stringval);
     55        // Perform string compare
     56        result = strcmp(strResult, stringval);
     57        // Modify original string
     58        stringval[0]='G';
     59        result1 = strcmp(strResult, stringval);
     60        stringval[0]='E';
     61        ok(( result == 0 ) && ( result1 != 0),
     62             "Failed test point #1 strcmp result = %d expected 0",result);
     63        // Free memory allocated
     64        psFree(strResult);
     65        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     66    }
     67
     68
     69    // testStringCopy01()
     70    {
     71        psMemId id = psMemGetId();
     72        char  *emptyval = "";
     73        psS32   result = 0;
     74        char  *strResult;
     75
     76        // Test point #2 Verify empty string copy - psStringCopy
     77        strResult = psStringCopy(emptyval);
     78        // Perform string compare
     79        result = strcmp(strResult, emptyval);
     80        ok(result == 0,
     81             "test point #2 strcmp result = %d expected 0",result);
     82        // Free memory allocated
     83        psFree(strResult);
     84        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     85    }
     86
     87
     88    // testStringCopy02()
     89    {
     90        psMemId id = psMemGetId();
     91        psS32   result = 0;
     92        psS32   result1 = 0;
     93        char  *strResult;
     94        char  stringval1[20] = "e r r o r";
     95        psS32   substringlen = 5;
     96        char  *substringval = "e r r";
     97
     98        // Test point #3 Verify string copy with length - psStringNCopy
     99        strResult = psStringNCopy(stringval1, substringlen);
     100        // Perform string compare and get string length
     101        result = strncmp(strResult, substringval, substringlen);
     102        // Change original string
     103        stringval1[0] = 'g';
     104        result1 = strncmp(strResult, substringval, substringlen);
     105        ok(( result == 0 ) && ( result1 == 0 ),
     106             "Failed test point #3 strcmp result = %d expected 0",result);
     107        psFree(strResult);
     108        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     109    }
     110
     111
     112    // testStringCopy03()
     113    {
     114        psMemId id = psMemGetId();
     115        psS32   result = 0;
     116        psS32   result1 = 0;
     117        char  *strResult;
     118        char  *stringvalnocopy = "F A I L";
     119
     120        // Test point #4 Verify empty string copy with length - psStringNCopy
     121        strResult = psStringNCopy(stringvalnocopy, 0);
     122        // Perform string compare and get sting length
     123        result = strcmp(strResult, stringvalnocopy);
     124        result1 = strlen(strResult);
     125        ok(result != 0,
     126             "test point #4 strcmp result = %d didn't expected %d",result,0);
     127        psFree(strResult);
     128        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     129    }
     130
     131
     132    // testStringCopy04()
     133    {
     134        psMemId id = psMemGetId();
     135        psS32   result = 0;
     136        psS32   result1 = 0;
     137        char  *strResult;
     138        char  stringval[20] = "E R R O R";
     139        psS32   increaseSize = 5;
     140
     141        // Test point #5 Copy string to larger string - psStringNCopy
     142        strResult = psStringNCopy(stringval, (strlen(stringval) + increaseSize));
     143        // Perform string compare and get string length
     144        result = strcmp(strResult, stringval);
     145        result1 = strlen(strResult);
     146        // The strings should still compare
     147        ok(result == 0 && result1 == strlen(stringval),
     148             "test point #5 strcmp result = %d expected %d",result,0);
     149        psFree(strResult);
     150        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     151    }
    210152
    211153// XXX This test needs to be modified to check for maximum size
    212154//     This will require a mod to psStringNCopy source to check for maximum size
    213155//
    214 //psS32 testStringCopy05(void)
     156//psS32 testStringCopy05()
    215157//{
    216158//    char  *strResult;
     
    231173
    232174
    233 psS32 testStringCopy06(void)
    234 {
    235 //    diag("testStringCopy06");
    236 
    237     char  *strResult;
    238     char  stringval[20] = "E R R O R";
    239     psS32   result = 0;
    240 
    241     // Test point #7 Verify creation of string literal - PS_STRING
    242     strResult = PS_STRING(E R R O R);
    243     result = strcmp(strResult, stringval);
    244     ok ( result == 0,
    245          "test point #7 strcmp result = %d expected %d",result,0);
    246 
    247     // Memory should not have been allocated
    248     return 0;
     175    // testStringCopy06()
     176    {
     177        psMemId id = psMemGetId();
     178        char  *strResult;
     179        char  stringval[20] = "E R R O R";
     180        psS32   result = 0;
     181
     182        // Test point #7 Verify creation of string literal - PS_STRING
     183        strResult = PS_STRING(E R R O R);
     184        result = strcmp(strResult, stringval);
     185        ok(result == 0,
     186             "test point #7 strcmp result = %d expected %d",result,0);
     187        // Memory should not have been allocated
     188        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     189    }
     190
     191
     192    // testStrAppend00()
     193    {
     194        psMemId id = psMemGetId();
     195        char *str = psStringCopy("3.14159");
     196        psStringAppend(&str, "%d%s", 2653589, "79323846");
     197        // Test point: Verify string append
     198        int result = strcmp(str, "3.14159265358979323846");
     199        ok(result == 0, "Failed test point");
     200        psFree(str);
     201        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     202    }
     203
     204
     205    // testStrAppend01()
     206    {
     207        psMemId id = psMemGetId();
     208        char *str=NULL;
     209        // test nonsensical invocations ...
     210        ssize_t sz = psStringAppend(NULL, NULL);
     211        ok(sz == 0, "Failed test point");
     212        sz = psStringAppend(&str, NULL);
     213        ok(sz == 0, "Failed test point");
     214        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     215    }
     216
     217
     218    // testStrAppend02()
     219    {
     220        psMemId id = psMemGetId();
     221        char *str=NULL;
     222        // test string creation
     223        psStringAppend(&str, "%s", "fubar");
     224        int result = strcmp(str, "fubar");
     225        ok(result == 0, "Failed test point");
     226        psFree(str);
     227        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     228    }
     229
     230
     231    // testStrAppend03()
     232    {
     233        psMemId id = psMemGetId();
     234        char *str =psStringCopy(STR_0);
     235        // test null-op
     236        psStringAppend(&str, "%s", "");
     237        is_str(str, STR_0, "Failed test point");
     238        psFree(str);
     239        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     240    }
     241
     242
     243    // testStrPrepend00()
     244    {
     245        psMemId id = psMemGetId();
     246        char *str = psStringCopy("79323846");
     247        psStringPrepend(&str, "%s%d","3.14159", 2653589 );
     248        // Test point: Verify string append
     249        int result = strcmp(str, "3.14159265358979323846");
     250        ok(result == 0, "Failed test point");
     251        psFree(str);
     252        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     253    }
     254
     255
     256    // testStrPrepend01()
     257    {
     258        psMemId id = psMemGetId();
     259        char *str=NULL;
     260        // test nonsensical invocations ...
     261        ssize_t sz = psStringPrepend(NULL, NULL);
     262        ok(sz == 0, "Failed test point");
     263        sz = psStringPrepend(&str, NULL);
     264        ok(sz == 0, "Failed test point");
     265        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     266    }
     267
     268
     269    // testStrPrepend02()
     270    {
     271        psMemId id = psMemGetId();
     272        char *str=NULL;
     273        // test string creation
     274        psStringPrepend(&str, "%s", "fubar");
     275        int result = strcmp(str, "fubar");
     276        ok(result == 0, "Failed test point");
     277        psFree(str);
     278        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     279    }
     280
     281
     282    // testStrPrepend03()
     283    {
     284        // test null-op
     285        psMemId id = psMemGetId();
     286        char *str =  psStringCopy(STR_0);
     287        psStringPrepend(&str, "%s", "");
     288        int result = strcmp(str, STR_0);
     289        ok(result == 0, "test point str=[%s]", str);
     290        psFree(str);
     291        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     292    }
     293
     294
     295    // testStrSplit00()
     296    {
     297        psMemId id = psMemGetId();
     298        psList *strList = NULL;
     299        char str[35];
     300        char split[5];
     301        strncpy(str, "This is, a, test case, to check", 35);
     302        strncpy(split, ",", 2);
     303        psString psStr;
     304        psString psSplit;
     305        psStr = psStringCopy(str);
     306        psSplit = psStringCopy(split);
     307
     308        //Return NULL for NULL inputs
     309        strList = psStringSplit(NULL, NULL, true);
     310        ok(!strList, "psStringSplit" );
     311        psFree(strList);
     312
     313        strList = NULL;
     314        //Return empty list for NULL string input
     315        strList = psStringSplit(NULL, split, true);
     316        ok(!psListLength(strList), "psListLength()" );
     317        psFree(strList);
     318
     319        strList = NULL;
     320        //Return NULL for NULL splitter input
     321        strList = psStringSplit(str, NULL, true);
     322        ok(!strList, "psStringSplit" );
     323        psFree(strList);
     324
     325        strList = NULL;
     326        //Return a psList* of psStrings
     327        strList = psStringSplit(str, split, true);
     328        ok(strList->n == 4,
     329            "psStringSplit to return the correct number of strings");
     330        ok(!strncmp((psString)(strList->head->data), "This is", 10),
     331             "psStringSplit to return expected strings");
     332        ok(!strncmp((psString)(strList->head->next->data), " a", 10),
     333             "psStringSplit to return expected strings");
     334        ok(!strncmp((psString)(strList->head->next->next->data), " test case",10),
     335             "psStringSplit to return expected strings");
     336        ok(!strncmp((psString)(strList->head->next->next->next->data), " to check", 10),
     337             "psStringSplit failed to return expected strings");
     338
     339        psFree(strList);
     340        //Return correct psList when using (psString, char*)
     341        strList = psStringSplit(psStr, split, true);
     342        ok(strList->n == 4,
     343            "psStringSplit to return the correct number of strings");
     344        ok(!strncmp((psString)(strList->head->data), "This is", 10),
     345             "psStringSplit to return expected strings");
     346        ok(!strncmp((psString)(strList->head->next->data), " a", 10),
     347             "psStringSplit failed to return expected strings");
     348        ok(!strncmp((psString)(strList->head->next->next->data), " test case",10),
     349             "psStringSplit failed to return expected strings");
     350        ok(!strncmp((psString)(strList->head->next->next->next->data), " to check", 10),
     351             "psStringSplit to return expected strings");
     352
     353        psFree(strList);
     354        //Return correct psList when using (char*, psString)
     355        strList = psStringSplit(str, psSplit, true);
     356        ok(strList->n == 4,
     357            "psStringSplit to return the correct number of strings");
     358        ok(!strncmp((psString)(strList->head->data), "This is", 10),
     359             "psStringSplit to return expected strings");
     360        ok(!strncmp((psString)(strList->head->next->data), " a", 10),
     361             "psStringSplit to return expected strings");
     362        ok(!strncmp((psString)(strList->head->next->next->data), " test case",10),
     363             "psStringSplit to return expected strings");
     364        ok(!strncmp((psString)(strList->head->next->next->next->data), " to check", 10),
     365             "psStringSplit to return expected strings");
     366
     367        psFree(strList);
     368        //Return correct psList when using (psString, psString)
     369        strList = psStringSplit(psStr, psSplit, true);
     370        ok(strList->n == 4,
     371            "psStringSplit to return the correct number of strings");
     372        ok(!strncmp((psString)(strList->head->data), "This is", 10),
     373             "psStringSplit to return expected strings");
     374        ok(!strncmp((psString)(strList->head->next->data), " a", 10),
     375             "psStringSplit to return expected strings");
     376        ok(!strncmp((psString)(strList->head->next->next->data), " test case",10),
     377             "psStringSplit  to return expected strings");
     378        ok(!strncmp((psString)(strList->head->next->next->next->data), " to check", 10),
     379             "psStringSplit to return expected strings");
     380   
     381        psFree(strList);
     382        //Return correct psList output for string of zero length case
     383        strncpy(str, "This is,, a,, test case,, to check", 35);
     384        strList = psStringSplit(str, split, false);
     385        ok(strList->n == 4,
     386            "psStringSplit to return the correct number of strings");
     387        ok(!strncmp((psString)(strList->head->data), "This is", 10),
     388             "psStringSplit to return expected strings");
     389        ok(!strncmp((psString)(strList->head->next->data), " a", 10),
     390             "psStringSplit to return expected strings");
     391        ok(!strncmp((psString)(strList->head->next->next->data), " test case",10),
     392             "psStringSplit to return expected strings");
     393        ok(!strncmp((psString)(strList->head->next->next->next->data), " to check", 10),
     394             "psStringSplit to return expected strings");
     395        psFree(strList);
     396        psFree(psStr);
     397        psFree(psSplit);
     398        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     399    }
     400
     401
     402    // testNULLStrings()
     403    {
     404        psMemId id = psMemGetId();
     405        psString nullTest = NULL;
     406        psString output = NULL;
     407        ssize_t outSize = 0;
     408        char** nullDest = NULL;
     409        char** test = NULL;
     410        //psStringCopy should return NULL for NULL input string
     411        //    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message");
     412        output = psStringCopy(nullTest);
     413        ok(output == NULL, "psStringCopy to return NULL for NULL input string");
     414   
     415        //psStringNCopy should return NULL for NULL input string
     416        output = psStringNCopy(nullTest, 100);
     417        ok(output == NULL, "psStringNCopy to return NULL for NULL input string");
     418   
     419        //psStringAppend should return 0 for NULL input destination
     420        outSize = psStringAppend(nullDest, "%s", "");
     421        ok(outSize == 0, "psStringAppend to return 0 for NULL input destination");
     422   
     423        //psStringAppend should return 0 for NULL input format
     424        outSize = psStringAppend(test, nullTest);
     425        ok(outSize == 0, "psStringAppend to return 0 for NULL input format");
     426   
     427        //psStringPrepend should return 0 for NULL input destination
     428        outSize = psStringPrepend(nullDest, " ");
     429        ok(outSize == 0, "psStringPrepend to return 0 for NULL input destination");
     430   
     431        //psStringPrepend should return 0 for NULL input format
     432        outSize = psStringPrepend(test, nullTest);
     433        ok(outSize == 0, "psStringPrepend to return 0 for NULL input format");
     434   
     435        //psStringSplit should return empty list for NULL input string
     436        psList *nullList = NULL;
     437        nullList = psStringSplit(nullTest, ",", true);
     438        ok(!psListLength(nullList), "psStringSplit to return NULL for NULL input string");
     439        psFree(nullList);
     440   
     441        nullList = NULL;
     442        //psStringSplit should return NULL for NULL input splitter
     443        nullList = psStringSplit("Hello World", nullTest, true);
     444        ok(!nullList, "psStringSplit to return NULL for NULL input splitter");
     445        psFree(nullList);
     446        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     447    }
     448
     449
     450    // testStrCheck()
     451    {
     452        psMemId id = psMemGetId();
     453        psString str = psStringAlloc(10);
     454        strcpy(str, "Hello");
     455        ok(psMemCheckString(str), "psString allocated!");
     456        ok(psMemCheckType(PS_DATA_STRING, str), "psString allocated");
     457        psFree(str);
     458   
     459        char charStr[10];
     460        ok(!psMemCheckType(PS_DATA_STRING, charStr),
     461            "Input string is a psDataType");
     462        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     463    }
    249464}
    250 
    251 
    252 psS32 testStrAppend00(void)
    253 {
    254 //    diag("testStrAppend00");
    255 
    256     char *str=NULL;
    257     int result = 0;
    258 
    259     str = psStringCopy("3.14159");
    260 
    261     psStringAppend(&str, "%d%s", 2653589, "79323846");
    262 
    263     // Test point: Verify string append
    264     result = strcmp(str, "3.14159265358979323846");
    265     ok ( result == 0, "Failed test point\n");
    266 
    267     psFree(str);
    268 
    269     return 0;
    270 }
    271 
    272 psS32 testStrAppend01(void)
    273 {
    274 //    diag("testStrAppend01");
    275 
    276     ssize_t sz;
    277     char *str=NULL;
    278 
    279     // test nonsensical invocations ...
    280     sz = psStringAppend(NULL, NULL);
    281     ok ( sz == 0, "Failed test point\n");
    282 
    283     sz = psStringAppend(&str, NULL);
    284     ok ( sz == 0, "Failed test point\n");
    285 
    286     return 0;
    287 }
    288 
    289 
    290 psS32 testStrAppend02(void)
    291 {
    292 //    diag("testStrAppend02");
    293 
    294     char *str=NULL;
    295     int result;
    296 
    297     // test string creation
    298     psStringAppend(&str, "%s", "fubar");
    299     result = strcmp(str, "fubar");
    300     ok ( result == 0, "Failed test point\n");
    301 
    302     psFree(str);
    303 
    304     return 0;
    305 }
    306 
    307 psS32 testStrAppend03(void)
    308 {
    309 //    diag("testStrAppend03");
    310 
    311     char *str =psStringCopy(STR_0);
    312 
    313     // test null-op
    314     psStringAppend(&str, "%s", "");
    315     is_str(str, STR_0, "Failed test point");
    316     psFree(str);
    317 
    318     return 0;
    319 }
    320 
    321 
    322 psS32 testStrPrepend00(void)
    323 {
    324 //    diag("testStrPrepend00");
    325 
    326     char *str=NULL;
    327     int result = 0;
    328 
    329     str = psStringCopy("79323846");
    330 
    331     psStringPrepend(&str, "%s%d","3.14159", 2653589 );
    332 
    333     // Test point: Verify string append
    334     result = strcmp(str, "3.14159265358979323846");
    335     ok ( result == 0, "Failed test point\n");
    336 
    337     psFree(str);
    338 
    339     return 0;
    340 }
    341 
    342 
    343 psS32 testStrPrepend01(void)
    344 {
    345 //    diag("testStrPrepend01");
    346 
    347     ssize_t sz;
    348     char *str=NULL;
    349 
    350     // test nonsensical invocations ...
    351     sz = psStringPrepend(NULL, NULL);
    352     ok ( sz == 0, "Failed test point\n");
    353 
    354     sz = psStringPrepend(&str, NULL);
    355     ok ( sz == 0, "Failed test point\n");
    356 
    357     return 0;
    358 }
    359 
    360 psS32 testStrPrepend02(void)
    361 {
    362 //    diag("testStrPrepend02");
    363 
    364     char *str=NULL;
    365     int result;
    366 
    367     // test string creation
    368     psStringPrepend(&str, "%s", "fubar");
    369     result = strcmp(str, "fubar");
    370     ok ( result == 0, "Failed test point\n");
    371 
    372     psFree(str);
    373 
    374     return 0;
    375 }
    376 
    377 psS32 testStrPrepend03(void)
    378 {
    379 //    diag("testStrPrepend03");
    380 
    381     char *str=NULL;
    382     int result;
    383 
    384     str = psStringCopy(STR_0);
    385 
    386     // test null-op
    387     psStringPrepend(&str, "%s", "");
    388     result = strcmp(str, STR_0);
    389     ok ( result == 0, "test point str=[%s]\n", str);
    390 
    391     psFree(str);
    392 
    393     return 0;
    394 }
    395 
    396 
    397 psS32 testStrSplit00(void)
    398 {
    399 //    diag("testStrSplit00");
    400 
    401     psList *strList = NULL;
    402     char str[35];
    403     char split[5];
    404     strncpy(str, "This is, a, test case, to check.", 35);
    405     strncpy(split, ",", 2);
    406     psString psStr;
    407     psString psSplit;
    408     psStr = psStringCopy(str);
    409     psSplit = psStringCopy(split);
    410 
    411     //Return NULL for NULL inputs
    412     strList = psStringSplit(NULL, NULL, true);
    413     ok (!strList, "psStringSplit" );
    414     psFree(strList);
    415 
    416     strList = NULL;
    417     //Return empty list for NULL string input
    418     strList = psStringSplit(NULL, split, true);
    419     ok ( !psListLength(strList), "psListLength()" );
    420     psFree(strList);
    421 
    422     strList = NULL;
    423     //Return NULL for NULL splitter input
    424     strList = psStringSplit(str, NULL, true);
    425     ok ( !strList, "psStringSplit" );
    426     psFree(strList);
    427 
    428     strList = NULL;
    429     //Return a psList* of psStrings
    430     strList = psStringSplit(str, split, true);
    431     ok (strList->n == 4,
    432         "psStringSplit to return the correct number of strings.\n");
    433 
    434     ok ( !strncmp((psString)(strList->head->data), "This is", 10),
    435          "psStringSplit to return expected strings.");
    436 
    437     ok ( !strncmp((psString)(strList->head->next->data), " a", 10),
    438          "psStringSplit to return expected strings.");
    439 
    440     ok ( !strncmp((psString)(strList->head->next->next->data), " test case",10),
    441          "psStringSplit to return expected strings.");
    442 
    443     ok ( !strncmp((psString)(strList->head->next->next->next->data), " to check.", 10),
    444          "psStringSplit failed to return expected strings.");
    445 
    446     psFree(strList);
    447     //Return correct psList when using (psString, char*)
    448     strList = psStringSplit(psStr, split, true);
    449     ok (strList->n == 4,
    450         "psStringSplit to return the correct number of strings.\n");
    451 
    452     ok ( !strncmp((psString)(strList->head->data), "This is", 10),
    453          "psStringSplit to return expected strings.");
    454 
    455     ok ( !strncmp((psString)(strList->head->next->data), " a", 10),
    456          "psStringSplit failed to return expected strings.");
    457 
    458     ok ( !strncmp((psString)(strList->head->next->next->data), " test case",10),
    459          "psStringSplit failed to return expected strings.");
    460 
    461     ok ( !strncmp((psString)(strList->head->next->next->next->data), " to check.", 10),
    462          "psStringSplit to return expected strings.");
    463 
    464     psFree(strList);
    465     //Return correct psList when using (char*, psString)
    466     strList = psStringSplit(str, psSplit, true);
    467     ok (strList->n == 4,
    468         "psStringSplit to return the correct number of strings.\n");
    469 
    470     ok ( !strncmp((psString)(strList->head->data), "This is", 10),
    471          "psStringSplit to return expected strings.");
    472 
    473     ok ( !strncmp((psString)(strList->head->next->data), " a", 10),
    474          "psStringSplit to return expected strings.");
    475 
    476     ok ( !strncmp((psString)(strList->head->next->next->data), " test case",10),
    477          "psStringSplit to return expected strings.");
    478 
    479     ok ( !strncmp((psString)(strList->head->next->next->next->data), " to check.", 10),
    480          "psStringSplit to return expected strings.");
    481 
    482     psFree(strList);
    483     //Return correct psList when using (psString, psString)
    484     strList = psStringSplit(psStr, psSplit, true);
    485     ok (strList->n == 4,
    486         "psStringSplit to return the correct number of strings.\n");
    487 
    488     ok ( !strncmp((psString)(strList->head->data), "This is", 10),
    489          "psStringSplit to return expected strings.");
    490 
    491     ok ( !strncmp((psString)(strList->head->next->data), " a", 10),
    492          "psStringSplit to return expected strings.");
    493 
    494     ok ( !strncmp((psString)(strList->head->next->next->data), " test case",10),
    495          "psStringSplit  to return expected strings.");
    496 
    497     ok ( !strncmp((psString)(strList->head->next->next->next->data), " to check.", 10),
    498          "psStringSplit to return expected strings.");
    499 
    500     psFree(strList);
    501     //Return correct psList output for string of zero length case
    502     strncpy(str, "This is,, a,, test case,, to check.", 35);
    503     strList = psStringSplit(str, split, false);
    504     ok (strList->n == 4,
    505         "psStringSplit to return the correct number of strings.\n");
    506 
    507     ok ( !strncmp((psString)(strList->head->data), "This is", 10),
    508          "psStringSplit to return expected strings.");
    509 
    510     ok ( !strncmp((psString)(strList->head->next->data), " a", 10),
    511          "psStringSplit to return expected strings.");
    512 
    513     ok ( !strncmp((psString)(strList->head->next->next->data), " test case",10),
    514          "psStringSplit to return expected strings.");
    515 
    516     ok ( !strncmp((psString)(strList->head->next->next->next->data), " to check.", 10),
    517          "psStringSplit to return expected strings.");
    518 
    519     psFree(strList);
    520     psFree(psStr);
    521     psFree(psSplit);
    522     return 0;
    523 }
    524 
    525 psS32 testNULLStrings(void)
    526 {
    527 //    diag("test""s");
    528 
    529     psString nullTest = NULL;
    530     psString output = NULL;
    531     ssize_t outSize = 0;
    532     char** nullDest = NULL;
    533     char** test = NULL;
    534     //psStringCopy should return NULL for NULL input string
    535     //    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message");
    536     output = psStringCopy(nullTest);
    537     ok (output == NULL,
    538         "psStringCopy to return NULL for NULL input string.\n");
    539 
    540     //psStringNCopy should return NULL for NULL input string
    541     output = psStringNCopy(nullTest, 100);
    542     ok (output == NULL,
    543         "psStringNCopy to return NULL for NULL input string.\n");
    544 
    545     //psStringAppend should return 0 for NULL input destination
    546     outSize = psStringAppend(nullDest, "%s", "");
    547     ok (outSize == 0,
    548         "psStringAppend to return 0 for NULL input destination.\n");
    549 
    550     //psStringAppend should return 0 for NULL input format
    551     outSize = psStringAppend(test, nullTest);
    552     ok (outSize == 0,
    553         "psStringAppend to return 0 for NULL input format.\n");
    554 
    555     //psStringPrepend should return 0 for NULL input destination
    556     outSize = psStringPrepend(nullDest, " ");
    557     ok (outSize == 0,
    558         "psStringPrepend to return 0 for NULL input destination.\n");
    559 
    560     //psStringPrepend should return 0 for NULL input format
    561     outSize = psStringPrepend(test, nullTest);
    562     ok (outSize == 0,
    563         "psStringPrepend to return 0 for NULL input format.\n");
    564 
    565     //psStringSplit should return empty list for NULL input string
    566     psList *nullList = NULL;
    567     nullList = psStringSplit(nullTest, ",", true);
    568     ok ( !psListLength(nullList),
    569          "psStringSplit to return NULL for NULL input string.\n");
    570     psFree(nullList);
    571 
    572     nullList = NULL;
    573     //psStringSplit should return NULL for NULL input splitter
    574     nullList = psStringSplit("Hello World", nullTest, true);
    575     ok ( !nullList,
    576          "psStringSplit to return NULL for NULL input splitter.\n");
    577     psFree(nullList);
    578 
    579     return 0;
    580 }
    581 
    582 psS32 testStrCheck(void)
    583 {
    584 //    diag("testStrCheck");
    585 
    586     psString str = NULL;
    587     str = psStringAlloc(10);
    588     strcpy(str, "Hello");
    589     ok (psMemCheckString(str), "psString allocated!\n");
    590 
    591     ok (psMemCheckType(PS_DATA_STRING, str), "psString allocated!\n");
    592     psFree(str);
    593 
    594     char charStr[10];
    595     ok (!psMemCheckType(PS_DATA_STRING, charStr),
    596         "Input string is a psDataType");
    597 
    598     return 0;
    599 }
     465// HERE
Note: See TracChangeset for help on using the changeset viewer.