Skip to content

Commit 6f33026

Browse files
update test cases
1 parent a72ed29 commit 6f33026

File tree

2 files changed

+134
-30
lines changed

2 files changed

+134
-30
lines changed

code/tests/cases/test_cstring.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,39 @@ FOSSIL_TEST_CASE(c_test_cstring_pad_right) {
211211
fossil_io_cstring_free(result);
212212
}
213213

214+
FOSSIL_TEST_CASE(c_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(c_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(c_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(c_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+
214247
// * * * * * * * * * * * * * * * * * * * * * * * *
215248
// * Fossil Logic Test Pool
216249
// * * * * * * * * * * * * * * * * * * * * * * * *
@@ -237,5 +270,10 @@ FOSSIL_TEST_GROUP(c_string_tests) {
237270
FOSSIL_TEST_ADD(c_string_suite, c_test_cstring_pad_left);
238271
FOSSIL_TEST_ADD(c_string_suite, c_test_cstring_pad_right);
239272

273+
FOSSIL_TEST_ADD(c_string_suite, c_test_cstring_stream_create_and_free);
274+
FOSSIL_TEST_ADD(c_string_suite, c_test_cstring_stream_write_and_read);
275+
FOSSIL_TEST_ADD(c_string_suite, c_test_cstring_stream_multiple_writes);
276+
FOSSIL_TEST_ADD(c_string_suite, c_test_cstring_stream_empty_read);
277+
240278
FOSSIL_TEST_REGISTER(c_string_suite);
241279
}

code/tests/cases/test_cstring.cpp

Lines changed: 96 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -211,22 +211,56 @@ FOSSIL_TEST_CASE(cpp_test_cstring_pad_right) {
211211
fossil_io_cstring_free(result);
212212
}
213213

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+
214247
FOSSIL_TEST_CASE(cpp_test_cstring_class_create_and_free) {
215248
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());
217251
}
218252

219253
FOSSIL_TEST_CASE(cpp_test_cstring_class_copy) {
220254
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());
223258
}
224259

225260
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());
230264
}
231265

232266
FOSSIL_TEST_CASE(cpp_test_cstring_class_length) {
@@ -236,18 +270,18 @@ FOSSIL_TEST_CASE(cpp_test_cstring_class_length) {
236270
}
237271

238272
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);
245279
}
246280

247281
FOSSIL_TEST_CASE(cpp_test_cstring_class_trim) {
248282
fossil::io::CString str(" Hello, World! ");
249283
str.trim();
250-
ASSUME_ITS_EQUAL_CSTR("Hello, World!", str.str().c_str());
284+
ASSUME_ITS_EQUAL_CSTR("Hello, World!", str.str());
251285
}
252286

253287
FOSSIL_TEST_CASE(cpp_test_cstring_class_split) {
@@ -263,19 +297,22 @@ FOSSIL_TEST_CASE(cpp_test_cstring_class_split) {
263297
FOSSIL_TEST_CASE(cpp_test_cstring_class_replace) {
264298
fossil::io::CString str("Hello, World!");
265299
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());
267302
}
268303

269304
FOSSIL_TEST_CASE(cpp_test_cstring_class_to_upper) {
270305
fossil::io::CString str("Hello, World!");
271306
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());
273309
}
274310

275311
FOSSIL_TEST_CASE(cpp_test_cstring_class_to_lower) {
276312
fossil::io::CString str("Hello, World!");
277313
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());
279316
}
280317

281318
FOSSIL_TEST_CASE(cpp_test_cstring_class_starts_with) {
@@ -291,13 +328,15 @@ FOSSIL_TEST_CASE(cpp_test_cstring_class_ends_with) {
291328
FOSSIL_TEST_CASE(cpp_test_cstring_class_substring) {
292329
fossil::io::CString str("Hello, World!");
293330
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());
295333
}
296334

297335
FOSSIL_TEST_CASE(cpp_test_cstring_class_reverse) {
298336
fossil::io::CString str("Hello, World!");
299337
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());
301340
}
302341

303342
FOSSIL_TEST_CASE(cpp_test_cstring_class_contains) {
@@ -308,13 +347,15 @@ FOSSIL_TEST_CASE(cpp_test_cstring_class_contains) {
308347
FOSSIL_TEST_CASE(cpp_test_cstring_class_repeat) {
309348
fossil::io::CString str("Hello");
310349
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());
312352
}
313353

314354
FOSSIL_TEST_CASE(cpp_test_cstring_class_strip) {
315355
fossil::io::CString str("!!!Hello, World!!!");
316356
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());
318359
}
319360

320361
FOSSIL_TEST_CASE(cpp_test_cstring_class_count) {
@@ -326,27 +367,44 @@ FOSSIL_TEST_CASE(cpp_test_cstring_class_count) {
326367
FOSSIL_TEST_CASE(cpp_test_cstring_class_pad_left) {
327368
fossil::io::CString str("Hello");
328369
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());
330372
}
331373

332374
FOSSIL_TEST_CASE(cpp_test_cstring_class_pad_right) {
333375
fossil::io::CString str("Hello");
334376
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());
336379
}
337380

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());
341384
}
342385

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);
345388
stream.write("Hello, World!");
346389
std::string result = stream.read();
347390
ASSUME_ITS_EQUAL_CSTR("Hello, World!", result.c_str());
348391
}
349392

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+
350408
// * * * * * * * * * * * * * * * * * * * * * * * *
351409
// * Fossil Logic Test Pool
352410
// * * * * * * * * * * * * * * * * * * * * * * * *
@@ -373,6 +431,11 @@ FOSSIL_TEST_GROUP(cpp_string_tests) {
373431
FOSSIL_TEST_ADD(cpp_string_suite, cpp_test_cstring_pad_left);
374432
FOSSIL_TEST_ADD(cpp_string_suite, cpp_test_cstring_pad_right);
375433

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+
376439
FOSSIL_TEST_ADD(cpp_string_suite, cpp_test_cstring_class_create_and_free);
377440
FOSSIL_TEST_ADD(cpp_string_suite, cpp_test_cstring_class_copy);
378441
FOSSIL_TEST_ADD(cpp_string_suite, cpp_test_cstring_class_concat);
@@ -393,8 +456,11 @@ FOSSIL_TEST_GROUP(cpp_string_tests) {
393456
FOSSIL_TEST_ADD(cpp_string_suite, cpp_test_cstring_class_count);
394457
FOSSIL_TEST_ADD(cpp_string_suite, cpp_test_cstring_class_pad_left);
395458
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);
398464

399465
FOSSIL_TEST_REGISTER(cpp_string_suite);
400466
}

0 commit comments

Comments
 (0)