3 * Copyright 2002 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
23 #include <qa_atsci_randomizer.h>
25 #include <cppunit/TestAssert.h>
28 static unsigned int expected_initial_states[] = {
39 static unsigned char expected_initial_values[] = {
50 #define NELEMENTS(ary) ((sizeof (ary)) / sizeof (ary[0]))
53 qa_atsci_randomizer::t0_compare_output_maps ()
55 for (int i = 0; i < 0x10000; i++){
56 unsigned char slow = atsci_randomizer::slow_output_map(i);
57 unsigned char fast = atsci_randomizer::fast_output_map(i);
58 CPPUNIT_ASSERT_EQUAL (slow, fast);
63 qa_atsci_randomizer::t1_initial_states ()
65 // LFSR should start with expected states
67 for (unsigned int i = 0; i < NELEMENTS (expected_initial_values); i++){
68 unsigned int got = randomizer.state();
70 CPPUNIT_ASSERT_EQUAL (expected_initial_states[i], got);
75 qa_atsci_randomizer::t2_initial_values ()
77 // LFSR should start with expected values
79 for (unsigned int i = 0; i < NELEMENTS (expected_initial_values); i++){
80 unsigned char got = randomizer.output_and_clk ();
81 CPPUNIT_ASSERT_EQUAL (expected_initial_values[i], got);
86 qa_atsci_randomizer::t3_reset ()
88 // LFSR should start with expected values
90 for (unsigned int i = 0; i < NELEMENTS (expected_initial_values); i++){
91 unsigned char got = randomizer.output_and_clk ();
92 CPPUNIT_ASSERT_EQUAL (expected_initial_values[i], got);
95 randomizer.reset (); // reset LFSR
97 // and now should repeat expected values
99 for (unsigned int i = 0; i < NELEMENTS (expected_initial_values); i++){
100 unsigned char got = randomizer.output_and_clk ();
101 CPPUNIT_ASSERT_EQUAL (expected_initial_values[i], got);
106 qa_atsci_randomizer::t4_high_level ()
108 static const int N = 5;
110 atsc_mpeg_packet in[N];
111 atsc_mpeg_packet_no_sync middle[N];
112 atsc_mpeg_packet out[N];
114 memset (in, 0, sizeof (in));
115 memset (middle, 0, sizeof (middle));
116 memset (out, 0, sizeof (out));
118 // setup input test data
121 for (int n = 0; n < N; n++){
122 in[n].data[0] = MPEG_SYNC_BYTE;
123 for (int i = 0; i < ATSC_MPEG_DATA_LENGTH; i++)
124 in[n].data[i + 1] = counter++;
127 // randomize N packets
129 for (int n = 0; n < N; n++)
130 randomizer.randomize (middle[n], in[n]);
132 // reset LFSR and derandomize N packets
134 randomizer.reset (); // reset LFSR
136 for (int n = 0; n < N; n++)
137 randomizer.derandomize (out[n], middle[n]);
141 for (int n = 0; n < N; n++){
142 CPPUNIT_ASSERT (in[n] == out[n]);