forked from kynesim/tstools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_nal_unit_list.c
174 lines (163 loc) · 4.38 KB
/
test_nal_unit_list.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
* A simple test for the NAL unit lists from nalunit.c
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the MPEG TS, PS and ES tools.
*
* The Initial Developer of the Original Code is Amino Communications Ltd.
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Amino Communications Ltd, Swavesey, Cambridge UK
*
* ***** END LICENSE BLOCK *****
*/
#include <stdio.h>
#include <stdlib.h>
#include "compat.h"
#include "nalunit_fns.h"
int main(int argc, char **argv)
{
int err, ii;
int max = NAL_UNIT_LIST_START_SIZE + NAL_UNIT_LIST_INCREMENT + 3;
nal_unit_list_p list = NULL;
nal_unit_p unit = NULL;
printf("NAL unit lists are now handled as NAL unit lists, so...\n");
printf("Testing NAL unit list\n");
printf("Test 1 - differing NAL units\n");
err = build_nal_unit_list(&list);
if (err)
{
printf("Test failed - constructing list\n");
return 1;
}
for (ii=0; ii<max; ii++)
{
err = build_nal_unit(&unit);
if (err)
{
printf("Test failed - constructing NAL unit\n");
return 1;
}
err = append_to_nal_unit_list(list,unit);
if (err)
{
printf("Test failed - appending NAL unit %d\n",ii);
return 1;
}
if (list->length > list->size)
{
printf("Test failed - list length = %d, size = %d\n",
list->length,list->size);
return 1;
}
else if (list->length != ii+1)
{
printf("Test failed - list length is %d, expected %d\n",
list->length,ii+1);
return 1;
}
else if (list->array[ii] != unit)
{
printf("Test failed - list->array[%d] is %p, expected %p\n",
ii,list->array[ii],unit);
return 1;
}
}
printf("Test 1 - resetting list\n");
reset_nal_unit_list(list,TRUE);
if (list->length != 0)
{
printf("Test failed - list length is %d, not 0\n",list->length);
return 1;
}
if (list->array[0] != NULL)
{
printf("Test failed - list->array[0] is %p, not NULL\n",list->array[0]);
return 1;
}
// And try populating the list again, but a bit further this time
for (ii=0; ii<max+NAL_UNIT_LIST_INCREMENT; ii++)
{
err = build_nal_unit(&unit);
if (err)
{
printf("Test failed - constructing NAL unit\n");
return 1;
}
err = append_to_nal_unit_list(list,unit);
if (err)
{
printf("Test failed - appending NAL unit %d\n",ii);
return 1;
}
if (list->length > list->size)
{
printf("Test failed - list length = %d, size = %d\n",
list->length,list->size);
return 1;
}
else if (list->length != ii+1)
{
printf("Test failed - list length is %d, expected %d\n",
list->length,ii+1);
return 1;
}
else if (list->array[ii] != unit)
{
printf("Test failed - list->array[%d] is %p, expected %p\n",
ii,list->array[ii],unit);
return 1;
}
}
printf("Test 1 - clearing list\n");
free_nal_unit_list(&list,TRUE);
printf("Test 1 succeeded\n");
printf("Test 2 - the same NAL unit inserted multiple times\n");
err = build_nal_unit_list(&list);
if (err)
{
printf("Test failed - constructing list\n");
return 1;
}
err = build_nal_unit(&unit);
if (err)
{
printf("Test failed - constructing NAL unit\n");
return 1;
}
// We aren't testing allocation limits this time round
for (ii=0; ii<5; ii++)
{
err = append_to_nal_unit_list(list,unit);
if (err)
{
printf("Test failed - appending NAL unit %d\n",ii);
return 1;
}
}
printf("Test 2 - clearing list\n");
free_nal_unit_list(&list,FALSE); // better only do a shallow free
free_nal_unit(&unit);
printf("Test 2 succeeded\n");
return 0;
}
// Local Variables:
// tab-width: 8
// indent-tabs-mode: nil
// c-basic-offset: 2
// End:
// vim: set tabstop=8 shiftwidth=2 expandtab: