Ignore:
Timestamp:
03/28/08 22:32:22 (4 years ago)
Author:
wd
Message:

Interrim update for superstring bits.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/superstring/source/test.c

    r812 r815  
    2929void test_anonymous(void); 
    3030void test_compare(void); 
     31void test_setchar(void); 
     32void test_append(void); 
    3133 
    3234#define TEST_INIT_VALUE "Hello, world!" 
     
    156158} 
    157159 
     160void test_setchar(void) { 
     161    superstring str = ss_create(TEST_INIT_VALUE); 
     162 
     163    tassert(ss_char(str, 0) == TEST_INIT_VALUE[0]); 
     164    tassert(ss_setchar(str, 0, 'y') == SS_ERROR_SUCCESS); 
     165    tassert(ss_char(str, 0) == 'y'); 
     166    tassert(ss_char(str, 0) != TEST_INIT_VALUE[0]); 
     167 
     168    tassert(ss_setchar(str, 1024, '!') == SS_ERROR_INVALID_PARAMETER); 
     169} 
     170 
     171void test_append(void) { 
     172    superstring str = ss_create("abc"); 
     173    superstring str2 = ss_create("123"); 
     174 
     175    tassert(ss_append(&str, NULL) == SS_ERROR_INVALID_PARAMETER); 
     176    tassert(ss_append(&str, str2) == SS_ERROR_SUCCESS); 
     177    tassert(ss_compare_cs(str, "abc123") == 0); 
     178    ss_destroy(&str); 
     179    ss_destroy(&str2); 
     180 
     181    /* test an allocation which forces growth */ 
     182    size_t len; 
     183    str = ss_create("abc"); 
     184    len = ss_length(str); 
     185    for (int i = 0;i < 100;i++) { 
     186        tassert(ss_append_cs(&str, "123") == SS_ERROR_SUCCESS); 
     187        len += 3; /* length should grow by 3 .. */ 
     188    } 
     189    tassert(ss_length(str) == len); 
     190 
     191    ss_destroy(&str); 
     192} 
     193 
    158194int main(void) { 
    159195 
     
    162198    runtest(anonymous); 
    163199    runtest(compare); 
     200    runtest(setchar); 
     201    runtest(append); 
    164202 
    165203    /* If we made it here we are at the end!  Let them know we succeeded. */ 
Note: See TracChangeset for help on using the changeset viewer.