| 1 | #ifndef __PACK_BYTE_TEST_H__ |
|---|
| 2 | #define __PACK_BYTE_TEST_H__ |
|---|
| 3 | |
|---|
| 4 | #include <cxxtest/TestSuite.h> |
|---|
| 5 | #include "../SigProc.h" |
|---|
| 6 | |
|---|
| 7 | using namespace SigProc; |
|---|
| 8 | |
|---|
| 9 | // |
|---|
| 10 | // A simple test suite: Just inherit CxxTest::TestSuite and write tests! |
|---|
| 11 | // |
|---|
| 12 | |
|---|
| 13 | class pack_bytes_Testsuite : public CxxTest::TestSuite |
|---|
| 14 | { |
|---|
| 15 | public: |
|---|
| 16 | |
|---|
| 17 | // |
|---|
| 18 | // pack_bytes |
|---|
| 19 | // |
|---|
| 20 | |
|---|
| 21 | void test_pack_bytes_01() { |
|---|
| 22 | char * output = (char*) calloc(8, sizeof(char)); |
|---|
| 23 | unsigned int N; |
|---|
| 24 | |
|---|
| 25 | char input[36] = { |
|---|
| 26 | 0, 0, 0, 0, 0, 0, 0, 0, // 0: 0000 0000 |
|---|
| 27 | 1, 1, 1, 1, 1, 1, 1, 1, // 255: 1111 1111 |
|---|
| 28 | 0, 0, 0, 0, 1, 1, 1, 1, // 15: 0000 1111 |
|---|
| 29 | 1, 0, 1, 0, 1, 0, 1, 0 // 170: 1010 1010 |
|---|
| 30 | }; |
|---|
| 31 | |
|---|
| 32 | // Test packing entire array |
|---|
| 33 | char output_test_01[4] = {0x00, 0xFF, 0x0F, 0xAA}; |
|---|
| 34 | pack_bytes( input, 32, output, 8, &N ); |
|---|
| 35 | TS_ASSERT_EQUALS( N, 4 ); |
|---|
| 36 | TS_ASSERT_SAME_DATA( output, output_test_01, 4 ); |
|---|
| 37 | |
|---|
| 38 | // Test packing only 28 elements |
|---|
| 39 | char output_test_02[4] = {0x00, 0xFF, 0x0F, 0x0A}; |
|---|
| 40 | pack_bytes( input, 28, output, 8, &N ); |
|---|
| 41 | TS_ASSERT_EQUALS( N, 4 ); |
|---|
| 42 | TS_ASSERT_SAME_DATA( output, output_test_02, 4 ); |
|---|
| 43 | |
|---|
| 44 | // Test packing only 25 elements |
|---|
| 45 | char output_test_03[4] = {0x00, 0xFF, 0x0F, 0x01}; |
|---|
| 46 | pack_bytes( input, 25, output, 8, &N ); |
|---|
| 47 | TS_ASSERT_EQUALS( N, 4 ); |
|---|
| 48 | TS_ASSERT_SAME_DATA( output, output_test_03, 4 ); |
|---|
| 49 | |
|---|
| 50 | // Test packing only 24 elements (3 bytes) |
|---|
| 51 | char output_test_04[3] = {0x00, 0xFF, 0x0F}; |
|---|
| 52 | pack_bytes( input, 24, output, 8, &N ); |
|---|
| 53 | TS_ASSERT_EQUALS( N, 3 ); |
|---|
| 54 | TS_ASSERT_SAME_DATA( output, output_test_04, 3 ); |
|---|
| 55 | |
|---|
| 56 | free(output); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | // |
|---|
| 61 | // unpack_bytes |
|---|
| 62 | // |
|---|
| 63 | |
|---|
| 64 | void test_unpack_bytes_01() { |
|---|
| 65 | char input[5] = {0x00, 0x01, 0xFF, 0x0F, 0xAA}; |
|---|
| 66 | |
|---|
| 67 | char * output = (char*) calloc(64, sizeof(char)); |
|---|
| 68 | unsigned int N; |
|---|
| 69 | |
|---|
| 70 | char output_test[40] = { |
|---|
| 71 | 0, 0, 0, 0, 0, 0, 0, 0, // 0: 0000 0000 |
|---|
| 72 | 0, 0, 0, 0, 0, 0, 0, 1, // 1: 0000 0001 |
|---|
| 73 | 1, 1, 1, 1, 1, 1, 1, 1, // 255: 1111 1111 |
|---|
| 74 | 0, 0, 0, 0, 1, 1, 1, 1, // 15: 0000 1111 |
|---|
| 75 | 1, 0, 1, 0, 1, 0, 1, 0 // 170: 1010 1010 |
|---|
| 76 | }; |
|---|
| 77 | |
|---|
| 78 | // Test packing entire array |
|---|
| 79 | unpack_bytes( input, 4, output, 40, &N ); |
|---|
| 80 | TS_ASSERT_EQUALS( N, 32 ); |
|---|
| 81 | TS_ASSERT_SAME_DATA( output, output_test, 32 ); |
|---|
| 82 | |
|---|
| 83 | free(output); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | // |
|---|
| 88 | // repack_bytes |
|---|
| 89 | // |
|---|
| 90 | |
|---|
| 91 | void test_repack_bytes_01() { |
|---|
| 92 | char input[] = { |
|---|
| 93 | 0x07, // 111 |
|---|
| 94 | 0x00, // 000 |
|---|
| 95 | 0x06, // 110 |
|---|
| 96 | 0x07 // 111 |
|---|
| 97 | }; |
|---|
| 98 | |
|---|
| 99 | char output_test[] = { |
|---|
| 100 | 0x03, // 11 |
|---|
| 101 | 0x02, // 10 |
|---|
| 102 | 0x00, // 00 |
|---|
| 103 | 0x03, // 11 |
|---|
| 104 | 0x01, // 01 |
|---|
| 105 | 0x03 // 11 |
|---|
| 106 | }; |
|---|
| 107 | |
|---|
| 108 | char * output = (char*) calloc(8, sizeof(char)); |
|---|
| 109 | unsigned int N; |
|---|
| 110 | |
|---|
| 111 | repack_bytes( input, 3, 4, output, 2, 8, &N ); |
|---|
| 112 | |
|---|
| 113 | TS_ASSERT_EQUALS( N, 6 ); |
|---|
| 114 | TS_ASSERT_SAME_DATA( output, output_test, 6 ); |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | void test_repack_bytes_02() { |
|---|
| 118 | char input[] = { |
|---|
| 119 | 0x01, // 00001 |
|---|
| 120 | 0x02, // 00010 |
|---|
| 121 | 0x04 // 00100 |
|---|
| 122 | }; |
|---|
| 123 | |
|---|
| 124 | char output_test[] = { |
|---|
| 125 | 0x00, // 000 |
|---|
| 126 | 0x02, // 010 |
|---|
| 127 | 0x01, // 001 |
|---|
| 128 | 0x00, // 000 |
|---|
| 129 | 0x04 // 100 |
|---|
| 130 | }; |
|---|
| 131 | |
|---|
| 132 | char * output = (char*) calloc(8, sizeof(char)); |
|---|
| 133 | unsigned int N; |
|---|
| 134 | |
|---|
| 135 | repack_bytes( input, 5, 3, output, 3, 8, &N ); |
|---|
| 136 | |
|---|
| 137 | TS_ASSERT_EQUALS( N, 5 ); |
|---|
| 138 | TS_ASSERT_SAME_DATA( output, output_test, 5 ); |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | void test_repack_bytes_03() { |
|---|
| 142 | char input[] = { |
|---|
| 143 | 0x00, // 000 |
|---|
| 144 | 0x02, // 010 |
|---|
| 145 | 0x01, // 001 |
|---|
| 146 | 0x00, // 000 |
|---|
| 147 | 0x04 // 100 |
|---|
| 148 | }; |
|---|
| 149 | |
|---|
| 150 | char output_test[] = { |
|---|
| 151 | 0x01, // 00001 |
|---|
| 152 | 0x02, // 00010 |
|---|
| 153 | 0x04 // 00100 |
|---|
| 154 | }; |
|---|
| 155 | |
|---|
| 156 | char * output = (char*) calloc(8, sizeof(char)); |
|---|
| 157 | unsigned int N; |
|---|
| 158 | |
|---|
| 159 | repack_bytes( input, 3, 5, output, 5, 8, &N ); |
|---|
| 160 | |
|---|
| 161 | TS_ASSERT_EQUALS( N, 3 ); |
|---|
| 162 | TS_ASSERT_SAME_DATA( output, output_test, 3 ); |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | }; |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | #endif // __PACK_BYTE_TEST_H__ |
|---|
| 169 | |
|---|