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>
27 static unsigned int expected_initial_states[] = {
38 static unsigned char expected_initial_values[] = {
49 #define NELEMENTS(ary) ((sizeof (ary)) / sizeof (ary[0]))
52 qa_atsci_randomizer::t0_compare_output_maps ()
54 for (int i = 0; i < 0x10000; i++){
55 unsigned char slow = atsci_randomizer::slow_output_map(i);
56 unsigned char fast = atsci_randomizer::fast_output_map(i);
57 CPPUNIT_ASSERT_EQUAL (slow, fast);
62 qa_atsci_randomizer::t1_initial_states ()
64 // LFSR should start with expected states
66 for (unsigned int i = 0; i < NELEMENTS (expected_initial_values); i++){
67 unsigned int got = randomizer.state();
69 CPPUNIT_ASSERT_EQUAL (expected_initial_states[i], got);
74 qa_atsci_randomizer::t2_initial_values ()
76 // LFSR should start with expected values
78 for (unsigned int i = 0; i < NELEMENTS (expected_initial_values); i++){
79 unsigned char got = randomizer.output_and_clk ();
80 CPPUNIT_ASSERT_EQUAL (expected_initial_values[i], got);
85 qa_atsci_randomizer::t3_reset ()
87 // LFSR should start with expected values
89 for (unsigned int i = 0; i < NELEMENTS (expected_initial_values); i++){
90 unsigned char got = randomizer.output_and_clk ();
91 CPPUNIT_ASSERT_EQUAL (expected_initial_values[i], got);
94 randomizer.reset (); // reset LFSR
96 // and now should repeat expected values
98 for (unsigned int i = 0; i < NELEMENTS (expected_initial_values); i++){
99 unsigned char got = randomizer.output_and_clk ();
100 CPPUNIT_ASSERT_EQUAL (expected_initial_values[i], got);
105 qa_atsci_randomizer::t4_high_level ()
107 static const int N = 5;
109 atsc_mpeg_packet in[N];
110 atsc_mpeg_packet_no_sync middle[N];
111 atsc_mpeg_packet out[N];
113 memset (in, 0, sizeof (in));
114 memset (middle, 0, sizeof (middle));
115 memset (out, 0, sizeof (out));
117 // setup input test data
120 for (int n = 0; n < N; n++){
121 in[n].data[0] = MPEG_SYNC_BYTE;
122 for (int i = 0; i < ATSC_MPEG_DATA_LENGTH; i++)
123 in[n].data[i + 1] = counter++;
126 // randomize N packets
128 for (int n = 0; n < N; n++)
129 randomizer.randomize (middle[n], in[n]);
131 // reset LFSR and derandomize N packets
133 randomizer.reset (); // reset LFSR
135 for (int n = 0; n < N; n++)
136 randomizer.derandomize (out[n], middle[n]);
140 for (int n = 0; n < N; n++){
141 CPPUNIT_ASSERT (in[n] == out[n]);