|
@@ -4,15 +4,30 @@
|
4
|
4
|
#include <ScHex.h>
|
5
|
5
|
#include <ScReader.h>
|
6
|
6
|
|
|
7
|
+#define TEST_Hex(FUNCTION) do { \
|
|
8
|
+ FUNCTION("", "", 0); \
|
|
9
|
+ FUNCTION("42", "\x42", 1); \
|
|
10
|
+ FUNCTION("42 00 FF AA 24", "\x42\x00\xff\xaa\x24", 5); \
|
|
11
|
+ FUNCTION("00 01 02 03 04 05 06 FF", "\x00\x01\x02\x03\x04\x05\x06\xff", 8); \
|
|
12
|
+ } while (0)
|
|
13
|
+
|
7
|
14
|
#define TEST_byteArrayToString(STR, DATA, SIZE) \
|
8
|
15
|
EXPECT_EQ(STR, ScHex::byteArrayToString(ScByteArray((BYTE*)memcpy(new BYTE[SIZE], DATA, SIZE), SIZE)))
|
9
|
16
|
|
10
|
|
-TEST(Hex, ByteToString)
|
|
17
|
+TEST(Hex, ByteArrayToString)
|
|
18
|
+{
|
|
19
|
+ TEST_Hex(TEST_byteArrayToString);
|
|
20
|
+}
|
|
21
|
+
|
|
22
|
+#define TEST_stringToByteArray(STR, DATA, SIZE) do { \
|
|
23
|
+ auto bytes = ScHex::stringToByteArray(STR); \
|
|
24
|
+ EXPECT_EQ(SIZE, bytes.getSize()); \
|
|
25
|
+ EXPECT_EQ(0, memcmp(bytes.getData(), DATA, SIZE)); \
|
|
26
|
+ } while (0)
|
|
27
|
+
|
|
28
|
+TEST(Hex, StringToByteArray)
|
11
|
29
|
{
|
12
|
|
- TEST_byteArrayToString("", "", 0);
|
13
|
|
- TEST_byteArrayToString("42", "\x42", 1);
|
14
|
|
- TEST_byteArrayToString("42 00 FF AA 24", "\x42\x00\xff\xaa\x24", 5);
|
15
|
|
- TEST_byteArrayToString("00 01 02 03 04 05 06 FF", "\x00\x01\x02\x03\x04\x05\x06\xff", 8);
|
|
30
|
+ TEST_Hex( TEST_stringToByteArray);
|
16
|
31
|
}
|
17
|
32
|
|
18
|
33
|
int main(int argc, char* argv[])
|