| 1 |
#include "config.h" |
| 2 |
#include "../compat/compat.h" |
| 3 |
#include <mpg123.h> |
| 4 |
#include "../common/debug.h" |
| 5 |
|
| 6 |
int test_whence(const char* path, int scan_before) |
| 7 |
{ |
| 8 |
int err = MPG123_OK; |
| 9 |
mpg123_handle* mh = NULL; |
| 10 |
off_t length, pos; |
| 11 |
|
| 12 |
mh = mpg123_new(NULL, &err ); |
| 13 |
if(mh == NULL) return -1; |
| 14 |
|
| 15 |
err = mpg123_open(mh, path ); |
| 16 |
if(err != MPG123_OK) return -1; |
| 17 |
|
| 18 |
if(scan_before) mpg123_scan(mh); |
| 19 |
|
| 20 |
pos = mpg123_seek( mh, 0, SEEK_END); |
| 21 |
if(pos < 0){ error1("seek failed: %s", mpg123_strerror(mh)); return -1; } |
| 22 |
|
| 23 |
pos = mpg123_tell(mh); |
| 24 |
length = mpg123_length(mh); |
| 25 |
|
| 26 |
/* Later: Read samples and compare different whence values with identical seek positions. */ |
| 27 |
|
| 28 |
mpg123_close(mh); |
| 29 |
mpg123_delete(mh); |
| 30 |
|
| 31 |
fprintf(stdout, "length %" PRIiMAX " vs. pos %" PRIiMAX "\n", (intmax_t)length, (intmax_t)pos); |
| 32 |
|
| 33 |
return (pos == length) ? 0 : -1; |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
int main(int argc, char **argv) |
| 38 |
{ |
| 39 |
int err = 0, errsum = 0; |
| 40 |
if(argc < 2) |
| 41 |
{ |
| 42 |
printf("Gimme a MPEG file name...\n"); |
| 43 |
return 0; |
| 44 |
} |
| 45 |
mpg123_init(); |
| 46 |
fprintf(stderr, "End seek without (explicit) scanning: "); |
| 47 |
err = test_whence(argv[1], 0); |
| 48 |
fprintf(stdout, "%s\n", err == 0 ? "PASS" : "FAIL"); |
| 49 |
errsum += err; |
| 50 |
fprintf(stderr, "End seek with explicit scanning: "); |
| 51 |
err = test_whence(argv[1], 1); |
| 52 |
fprintf(stdout, "%s\n", err == 0 ? "PASS" : "FAIL"); |
| 53 |
errsum += err; |
| 54 |
mpg123_exit(); |
| 55 |
printf("%s\n", errsum ? "FAIL" : "PASS"); |
| 56 |
return errsum; |
| 57 |
} |