Changeset 6
- Timestamp:
- 02/27/2003 00:33:04 (6 years ago)
- Location:
- trunk
- Files:
-
- 5 added
- 1 removed
- 3 modified
-
Makefile.am (added)
-
bootstrap (added)
-
configure.in (added)
-
lib/Makefile.am (added)
-
lib/syck.c (modified) (2 diffs)
-
lib/syck.h (modified) (3 diffs)
-
tests/AllTests.c (deleted)
-
tests/Basic.c (modified) (3 diffs)
-
tests/Makefile.am (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/syck.c
r2 r6 71 71 } 72 72 73 char * 74 read_str_node( struct SyckNode *n ) 75 { 76 //assert( n != NULL ); 77 return n->data.str; 78 } 79 73 80 struct SyckNode * 74 81 new_map_node( struct SyckNode *key, struct SyckNode *value ) … … 100 107 } 101 108 109 struct SyckNode * 110 read_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 127 struct SyckNode * 128 new_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 138 void 139 add_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 154 struct SyckNode * 155 read_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 102 165 //static char * 103 166 //syckp_read( prsr, len ) -
trunk/lib/syck.h
r2 r6 46 46 }; 47 47 48 enum map_part { 49 map_key, 50 map_value 51 }; 52 48 53 struct SyckNode { 54 // Underlying kind 49 55 enum syck_kind_tag kind; 56 // Fully qualified tag-uri for type 57 char *type_id; 50 58 union { 59 // Storage for map data 51 60 struct SyckMap { 52 61 struct SyckNode **keys; … … 54 63 long capa; 55 64 } *pairs; 65 // Storage for sequence data 56 66 struct SyckSeq { 57 struct SyckNode ** values;67 struct SyckNode **items; 58 68 long capa; 59 69 } *list; 70 // Storage for string data 60 71 char *str; 61 72 } data; … … 76 87 // 77 88 struct SyckNode *new_str_node( char *str ); 89 char *read_str_node( struct SyckNode *n ); 78 90 struct SyckNode *new_map_node( struct SyckNode *key, struct SyckNode *value ); 79 91 void add_map_pair( struct SyckNode *map, struct SyckNode *key, struct SyckNode *value ); 92 struct SyckNode *read_map_node( struct SyckNode *map, enum map_part p, long idx ); 93 struct SyckNode *new_seq_node( struct SyckNode *value ); 94 void add_seq_item( struct SyckNode *arr, struct SyckNode *value ); 95 struct SyckNode *read_seq_node( struct SyckNode *seq, long idx ); 80 96 81 97 #if defined(__cplusplus) -
trunk/tests/Basic.c
r2 r6 24 24 CuAssert( tc, "Allocated 'str' node reporting as 'map'.", n->kind != map_kind ); 25 25 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 ) ); 27 27 28 free( n ); 29 } 30 31 // 32 // Test building a simple sequence 33 // 34 void 35 TestSyckSeqAlloc( 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 ); 28 49 free( n ); 29 50 } … … 41 62 n = new_map_node( n1, n2 ); 42 63 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 ) ) ); 44 66 45 67 free( n2 ); … … 53 75 CuSuite *suite = CuSuiteNew(); 54 76 SUITE_ADD_TEST( suite, TestSyckNodeAlloc ); 77 SUITE_ADD_TEST( suite, TestSyckSeqAlloc ); 55 78 SUITE_ADD_TEST( suite, TestSyckMapAlloc ); 56 79 return suite; 57 80 } 81 82 int 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 }