Houston, we have a trunk.
[debian/gnuradio] / gr-atsc / src / lib / qa_atsci_trellis_encoder.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2002 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
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 2, or (at your option)
10  * any later version.
11  * 
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.
16  * 
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., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <cppunit/TestAssert.h>
28 #include <qa_atsci_trellis_encoder.h>
29 #include <cstdio>
30 #include <string.h>
31 #include <stdlib.h>
32 #include <time.h>
33
34 #define NELEM(x) (sizeof (x) / sizeof (x[0]))
35
36
37 static const int NCODERS = atsci_trellis_encoder::NCODERS;
38
39 void
40 qa_atsci_trellis_encoder::t0 ()
41 {
42 #if 0           // generate i/o test data for t1
43
44   atsc_mpeg_packet_rs_encoded   in[NCODERS];
45   atsc_data_segment             out[NCODERS];
46
47   
48   memset (in,  0, sizeof (in));
49   memset (out, 0, sizeof (out));
50
51   srandom (1);
52
53   printf ("@@@ INPUT @@@\n");
54   for (int i = 0; i < NCODERS; i++){
55     for (unsigned int j = 0; j < NELEM (in[i].data); j++){
56       int t = (random () >> 8) & 0xff;  // 8 random bits
57       in[i].data[j] = t;
58       printf ("%d\n", t);
59     }
60   }
61   
62   enc.reset ();
63   enc.encode (out, in);
64
65   printf ("@@@ OUTPUT @@@\n");
66   for (int i = 0; i < NCODERS; i++){
67     for (unsigned int j = 0; j < NELEM (out[i].data); j++){
68        printf ("%d\n", out[i].data[j]);
69     }
70   }
71 #endif
72 }
73
74 void
75 qa_atsci_trellis_encoder::t1 ()
76 {
77   atsc_mpeg_packet_rs_encoded   in[NCODERS];
78   atsc_data_segment             expected_out[NCODERS];
79   atsc_data_segment             actual_out[NCODERS];
80   static const unsigned char    raw_input[NCODERS * NELEM (in[0].data)] = {
81 #include "qa_atsci_trellis_encoder_t1_input.dat"
82   };
83   static const unsigned char    raw_output[NCODERS * NELEM (expected_out[0].data)] = {
84 #include "qa_atsci_trellis_encoder_t1_output.dat"
85   };
86
87
88   // load up input
89   const unsigned char *r = &raw_input[0];
90   for (int i = 0; i < NCODERS; i++){
91     in[i].pli.set_regular_seg (false, i);
92     for (unsigned int j = 0; j < NELEM (in[i].data); j++){
93       in[i].data[j] = *r++;
94     }
95   }
96
97   // load up expected output
98   r = &raw_output[0];
99   for (int i = 0; i < NCODERS; i++){
100     expected_out[i].pli.set_regular_seg (false, i);
101     for (unsigned int j = 0; j < NELEM (expected_out[i].data); j++){
102       expected_out[i].data[j] = *r++;
103     }
104   }
105
106   memset (&actual_out, 0, sizeof (actual_out));         // ensure zero
107
108   enc.reset ();
109   enc.encode (actual_out, in);                          // trellis code test data
110
111   for (int i = 0; i < NCODERS; i++){                    // check the result
112     CPPUNIT_ASSERT (expected_out[i] == actual_out[i]);
113     CPPUNIT_ASSERT (expected_out[i].pli == actual_out[i].pli);
114   }
115 }