1 /*
2 * libzvbi -- PDC functions unit test
3 *
4 * Copyright (C) 2008 Michael H. Schimek
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 * MA 02110-1301, USA.
20 */
21
22 /* $Id: test-pdc.h,v 1.1 2009/03/04 21:48:57 mschimek Exp $ */
23
24 #include <float.h>
25 #include <assert.h>
26 #include "src/pdc.h"
27 #include "test-common.h"
28
29 static const vbi_pil max_pil = VBI_PIL (15, 31, 31, 63);
30
31 class test_pid : public vbi_program_id {
assert_valid_any(void)32 void assert_valid_any (void) {
33 assert ((unsigned int) this->pil <= max_pil);
34 assert (0 == (this->luf & ~1));
35 assert (0 == (this->mi & ~1));
36 assert (0 == (this->prf & ~1));
37 assert ((unsigned int) this->pcs_audio <= 3);
38 assert ((unsigned int) this->pty <= 0xFF);
39 assert (0 == (this->tape_delayed & ~1));
40 assert (0 == memcmp_zero (this->_reserved2,
41 sizeof (this->_reserved2)));
42 assert (0 == memcmp_zero (this->_reserved3,
43 sizeof (this->_reserved3)));
44 }
45
assert_valid_simple(void)46 void assert_valid_simple (void) {
47 assert_valid_any ();
48 assert (0 == this->luf);
49 assert (1 == this->mi);
50 assert (0 == this->prf);
51 }
52
53 public:
clear(void)54 void clear (void) {
55 memset (this, 0, sizeof (*this));
56 }
57
randomize(void)58 void randomize (void) {
59 memset_rand (this, sizeof (*this));
60 }
61
populate_dvb(void)62 void populate_dvb (void) {
63 randomize ();
64 this->pil &= max_pil;
65 }
66
populate_vps(void)67 void populate_vps (void) {
68 populate_dvb ();
69 this->cni &= 0xFFF;
70 this->pcs_audio = (vbi_pcs_audio)
71 ((int) this->pcs_audio & 3);
72 this->pty &= 0xFF;
73 }
74
populate_ttx(void)75 void populate_ttx (void) {
76 populate_vps ();
77 this->channel = (vbi_pid_channel)
78 ((int) this->channel & 3);
79 this->luf &= 1;
80 this->mi &= 1;
81 this->prf &= 1;
82 }
83
populate_xds(void)84 void populate_xds (void) {
85 randomize ();
86 this->pil &= max_pil;
87 this->tape_delayed &= 1;
88 }
89
90 bool operator == (const test_pid& other) const {
91 /* Note: bitwise equal. */
92 return (0 == memcmp (this, &other, sizeof (this)));
93 }
94
assert_valid_ttx(void)95 void assert_valid_ttx (void) {
96 assert_valid_any ();
97 assert (this->channel >= VBI_PID_CHANNEL_LCI_0
98 && this->channel <= VBI_PID_CHANNEL_LCI_3);
99 assert (VBI_CNI_TYPE_8302 == this->cni_type);
100 assert (0 == this->tape_delayed);
101 }
102
assert_valid_vps(void)103 void assert_valid_vps (void) {
104 assert_valid_simple ();
105 assert (VBI_PID_CHANNEL_VPS == this->channel);
106 assert (VBI_CNI_TYPE_VPS == this->cni_type);
107 assert (0 == this->tape_delayed);
108 }
109
assert_valid_dvb(void)110 void assert_valid_dvb (void) {
111 assert_valid_simple ();
112 assert (VBI_PID_CHANNEL_PDC_DESCRIPTOR == this->channel);
113 assert (VBI_CNI_TYPE_NONE == this->cni_type);
114 assert (0 == this->cni);
115 assert (VBI_PCS_AUDIO_UNKNOWN == this->pcs_audio);
116 assert (0 == this->pty);
117 assert (0 == this->tape_delayed);
118 }
119
assert_valid_xds(void)120 void assert_valid_xds (void) {
121 assert_valid_simple ();
122 assert (VBI_PID_CHANNEL_XDS_CURRENT == this->channel
123 || VBI_PID_CHANNEL_XDS_FUTURE == this->channel);
124 assert (VBI_CNI_TYPE_NONE == this->cni_type);
125 assert (0 == this->cni);
126 assert (VBI_PCS_AUDIO_UNKNOWN == this->pcs_audio);
127 assert (0 == this->pty);
128 }
129 };
130
131 static time_t
132 ztime (const char * s)
133 _vbi_unused;
134
135 static time_t
ztime(const char * s)136 ztime (const char * s)
137 {
138 struct tm tm;
139 time_t t;
140
141 memset (&tm, 0, sizeof (tm));
142 assert (NULL != strptime (s, "%n%Y%m%dT%H%M%S", &tm));
143 t = timegm (&tm);
144 assert ((time_t) -1 != t);
145 return t;
146 }
147
148 #define ANY_TIME (TIME_MAX - 12345)
149
150 /*
151 Local variables:
152 c-set-style: K&R
153 c-basic-offset: 8
154 End:
155 */
156