From: <pa...@us...> - 2007-09-25 15:38:19
|
Revision: 3171 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=3171&view=rev Author: pak21 Date: 2007-09-25 08:38:23 -0700 (Tue, 25 Sep 2007) Log Message: ----------- Add beginnings of test to check implementation of every TZX block type. Modified Paths: -------------- trunk/libspectrum/Makefile.am trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/test/Makefile.am trunk/libspectrum/test/test.c Added Paths: ----------- trunk/libspectrum/test/complete-tzx.pl trunk/libspectrum/test/edges.c trunk/libspectrum/test/test.h trunk/libspectrum/test/test15.c Property Changed: ---------------- trunk/libspectrum/test/ Modified: trunk/libspectrum/Makefile.am =================================================================== --- trunk/libspectrum/Makefile.am 2007-09-25 13:27:48 UTC (rev 3170) +++ trunk/libspectrum/Makefile.am 2007-09-25 15:38:23 UTC (rev 3171) @@ -67,6 +67,7 @@ noinst_HEADERS = internals.h noinst_PROGRAMS = +noinst_DATA = AM_CFLAGS = -DLIBSPECTRUM_EXPORTS Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2007-09-25 13:27:48 UTC (rev 3170) +++ trunk/libspectrum/hacking/ChangeLog 2007-09-25 15:38:23 UTC (rev 3171) @@ -519,3 +519,6 @@ 20070905 Makefile.am: clean generated files on 'make clean' etc. (Stuart). 20070905 configure.in: add --disable-libaudiofile option (Stuart). 20070925 test/invalid-warajevo-blockoffset.tap: reduce to minimal testcase. +20070925 Makefile.am,test/{Makefile.am,complete-tzx.pl,edges.c,test.c,test.h, + test15.c}: add beginnings of test to check implementation of every + TZX block type. Property changes on: trunk/libspectrum/test ___________________________________________________________________ Name: svn:ignore - .deps .dirstamp .libs Makefile Makefile.in test test.exe + .deps .dirstamp .libs Makefile Makefile.in complete-tzx.tzx test test.exe Modified: trunk/libspectrum/test/Makefile.am =================================================================== --- trunk/libspectrum/test/Makefile.am 2007-09-25 13:27:48 UTC (rev 3170) +++ trunk/libspectrum/test/Makefile.am 2007-09-25 15:38:23 UTC (rev 3171) @@ -23,6 +23,18 @@ noinst_PROGRAMS += test/test +test_test_SOURCES = \ + test/edges.c \ + test/test.c \ + test/test15.c + +noinst_DATA += test/complete-tzx.tzx + +noinst_HEADERS += test/test.h + +test/complete-tzx.tzx: test/complete-tzx.pl + perl $< > $@.tmp && mv $@.tmp $@ + test_test_LDADD = libspectrum.la EXTRA_DIST += \ Added: trunk/libspectrum/test/complete-tzx.pl =================================================================== --- trunk/libspectrum/test/complete-tzx.pl (rev 0) +++ trunk/libspectrum/test/complete-tzx.pl 2007-09-25 15:38:23 UTC (rev 3171) @@ -0,0 +1,81 @@ +#!/usr/bin/perl + +use warnings; +use strict; + +sub write_byte { + + my( $b ) = @_; + + printf "%c", $b; +} + +sub write_word { + + my( $w ) = @_; + + write_byte( $w % 0x100 ); + write_byte( $w / 0x100 ); +} + +sub write_three { + + my( $three ) = @_; + + write_byte( $three % 0x100 ); + write_word( $three / 0x100 ); + +} + +sub write_dword { + + my( $dw ) = @_; + + write_word( $dw % 0x10000 ); + write_word( $dw / 0x10000 ); +} + +sub write_header { + + print "ZXTape!\x1a"; # Signature + write_byte( 1 ); # Major version number + write_byte( 20 ); # Minor version number + +} + +sub write_standard_speed_data_block { + + my( $data, $pause ) = @_; + + write_byte( 0x10 ); + write_word( $pause ); + write_word( length $data ); + print $data; + +} + +sub write_turbo_speed_data_block { + + my( $pilot_length, $pilot_count, $sync1_length, $sync2_length, + $zero_length, $one_length, $data, $bits_in_last_byte, $pause ) = @_; + + write_byte( 0x11 ); + write_word( $pilot_length ); + write_word( $sync1_length ); + write_word( $sync2_length ); + write_word( $zero_length ); + write_word( $one_length ); + write_word( $pilot_count ); + write_byte( $bits_in_last_byte ); + write_word( $pause ); + write_three( length $data ); + print $data; + +} + +write_header(); + +write_standard_speed_data_block( "\xaa", 2345 ); + +write_turbo_speed_data_block( 1000, 5, 123, 456, 789, 400, "\x00\xff\x55\xa0", + 4, 987 ); Property changes on: trunk/libspectrum/test/complete-tzx.pl ___________________________________________________________________ Name: svn:executable + * Added: trunk/libspectrum/test/edges.c =================================================================== --- trunk/libspectrum/test/edges.c (rev 0) +++ trunk/libspectrum/test/edges.c 2007-09-25 15:38:23 UTC (rev 3171) @@ -0,0 +1,64 @@ +#include "test.h" + +test_return_t +check_edges( const char *filename, test_edge_sequence_t *edges ) +{ + libspectrum_byte *buffer = NULL; + size_t filesize = 0; + libspectrum_tape *tape; + test_return_t r = TEST_FAIL; + test_edge_sequence_t *ptr = edges; + + if( read_file( &buffer, &filesize, filename ) ) return TEST_INCOMPLETE; + + if( libspectrum_tape_alloc( &tape ) ) { + free( buffer ); + return TEST_INCOMPLETE; + } + + if( libspectrum_tape_read( tape, buffer, filesize, LIBSPECTRUM_ID_UNKNOWN, + filename ) != LIBSPECTRUM_ERROR_NONE ) { + libspectrum_tape_free( tape ); + free( buffer ); + return TEST_INCOMPLETE; + } + + free( buffer ); + + while( 1 ) { + + libspectrum_dword tstates; + int flags; + libspectrum_error e; + + e = libspectrum_tape_get_next_edge( &tstates, &flags, tape ); + if( e ) { + libspectrum_tape_free( tape ); + return TEST_INCOMPLETE; + } + + if( flags & LIBSPECTRUM_TAPE_FLAGS_STOP ) { + if( ptr->length == 0 ) { + r = TEST_PASS; + } else { + fprintf( stderr, "%s: expected end of tape, got %d tstates\n", + progname, tstates ); + } + break; + } + + if( tstates != ptr->length ) { + fprintf( stderr, "%s: expected %d tstates, got %d tstates\n", progname, + ptr->length, tstates ); + break; + } + + if( --ptr->count == 0 ) ptr++; + } + + if( libspectrum_tape_free( tape ) ) return TEST_INCOMPLETE; + + return r; +} + + Modified: trunk/libspectrum/test/test.c =================================================================== --- trunk/libspectrum/test/test.c 2007-09-25 13:27:48 UTC (rev 3170) +++ trunk/libspectrum/test/test.c 2007-09-25 15:38:23 UTC (rev 3171) @@ -6,24 +6,18 @@ #include <sys/types.h> #include <unistd.h> -#include "libspectrum.h" +#include "test.h" const char *progname; -const char *LIBSPECTRUM_MIN_VERSION = "0.3.0.1"; +static const char *LIBSPECTRUM_MIN_VERSION = "0.3.0.1"; -typedef enum test_return_t { - TEST_PASS, - TEST_FAIL, - TEST_INCOMPLETE, -} test_return_t; - typedef test_return_t (*test_fn)( void ); #ifndef O_BINARY #define O_BINARY 0 #endif -static int +int read_file( libspectrum_byte **buffer, size_t *length, const char *filename ) { int fd; @@ -389,6 +383,7 @@ { test_12, "Invalid TZX custom info block causes memory leak", 0 }, { test_13, "TZX loop end block with loop start block", 0 }, { test_14, "TZX loop blocks", 0 }, + { test_15, "Complete TZX file", 0 }, }; static size_t test_count = sizeof( tests ) / sizeof( tests[0] ); Added: trunk/libspectrum/test/test.h =================================================================== --- trunk/libspectrum/test/test.h (rev 0) +++ trunk/libspectrum/test/test.h 2007-09-25 15:38:23 UTC (rev 3171) @@ -0,0 +1,28 @@ +#ifndef TEST_TEST_H +#define TEST_TEST_H + +#include "libspectrum.h" + +extern const char *progname; + +typedef enum test_return_t { + TEST_PASS, + TEST_FAIL, + TEST_INCOMPLETE, +} test_return_t; + +typedef struct test_edge_sequence_t { + + libspectrum_dword length; + size_t count; + +} test_edge_sequence_t; + +int read_file( libspectrum_byte **buffer, size_t *length, + const char *filename ); + +test_return_t check_edges( const char *filename, test_edge_sequence_t *edges ); + +test_return_t test_15( void ); + +#endif Added: trunk/libspectrum/test/test15.c =================================================================== --- trunk/libspectrum/test/test15.c (rev 0) +++ trunk/libspectrum/test/test15.c 2007-09-25 15:38:23 UTC (rev 3171) @@ -0,0 +1,53 @@ +#include "test.h" + +static test_edge_sequence_t +complete_edges_list[] = +{ + /* Standard speed data block */ + { 2168, 3223 }, /* Pilot */ + { 667, 1 }, /* Sync 1 */ + { 735, 1 }, /* Sync 2 */ + + { 1710, 2 }, /* Bit 1 */ + { 855, 2 }, /* Bit 2 */ + { 1710, 2 }, /* Bit 3 */ + { 855, 2 }, /* Bit 4 */ + { 1710, 2 }, /* Bit 5 */ + { 855, 2 }, /* Bit 6 */ + { 1710, 2 }, /* Bit 7 */ + { 855, 2 }, /* Bit 8 */ + + { 8194368, 1 }, /* Pause */ + + /* Turbo speed data block */ + { 1000, 5 }, /* Pilot */ + { 123, 1 }, /* Sync 1 */ + { 456, 1 }, /* Sync 2 */ + + { 789, 16 }, /* Byte 1, bits 1-8 */ + { 400, 16 }, /* Byte 2, bits 1-8 */ + + { 789, 2 }, /* Byte 3, bit 1 */ + { 400, 2 }, /* Byte 3, bit 2 */ + { 789, 2 }, /* Byte 3, bit 3 */ + { 400, 2 }, /* Byte 3, bit 4 */ + { 789, 2 }, /* Byte 3, bit 5 */ + { 400, 2 }, /* Byte 3, bit 6 */ + { 789, 2 }, /* Byte 3, bit 7 */ + { 400, 2 }, /* Byte 3, bit 8 */ + + { 400, 2 }, /* Byte 4, bit 1 */ + { 789, 2 }, /* Byte 4, bit 2 */ + { 400, 2 }, /* Byte 4, bit 3 */ + { 789, 2 }, /* Byte 4, bit 4 */ + + { 0, 0 } /* End marker */ + +}; + +test_return_t +test_15( void ) +{ + return check_edges( "complete-tzx.tzx", complete_edges_list ); +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |