| 251 | } |
| 252 | |
| 253 | void testBytesConversion() { |
| 254 | |
| 255 | { |
| 256 | RNS::Bytes bytes("Hello World"); |
| 257 | std::string hex = bytes.toHex(true); |
| 258 | TRACEF("text: \"%s\" upper hex: \"%s\"", bytes.toString().c_str(), hex.c_str()); |
| 259 | TEST_ASSERT_EQUAL_size_t(22, hex.length()); |
| 260 | TEST_ASSERT_EQUAL_STRING("48656C6C6F20576F726C64", hex.c_str()); |
| 261 | } |
| 262 | { |
| 263 | RNS::Bytes bytes("Hello World"); |
| 264 | std::string hex = bytes.toHex(false); |
| 265 | TRACEF("text: \"%s\" lower hex: \"%s\"", bytes.toString().c_str(), hex.c_str()); |
| 266 | TEST_ASSERT_EQUAL_size_t(22, hex.length()); |
| 267 | TEST_ASSERT_EQUAL_STRING("48656c6c6f20576f726c64", hex.c_str()); |
| 268 | } |
| 269 | { |
| 270 | std::string hex("48656C6C6F20576F726C64"); |
| 271 | RNS::Bytes bytes; |
| 272 | bytes.assignHex(hex.c_str()); |
| 273 | std::string text = bytes.toString(); |
| 274 | TRACEF("hex: \"%s\" text: \"%s\"", hex.c_str(), text.c_str()); |
| 275 | TEST_ASSERT_EQUAL_size_t(11, text.length()); |
| 276 | TEST_ASSERT_EQUAL_STRING("Hello World", text.c_str()); |
| 277 | } |
| 278 | { |
| 279 | std::string hex("48656c6c6f20576f726c64"); |
| 280 | RNS::Bytes bytes; |
| 281 | bytes.assignHex(hex.c_str()); |
| 282 | std::string text = bytes.toString(); |
| 283 | TRACEF("hex: \"%s\" text: \"%s\"", hex.c_str(), text.c_str()); |
| 284 | TEST_ASSERT_EQUAL_size_t(11, text.length()); |
| 285 | TEST_ASSERT_EQUAL_STRING("Hello World", text.c_str()); |
| 286 | |
| 287 | // overwrite |
| 288 | bytes.assignHex(hex.c_str()); |
| 289 | text = bytes.toString(); |
| 290 | TRACEF("hex: \"%s\" text: \"%s\"", hex.c_str(), text.c_str()); |
| 291 | TEST_ASSERT_EQUAL_size_t(11, text.length()); |
| 292 | TEST_ASSERT_EQUAL_STRING("Hello World", text.c_str()); |
| 293 | |
| 294 | // apend |
| 295 | bytes.appendHex(hex.c_str()); |
| 296 | text = bytes.toString(); |
| 297 | TRACEF("hex: \"%s\" text: \"%s\"", hex.c_str(), text.c_str()); |
| 298 | TEST_ASSERT_EQUAL_size_t(22, text.length()); |
| 299 | TEST_ASSERT_EQUAL_STRING("Hello WorldHello World", text.c_str()); |
| 300 | } |
| 301 | |
| 302 | } |
| 303 | |
| 304 | void testBytesResize() { |
| 305 | TRACE("Testing downsize of Bytes with initial capacity"); |