1 /* ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License
8 * Version 1.1 (the "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
14 * the specific language governing rights and limitations under the License.
16 * The Original Code is BBC Research code.
18 * The Initial Developer of the Original Code is the British Broadcasting
20 * Portions created by the Initial Developer are Copyright (C) 2007.
21 * All Rights Reserved.
23 * Contributor(s): Andrea Gabriellini (Original Author)
25 * Alternatively, the contents of this file may be used under the terms of
26 * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
27 * Public License Version 2.1 (the "LGPL"), in which case the provisions of
28 * the GPL or the LGPL are applicable instead of those above. If you wish to
29 * allow use of your version of this file only under the terms of the either
30 * the GPL or LGPL and not to allow others to use your version of this file
31 * under the MPL, indicate your decision by deleting the provisions above
32 * and replace them with the notice and other provisions required by the GPL
33 * or LGPL. If you do not delete the provisions above, a recipient may use
34 * your version of this file under the terms of any one of the MPL, the GPL
36 * ***** END LICENSE BLOCK ***** */
42 #include <unittest/AccessUnitTest.hpp>
43 #include <unittest/core_suite.hpp>
45 #include <parser/AccessUnit.hpp>
47 using ::dirac::parser_project::AccessUnit
;
49 //NOTE: ensure that the suite is added to the default registry in
50 //cppunit_testsuite.cpp
51 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION (AccessUnitTest
, coreSuiteName());
53 AccessUnitTest::AccessUnitTest() {}
55 AccessUnitTest::~AccessUnitTest() {}
58 AccessUnitTest::setUp()
60 data_
= new uint8
[ARRAY_SIZE
];
61 memset ( static_cast<void*> ( data_
), 0, ARRAY_SIZE
);
63 fillBuffer ( data_
+ SEQHDR_START
, SEQUENCE_HEADER
64 , SEQHDR_NEXT
, SEQHDR_PREV
);
65 fillBuffer ( data_
+ PIC1_START
, INTRA_REF_AC
, PIC1_NEXT
, PIC1_PREV
);
66 write4Bytes ( data_
+ PIC1_START
+ 13, 0 );
67 fillBuffer ( data_
+ PIC2_START
, INTER_REF_AC_1REF
, PIC2_NEXT
, PIC2_PREV
);
68 write4Bytes ( data_
+ PIC2_START
+ 13, 1 );
69 fillBuffer ( data_
+ PAD_START
, PADDING_DATA
, PAD_NEXT
, PAD_PREV
);
70 fillBuffer ( data_
+ PIC3_START
, INTER_NON_REF_AC_1REF
71 , PIC3_NEXT
, PIC3_PREV
);
72 write4Bytes ( data_
+ PIC3_START
+ 13, 2 );
73 fillBuffer ( data_
+ AUX_START
, AUX_DATA
, AUX_NEXT
, AUX_PREV
);
74 fillBuffer ( data_
+ EOS_START
, END_OF_SEQUENCE
, EOS_NEXT
, EOS_PREV
);
78 AccessUnitTest::tearDown()
84 AccessUnitTest::testAccessUnit()
86 uint8
* buffer
= data_
+ SEQHDR_START
;
87 CPPUNIT_ASSERT ( AccessUnit ( buffer
, SEQHDR_NEXT
).isSequenceHeader() );
88 CPPUNIT_ASSERT_EQUAL ( AccessUnit ( buffer
, SEQHDR_NEXT
).size()
89 , static_cast<size_t> ( SEQHDR_NEXT
) );
91 au
.setp ( data_
+ PIC1_START
, PIC1_NEXT
);
92 CPPUNIT_ASSERT ( !au
.empty() );
93 CPPUNIT_ASSERT_EQUAL ( au
.size(), static_cast<size_t> ( PIC1_NEXT
) );
94 CPPUNIT_ASSERT ( au
.isPicture() );
95 CPPUNIT_ASSERT ( au
.isIPicture() );
96 std::auto_ptr
<AccessUnit::Buffer
> buf ( au
.releaseBuffer() );
97 CPPUNIT_ASSERT_EQUAL ( buf
->size(), static_cast<size_t> ( PIC1_NEXT
) );
98 au
.setp ( data_
+ PAD_START
, PAD_NEXT
);
99 CPPUNIT_ASSERT ( !au
.isAuxiliaryData() );
100 CPPUNIT_ASSERT ( au
.isPaddingData() );
101 CPPUNIT_ASSERT ( AccessUnit ( data_
+ EOS_START
, 13 ).isEndOfSequence() );
102 CPPUNIT_ASSERT ( !AccessUnit ( data_
+ EOS_START
, 13 ).isSequenceHeader() );
106 AccessUnitTest::fillBuffer ( uint8
* buffer
, uint8 parseCode
107 , uint32 next
, uint32 prev
)
113 *buffer
++ = parseCode
;
114 write4Bytes ( buffer
, next
);
115 write4Bytes ( buffer
+ 4, prev
);
119 AccessUnitTest::write4Bytes ( uint8
* buffer
, uint32 data
)
121 *buffer
++ = static_cast<uint8
> ( ( data
& 0xFF000000 ) >> 24 );
122 *buffer
++ = static_cast<uint8
> ( ( data
& 0x00FF0000 ) >> 16 );
123 *buffer
++ = static_cast<uint8
> ( ( data
& 0x0000FF00 ) >> 8 );
124 *buffer
= static_cast<uint8
> ( data
& 0x000000FF );