IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 19, 2005, 3:40:40 PM (21 years ago)
Author:
asc
Message:

added append/prepend tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/sysUtils/tst_psString.c

    r3994 r3996  
    11/** @file  tst_psString.c
     2 *
     3 * -*- mode: C; c-basic-indent: 4; tab-width: 8; indent-tabs-mode: nil -*-
     4 * vim: set cindent ts=8 sw=4 expandtab:
    25 *
    36 *  @brief Test driver for psString functions
     
    1720 *  @author  Eric Van Alst, MHPCC
    1821 *
    19  *  @version $Revision: 1.14 $  $Name: not supported by cvs2svn $
    20  *  @date  $Date: 2005-05-20 00:44:55 $
     22 *  @version $Revision: 1.15 $  $Name: not supported by cvs2svn $
     23 *  @date  $Date: 2005-05-20 01:40:40 $
    2124 *
    2225 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2730#include "pslib_strict.h"
    2831#include "psTest.h"
     32
     33#define STR_0 "binky had a leeeetle lamb"
    2934
    3035static psS32 testStringCopy00(void);
     
    3540static psS32 testStringCopy05(void);
    3641static psS32 testStringCopy06(void);
     42
     43static psS32 testStrAppend00(void);
     44static psS32 testStrAppend01(void);
     45static psS32 testStrAppend02(void);
     46static psS32 testStrAppend03(void);
     47
     48static psS32 testStrPrepend00(void);
     49static psS32 testStrPrepend01(void);
     50static psS32 testStrPrepend02(void);
     51static psS32 testStrPrepend03(void);
    3752
    3853testDescription tests[] = {
     
    4459                              {testStringCopy05, 5, "Copy string with negative size", 0, false},
    4560                              {testStringCopy06, 6, "Verify creation of string literal", 0, false},
     61
     62                              {testStrAppend00,  7, "Verify generic string append", 0, false},
     63                              {testStrAppend01,  8, "Test append NULL handling", 0, false},
     64                              {testStrAppend02,  9, "Verify append string creation", 0, false},
     65                              {testStrAppend03, 10, "Test append null-op", 0, false},
     66
     67                              {testStrPrepend00,11, "Verify generic string prepend", 0, false},
     68                              {testStrPrepend01,12, "Test prepend NULL handling", 0, false},
     69                              {testStrPrepend02,13, "Verify prepend string creation", 0, false},
     70                              {testStrPrepend03,14, "Test prepend null-op", 0, false},
    4671                              {NULL}
    4772                          };
     
    249274    return 0;
    250275}
     276
     277static psS32 testStrAppend00(void)
     278{
     279    char *str=NULL;
     280    int result = 0;
     281
     282    str = psStringCopy("3.14159");
     283
     284    psStringAppend(&str, "%d%s", 2653589, "79323846");
     285
     286    // Test point: Verify string append
     287    result = strcmp(str, "3.14159265358979323846");
     288    if ( result != 0 ) {
     289        fprintf(stderr,"%s","Failed test point\n");
     290        return 1;
     291    }
     292
     293    psFree(str);
     294
     295    return 0;
     296}
     297
     298static psS32 testStrAppend01(void)
     299{
     300    ssize_t sz;
     301    char *str=NULL;
     302
     303    // test nonsensical invocations ...
     304    sz = psStringAppend(NULL, NULL);
     305    if ( sz != 0 ) {
     306        fprintf(stderr,"%s","Failed test point\n");
     307        return 1;
     308    }
     309    sz = psStringAppend(&str, NULL);
     310    if ( sz != 0 ) {
     311        fprintf(stderr,"%s","Failed test point\n");
     312        return 1;
     313    }
     314
     315    return 0;
     316}
     317
     318static psS32 testStrAppend02(void)
     319{
     320    char *str=NULL;
     321    int result;
     322
     323    // test string creation
     324    psStringAppend(&str, "%s", "fubar");
     325    result = strcmp(str, "fubar");
     326    if ( result != 0 ) {
     327        fprintf(stderr,"%s","Failed test point\n");
     328        return 1;
     329    }
     330
     331    psFree(str);
     332
     333    return 0;
     334}
     335
     336static psS32 testStrAppend03(void)
     337{
     338    char *str=NULL;
     339    int result;
     340
     341    str = psStringCopy(STR_0);
     342
     343    // test null-op
     344    psStringAppend(&str, "");
     345    result = strcmp(str, STR_0);
     346    if ( result != 0 ) {
     347        fprintf(stderr,"Failed test point str=[%s]\n", str);
     348        return 1;
     349    }
     350
     351    psFree(str);
     352
     353    return 0;
     354}
     355
     356static psS32 testStrPrepend00(void)
     357{
     358    char *str=NULL;
     359    int result = 0;
     360
     361    str = psStringCopy("79323846");
     362
     363    psStringPrepend(&str, "%s%d","3.14159", 2653589 );
     364
     365    // Test point: Verify string append
     366    result = strcmp(str, "3.14159265358979323846");
     367    if ( result != 0 ) {
     368        fprintf(stderr,"%s","Failed test point\n");
     369        return 1;
     370    }
     371
     372    psFree(str);
     373
     374    return 0;
     375}
     376
     377static psS32 testStrPrepend01(void)
     378{
     379    ssize_t sz;
     380    char *str=NULL;
     381
     382    // test nonsensical invocations ...
     383    sz = psStringPrepend(NULL, NULL);
     384    if ( sz != 0 ) {
     385        fprintf(stderr,"%s","Failed test point\n");
     386        return 1;
     387    }
     388    sz = psStringPrepend(&str, NULL);
     389    if ( sz != 0 ) {
     390        fprintf(stderr,"%s","Failed test point\n");
     391        return 1;
     392    }
     393
     394    return 0;
     395}
     396
     397static psS32 testStrPrepend02(void)
     398{
     399    char *str=NULL;
     400    int result;
     401
     402    // test string creation
     403    psStringPrepend(&str, "%s", "fubar");
     404    result = strcmp(str, "fubar");
     405    if ( result != 0 ) {
     406        fprintf(stderr,"%s","Failed test point\n");
     407        return 1;
     408    }
     409
     410    psFree(str);
     411
     412    return 0;
     413}
     414
     415static psS32 testStrPrepend03(void)
     416{
     417    char *str=NULL;
     418    int result;
     419
     420    str = psStringCopy(STR_0);
     421
     422    // test null-op
     423    psStringPrepend(&str, "");
     424    result = strcmp(str, STR_0);
     425    if ( result != 0 ) {
     426        fprintf(stderr,"Failed test point str=[%s]\n", str);
     427        return 1;
     428    }
     429
     430    psFree(str);
     431
     432    return 0;
     433}
Note: See TracChangeset for help on using the changeset viewer.