| 188 | |
| 189 | #ifndef NDEBUG |
| 190 | void string_unit_test() |
| 191 | { |
| 192 | { |
| 193 | string s[ 1 ]; |
| 194 | unsigned long i; |
| 195 | unsigned long const limit = sizeof( s->opt ) * 2 + 2; |
| 196 | string_new( s ); |
| 197 | assert( s->value == s->opt ); |
| 198 | for ( i = 0; i < limit; ++i ) |
| 199 | { |
| 200 | string_push_back( s, (char)( i + 1 ) ); |
| 201 | assert( s->size == int32_t(i + 1) ); |
| 202 | } |
| 203 | assert( s->size == int32_t(limit) ); |
| 204 | assert( s->value != s->opt ); |
| 205 | for ( i = 0; i < limit; ++i ) |
| 206 | assert( s->value[ i ] == (char)( i + 1 ) ); |
| 207 | string_free( s ); |
| 208 | } |
| 209 | |
| 210 | { |
| 211 | const char * const original = " \n\t\v Foo \r\n\v \tBar\n\n\r\r\t\n\v\t \t"; |
| 212 | string copy[ 1 ]; |
| 213 | string_copy( copy, original ); |
| 214 | assert( !strcmp( copy->value, original ) ); |
| 215 | assert( copy->size == int32_t(strlen( original )) ); |
| 216 | string_free( copy ); |
| 217 | } |
| 218 | |
| 219 | { |
| 220 | const char * const foo = "Foo "; |
| 221 | string foo_copy[ 1 ]; |
| 222 | string_copy( foo_copy, foo ); |
| 223 | string_rtrim( foo_copy ); |
| 224 | assert( !strcmp( foo_copy->value, "Foo" ) ); |
| 225 | |
| 226 | string_rtrim( foo_copy ); |
| 227 | assert( !strcmp( foo_copy->value, "Foo" ) ); |
| 228 | } |
| 229 | { |
| 230 | const char * const bar = "Bar\0\0\0"; |
| 231 | string bar_copy[ 1 ]; |
| 232 | string_copy( bar_copy, bar ); |
| 233 | string_rtrim( bar_copy ); |
| 234 | assert( !strcmp( bar_copy->value, "Bar" ) ); |
| 235 | |
| 236 | string_rtrim( bar_copy ); |
| 237 | assert( !strcmp( bar_copy->value, "Bar" ) ); |
| 238 | } |
| 239 | } |
| 240 | #endif |
no test coverage detected