add tests

git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@3 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
halleyscometsw 2008-01-31 06:15:03 +00:00
parent 354d29cf92
commit 8cc4d7d934
3 changed files with 86 additions and 0 deletions

6
test/Makefile Normal file
View File

@ -0,0 +1,6 @@
CFLAGS=-lm
test: test.c ../src/streamfile.c ../src/vgmstream.c ../src/util.c ../src/fmt/adx.c ../src/fmt/interleave.c
clean:
rm test

38
test/filetest.c Normal file
View File

@ -0,0 +1,38 @@
#include <stdio.h>
#include "streamfile.h"
char buf[0x1002];
int main(void) {
STREAMFILE * infile;
FILE * outfile;
size_t filesize,i;
infile = open_streamfile("bob.bin");
if (!infile) {
printf("failed to open\n");
return 1;
}
outfile = fopen("fred.bin","wb");
filesize = get_streamfile_size(infile);
for (i=0;i<filesize;i+=0x1002) {
size_t bytes_read = read_streamfile(buf,i,0x1002,infile);
fwrite(buf,1,bytes_read,outfile);
if (bytes_read != 0x1002) {
if (bytes_read+i==filesize) break;
printf("error, short read\n");
break;
}
}
fclose(outfile);
close_streamfile(infile);
return 0;
}

42
test/test.c Normal file
View File

@ -0,0 +1,42 @@
#include "../src/vgmstream.h"
#include "../src/util.h"
#define BUFSIZE 4000
int main(int argc, char ** argv) {
VGMSTREAM * s;
sample buf[BUFSIZE*2];
int32_t len;
int i;
FILE * outfile = fopen("dump.bin","wb");
if (argc!=2) {printf("1 arg\n"); return 1;}
s = init_vgmstream(argv[1]);
if (!s) {
printf("open failed\n");
return 1;
}
printf("samplerate %d Hz\n",s->sample_rate);
printf("channels: %d\n",s->channels);
if (s->loop_flag) {
printf("loop start: %d samples (%lf seconds)\n",s->loop_start_sample,(double)s->loop_start_sample/s->sample_rate);
printf("loop end: %d samples (%lf seconds)\n",s->loop_end_sample,(double)s->loop_end_sample/s->sample_rate);
}
printf("file total samples %d (%lf seconds)\n",s->num_samples);
len = get_vgmstream_play_samples(2.0,10.0,s);
printf("samples to play %d (%lf seconds)\n",len,(double)len/s->sample_rate);
for (i=0;i<len;i+=BUFSIZE) {
int toget=BUFSIZE;
if (i+BUFSIZE>len) toget=len-i;
render_vgmstream(buf,toget,s);
fwrite(buf,sizeof(sample)*2,toget,outfile);
}
close_vgmstream(s);
}