| 323 | } |
| 324 | |
| 325 | void testBytesStream() { |
| 326 | |
| 327 | const uint8_t prestr[] = "Hello"; |
| 328 | const uint8_t poststr[] = " World"; |
| 329 | |
| 330 | const RNS::Bytes prebuf(prestr, 5); |
| 331 | TEST_ASSERT_TRUE(prebuf); |
| 332 | TEST_ASSERT_EQUAL_size_t(5, prebuf.size()); |
| 333 | TEST_ASSERT_EQUAL_MEMORY("Hello", prebuf.data(), prebuf.size()); |
| 334 | |
| 335 | const RNS::Bytes postbuf(poststr, 6); |
| 336 | TEST_ASSERT_TRUE(postbuf); |
| 337 | TEST_ASSERT_EQUAL_size_t(6, postbuf.size()); |
| 338 | TEST_ASSERT_EQUAL_MEMORY(" World", postbuf.data(), postbuf.size()); |
| 339 | |
| 340 | // stream into empty bytes |
| 341 | HEAD("TestBytes: stream into empty bytes", RNS::LOG_TRACE); |
| 342 | { |
| 343 | RNS::Bytes strmbuf; |
| 344 | strmbuf << prebuf << postbuf; |
| 345 | TRACE("Results:"); |
| 346 | TRACEF("stream prebuf: %s", prebuf.toString().c_str()); |
| 347 | TRACEF("stream postbuf: %s", postbuf.toString().c_str()); |
| 348 | TRACEF("stream strmbuf: %s", strmbuf.toString().c_str()); |
| 349 | TEST_ASSERT_EQUAL_size_t(11, strmbuf.size()); |
| 350 | TEST_ASSERT_EQUAL_MEMORY("Hello World", strmbuf.data(), strmbuf.size()); |
| 351 | TEST_ASSERT_EQUAL_size_t(5, prebuf.size()); |
| 352 | TEST_ASSERT_EQUAL_MEMORY("Hello", prebuf.data(), prebuf.size()); |
| 353 | TEST_ASSERT_EQUAL_size_t(6, postbuf.size()); |
| 354 | TEST_ASSERT_EQUAL_MEMORY(" World", postbuf.data(), postbuf.size()); |
| 355 | } |
| 356 | |
| 357 | // stream into reserved empty bytes |
| 358 | HEAD("TestBytes: stream into reserved empty bytes", RNS::LOG_TRACE); |
| 359 | { |
| 360 | RNS::Bytes strmbuf(256); |
| 361 | //strmbuf << prebuf << postbuf; |
| 362 | strmbuf << prebuf; |
| 363 | strmbuf << postbuf; |
| 364 | TRACE("Results:"); |
| 365 | //TRACEF("stream prebuf: %s", prebuf.toString().c_str()); |
| 366 | //TRACEF("stream postbuf: %s", postbuf.toString().c_str()); |
| 367 | //TRACEF("stream strmbuf: %s", strmbuf.toString().c_str()); |
| 368 | TEST_ASSERT_EQUAL_size_t(11, strmbuf.size()); |
| 369 | TEST_ASSERT_EQUAL_MEMORY("Hello World", strmbuf.data(), strmbuf.size()); |
| 370 | TEST_ASSERT_EQUAL_size_t(5, prebuf.size()); |
| 371 | TEST_ASSERT_EQUAL_MEMORY("Hello", prebuf.data(), prebuf.size()); |
| 372 | TEST_ASSERT_EQUAL_size_t(6, postbuf.size()); |
| 373 | TEST_ASSERT_EQUAL_MEMORY(" World", postbuf.data(), postbuf.size()); |
| 374 | } |
| 375 | |
| 376 | // stream into populated bytes |
| 377 | HEAD("TestBytes: stream into populated bytes", RNS::LOG_TRACE); |
| 378 | { |
| 379 | RNS::Bytes strmbuf("Stream "); |
| 380 | TEST_ASSERT_TRUE(strmbuf); |
| 381 | TEST_ASSERT_EQUAL_size_t(7, strmbuf.size()); |
| 382 | TEST_ASSERT_EQUAL_MEMORY("Stream ", strmbuf.data(), strmbuf.size()); |