| 1 | #ifndef __CREATE_EXTRACT_TEST_H__ |
|---|
| 2 | #define __CREATE_EXTRACT_TEST_H__ |
|---|
| 3 | |
|---|
| 4 | #include <cxxtest/TestSuite.h> |
|---|
| 5 | #include "src/PacketizerDSP.h" |
|---|
| 6 | |
|---|
| 7 | // |
|---|
| 8 | // A simple test suite: Just inherit CxxTest::TestSuite and write tests! |
|---|
| 9 | // |
|---|
| 10 | // NOTE: " : public CxxTest::TestSuite" must be on the same line as the class |
|---|
| 11 | // definition, otherwise the python script does not recognize it |
|---|
| 12 | // as a test class |
|---|
| 13 | class CreateExtract_testsuite1 : public CxxTest::TestSuite, |
|---|
| 14 | public PacketizerDSP |
|---|
| 15 | { |
|---|
| 16 | public: |
|---|
| 17 | |
|---|
| 18 | // |
|---|
| 19 | // Basic test for creating and extracting a packet of type PACKET_RAW_400 |
|---|
| 20 | // |
|---|
| 21 | void test_CreateExtract_PACKET_RAW_400_01() { |
|---|
| 22 | // generate input buffer |
|---|
| 23 | char * input; |
|---|
| 24 | input = (char*) calloc( 400, sizeof(char) ); |
|---|
| 25 | input[0] = 1; |
|---|
| 26 | input[1] = 0; |
|---|
| 27 | input[2] = 1; |
|---|
| 28 | |
|---|
| 29 | // generate packet buffer |
|---|
| 30 | char * packet; |
|---|
| 31 | packet = (char*) calloc( 1024, sizeof(char) ); |
|---|
| 32 | memset( packet, 0x01, 1024*sizeof(char) ); |
|---|
| 33 | unsigned int packet_length = 1024; |
|---|
| 34 | |
|---|
| 35 | // generate output buffer |
|---|
| 36 | char * output; |
|---|
| 37 | output = (char*) calloc( 1024, sizeof(char) ); |
|---|
| 38 | memset( output, 0x01, 1024*sizeof(char) ); |
|---|
| 39 | unsigned int output_length = 1024; |
|---|
| 40 | |
|---|
| 41 | // generate processing buffers |
|---|
| 42 | char * b1 = (char*) calloc( MAX_PACKET_SIZE, sizeof(char) ); |
|---|
| 43 | char * b2 = (char*) calloc( MAX_PACKET_SIZE, sizeof(char) ); |
|---|
| 44 | SetBuffer(b1, b2, MAX_PACKET_SIZE); |
|---|
| 45 | |
|---|
| 46 | // Initialize properties |
|---|
| 47 | packet_id = 6; |
|---|
| 48 | CreatePacket(PACKET_RAW_400, input, 400, &packet[0], 1024, packet_length ); |
|---|
| 49 | |
|---|
| 50 | packet_id = 0; |
|---|
| 51 | |
|---|
| 52 | bool packet_extracted; |
|---|
| 53 | packet_extracted = ExtractPacket(packet, packet_length, output, 1024, output_length); |
|---|
| 54 | |
|---|
| 55 | TS_ASSERT_EQUALS( packet_extracted, true ); |
|---|
| 56 | TS_ASSERT_EQUALS( packet_id, 6 ); |
|---|
| 57 | TS_ASSERT_EQUALS( output_length, 400 ); |
|---|
| 58 | TS_ASSERT_SAME_DATA( input, output, 400 ); |
|---|
| 59 | |
|---|
| 60 | // Test again, but set output to offset position in buffer and break data into pieces |
|---|
| 61 | packet_id = 6; |
|---|
| 62 | CreatePacket(PACKET_RAW_400, input, 400, &packet[55], 1024, packet_length ); |
|---|
| 63 | |
|---|
| 64 | packet_id = 0; |
|---|
| 65 | |
|---|
| 66 | for (unsigned int i=0; i<1024; i+=16) { |
|---|
| 67 | packet_extracted = ExtractPacket(packet+i, 16, output, 1024, output_length); |
|---|
| 68 | if (packet_extracted) |
|---|
| 69 | break; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | TS_ASSERT_EQUALS( packet_extracted, true ); |
|---|
| 73 | TS_ASSERT_EQUALS( packet_id, 6 ); |
|---|
| 74 | TS_ASSERT_EQUALS( output_length, 400 ); |
|---|
| 75 | TS_ASSERT_SAME_DATA( input, output, 400 ); |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | free(input); |
|---|
| 80 | free(packet); |
|---|
| 81 | free(output); |
|---|
| 82 | free(b1); |
|---|
| 83 | free(b2); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | }; |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | #endif |
|---|
| 90 | |
|---|