Changeset 6

Show
Ignore:
Timestamp:
02/27/2003 00:33:04 (6 years ago)
Author:
whythluckystiff
Message:

Build, test environment improved.

Location:
trunk
Files:
5 added
1 removed
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/syck.c

    r2 r6  
    7171} 
    7272 
     73char * 
     74read_str_node( struct SyckNode *n ) 
     75{ 
     76    //assert( n != NULL ); 
     77    return n->data.str; 
     78} 
     79 
    7380struct SyckNode * 
    7481new_map_node( struct SyckNode *key, struct SyckNode *value ) 
     
    100107} 
    101108 
     109struct SyckNode * 
     110read_map_node( struct SyckNode *map, enum map_part p, long idx ) 
     111{ 
     112    struct SyckMap *m; 
     113 
     114    //assert( map != NULL ); 
     115    m = map->data.pairs; 
     116    //assert( m != NULL ); 
     117    if ( p == map_key ) 
     118    { 
     119        return m->keys[idx]; 
     120    } 
     121    else 
     122    { 
     123        return m->values[idx]; 
     124    } 
     125} 
     126 
     127struct SyckNode * 
     128new_seq_node( struct SyckNode *value ) 
     129{ 
     130    struct SyckNode *n; 
     131 
     132    n = alloc_seq_node(); 
     133    add_seq_item( n, value ); 
     134 
     135    return n; 
     136} 
     137 
     138void 
     139add_seq_item( struct SyckNode *arr, struct SyckNode *value ) 
     140{ 
     141    struct SyckSeq *s; 
     142    long idx; 
     143 
     144    //assert( arr != NULL ); 
     145    //assert( arr->data.list != NULL ); 
     146     
     147    s = arr->data.list; 
     148    idx = s->capa; 
     149    s->capa += 1; 
     150    REALLOC_N( s->items, struct SyckNode *, s->capa ); 
     151    s->items[idx] = value; 
     152} 
     153 
     154struct SyckNode * 
     155read_seq_node( struct SyckNode *seq, long idx ) 
     156{ 
     157    struct SyckSeq *s; 
     158 
     159    //assert( seq != NULL ); 
     160    s = seq->data.list; 
     161    //assert( s != NULL ); 
     162    return s->items[idx]; 
     163} 
     164 
    102165//static char * 
    103166//syckp_read( prsr, len ) 
  • trunk/lib/syck.h

    r2 r6  
    4646}; 
    4747 
     48enum map_part { 
     49    map_key, 
     50    map_value 
     51}; 
     52 
    4853struct SyckNode { 
     54    // Underlying kind 
    4955    enum syck_kind_tag kind; 
     56    // Fully qualified tag-uri for type 
     57    char *type_id; 
    5058    union { 
     59        // Storage for map data 
    5160        struct SyckMap { 
    5261            struct SyckNode **keys; 
     
    5463            long capa; 
    5564        } *pairs; 
     65        // Storage for sequence data 
    5666        struct SyckSeq { 
    57             struct SyckNode **values; 
     67            struct SyckNode **items; 
    5868            long capa; 
    5969        } *list; 
     70        // Storage for string data 
    6071        char *str; 
    6172    } data; 
     
    7687// 
    7788struct SyckNode *new_str_node( char *str ); 
     89char *read_str_node( struct SyckNode *n ); 
    7890struct SyckNode *new_map_node( struct SyckNode *key, struct SyckNode *value ); 
    7991void add_map_pair( struct SyckNode *map, struct SyckNode *key, struct SyckNode *value ); 
     92struct SyckNode *read_map_node( struct SyckNode *map, enum map_part p, long idx ); 
     93struct SyckNode *new_seq_node( struct SyckNode *value ); 
     94void add_seq_item( struct SyckNode *arr, struct SyckNode *value ); 
     95struct SyckNode *read_seq_node( struct SyckNode *seq, long idx ); 
    8096 
    8197#if defined(__cplusplus) 
  • trunk/tests/Basic.c

    r2 r6  
    2424    CuAssert( tc, "Allocated 'str' node reporting as 'map'.", n->kind != map_kind ); 
    2525    CuAssert( tc, "Allocated 'str' not reporting as 'str'.", n->kind == str_kind ); 
    26     CuAssertStrEquals( tc, "YAML", n->data.str ); 
     26    CuAssertStrEquals( tc, "YAML", read_str_node( n ) ); 
    2727 
     28    free( n ); 
     29} 
     30 
     31// 
     32// Test building a simple sequence 
     33// 
     34void 
     35TestSyckSeqAlloc( CuTest *tc ) 
     36{ 
     37    struct SyckNode *n, *n1, *n2; 
     38 
     39    n1 = new_str_node( "ONE" ); 
     40    n2 = new_str_node( "TWO" ); 
     41    n = new_seq_node( n1 ); 
     42    add_seq_item( n, n2 ); 
     43 
     44    CuAssertStrEquals( tc, "ONE", read_str_node( read_seq_node( n, 0 ) ) ); 
     45    CuAssertStrEquals( tc, "TWO", read_str_node( read_seq_node( n, 1 ) ) ); 
     46 
     47    free( n2 ); 
     48    free( n1 ); 
    2849    free( n ); 
    2950} 
     
    4162    n = new_map_node( n1, n2 ); 
    4263 
    43     CuAssertStrEquals( tc, "VALUE", n->data.pairs->values[0]->data.str ); 
     64    CuAssertStrEquals( tc, "VALUE", read_str_node( read_map_node( n, map_value, 0 ) ) ); 
     65    CuAssertStrEquals( tc, "KEY", read_str_node( read_map_node( n, map_key, 0 ) ) ); 
    4466 
    4567    free( n2 ); 
     
    5375    CuSuite *suite = CuSuiteNew(); 
    5476    SUITE_ADD_TEST( suite, TestSyckNodeAlloc ); 
     77    SUITE_ADD_TEST( suite, TestSyckSeqAlloc ); 
    5578    SUITE_ADD_TEST( suite, TestSyckMapAlloc ); 
    5679    return suite; 
    5780} 
     81 
     82int main(void) 
     83{ 
     84        CuString *output = CuStringNew(); 
     85        CuSuite* suite = CuSuiteNew(); 
     86         
     87        CuSuiteAddSuite(suite, SyckGetSuite()); 
     88 
     89        CuSuiteRun(suite); 
     90        CuSuiteSummary(suite, output); 
     91        CuSuiteDetails(suite, output); 
     92        printf("%s\n", output->buffer); 
     93    return suite->failCount; 
     94}