@@ -211,22 +211,56 @@ FOSSIL_TEST_CASE(cpp_test_cstring_pad_right) {
211
211
fossil_io_cstring_free (result);
212
212
}
213
213
214
+ FOSSIL_TEST_CASE (cpp_test_cstring_stream_create_and_free) {
215
+ fossil_io_cstring_stream *stream = fossil_io_cstring_stream_create (1024 );
216
+ ASSUME_NOT_CNULL (stream);
217
+ fossil_io_cstring_stream_free (stream);
218
+ }
219
+
220
+ FOSSIL_TEST_CASE (cpp_test_cstring_stream_write_and_read) {
221
+ fossil_io_cstring_stream *stream = fossil_io_cstring_stream_create (1024 );
222
+ fossil_io_cstring_stream_write (stream, " Hello, World!" );
223
+ ccstring result = fossil_io_cstring_stream_read (stream);
224
+ ASSUME_NOT_CNULL (result);
225
+ ASSUME_ITS_EQUAL_CSTR (" Hello, World!" , result);
226
+ fossil_io_cstring_stream_free (stream);
227
+ }
228
+
229
+ FOSSIL_TEST_CASE (cpp_test_cstring_stream_multiple_writes) {
230
+ fossil_io_cstring_stream *stream = fossil_io_cstring_stream_create (1024 );
231
+ fossil_io_cstring_stream_write (stream, " Hello, " );
232
+ fossil_io_cstring_stream_write (stream, " World!" );
233
+ ccstring result = fossil_io_cstring_stream_read (stream);
234
+ ASSUME_NOT_CNULL (result);
235
+ ASSUME_ITS_EQUAL_CSTR (" Hello, World!" , result);
236
+ fossil_io_cstring_stream_free (stream);
237
+ }
238
+
239
+ FOSSIL_TEST_CASE (cpp_test_cstring_stream_empty_read) {
240
+ fossil_io_cstring_stream *stream = fossil_io_cstring_stream_create (1024 );
241
+ ccstring result = fossil_io_cstring_stream_read (stream);
242
+ ASSUME_NOT_CNULL (result);
243
+ ASSUME_ITS_EQUAL_CSTR (" " , result);
244
+ fossil_io_cstring_stream_free (stream);
245
+ }
246
+
214
247
FOSSIL_TEST_CASE (cpp_test_cstring_class_create_and_free) {
215
248
fossil::io::CString str (" Hello, World!" );
216
- ASSUME_ITS_EQUAL_CSTR (" Hello, World!" , str.str ().c_str ());
249
+ ASSUME_NOT_CNULL (str.str ());
250
+ ASSUME_ITS_EQUAL_CSTR (" Hello, World!" , str.str ());
217
251
}
218
252
219
253
FOSSIL_TEST_CASE (cpp_test_cstring_class_copy) {
220
254
fossil::io::CString str (" Hello, World!" );
221
- fossil::io::CString copy = fossil::io::CString::copy (str.str ());
222
- ASSUME_ITS_EQUAL_CSTR (" Hello, World!" , copy.str ().c_str ());
255
+ fossil::io::CString copy = fossil::io::CString::copy (" Hello, World!" );
256
+ ASSUME_NOT_CNULL (copy.str ());
257
+ ASSUME_ITS_EQUAL_CSTR (" Hello, World!" , copy.str ());
223
258
}
224
259
225
260
FOSSIL_TEST_CASE (cpp_test_cstring_class_concat) {
226
- fossil::io::CString str1 (" Hello, " );
227
- fossil::io::CString str2 (" World!" );
228
- fossil::io::CString result = fossil::io::CString::concat (str1.str (), str2.str ());
229
- ASSUME_ITS_EQUAL_CSTR (" Hello, World!" , result.str ().c_str ());
261
+ fossil::io::CString result = fossil::io::CString::concat (" Hello, " , " World!" );
262
+ ASSUME_NOT_CNULL (result.str ());
263
+ ASSUME_ITS_EQUAL_CSTR (" Hello, World!" , result.str ());
230
264
}
231
265
232
266
FOSSIL_TEST_CASE (cpp_test_cstring_class_length) {
@@ -236,18 +270,18 @@ FOSSIL_TEST_CASE(cpp_test_cstring_class_length) {
236
270
}
237
271
238
272
FOSSIL_TEST_CASE (cpp_test_cstring_class_compare) {
239
- fossil::io::CString str1 (" Hello" );
240
- fossil::io::CString str2 (" Hello" );
241
- fossil::io::CString str3 (" World" );
242
- ASSUME_ITS_EQUAL_I32 (0 , str1 .compare (str2. str () ));
243
- ASSUME_ITS_TRUE (str1 .compare (str3. str () ) < 0 );
244
- ASSUME_ITS_TRUE (str3 .compare (str1. str () ) > 0 );
273
+ fossil::io::CString s1 (" Hello" );
274
+ fossil::io::CString s2 (" Hello" );
275
+ fossil::io::CString s3 (" World" );
276
+ ASSUME_ITS_EQUAL_I32 (0 , s1 .compare (" Hello " ));
277
+ ASSUME_ITS_TRUE (s1 .compare (" World " ) < 0 );
278
+ ASSUME_ITS_TRUE (s3 .compare (" Hello " ) > 0 );
245
279
}
246
280
247
281
FOSSIL_TEST_CASE (cpp_test_cstring_class_trim) {
248
282
fossil::io::CString str (" Hello, World! " );
249
283
str.trim ();
250
- ASSUME_ITS_EQUAL_CSTR (" Hello, World!" , str.str (). c_str () );
284
+ ASSUME_ITS_EQUAL_CSTR (" Hello, World!" , str.str ());
251
285
}
252
286
253
287
FOSSIL_TEST_CASE (cpp_test_cstring_class_split) {
@@ -263,19 +297,22 @@ FOSSIL_TEST_CASE(cpp_test_cstring_class_split) {
263
297
FOSSIL_TEST_CASE (cpp_test_cstring_class_replace) {
264
298
fossil::io::CString str (" Hello, World!" );
265
299
fossil::io::CString result = str.replace (" World" , " Fossil" );
266
- ASSUME_ITS_EQUAL_CSTR (" Hello, Fossil!" , result.str ().c_str ());
300
+ ASSUME_NOT_CNULL (result.str ());
301
+ ASSUME_ITS_EQUAL_CSTR (" Hello, Fossil!" , result.str ());
267
302
}
268
303
269
304
FOSSIL_TEST_CASE (cpp_test_cstring_class_to_upper) {
270
305
fossil::io::CString str (" Hello, World!" );
271
306
fossil::io::CString result = str.to_upper ();
272
- ASSUME_ITS_EQUAL_CSTR (" HELLO, WORLD!" , result.str ().c_str ());
307
+ ASSUME_NOT_CNULL (result.str ());
308
+ ASSUME_ITS_EQUAL_CSTR (" HELLO, WORLD!" , result.str ());
273
309
}
274
310
275
311
FOSSIL_TEST_CASE (cpp_test_cstring_class_to_lower) {
276
312
fossil::io::CString str (" Hello, World!" );
277
313
fossil::io::CString result = str.to_lower ();
278
- ASSUME_ITS_EQUAL_CSTR (" hello, world!" , result.str ().c_str ());
314
+ ASSUME_NOT_CNULL (result.str ());
315
+ ASSUME_ITS_EQUAL_CSTR (" hello, world!" , result.str ());
279
316
}
280
317
281
318
FOSSIL_TEST_CASE (cpp_test_cstring_class_starts_with) {
@@ -291,13 +328,15 @@ FOSSIL_TEST_CASE(cpp_test_cstring_class_ends_with) {
291
328
FOSSIL_TEST_CASE (cpp_test_cstring_class_substring) {
292
329
fossil::io::CString str (" Hello, World!" );
293
330
fossil::io::CString result = str.substring (7 , 5 );
294
- ASSUME_ITS_EQUAL_CSTR (" World" , result.str ().c_str ());
331
+ ASSUME_NOT_CNULL (result.str ());
332
+ ASSUME_ITS_EQUAL_CSTR (" World" , result.str ());
295
333
}
296
334
297
335
FOSSIL_TEST_CASE (cpp_test_cstring_class_reverse) {
298
336
fossil::io::CString str (" Hello, World!" );
299
337
fossil::io::CString result = str.reverse ();
300
- ASSUME_ITS_EQUAL_CSTR (" !dlroW ,olleH" , result.str ().c_str ());
338
+ ASSUME_NOT_CNULL (result.str ());
339
+ ASSUME_ITS_EQUAL_CSTR (" !dlroW ,olleH" , result.str ());
301
340
}
302
341
303
342
FOSSIL_TEST_CASE (cpp_test_cstring_class_contains) {
@@ -308,13 +347,15 @@ FOSSIL_TEST_CASE(cpp_test_cstring_class_contains) {
308
347
FOSSIL_TEST_CASE (cpp_test_cstring_class_repeat) {
309
348
fossil::io::CString str (" Hello" );
310
349
fossil::io::CString result = str.repeat (3 );
311
- ASSUME_ITS_EQUAL_CSTR (" HelloHelloHello" , result.str ().c_str ());
350
+ ASSUME_NOT_CNULL (result.str ());
351
+ ASSUME_ITS_EQUAL_CSTR (" HelloHelloHello" , result.str ());
312
352
}
313
353
314
354
FOSSIL_TEST_CASE (cpp_test_cstring_class_strip) {
315
355
fossil::io::CString str (" !!!Hello, World!!!" );
316
356
fossil::io::CString result = str.strip (' !' );
317
- ASSUME_ITS_EQUAL_CSTR (" Hello, World" , result.str ().c_str ());
357
+ ASSUME_NOT_CNULL (result.str ());
358
+ ASSUME_ITS_EQUAL_CSTR (" Hello, World" , result.str ());
318
359
}
319
360
320
361
FOSSIL_TEST_CASE (cpp_test_cstring_class_count) {
@@ -326,27 +367,44 @@ FOSSIL_TEST_CASE(cpp_test_cstring_class_count) {
326
367
FOSSIL_TEST_CASE (cpp_test_cstring_class_pad_left) {
327
368
fossil::io::CString str (" Hello" );
328
369
fossil::io::CString result = str.pad_left (10 , ' *' );
329
- ASSUME_ITS_EQUAL_CSTR (" *****Hello" , result.str ().c_str ());
370
+ ASSUME_NOT_CNULL (result.str ());
371
+ ASSUME_ITS_EQUAL_CSTR (" *****Hello" , result.str ());
330
372
}
331
373
332
374
FOSSIL_TEST_CASE (cpp_test_cstring_class_pad_right) {
333
375
fossil::io::CString str (" Hello" );
334
376
fossil::io::CString result = str.pad_right (10 , ' *' );
335
- ASSUME_ITS_EQUAL_CSTR (" Hello*****" , result.str ().c_str ());
377
+ ASSUME_NOT_CNULL (result.str ());
378
+ ASSUME_ITS_EQUAL_CSTR (" Hello*****" , result.str ());
336
379
}
337
380
338
- FOSSIL_TEST_CASE (cpp_test_cstring_stream_create_and_free ) {
339
- fossil::io::CStringStream stream (100 );
340
- ASSUME_NOT_CNULL (& stream);
381
+ FOSSIL_TEST_CASE (cpp_test_cstring_stream_class_create_and_free ) {
382
+ fossil::io::CStringStream stream (1024 );
383
+ ASSUME_NOT_CNULL (stream. read (). c_str () );
341
384
}
342
385
343
- FOSSIL_TEST_CASE (cpp_test_cstring_stream_write_and_read ) {
344
- fossil::io::CStringStream stream (100 );
386
+ FOSSIL_TEST_CASE (cpp_test_cstring_stream_class_write_and_read ) {
387
+ fossil::io::CStringStream stream (1024 );
345
388
stream.write (" Hello, World!" );
346
389
std::string result = stream.read ();
347
390
ASSUME_ITS_EQUAL_CSTR (" Hello, World!" , result.c_str ());
348
391
}
349
392
393
+ FOSSIL_TEST_CASE (cpp_test_cstring_stream_class_multiple_writes) {
394
+ fossil::io::CStringStream stream (1024 );
395
+ stream.write (" Hello, " );
396
+ stream.write (" World!" );
397
+ std::string result = stream.read ();
398
+ ASSUME_ITS_EQUAL_CSTR (" Hello, World!" , result.c_str ());
399
+ }
400
+
401
+ FOSSIL_TEST_CASE (cpp_test_cstring_stream_class_empty_read) {
402
+ fossil::io::CStringStream stream (1024 );
403
+ std::string result = stream.read ();
404
+ ASSUME_ITS_EQUAL_CSTR (" " , result.c_str ());
405
+ }
406
+
407
+
350
408
// * * * * * * * * * * * * * * * * * * * * * * * *
351
409
// * Fossil Logic Test Pool
352
410
// * * * * * * * * * * * * * * * * * * * * * * * *
@@ -373,6 +431,11 @@ FOSSIL_TEST_GROUP(cpp_string_tests) {
373
431
FOSSIL_TEST_ADD (cpp_string_suite, cpp_test_cstring_pad_left);
374
432
FOSSIL_TEST_ADD (cpp_string_suite, cpp_test_cstring_pad_right);
375
433
434
+ FOSSIL_TEST_ADD (cpp_string_suite, cpp_test_cstring_stream_create_and_free);
435
+ FOSSIL_TEST_ADD (cpp_string_suite, cpp_test_cstring_stream_write_and_read);
436
+ FOSSIL_TEST_ADD (cpp_string_suite, cpp_test_cstring_stream_multiple_writes);
437
+ FOSSIL_TEST_ADD (cpp_string_suite, cpp_test_cstring_stream_empty_read);
438
+
376
439
FOSSIL_TEST_ADD (cpp_string_suite, cpp_test_cstring_class_create_and_free);
377
440
FOSSIL_TEST_ADD (cpp_string_suite, cpp_test_cstring_class_copy);
378
441
FOSSIL_TEST_ADD (cpp_string_suite, cpp_test_cstring_class_concat);
@@ -393,8 +456,11 @@ FOSSIL_TEST_GROUP(cpp_string_tests) {
393
456
FOSSIL_TEST_ADD (cpp_string_suite, cpp_test_cstring_class_count);
394
457
FOSSIL_TEST_ADD (cpp_string_suite, cpp_test_cstring_class_pad_left);
395
458
FOSSIL_TEST_ADD (cpp_string_suite, cpp_test_cstring_class_pad_right);
396
- FOSSIL_TEST_ADD (cpp_string_suite, cpp_test_cstring_stream_create_and_free);
397
- FOSSIL_TEST_ADD (cpp_string_suite, cpp_test_cstring_stream_write_and_read);
459
+
460
+ FOSSIL_TEST_ADD (cpp_string_suite, cpp_test_cstring_stream_class_create_and_free);
461
+ FOSSIL_TEST_ADD (cpp_string_suite, cpp_test_cstring_stream_class_write_and_read);
462
+ FOSSIL_TEST_ADD (cpp_string_suite, cpp_test_cstring_stream_class_multiple_writes);
463
+ FOSSIL_TEST_ADD (cpp_string_suite, cpp_test_cstring_stream_class_empty_read);
398
464
399
465
FOSSIL_TEST_REGISTER (cpp_string_suite);
400
466
}
0 commit comments