| 1 | #ifndef __DIGITALMODULATORTEST_H__ |
|---|
| 2 | #define __DIGITALMODULATORTEST_H__ |
|---|
| 3 | |
|---|
| 4 | #include <cxxtest/TestSuite.h> |
|---|
| 5 | #include "src/DigitalModem.h" |
|---|
| 6 | // |
|---|
| 7 | // A simple test suite: Just inherit CxxTest::TestSuite and write tests! |
|---|
| 8 | // |
|---|
| 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 DigitalModulator_TestMiscellaneousFunctions : public CxxTest::TestSuite, |
|---|
| 14 | public DigitalModem |
|---|
| 15 | { |
|---|
| 16 | public: |
|---|
| 17 | |
|---|
| 18 | void test_ConvertBitsToSymbol_01() { |
|---|
| 19 | char b[2] = {BIT0, BIT1}; |
|---|
| 20 | |
|---|
| 21 | unsigned short s; |
|---|
| 22 | |
|---|
| 23 | SetModulationScheme( SigProc::BPSK ); |
|---|
| 24 | |
|---|
| 25 | for (unsigned int i=0; i<2; i++) { |
|---|
| 26 | ConvertBitsToSymbol(b+i*bitsPerSymbol, s); |
|---|
| 27 | TS_ASSERT_EQUALS( s, i ); |
|---|
| 28 | } |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | void test_ConvertBitsToSymbol_02() { |
|---|
| 32 | char b[8] = {BIT0, BIT0, |
|---|
| 33 | BIT0, BIT1, |
|---|
| 34 | BIT1, BIT0, |
|---|
| 35 | BIT1, BIT1}; |
|---|
| 36 | |
|---|
| 37 | unsigned short s; |
|---|
| 38 | |
|---|
| 39 | SetModulationScheme( SigProc::QPSK ); |
|---|
| 40 | |
|---|
| 41 | for (unsigned int i=0; i<4; i++) { |
|---|
| 42 | ConvertBitsToSymbol(b+i*bitsPerSymbol, s); |
|---|
| 43 | TS_ASSERT_EQUALS( s, i ); |
|---|
| 44 | } |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | void test_ConvertBitsToSymbol_03() { |
|---|
| 48 | char b[24] = {BIT0, BIT0, BIT0, |
|---|
| 49 | BIT0, BIT0, BIT1, |
|---|
| 50 | BIT0, BIT1, BIT0, |
|---|
| 51 | BIT0, BIT1, BIT1, |
|---|
| 52 | BIT1, BIT0, BIT0, |
|---|
| 53 | BIT1, BIT0, BIT1, |
|---|
| 54 | BIT1, BIT1, BIT0, |
|---|
| 55 | BIT1, BIT1, BIT1}; |
|---|
| 56 | |
|---|
| 57 | unsigned short s; |
|---|
| 58 | |
|---|
| 59 | SetModulationScheme( SigProc::PSK8 ); |
|---|
| 60 | |
|---|
| 61 | for (unsigned int i=0; i<8; i++) { |
|---|
| 62 | ConvertBitsToSymbol(b+i*bitsPerSymbol, s); |
|---|
| 63 | TS_ASSERT_EQUALS( s, i ); |
|---|
| 64 | } |
|---|
| 65 | } |
|---|
| 66 | }; |
|---|
| 67 | |
|---|
| 68 | // NOTE: " : public CxxTest::TestSuite" must be on the same line as the class |
|---|
| 69 | // definition, otherwise the python script does not recognize it |
|---|
| 70 | // as a test class |
|---|
| 71 | class DigitalModulator_TestModulation : public CxxTest::TestSuite, |
|---|
| 72 | public DigitalModem |
|---|
| 73 | { |
|---|
| 74 | public: |
|---|
| 75 | |
|---|
| 76 | void test_ModulateBPSK() { |
|---|
| 77 | char b[2] = {BIT0, BIT1}; |
|---|
| 78 | short * I_out = new short[2]; |
|---|
| 79 | short * Q_out = new short[2]; |
|---|
| 80 | |
|---|
| 81 | SetModulationScheme( SigProc::BPSK ); |
|---|
| 82 | ModulateSequence( b, 2, I_out, Q_out ); |
|---|
| 83 | |
|---|
| 84 | TS_ASSERT_EQUALS( I_out[0], -BPSK_LEVEL ); |
|---|
| 85 | TS_ASSERT_EQUALS( Q_out[0], 0 ); |
|---|
| 86 | |
|---|
| 87 | TS_ASSERT_EQUALS( I_out[1], BPSK_LEVEL ); |
|---|
| 88 | TS_ASSERT_EQUALS( Q_out[1], 0 ); |
|---|
| 89 | |
|---|
| 90 | delete [] I_out; |
|---|
| 91 | delete [] Q_out; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | void test_ModulateQPSK() { |
|---|
| 95 | char b[8] = {BIT0, BIT0, |
|---|
| 96 | BIT0, BIT1, |
|---|
| 97 | BIT1, BIT0, |
|---|
| 98 | BIT1, BIT1}; |
|---|
| 99 | |
|---|
| 100 | short * I_out = new short[4]; |
|---|
| 101 | short * Q_out = new short[4]; |
|---|
| 102 | |
|---|
| 103 | SetModulationScheme( SigProc::QPSK ); |
|---|
| 104 | ModulateSequence( b, 8, I_out, Q_out ); |
|---|
| 105 | |
|---|
| 106 | TS_ASSERT_EQUALS( I_out[0], QPSK_LEVEL ); |
|---|
| 107 | TS_ASSERT_EQUALS( Q_out[0], QPSK_LEVEL ); |
|---|
| 108 | |
|---|
| 109 | TS_ASSERT_EQUALS( I_out[1], QPSK_LEVEL ); |
|---|
| 110 | TS_ASSERT_EQUALS( Q_out[1], -QPSK_LEVEL ); |
|---|
| 111 | |
|---|
| 112 | TS_ASSERT_EQUALS( I_out[2], -QPSK_LEVEL ); |
|---|
| 113 | TS_ASSERT_EQUALS( Q_out[2], QPSK_LEVEL ); |
|---|
| 114 | |
|---|
| 115 | TS_ASSERT_EQUALS( I_out[3], -QPSK_LEVEL ); |
|---|
| 116 | TS_ASSERT_EQUALS( Q_out[3], -QPSK_LEVEL ); |
|---|
| 117 | |
|---|
| 118 | delete [] I_out; |
|---|
| 119 | delete [] Q_out; |
|---|
| 120 | |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | void test_Modulate8PSK() { |
|---|
| 124 | char b[24] = {BIT0, BIT0, BIT0, |
|---|
| 125 | BIT0, BIT0, BIT1, |
|---|
| 126 | BIT0, BIT1, BIT0, |
|---|
| 127 | BIT0, BIT1, BIT1, |
|---|
| 128 | BIT1, BIT0, BIT0, |
|---|
| 129 | BIT1, BIT0, BIT1, |
|---|
| 130 | BIT1, BIT1, BIT0, |
|---|
| 131 | BIT1, BIT1, BIT1}; |
|---|
| 132 | |
|---|
| 133 | short * I_out = new short[8]; |
|---|
| 134 | short * Q_out = new short[8]; |
|---|
| 135 | |
|---|
| 136 | SetModulationScheme( SigProc::PSK8 ); |
|---|
| 137 | ModulateSequence(b, 24, I_out, Q_out); |
|---|
| 138 | |
|---|
| 139 | TS_ASSERT_EQUALS( I_out[0], PSK8_LEVEL_2 ); |
|---|
| 140 | TS_ASSERT_EQUALS( Q_out[0], 0 ); |
|---|
| 141 | |
|---|
| 142 | TS_ASSERT_EQUALS( I_out[1], PSK8_LEVEL_1 ); |
|---|
| 143 | TS_ASSERT_EQUALS( Q_out[1], PSK8_LEVEL_1 ); |
|---|
| 144 | |
|---|
| 145 | TS_ASSERT_EQUALS( I_out[2], PSK8_LEVEL_1 ); |
|---|
| 146 | TS_ASSERT_EQUALS( Q_out[2], -PSK8_LEVEL_1 ); |
|---|
| 147 | |
|---|
| 148 | TS_ASSERT_EQUALS( I_out[3], 0 ); |
|---|
| 149 | TS_ASSERT_EQUALS( Q_out[3], -PSK8_LEVEL_2 ); |
|---|
| 150 | |
|---|
| 151 | TS_ASSERT_EQUALS( I_out[4], -PSK8_LEVEL_1 ); |
|---|
| 152 | TS_ASSERT_EQUALS( Q_out[4], PSK8_LEVEL_1 ); |
|---|
| 153 | |
|---|
| 154 | TS_ASSERT_EQUALS( I_out[5], 0 ); |
|---|
| 155 | TS_ASSERT_EQUALS( Q_out[5], PSK8_LEVEL_2 ); |
|---|
| 156 | |
|---|
| 157 | TS_ASSERT_EQUALS( I_out[6], -PSK8_LEVEL_2 ); |
|---|
| 158 | TS_ASSERT_EQUALS( Q_out[6], 0 ); |
|---|
| 159 | |
|---|
| 160 | TS_ASSERT_EQUALS( I_out[7], -PSK8_LEVEL_1 ); |
|---|
| 161 | TS_ASSERT_EQUALS( Q_out[7], -PSK8_LEVEL_1 ); |
|---|
| 162 | |
|---|
| 163 | delete [] I_out; |
|---|
| 164 | delete [] Q_out; |
|---|
| 165 | |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | void test_Modulate16QAM() { |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | void test_Modulate4PAM() { |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | }; |
|---|
| 175 | |
|---|
| 176 | #endif |
|---|
| 177 | |
|---|