| 19 | } |
| 20 | |
| 21 | void testBytesMain() { |
| 22 | |
| 23 | RNS::Bytes bytes; |
| 24 | TEST_ASSERT_FALSE(bytes); |
| 25 | TEST_ASSERT_EQUAL_size_t(0, bytes.size()); |
| 26 | TEST_ASSERT_TRUE(bytes.empty()); |
| 27 | TEST_ASSERT_NULL(bytes.data()); |
| 28 | |
| 29 | const uint8_t prestr[] = "Hello"; |
| 30 | const uint8_t poststr[] = " World"; |
| 31 | |
| 32 | const RNS::Bytes prebuf(prestr, 5); |
| 33 | TEST_ASSERT_TRUE(prebuf); |
| 34 | TEST_ASSERT_EQUAL_size_t(5, prebuf.size()); |
| 35 | TEST_ASSERT_EQUAL_MEMORY("Hello", prebuf.data(), prebuf.size()); |
| 36 | TEST_ASSERT_FALSE(bytes == prebuf); |
| 37 | TEST_ASSERT_TRUE(bytes != prebuf); |
| 38 | TEST_ASSERT_TRUE(bytes < prebuf); |
| 39 | |
| 40 | const RNS::Bytes postbuf(poststr, 6); |
| 41 | TEST_ASSERT_TRUE(postbuf); |
| 42 | TEST_ASSERT_EQUAL_size_t(6, postbuf.size()); |
| 43 | TEST_ASSERT_EQUAL_MEMORY(" World", postbuf.data(), postbuf.size()); |
| 44 | TEST_ASSERT_FALSE(postbuf == bytes); |
| 45 | TEST_ASSERT_TRUE(postbuf != bytes); |
| 46 | TEST_ASSERT_TRUE(postbuf > bytes); |
| 47 | |
| 48 | TEST_ASSERT_FALSE(prebuf == postbuf); |
| 49 | TEST_ASSERT_TRUE(prebuf != postbuf); |
| 50 | |
| 51 | if (prebuf == postbuf) { |
| 52 | TRACE("bytess are the same"); |
| 53 | } |
| 54 | else { |
| 55 | TRACE("bytess are different"); |
| 56 | } |
| 57 | |
| 58 | // test string assignment |
| 59 | bytes = "Foo"; |
| 60 | TEST_ASSERT_EQUAL_size_t(3, bytes.size()); |
| 61 | TEST_ASSERT_EQUAL_MEMORY("Foo", bytes.data(), bytes.size()); |
| 62 | |
| 63 | // test string concat with addition |
| 64 | bytes += prebuf + postbuf; |
| 65 | TEST_ASSERT_EQUAL_size_t(14, bytes.size()); |
| 66 | TEST_ASSERT_EQUAL_MEMORY("FooHello World", bytes.data(), bytes.size()); |
| 67 | TRACEF("assign bytes: %s", bytes.toString().c_str()); |
| 68 | TRACEF("assign prebuf: %s", prebuf.toString().c_str()); |
| 69 | TRACEF("assign postbuf: %s", postbuf.toString().c_str()); |
| 70 | |
| 71 | // test string assignment with addition |
| 72 | bytes = prebuf + postbuf; |
| 73 | TEST_ASSERT_EQUAL_size_t(11, bytes.size()); |
| 74 | TEST_ASSERT_EQUAL_MEMORY("Hello World", bytes.data(), bytes.size()); |
| 75 | |
| 76 | // test string constructor |
| 77 | { |
| 78 | RNS::Bytes str("Foo"); |