Skip to content

Commit df25f03

Browse files
committed
Fixed broken tests.
Incomplete tables not correctly returning error codes. Fixed incorrect test data when parsing pes headers.
1 parent b8382df commit df25f03

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ tests: static $(OBJ_TESTS)
6262
examples: static $(OBJ_EXAMPLES)
6363

6464
check: tests $(OBJ_TESTS)
65-
find test/*.o -type f -exec "{}" \;
65+
./test-runner.sh
66+
6667
ifeq ($(COVERAGE), 1)
6768
mkdir -p $(CCDIR)
6869
rm -f *.gcno

src/tsdemux.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ TSDCode get_data_context(TSDemuxContext *ctx,
346346
}
347347
ctx->buffers.pool = dataCtx;
348348
ctx->buffers.length = len;
349-
// reassign the active buffer
349+
// reassign the active buffer if it was previously set
350350
if(active_idx >= 0) {
351351
ctx->buffers.active = &ctx->buffers.pool[active_idx];
352352
}
@@ -432,10 +432,6 @@ TSDCode tsd_parse_table(TSDemuxContext *ctx,
432432
section_count++;
433433

434434
if((ptr+1) < dataCtx->write && (*(ptr+1) == 0xFF) || (0x00 == *(ptr+1))) {
435-
// we found the end of the table,
436-
// clear the active buffer seeing as we've finished with the table
437-
ctx->buffers.active = NULL;
438-
439435
// create and parse the sections.
440436
table->length = section_count;
441437
table->sections = (TSDTableSection*) ctx->calloc(section_count,
@@ -451,6 +447,13 @@ TSDCode tsd_parse_table(TSDemuxContext *ctx,
451447

452448
if(res != TSD_OK) {
453449
tsd_table_data_destroy(ctx, table);
450+
if(res == TSD_INVALID_DATA_SIZE) {
451+
res = TSD_INCOMPLETE_TABLE;
452+
}
453+
} else {
454+
// we found the end of the table,
455+
// clear the active buffer seeing as we've finished with the table
456+
ctx->buffers.active = NULL;
454457
}
455458
return res;
456459
}

test-runner.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
pass=0
3+
total=0;
4+
5+
for fname in test/*.o; do
6+
echo ======================================
7+
echo running test suite: $fname
8+
echo ======================================
9+
./$fname
10+
rc=$?; if [[ $rc == 0 ]]; then ((pass++)); fi
11+
((total++))
12+
done
13+
14+
echo
15+
echo ======================================
16+
echo $pass/$total test suites passing
17+
echo ======================================
18+
echo

test/parse_pes_header.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void test_parse_pes_data(void)
5757
0x00, 0x3C, // packet length
5858
0b10000010, // '10', scrmabling(2), priority(1), data alignment(1), copyright(1), original or copy(1)
5959
0b11101011, // pts dts(2), escr(1), es rate(1), dsm trick play(1), add copy info(1), crc (1), ext (1)
60-
0x34, // pes header data length
60+
0x49, // pes header data length
6161
0b00100001, 0x00, 0x01, 0x00, 0x01, // '0010', pts 4,3,1,15,1,15,1
6262
0b00011001, 0x00, 0x01, 0x00, 0x01, // '0001', dts 4,3,1,15,1,15,1
6363
0b11000100, 0x00, 0b00000100, 0x00, 0b00000100, 0x01, // ESCR, reserved(2), 3,1,15,1,15,1 ext 9,1
@@ -114,7 +114,7 @@ void test_parse_pes_data(void)
114114
test_assert_equal(pes.flags & TSD_PPF_ADDITIONAL_COPY_INFO_FLAG, 0x00, "additional copy info flag");
115115
test_assert_equal(pes.flags & TSD_PPF_PES_CRC_FLAG, TSD_PPF_PES_CRC_FLAG, "CRC flag");
116116
test_assert_equal(pes.flags & TSD_PPF_PES_EXTENSION_FLAG, TSD_PPF_PES_EXTENSION_FLAG, "PES extension flag");
117-
test_assert_equal(pes.header_data_length, 0x34, "header data length");
117+
test_assert_equal(pes.header_data_length, 0x49, "header data length");
118118
test_assert_equal(pes.pts, 0x00000000, "pts");
119119
test_assert_equal(pes.dts, 0x00000000, "dts");
120120
test_assert_equal(pes.escr, 0x00000000, "escr");

test/parse_table.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ void test_parse_multi_packet_table(void)
258258
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
259259
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
260260
// +46 bytes
261+
// The section_length says there is more data to this table
261262
};
262263

263264
uint8_t tableData2[] = {

0 commit comments

Comments
 (0)