decoders.c
上传用户:wstnjxml
上传日期:2014-04-03
资源大小:7248k
文件大小:77k
源码类别:

Windows CE

开发平台:

C/C++

  1. /* test_libOggFLAC - Unit tester for libOggFLAC
  2.  * Copyright (C) 2002,2003,2004,2005  Josh Coalson
  3.  *
  4.  * This program is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU General Public License
  6.  * as published by the Free Software Foundation; either version 2
  7.  * of the License, or (at your option) any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  17.  */
  18. #include "decoders.h"
  19. #include "file_utils.h"
  20. #include "metadata_utils.h"
  21. #include "FLAC/assert.h"
  22. #include "OggFLAC/file_decoder.h"
  23. #include "OggFLAC/seekable_stream_decoder.h"
  24. #include "OggFLAC/stream_decoder.h"
  25. #include "share/grabbag.h"
  26. #include <errno.h>
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. typedef struct {
  31. FILE *file;
  32. unsigned current_metadata_number;
  33. FLAC__bool ignore_errors;
  34. FLAC__bool error_occurred;
  35. } stream_decoder_client_data_struct;
  36. typedef stream_decoder_client_data_struct seekable_stream_decoder_client_data_struct;
  37. typedef stream_decoder_client_data_struct file_decoder_client_data_struct;
  38. static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, unknown_;
  39. static FLAC__StreamMetadata *expected_metadata_sequence_[8];
  40. static unsigned num_expected_;
  41. static const char *oggflacfilename_ = "metadata.ogg";
  42. static unsigned oggflacfilesize_;
  43. static FLAC__bool die_(const char *msg)
  44. {
  45. printf("ERROR: %sn", msg);
  46. return false;
  47. }
  48. static FLAC__bool die_s_(const char *msg, const OggFLAC__StreamDecoder *decoder)
  49. {
  50. OggFLAC__StreamDecoderState state = OggFLAC__stream_decoder_get_state(decoder);
  51. if(msg)
  52. printf("FAILED, %s", msg);
  53. else
  54. printf("FAILED");
  55. printf(", state = %u (%s)n", (unsigned)state, OggFLAC__StreamDecoderStateString[state]);
  56. if(state == OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR) {
  57. FLAC__StreamDecoderState state_ = OggFLAC__stream_decoder_get_FLAC_stream_decoder_state(decoder);
  58. printf("      FLAC stream decoder state = %u (%s)n", (unsigned)state_, FLAC__StreamDecoderStateString[state_]);
  59. }
  60. return false;
  61. }
  62. static FLAC__bool die_ss_(const char *msg, const OggFLAC__SeekableStreamDecoder *decoder)
  63. {
  64. OggFLAC__SeekableStreamDecoderState state = OggFLAC__seekable_stream_decoder_get_state(decoder);
  65. if(msg)
  66. printf("FAILED, %s", msg);
  67. else
  68. printf("FAILED");
  69. printf(", state = %u (%s)n", (unsigned)state, OggFLAC__SeekableStreamDecoderStateString[state]);
  70. if(state == OggFLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR) {
  71. OggFLAC__StreamDecoderState state_ = OggFLAC__seekable_stream_decoder_get_stream_decoder_state(decoder);
  72. printf("      stream decoder state = %u (%s)n", (unsigned)state_, OggFLAC__StreamDecoderStateString[state_]);
  73. if(state_ == OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR) {
  74. FLAC__StreamDecoderState state__ = OggFLAC__seekable_stream_decoder_get_FLAC_stream_decoder_state(decoder);
  75. printf("      FLAC stream decoder state = %u (%s)n", (unsigned)state__, FLAC__StreamDecoderStateString[state__]);
  76. }
  77. }
  78. return false;
  79. }
  80. static FLAC__bool die_f_(const char *msg, const OggFLAC__FileDecoder *decoder)
  81. {
  82. OggFLAC__FileDecoderState state = OggFLAC__file_decoder_get_state(decoder);
  83. if(msg)
  84. printf("FAILED, %s", msg);
  85. else
  86. printf("FAILED");
  87. printf(", state = %u (%s)n", (unsigned)state, OggFLAC__SeekableStreamDecoderStateString[state]);
  88. if(state == OggFLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR) {
  89. OggFLAC__SeekableStreamDecoderState state_ = OggFLAC__file_decoder_get_seekable_stream_decoder_state(decoder);
  90. printf("      seekable stream decoder state = %u (%s)n", (unsigned)state_, OggFLAC__SeekableStreamDecoderStateString[state_]);
  91. if(state_ == OggFLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR) {
  92. OggFLAC__StreamDecoderState state__ = OggFLAC__file_decoder_get_stream_decoder_state(decoder);
  93. printf("      stream decoder state = %u (%s)n", (unsigned)state__, OggFLAC__StreamDecoderStateString[state__]);
  94. if(state__ == OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR) {
  95. FLAC__StreamDecoderState state___ = OggFLAC__file_decoder_get_FLAC_stream_decoder_state(decoder);
  96. printf("      FLAC stream decoder state = %u (%s)n", (unsigned)state___, FLAC__StreamDecoderStateString[state___]);
  97. }
  98. }
  99. }
  100. return false;
  101. }
  102. static void init_metadata_blocks_()
  103. {
  104. mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
  105. }
  106. static void free_metadata_blocks_()
  107. {
  108. mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
  109. }
  110. static FLAC__bool generate_file_()
  111. {
  112. printf("nngenerating Ogg FLAC file for decoder tests...n");
  113. num_expected_ = 0;
  114. expected_metadata_sequence_[num_expected_++] = &padding_;
  115. expected_metadata_sequence_[num_expected_++] = &seektable_;
  116. expected_metadata_sequence_[num_expected_++] = &application1_;
  117. expected_metadata_sequence_[num_expected_++] = &application2_;
  118. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  119. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  120. expected_metadata_sequence_[num_expected_++] = &unknown_;
  121. /* WATCHOUT: the encoder should move the VORBIS_COMMENT block to the front, right after STREAMINFO */
  122. if(!file_utils__generate_oggflacfile(oggflacfilename_, &oggflacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_))
  123. return die_("creating the encoded file");
  124. return true;
  125. }
  126. static FLAC__StreamDecoderReadStatus stream_decoder_read_callback_(const OggFLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
  127. {
  128. stream_decoder_client_data_struct *dcd = (stream_decoder_client_data_struct*)client_data;
  129. (void)decoder;
  130. if(0 == dcd) {
  131. printf("ERROR: client_data in read callback is NULLn");
  132. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  133. }
  134. if(dcd->error_occurred)
  135. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  136. if(feof(dcd->file)) {
  137. *bytes = 0;
  138. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  139. }
  140. else if(*bytes > 0) {
  141. *bytes = fread(buffer, 1, *bytes, dcd->file);
  142. if(*bytes == 0) {
  143. if(feof(dcd->file))
  144. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  145. else
  146. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  147. }
  148. else {
  149. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  150. }
  151. }
  152. else
  153. return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
  154. }
  155. static FLAC__StreamDecoderWriteStatus stream_decoder_write_callback_(const OggFLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  156. {
  157. stream_decoder_client_data_struct *dcd = (stream_decoder_client_data_struct*)client_data;
  158. (void)decoder, (void)buffer;
  159. if(0 == dcd) {
  160. printf("ERROR: client_data in write callback is NULLn");
  161. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  162. }
  163. if(dcd->error_occurred)
  164. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  165. if(
  166. (frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER && frame->header.number.frame_number == 0) ||
  167. (frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER && frame->header.number.sample_number == 0)
  168. ) {
  169. printf("content... ");
  170. fflush(stdout);
  171. }
  172. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  173. }
  174. static void stream_decoder_metadata_callback_(const OggFLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  175. {
  176. stream_decoder_client_data_struct *dcd = (stream_decoder_client_data_struct*)client_data;
  177. (void)decoder;
  178. if(0 == dcd) {
  179. printf("ERROR: client_data in metadata callback is NULLn");
  180. return;
  181. }
  182. if(dcd->error_occurred)
  183. return;
  184. printf("%d... ", dcd->current_metadata_number);
  185. fflush(stdout);
  186. if(dcd->current_metadata_number >= num_expected_) {
  187. (void)die_("got more metadata blocks than expected");
  188. dcd->error_occurred = true;
  189. }
  190. else {
  191. if(!mutils__compare_block(expected_metadata_sequence_[dcd->current_metadata_number], metadata)) {
  192. (void)die_("metadata block mismatch");
  193. dcd->error_occurred = true;
  194. }
  195. }
  196. dcd->current_metadata_number++;
  197. }
  198. static void stream_decoder_error_callback_(const OggFLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  199. {
  200. stream_decoder_client_data_struct *dcd = (stream_decoder_client_data_struct*)client_data;
  201. (void)decoder;
  202. if(0 == dcd) {
  203. printf("ERROR: client_data in error callback is NULLn");
  204. return;
  205. }
  206. if(!dcd->ignore_errors) {
  207. printf("ERROR: got error callback: err = %u (%s)n", (unsigned)status, FLAC__StreamDecoderErrorStatusString[status]);
  208. dcd->error_occurred = true;
  209. }
  210. }
  211. static FLAC__bool stream_decoder_test_respond_(OggFLAC__StreamDecoder *decoder, stream_decoder_client_data_struct *dcd)
  212. {
  213. if(!OggFLAC__stream_decoder_set_read_callback(decoder, stream_decoder_read_callback_))
  214. return die_s_("at OggFLAC__stream_decoder_set_read_callback(), returned false", decoder);
  215. if(!OggFLAC__stream_decoder_set_write_callback(decoder, stream_decoder_write_callback_))
  216. return die_s_("at OggFLAC__stream_decoder_set_write_callback(), returned false", decoder);
  217. if(!OggFLAC__stream_decoder_set_metadata_callback(decoder, stream_decoder_metadata_callback_))
  218. return die_s_("at OggFLAC__stream_decoder_set_metadata_callback(), returned false", decoder);
  219. if(!OggFLAC__stream_decoder_set_error_callback(decoder, stream_decoder_error_callback_))
  220. return die_s_("at OggFLAC__stream_decoder_set_error_callback(), returned false", decoder);
  221. if(!OggFLAC__stream_decoder_set_client_data(decoder, dcd))
  222. return die_s_("at OggFLAC__stream_decoder_set_client_data(), returned false", decoder);
  223. printf("testing OggFLAC__stream_decoder_init()... ");
  224. if(OggFLAC__stream_decoder_init(decoder) != OggFLAC__STREAM_DECODER_OK)
  225. return die_s_(0, decoder);
  226. printf("OKn");
  227. dcd->current_metadata_number = 0;
  228. if(fseek(dcd->file, 0, SEEK_SET) < 0) {
  229. printf("FAILED rewinding input, errno = %dn", errno);
  230. return false;
  231. }
  232. printf("testing OggFLAC__stream_decoder_process_until_end_of_stream()... ");
  233. if(!OggFLAC__stream_decoder_process_until_end_of_stream(decoder))
  234. return die_s_("returned false", decoder);
  235. printf("OKn");
  236. printf("testing OggFLAC__stream_decoder_finish()... ");
  237. OggFLAC__stream_decoder_finish(decoder);
  238. printf("OKn");
  239. return true;
  240. }
  241. static FLAC__bool test_stream_decoder()
  242. {
  243. OggFLAC__StreamDecoder *decoder;
  244. OggFLAC__StreamDecoderState state;
  245. FLAC__StreamDecoderState fstate;
  246. stream_decoder_client_data_struct decoder_client_data;
  247. printf("n+++ libOggFLAC unit test: OggFLAC__StreamDecodernn");
  248. printf("testing OggFLAC__stream_decoder_new()... ");
  249. decoder = OggFLAC__stream_decoder_new();
  250. if(0 == decoder) {
  251. printf("FAILED, returned NULLn");
  252. return false;
  253. }
  254. printf("OKn");
  255. printf("testing OggFLAC__stream_decoder_delete()... ");
  256. OggFLAC__stream_decoder_delete(decoder);
  257. printf("OKn");
  258. printf("testing OggFLAC__stream_decoder_new()... ");
  259. decoder = OggFLAC__stream_decoder_new();
  260. if(0 == decoder) {
  261. printf("FAILED, returned NULLn");
  262. return false;
  263. }
  264. printf("OKn");
  265. printf("testing OggFLAC__stream_decoder_init()... ");
  266. if(OggFLAC__stream_decoder_init(decoder) == OggFLAC__STREAM_DECODER_OK)
  267. return die_s_(0, decoder);
  268. printf("OKn");
  269. printf("testing OggFLAC__stream_decoder_delete()... ");
  270. OggFLAC__stream_decoder_delete(decoder);
  271. printf("OKn");
  272. num_expected_ = 0;
  273. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  274. printf("testing OggFLAC__stream_decoder_new()... ");
  275. decoder = OggFLAC__stream_decoder_new();
  276. if(0 == decoder) {
  277. printf("FAILED, returned NULLn");
  278. return false;
  279. }
  280. printf("OKn");
  281. printf("testing OggFLAC__stream_decoder_set_serial_number()... ");
  282. if(!OggFLAC__stream_decoder_set_serial_number(decoder, file_utils__serial_number))
  283. return die_s_("returned false", decoder);
  284. printf("OKn");
  285. printf("testing OggFLAC__stream_decoder_set_read_callback()... ");
  286. if(!OggFLAC__stream_decoder_set_read_callback(decoder, stream_decoder_read_callback_))
  287. return die_s_("returned false", decoder);
  288. printf("OKn");
  289. printf("testing OggFLAC__stream_decoder_set_write_callback()... ");
  290. if(!OggFLAC__stream_decoder_set_write_callback(decoder, stream_decoder_write_callback_))
  291. return die_s_("returned false", decoder);
  292. printf("OKn");
  293. printf("testing OggFLAC__stream_decoder_set_metadata_callback()... ");
  294. if(!OggFLAC__stream_decoder_set_metadata_callback(decoder, stream_decoder_metadata_callback_))
  295. return die_s_("returned false", decoder);
  296. printf("OKn");
  297. printf("testing OggFLAC__stream_decoder_set_error_callback()... ");
  298. if(!OggFLAC__stream_decoder_set_error_callback(decoder, stream_decoder_error_callback_))
  299. return die_s_("returned false", decoder);
  300. printf("OKn");
  301. printf("testing OggFLAC__stream_decoder_set_client_data()... ");
  302. if(!OggFLAC__stream_decoder_set_client_data(decoder, &decoder_client_data))
  303. return die_s_("returned false", decoder);
  304. printf("OKn");
  305. printf("testing OggFLAC__stream_decoder_init()... ");
  306. if(OggFLAC__stream_decoder_init(decoder) != OggFLAC__STREAM_DECODER_OK)
  307. return die_s_(0, decoder);
  308. printf("OKn");
  309. printf("testing OggFLAC__stream_decoder_get_state()... ");
  310. state = OggFLAC__stream_decoder_get_state(decoder);
  311. printf("returned state = %u (%s)... OKn", state, OggFLAC__StreamDecoderStateString[state]);
  312. printf("testing OggFLAC__stream_decoder_get_FLAC_stream_decoder_state()... ");
  313. fstate = OggFLAC__stream_decoder_get_FLAC_stream_decoder_state(decoder);
  314. printf("returned state = %u (%s)... OKn", fstate, FLAC__StreamDecoderStateString[fstate]);
  315. decoder_client_data.current_metadata_number = 0;
  316. decoder_client_data.ignore_errors = false;
  317. decoder_client_data.error_occurred = false;
  318. printf("opening Ogg FLAC file... ");
  319. decoder_client_data.file = fopen(oggflacfilename_, "rb");
  320. if(0 == decoder_client_data.file) {
  321. printf("ERRORn");
  322. return false;
  323. }
  324. printf("OKn");
  325. printf("testing OggFLAC__stream_decoder_process_until_end_of_metadata()... ");
  326. if(!OggFLAC__stream_decoder_process_until_end_of_metadata(decoder))
  327. return die_s_("returned false", decoder);
  328. printf("OKn");
  329. printf("testing OggFLAC__stream_decoder_process_single()... ");
  330. if(!OggFLAC__stream_decoder_process_single(decoder))
  331. return die_s_("returned false", decoder);
  332. printf("OKn");
  333. printf("testing OggFLAC__stream_decoder_flush()... ");
  334. if(!OggFLAC__stream_decoder_flush(decoder))
  335. return die_s_("returned false", decoder);
  336. printf("OKn");
  337. decoder_client_data.ignore_errors = true;
  338. printf("testing OggFLAC__stream_decoder_process_single()... ");
  339. if(!OggFLAC__stream_decoder_process_single(decoder))
  340. return die_s_("returned false", decoder);
  341. printf("OKn");
  342. decoder_client_data.ignore_errors = false;
  343. printf("testing OggFLAC__stream_decoder_process_until_end_of_stream()... ");
  344. if(!OggFLAC__stream_decoder_process_until_end_of_stream(decoder))
  345. return die_s_("returned false", decoder);
  346. printf("OKn");
  347. printf("testing OggFLAC__stream_decoder_get_channels()... ");
  348. {
  349. unsigned channels = OggFLAC__stream_decoder_get_channels(decoder);
  350. if(channels != streaminfo_.data.stream_info.channels) {
  351. printf("FAILED, returned %u, expected %un", channels, streaminfo_.data.stream_info.channels);
  352. return false;
  353. }
  354. }
  355. printf("OKn");
  356. printf("testing OggFLAC__stream_decoder_get_bits_per_sample()... ");
  357. {
  358. unsigned bits_per_sample = OggFLAC__stream_decoder_get_bits_per_sample(decoder);
  359. if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
  360. printf("FAILED, returned %u, expected %un", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
  361. return false;
  362. }
  363. }
  364. printf("OKn");
  365. printf("testing OggFLAC__stream_decoder_get_sample_rate()... ");
  366. {
  367. unsigned sample_rate = OggFLAC__stream_decoder_get_sample_rate(decoder);
  368. if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
  369. printf("FAILED, returned %u, expected %un", sample_rate, streaminfo_.data.stream_info.sample_rate);
  370. return false;
  371. }
  372. }
  373. printf("OKn");
  374. printf("testing OggFLAC__stream_decoder_get_blocksize()... ");
  375. {
  376. unsigned blocksize = OggFLAC__stream_decoder_get_blocksize(decoder);
  377. /* value could be anything since we're at the last block, so accept any answer */
  378. printf("returned %u... OKn", blocksize);
  379. }
  380. printf("testing OggFLAC__stream_decoder_get_channel_assignment()... ");
  381. {
  382. FLAC__ChannelAssignment ca = OggFLAC__stream_decoder_get_channel_assignment(decoder);
  383. printf("returned %u (%s)... OKn", (unsigned)ca, FLAC__ChannelAssignmentString[ca]);
  384. }
  385. printf("testing OggFLAC__stream_decoder_reset()... ");
  386. if(!OggFLAC__stream_decoder_reset(decoder)) {
  387. state = OggFLAC__stream_decoder_get_state(decoder);
  388. printf("FAILED, returned false, state = %u (%s)n", state, FLAC__StreamDecoderStateString[state]);
  389. return false;
  390. }
  391. printf("OKn");
  392. decoder_client_data.current_metadata_number = 0;
  393. printf("rewinding input... ");
  394. if(fseek(decoder_client_data.file, 0, SEEK_SET) < 0) {
  395. printf("FAILED, errno = %dn", errno);
  396. return false;
  397. }
  398. printf("OKn");
  399. printf("testing OggFLAC__stream_decoder_process_until_end_of_stream()... ");
  400. if(!OggFLAC__stream_decoder_process_until_end_of_stream(decoder))
  401. return die_s_("returned false", decoder);
  402. printf("OKn");
  403. printf("testing OggFLAC__stream_decoder_finish()... ");
  404. OggFLAC__stream_decoder_finish(decoder);
  405. printf("OKn");
  406. /*
  407.  * respond all
  408.  */
  409. printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... ");
  410. if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder))
  411. return die_s_("returned false", decoder);
  412. printf("OKn");
  413. num_expected_ = 0;
  414. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  415. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  416. expected_metadata_sequence_[num_expected_++] = &padding_;
  417. expected_metadata_sequence_[num_expected_++] = &seektable_;
  418. expected_metadata_sequence_[num_expected_++] = &application1_;
  419. expected_metadata_sequence_[num_expected_++] = &application2_;
  420. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  421. expected_metadata_sequence_[num_expected_++] = &unknown_;
  422. if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
  423. return false;
  424. /*
  425.  * ignore all
  426.  */
  427. printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... ");
  428. if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder))
  429. return die_s_("returned false", decoder);
  430. printf("OKn");
  431. num_expected_ = 0;
  432. if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
  433. return false;
  434. /*
  435.  * respond all, ignore VORBIS_COMMENT
  436.  */
  437. printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... ");
  438. if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder))
  439. return die_s_("returned false", decoder);
  440. printf("OKn");
  441. printf("testing OggFLAC__stream_decoder_set_metadata_ignore(VORBIS_COMMENT)... ");
  442. if(!OggFLAC__stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT))
  443. return die_s_("returned false", decoder);
  444. printf("OKn");
  445. num_expected_ = 0;
  446. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  447. expected_metadata_sequence_[num_expected_++] = &padding_;
  448. expected_metadata_sequence_[num_expected_++] = &seektable_;
  449. expected_metadata_sequence_[num_expected_++] = &application1_;
  450. expected_metadata_sequence_[num_expected_++] = &application2_;
  451. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  452. expected_metadata_sequence_[num_expected_++] = &unknown_;
  453. if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
  454. return false;
  455. /*
  456.  * respond all, ignore APPLICATION
  457.  */
  458. printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... ");
  459. if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder))
  460. return die_s_("returned false", decoder);
  461. printf("OKn");
  462. printf("testing OggFLAC__stream_decoder_set_metadata_ignore(APPLICATION)... ");
  463. if(!OggFLAC__stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_APPLICATION))
  464. return die_s_("returned false", decoder);
  465. printf("OKn");
  466. num_expected_ = 0;
  467. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  468. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  469. expected_metadata_sequence_[num_expected_++] = &padding_;
  470. expected_metadata_sequence_[num_expected_++] = &seektable_;
  471. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  472. expected_metadata_sequence_[num_expected_++] = &unknown_;
  473. if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
  474. return false;
  475. /*
  476.  * respond all, ignore APPLICATION id of app#1
  477.  */
  478. printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... ");
  479. if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder))
  480. return die_s_("returned false", decoder);
  481. printf("OKn");
  482. printf("testing OggFLAC__stream_decoder_set_metadata_ignore_application(of app block #1)... ");
  483. if(!OggFLAC__stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id))
  484. return die_s_("returned false", decoder);
  485. printf("OKn");
  486. num_expected_ = 0;
  487. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  488. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  489. expected_metadata_sequence_[num_expected_++] = &padding_;
  490. expected_metadata_sequence_[num_expected_++] = &seektable_;
  491. expected_metadata_sequence_[num_expected_++] = &application2_;
  492. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  493. expected_metadata_sequence_[num_expected_++] = &unknown_;
  494. if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
  495. return false;
  496. /*
  497.  * respond all, ignore APPLICATION id of app#1 & app#2
  498.  */
  499. printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... ");
  500. if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder))
  501. return die_s_("returned false", decoder);
  502. printf("OKn");
  503. printf("testing OggFLAC__stream_decoder_set_metadata_ignore_application(of app block #1)... ");
  504. if(!OggFLAC__stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id))
  505. return die_s_("returned false", decoder);
  506. printf("OKn");
  507. printf("testing OggFLAC__stream_decoder_set_metadata_ignore_application(of app block #2)... ");
  508. if(!OggFLAC__stream_decoder_set_metadata_ignore_application(decoder, application2_.data.application.id))
  509. return die_s_("returned false", decoder);
  510. printf("OKn");
  511. num_expected_ = 0;
  512. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  513. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  514. expected_metadata_sequence_[num_expected_++] = &padding_;
  515. expected_metadata_sequence_[num_expected_++] = &seektable_;
  516. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  517. expected_metadata_sequence_[num_expected_++] = &unknown_;
  518. if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
  519. return false;
  520. /*
  521.  * ignore all, respond VORBIS_COMMENT
  522.  */
  523. printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... ");
  524. if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder))
  525. return die_s_("returned false", decoder);
  526. printf("OKn");
  527. printf("testing OggFLAC__stream_decoder_set_metadata_respond(VORBIS_COMMENT)... ");
  528. if(!OggFLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT))
  529. return die_s_("returned false", decoder);
  530. printf("OKn");
  531. num_expected_ = 0;
  532. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  533. if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
  534. return false;
  535. /*
  536.  * ignore all, respond APPLICATION
  537.  */
  538. printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... ");
  539. if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder))
  540. return die_s_("returned false", decoder);
  541. printf("OKn");
  542. printf("testing OggFLAC__stream_decoder_set_metadata_respond(APPLICATION)... ");
  543. if(!OggFLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_APPLICATION))
  544. return die_s_("returned false", decoder);
  545. printf("OKn");
  546. num_expected_ = 0;
  547. expected_metadata_sequence_[num_expected_++] = &application1_;
  548. expected_metadata_sequence_[num_expected_++] = &application2_;
  549. if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
  550. return false;
  551. /*
  552.  * ignore all, respond APPLICATION id of app#1
  553.  */
  554. printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... ");
  555. if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder))
  556. return die_s_("returned false", decoder);
  557. printf("OKn");
  558. printf("testing OggFLAC__stream_decoder_set_metadata_respond_application(of app block #1)... ");
  559. if(!OggFLAC__stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id))
  560. return die_s_("returned false", decoder);
  561. printf("OKn");
  562. num_expected_ = 0;
  563. expected_metadata_sequence_[num_expected_++] = &application1_;
  564. if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
  565. return false;
  566. /*
  567.  * ignore all, respond APPLICATION id of app#1 & app#2
  568.  */
  569. printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... ");
  570. if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder))
  571. return die_s_("returned false", decoder);
  572. printf("OKn");
  573. printf("testing OggFLAC__stream_decoder_set_metadata_respond_application(of app block #1)... ");
  574. if(!OggFLAC__stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id))
  575. return die_s_("returned false", decoder);
  576. printf("OKn");
  577. printf("testing OggFLAC__stream_decoder_set_metadata_respond_application(of app block #2)... ");
  578. if(!OggFLAC__stream_decoder_set_metadata_respond_application(decoder, application2_.data.application.id))
  579. return die_s_("returned false", decoder);
  580. printf("OKn");
  581. num_expected_ = 0;
  582. expected_metadata_sequence_[num_expected_++] = &application1_;
  583. expected_metadata_sequence_[num_expected_++] = &application2_;
  584. if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
  585. return false;
  586. /*
  587.  * respond all, ignore APPLICATION, respond APPLICATION id of app#1
  588.  */
  589. printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... ");
  590. if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder))
  591. return die_s_("returned false", decoder);
  592. printf("OKn");
  593. printf("testing OggFLAC__stream_decoder_set_metadata_ignore(APPLICATION)... ");
  594. if(!OggFLAC__stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_APPLICATION))
  595. return die_s_("returned false", decoder);
  596. printf("OKn");
  597. printf("testing OggFLAC__stream_decoder_set_metadata_respond_application(of app block #1)... ");
  598. if(!OggFLAC__stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id))
  599. return die_s_("returned false", decoder);
  600. printf("OKn");
  601. num_expected_ = 0;
  602. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  603. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  604. expected_metadata_sequence_[num_expected_++] = &padding_;
  605. expected_metadata_sequence_[num_expected_++] = &seektable_;
  606. expected_metadata_sequence_[num_expected_++] = &application1_;
  607. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  608. expected_metadata_sequence_[num_expected_++] = &unknown_;
  609. if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
  610. return false;
  611. /*
  612.  * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
  613.  */
  614. printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... ");
  615. if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder))
  616. return die_s_("returned false", decoder);
  617. printf("OKn");
  618. printf("testing OggFLAC__stream_decoder_set_metadata_respond(APPLICATION)... ");
  619. if(!OggFLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_APPLICATION))
  620. return die_s_("returned false", decoder);
  621. printf("OKn");
  622. printf("testing OggFLAC__stream_decoder_set_metadata_ignore_application(of app block #1)... ");
  623. if(!OggFLAC__stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id))
  624. return die_s_("returned false", decoder);
  625. printf("OKn");
  626. num_expected_ = 0;
  627. expected_metadata_sequence_[num_expected_++] = &application2_;
  628. if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
  629. return false;
  630. /* done, now leave the sequence the way we found it... */
  631. num_expected_ = 0;
  632. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  633. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  634. expected_metadata_sequence_[num_expected_++] = &padding_;
  635. expected_metadata_sequence_[num_expected_++] = &seektable_;
  636. expected_metadata_sequence_[num_expected_++] = &application1_;
  637. expected_metadata_sequence_[num_expected_++] = &application2_;
  638. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  639. expected_metadata_sequence_[num_expected_++] = &unknown_;
  640. printf("testing OggFLAC__stream_decoder_delete()... ");
  641. OggFLAC__stream_decoder_delete(decoder);
  642. printf("OKn");
  643. fclose(decoder_client_data.file);
  644. printf("nPASSED!n");
  645. return true;
  646. }
  647. static OggFLAC__SeekableStreamDecoderReadStatus seekable_stream_decoder_read_callback_(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
  648. {
  649. (void)decoder;
  650. switch(stream_decoder_read_callback_(0, buffer, bytes, client_data)) {
  651. case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
  652. case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
  653. return OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;
  654. case FLAC__STREAM_DECODER_READ_STATUS_ABORT:
  655. return OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
  656. default:
  657. FLAC__ASSERT(0);
  658. return OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
  659. }
  660. }
  661. static OggFLAC__SeekableStreamDecoderSeekStatus seekable_stream_decoder_seek_callback_(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  662. {
  663. seekable_stream_decoder_client_data_struct *dcd = (seekable_stream_decoder_client_data_struct*)client_data;
  664. (void)decoder;
  665. if(0 == dcd) {
  666. printf("ERROR: client_data in seek callback is NULLn");
  667. return OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
  668. }
  669. if(dcd->error_occurred)
  670. return OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
  671. if(fseek(dcd->file, (long)absolute_byte_offset, SEEK_SET) < 0) {
  672. dcd->error_occurred = true;
  673. return OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
  674. }
  675. return OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;
  676. }
  677. static OggFLAC__SeekableStreamDecoderTellStatus seekable_stream_decoder_tell_callback_(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  678. {
  679. seekable_stream_decoder_client_data_struct *dcd = (seekable_stream_decoder_client_data_struct*)client_data;
  680. long offset;
  681. (void)decoder;
  682. if(0 == dcd) {
  683. printf("ERROR: client_data in tell callback is NULLn");
  684. return OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
  685. }
  686. if(dcd->error_occurred)
  687. return OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
  688. offset = ftell(dcd->file);
  689. *absolute_byte_offset = (FLAC__uint64)offset;
  690. if(offset < 0) {
  691. dcd->error_occurred = true;
  692. return OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
  693. }
  694. return OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK;
  695. }
  696. static OggFLAC__SeekableStreamDecoderLengthStatus seekable_stream_decoder_length_callback_(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
  697. {
  698. seekable_stream_decoder_client_data_struct *dcd = (seekable_stream_decoder_client_data_struct*)client_data;
  699. (void)decoder;
  700. if(0 == dcd) {
  701. printf("ERROR: client_data in length callback is NULLn");
  702. return OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR;
  703. }
  704. if(dcd->error_occurred)
  705. return OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR;
  706. *stream_length = (FLAC__uint64)oggflacfilesize_;
  707. return OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK;
  708. }
  709. static FLAC__bool seekable_stream_decoder_eof_callback_(const OggFLAC__SeekableStreamDecoder *decoder, void *client_data)
  710. {
  711. seekable_stream_decoder_client_data_struct *dcd = (seekable_stream_decoder_client_data_struct*)client_data;
  712. (void)decoder;
  713. if(0 == dcd) {
  714. printf("ERROR: client_data in eof callback is NULLn");
  715. return true;
  716. }
  717. if(dcd->error_occurred)
  718. return true;
  719. return feof(dcd->file);
  720. }
  721. static FLAC__StreamDecoderWriteStatus seekable_stream_decoder_write_callback_(const OggFLAC__SeekableStreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  722. {
  723. (void)decoder;
  724. return stream_decoder_write_callback_(0, frame, buffer, client_data);
  725. }
  726. static void seekable_stream_decoder_metadata_callback_(const OggFLAC__SeekableStreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  727. {
  728. (void)decoder;
  729. stream_decoder_metadata_callback_(0, metadata, client_data);
  730. }
  731. static void seekable_stream_decoder_error_callback_(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  732. {
  733. (void)decoder;
  734. stream_decoder_error_callback_(0, status, client_data);
  735. }
  736. static FLAC__bool seekable_stream_decoder_test_respond_(OggFLAC__SeekableStreamDecoder *decoder, seekable_stream_decoder_client_data_struct *dcd)
  737. {
  738. if(!OggFLAC__seekable_stream_decoder_set_read_callback(decoder, seekable_stream_decoder_read_callback_))
  739. return die_ss_("at OggFLAC__seekable_stream_decoder_set_read_callback(), returned false", decoder);
  740. if(!OggFLAC__seekable_stream_decoder_set_seek_callback(decoder, seekable_stream_decoder_seek_callback_))
  741. return die_ss_("at OggFLAC__seekable_stream_decoder_set_seek_callback(), returned false", decoder);
  742. if(!OggFLAC__seekable_stream_decoder_set_tell_callback(decoder, seekable_stream_decoder_tell_callback_))
  743. return die_ss_("at OggFLAC__seekable_stream_decoder_set_tell_callback(), returned false", decoder);
  744. if(!OggFLAC__seekable_stream_decoder_set_length_callback(decoder, seekable_stream_decoder_length_callback_))
  745. return die_ss_("at OggFLAC__seekable_stream_decoder_set_length_callback(), returned false", decoder);
  746. if(!OggFLAC__seekable_stream_decoder_set_eof_callback(decoder, seekable_stream_decoder_eof_callback_))
  747. return die_ss_("at OggFLAC__seekable_stream_decoder_set_eof_callback(), returned false", decoder);
  748. if(!OggFLAC__seekable_stream_decoder_set_write_callback(decoder, seekable_stream_decoder_write_callback_))
  749. return die_ss_("at OggFLAC__seekable_stream_decoder_set_write_callback(), returned false", decoder);
  750. if(!OggFLAC__seekable_stream_decoder_set_metadata_callback(decoder, seekable_stream_decoder_metadata_callback_))
  751. return die_ss_("at OggFLAC__seekable_stream_decoder_set_metadata_callback(), returned false", decoder);
  752. if(!OggFLAC__seekable_stream_decoder_set_error_callback(decoder, seekable_stream_decoder_error_callback_))
  753. return die_ss_("at OggFLAC__seekable_stream_decoder_set_error_callback(), returned false", decoder);
  754. if(!OggFLAC__seekable_stream_decoder_set_client_data(decoder, dcd))
  755. return die_ss_("at OggFLAC__seekable_stream_decoder_set_client_data(), returned false", decoder);
  756. if(!OggFLAC__seekable_stream_decoder_set_md5_checking(decoder, true))
  757. return die_ss_("at OggFLAC__seekable_stream_decoder_set_md5_checking(), returned false", decoder);
  758. printf("testing OggFLAC__seekable_stream_decoder_init()... ");
  759. if(OggFLAC__seekable_stream_decoder_init(decoder) != OggFLAC__SEEKABLE_STREAM_DECODER_OK)
  760. return die_ss_(0, decoder);
  761. printf("OKn");
  762. dcd->current_metadata_number = 0;
  763. if(fseek(dcd->file, 0, SEEK_SET) < 0) {
  764. printf("FAILED rewinding input, errno = %dn", errno);
  765. return false;
  766. }
  767. printf("testing OggFLAC__seekable_stream_decoder_process_until_end_of_stream()... ");
  768. if(!OggFLAC__seekable_stream_decoder_process_until_end_of_stream(decoder))
  769. return die_ss_("returned false", decoder);
  770. printf("OKn");
  771. printf("testing OggFLAC__seekable_stream_decoder_finish()... ");
  772. (void) OggFLAC__seekable_stream_decoder_finish(decoder);
  773. printf("OKn");
  774. return true;
  775. }
  776. static FLAC__bool test_seekable_stream_decoder()
  777. {
  778. OggFLAC__SeekableStreamDecoder *decoder;
  779. OggFLAC__SeekableStreamDecoderState state;
  780. OggFLAC__StreamDecoderState sstate;
  781. FLAC__StreamDecoderState fstate;
  782. seekable_stream_decoder_client_data_struct decoder_client_data;
  783. printf("n+++ libOggFLAC unit test: OggFLAC__SeekableStreamDecodernn");
  784. printf("testing OggFLAC__seekable_stream_decoder_new()... ");
  785. decoder = OggFLAC__seekable_stream_decoder_new();
  786. if(0 == decoder) {
  787. printf("FAILED, returned NULLn");
  788. return false;
  789. }
  790. printf("OKn");
  791. printf("testing OggFLAC__seekable_stream_decoder_delete()... ");
  792. OggFLAC__seekable_stream_decoder_delete(decoder);
  793. printf("OKn");
  794. printf("testing OggFLAC__seekable_stream_decoder_new()... ");
  795. decoder = OggFLAC__seekable_stream_decoder_new();
  796. if(0 == decoder) {
  797. printf("FAILED, returned NULLn");
  798. return false;
  799. }
  800. printf("OKn");
  801. printf("testing OggFLAC__seekable_stream_decoder_init()... ");
  802. if(OggFLAC__seekable_stream_decoder_init(decoder) == OggFLAC__SEEKABLE_STREAM_DECODER_OK)
  803. return die_ss_(0, decoder);
  804. printf("OKn");
  805. printf("testing OggFLAC__seekable_stream_decoder_delete()... ");
  806. OggFLAC__seekable_stream_decoder_delete(decoder);
  807. printf("OKn");
  808. num_expected_ = 0;
  809. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  810. printf("testing OggFLAC__seekable_stream_decoder_new()... ");
  811. decoder = OggFLAC__seekable_stream_decoder_new();
  812. if(0 == decoder) {
  813. printf("FAILED, returned NULLn");
  814. return false;
  815. }
  816. printf("OKn");
  817. printf("testing OggFLAC__seekable_stream_decoder_set_serial_number()... ");
  818. if(!OggFLAC__seekable_stream_decoder_set_serial_number(decoder, file_utils__serial_number))
  819. return die_ss_("returned false", decoder);
  820. printf("OKn");
  821. printf("testing OggFLAC__seekable_stream_decoder_set_read_callback()... ");
  822. if(!OggFLAC__seekable_stream_decoder_set_read_callback(decoder, seekable_stream_decoder_read_callback_))
  823. return die_ss_("returned false", decoder);
  824. printf("OKn");
  825. printf("testing OggFLAC__seekable_stream_decoder_set_seek_callback()... ");
  826. if(!OggFLAC__seekable_stream_decoder_set_seek_callback(decoder, seekable_stream_decoder_seek_callback_))
  827. return die_ss_("returned false", decoder);
  828. printf("OKn");
  829. printf("testing OggFLAC__seekable_stream_decoder_set_tell_callback()... ");
  830. if(!OggFLAC__seekable_stream_decoder_set_tell_callback(decoder, seekable_stream_decoder_tell_callback_))
  831. return die_ss_("returned false", decoder);
  832. printf("OKn");
  833. printf("testing OggFLAC__seekable_stream_decoder_set_length_callback()... ");
  834. if(!OggFLAC__seekable_stream_decoder_set_length_callback(decoder, seekable_stream_decoder_length_callback_))
  835. return die_ss_("returned false", decoder);
  836. printf("OKn");
  837. printf("testing OggFLAC__seekable_stream_decoder_set_eof_callback()... ");
  838. if(!OggFLAC__seekable_stream_decoder_set_eof_callback(decoder, seekable_stream_decoder_eof_callback_))
  839. return die_ss_("returned false", decoder);
  840. printf("OKn");
  841. printf("testing OggFLAC__seekable_stream_decoder_set_write_callback()... ");
  842. if(!OggFLAC__seekable_stream_decoder_set_write_callback(decoder, seekable_stream_decoder_write_callback_))
  843. return die_ss_("returned false", decoder);
  844. printf("OKn");
  845. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_callback()... ");
  846. if(!OggFLAC__seekable_stream_decoder_set_metadata_callback(decoder, seekable_stream_decoder_metadata_callback_))
  847. return die_ss_("returned false", decoder);
  848. printf("OKn");
  849. printf("testing OggFLAC__seekable_stream_decoder_set_error_callback()... ");
  850. if(!OggFLAC__seekable_stream_decoder_set_error_callback(decoder, seekable_stream_decoder_error_callback_))
  851. return die_ss_("returned false", decoder);
  852. printf("OKn");
  853. printf("testing OggFLAC__seekable_stream_decoder_set_client_data()... ");
  854. if(!OggFLAC__seekable_stream_decoder_set_client_data(decoder, &decoder_client_data))
  855. return die_ss_("returned false", decoder);
  856. printf("OKn");
  857. printf("testing OggFLAC__seekable_stream_decoder_set_md5_checking()... ");
  858. if(!OggFLAC__seekable_stream_decoder_set_md5_checking(decoder, true))
  859. return die_ss_("returned false", decoder);
  860. printf("OKn");
  861. printf("testing OggFLAC__seekable_stream_decoder_init()... ");
  862. if(OggFLAC__seekable_stream_decoder_init(decoder) != OggFLAC__SEEKABLE_STREAM_DECODER_OK)
  863. return die_ss_(0, decoder);
  864. printf("OKn");
  865. printf("testing OggFLAC__seekable_stream_decoder_get_state()... ");
  866. state = OggFLAC__seekable_stream_decoder_get_state(decoder);
  867. printf("returned state = %u (%s)... OKn", state, OggFLAC__SeekableStreamDecoderStateString[state]);
  868. printf("testing OggFLAC__seekable_stream_decoder_get_stream_decoder_state()... ");
  869. sstate = OggFLAC__seekable_stream_decoder_get_stream_decoder_state(decoder);
  870. printf("returned state = %u (%s)... OKn", sstate, OggFLAC__StreamDecoderStateString[sstate]);
  871. printf("testing OggFLAC__seekable_stream_decoder_get_FLAC_stream_decoder_state()... ");
  872. fstate = OggFLAC__seekable_stream_decoder_get_FLAC_stream_decoder_state(decoder);
  873. printf("returned state = %u (%s)... OKn", fstate, FLAC__StreamDecoderStateString[fstate]);
  874. decoder_client_data.current_metadata_number = 0;
  875. decoder_client_data.ignore_errors = false;
  876. decoder_client_data.error_occurred = false;
  877. printf("opening Ogg FLAC file... ");
  878. decoder_client_data.file = fopen(oggflacfilename_, "rb");
  879. if(0 == decoder_client_data.file) {
  880. printf("ERRORn");
  881. return false;
  882. }
  883. printf("OKn");
  884. printf("testing OggFLAC__seekable_stream_decoder_get_md5_checking()... ");
  885. if(!OggFLAC__seekable_stream_decoder_get_md5_checking(decoder)) {
  886. printf("FAILED, returned false, expected truen");
  887. return false;
  888. }
  889. printf("OKn");
  890. printf("testing OggFLAC__seekable_stream_decoder_process_until_end_of_metadata()... ");
  891. if(!OggFLAC__seekable_stream_decoder_process_until_end_of_metadata(decoder))
  892. return die_ss_("returned false", decoder);
  893. printf("OKn");
  894. printf("testing OggFLAC__seekable_stream_decoder_process_single()... ");
  895. if(!OggFLAC__seekable_stream_decoder_process_single(decoder))
  896. return die_ss_("returned false", decoder);
  897. printf("OKn");
  898. printf("testing OggFLAC__seekable_stream_decoder_flush()... ");
  899. if(!OggFLAC__seekable_stream_decoder_flush(decoder))
  900. return die_ss_("returned false", decoder);
  901. printf("OKn");
  902. decoder_client_data.ignore_errors = true;
  903. printf("testing OggFLAC__seekable_stream_decoder_process_single()... ");
  904. if(!OggFLAC__seekable_stream_decoder_process_single(decoder))
  905. return die_ss_("returned false", decoder);
  906. printf("OKn");
  907. decoder_client_data.ignore_errors = false;
  908. printf("testing OggFLAC__seekable_stream_decoder_seek_absolute()... ");
  909. if(!OggFLAC__seekable_stream_decoder_seek_absolute(decoder, 0))
  910. return die_ss_("returned false", decoder);
  911. printf("OKn");
  912. printf("testing OggFLAC__seekable_stream_decoder_process_until_end_of_stream()... ");
  913. if(!OggFLAC__seekable_stream_decoder_process_until_end_of_stream(decoder))
  914. return die_ss_("returned false", decoder);
  915. printf("OKn");
  916. printf("testing OggFLAC__seekable_stream_decoder_get_channels()... ");
  917. {
  918. unsigned channels = OggFLAC__seekable_stream_decoder_get_channels(decoder);
  919. if(channels != streaminfo_.data.stream_info.channels) {
  920. printf("FAILED, returned %u, expected %un", channels, streaminfo_.data.stream_info.channels);
  921. return false;
  922. }
  923. }
  924. printf("OKn");
  925. printf("testing OggFLAC__seekable_stream_decoder_get_bits_per_sample()... ");
  926. {
  927. unsigned bits_per_sample = OggFLAC__seekable_stream_decoder_get_bits_per_sample(decoder);
  928. if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
  929. printf("FAILED, returned %u, expected %un", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
  930. return false;
  931. }
  932. }
  933. printf("OKn");
  934. printf("testing OggFLAC__seekable_stream_decoder_get_sample_rate()... ");
  935. {
  936. unsigned sample_rate = OggFLAC__seekable_stream_decoder_get_sample_rate(decoder);
  937. if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
  938. printf("FAILED, returned %u, expected %un", sample_rate, streaminfo_.data.stream_info.sample_rate);
  939. return false;
  940. }
  941. }
  942. printf("OKn");
  943. printf("testing OggFLAC__seekable_stream_decoder_get_blocksize()... ");
  944. {
  945. unsigned blocksize = OggFLAC__seekable_stream_decoder_get_blocksize(decoder);
  946. /* value could be anything since we're at the last block, so accept any answer */
  947. printf("returned %u... OKn", blocksize);
  948. }
  949. printf("testing OggFLAC__seekable_stream_decoder_get_channel_assignment()... ");
  950. {
  951. FLAC__ChannelAssignment ca = OggFLAC__seekable_stream_decoder_get_channel_assignment(decoder);
  952. printf("returned %u (%s)... OKn", (unsigned)ca, FLAC__ChannelAssignmentString[ca]);
  953. }
  954. printf("testing OggFLAC__seekable_stream_decoder_reset()... ");
  955. if(!OggFLAC__seekable_stream_decoder_reset(decoder))
  956. return die_ss_("returned false", decoder);
  957. printf("OKn");
  958. decoder_client_data.current_metadata_number = 0;
  959. printf("rewinding input... ");
  960. if(fseek(decoder_client_data.file, 0, SEEK_SET) < 0) {
  961. printf("FAILED, errno = %dn", errno);
  962. return false;
  963. }
  964. printf("OKn");
  965. printf("testing OggFLAC__seekable_stream_decoder_process_until_end_of_stream()... ");
  966. if(!OggFLAC__seekable_stream_decoder_process_until_end_of_stream(decoder))
  967. return die_ss_("returned false", decoder);
  968. printf("OKn");
  969. printf("testing OggFLAC__seekable_stream_decoder_finish()... ");
  970. (void) OggFLAC__seekable_stream_decoder_finish(decoder);
  971. printf("OKn");
  972. /*
  973.  * respond all
  974.  */
  975. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_respond_all()... ");
  976. if(!OggFLAC__seekable_stream_decoder_set_metadata_respond_all(decoder))
  977. return die_ss_("returned false", decoder);
  978. printf("OKn");
  979. num_expected_ = 0;
  980. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  981. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  982. expected_metadata_sequence_[num_expected_++] = &padding_;
  983. expected_metadata_sequence_[num_expected_++] = &seektable_;
  984. expected_metadata_sequence_[num_expected_++] = &application1_;
  985. expected_metadata_sequence_[num_expected_++] = &application2_;
  986. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  987. expected_metadata_sequence_[num_expected_++] = &unknown_;
  988. if(!seekable_stream_decoder_test_respond_(decoder, &decoder_client_data))
  989. return false;
  990. /*
  991.  * ignore all
  992.  */
  993. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_ignore_all()... ");
  994. if(!OggFLAC__seekable_stream_decoder_set_metadata_ignore_all(decoder))
  995. return die_ss_("returned false", decoder);
  996. printf("OKn");
  997. num_expected_ = 0;
  998. if(!seekable_stream_decoder_test_respond_(decoder, &decoder_client_data))
  999. return false;
  1000. /*
  1001.  * respond all, ignore VORBIS_COMMENT
  1002.  */
  1003. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_respond_all()... ");
  1004. if(!OggFLAC__seekable_stream_decoder_set_metadata_respond_all(decoder))
  1005. return die_ss_("returned false", decoder);
  1006. printf("OKn");
  1007. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_ignore(VORBIS_COMMENT)... ");
  1008. if(!OggFLAC__seekable_stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT))
  1009. return die_ss_("returned false", decoder);
  1010. printf("OKn");
  1011. num_expected_ = 0;
  1012. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1013. expected_metadata_sequence_[num_expected_++] = &padding_;
  1014. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1015. expected_metadata_sequence_[num_expected_++] = &application1_;
  1016. expected_metadata_sequence_[num_expected_++] = &application2_;
  1017. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1018. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1019. if(!seekable_stream_decoder_test_respond_(decoder, &decoder_client_data))
  1020. return false;
  1021. /*
  1022.  * respond all, ignore APPLICATION
  1023.  */
  1024. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_respond_all()... ");
  1025. if(!OggFLAC__seekable_stream_decoder_set_metadata_respond_all(decoder))
  1026. return die_ss_("returned false", decoder);
  1027. printf("OKn");
  1028. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_ignore(APPLICATION)... ");
  1029. if(!OggFLAC__seekable_stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_APPLICATION))
  1030. return die_ss_("returned false", decoder);
  1031. printf("OKn");
  1032. num_expected_ = 0;
  1033. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1034. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1035. expected_metadata_sequence_[num_expected_++] = &padding_;
  1036. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1037. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1038. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1039. if(!seekable_stream_decoder_test_respond_(decoder, &decoder_client_data))
  1040. return false;
  1041. /*
  1042.  * respond all, ignore APPLICATION id of app#1
  1043.  */
  1044. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_respond_all()... ");
  1045. if(!OggFLAC__seekable_stream_decoder_set_metadata_respond_all(decoder))
  1046. return die_ss_("returned false", decoder);
  1047. printf("OKn");
  1048. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_ignore_application(of app block #1)... ");
  1049. if(!OggFLAC__seekable_stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id))
  1050. return die_ss_("returned false", decoder);
  1051. printf("OKn");
  1052. num_expected_ = 0;
  1053. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1054. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1055. expected_metadata_sequence_[num_expected_++] = &padding_;
  1056. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1057. expected_metadata_sequence_[num_expected_++] = &application2_;
  1058. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1059. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1060. if(!seekable_stream_decoder_test_respond_(decoder, &decoder_client_data))
  1061. return false;
  1062. /*
  1063.  * respond all, ignore APPLICATION id of app#1 & app#2
  1064.  */
  1065. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_respond_all()... ");
  1066. if(!OggFLAC__seekable_stream_decoder_set_metadata_respond_all(decoder))
  1067. return die_ss_("returned false", decoder);
  1068. printf("OKn");
  1069. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_ignore_application(of app block #1)... ");
  1070. if(!OggFLAC__seekable_stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id))
  1071. return die_ss_("returned false", decoder);
  1072. printf("OKn");
  1073. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_ignore_application(of app block #2)... ");
  1074. if(!OggFLAC__seekable_stream_decoder_set_metadata_ignore_application(decoder, application2_.data.application.id))
  1075. return die_ss_("returned false", decoder);
  1076. printf("OKn");
  1077. num_expected_ = 0;
  1078. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1079. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1080. expected_metadata_sequence_[num_expected_++] = &padding_;
  1081. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1082. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1083. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1084. if(!seekable_stream_decoder_test_respond_(decoder, &decoder_client_data))
  1085. return false;
  1086. /*
  1087.  * ignore all, respond VORBIS_COMMENT
  1088.  */
  1089. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_ignore_all()... ");
  1090. if(!OggFLAC__seekable_stream_decoder_set_metadata_ignore_all(decoder))
  1091. return die_ss_("returned false", decoder);
  1092. printf("OKn");
  1093. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_respond(VORBIS_COMMENT)... ");
  1094. if(!OggFLAC__seekable_stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT))
  1095. return die_ss_("returned false", decoder);
  1096. printf("OKn");
  1097. num_expected_ = 0;
  1098. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1099. if(!seekable_stream_decoder_test_respond_(decoder, &decoder_client_data))
  1100. return false;
  1101. /*
  1102.  * ignore all, respond APPLICATION
  1103.  */
  1104. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_ignore_all()... ");
  1105. if(!OggFLAC__seekable_stream_decoder_set_metadata_ignore_all(decoder))
  1106. return die_ss_("returned false", decoder);
  1107. printf("OKn");
  1108. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_respond(APPLICATION)... ");
  1109. if(!OggFLAC__seekable_stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_APPLICATION))
  1110. return die_ss_("returned false", decoder);
  1111. printf("OKn");
  1112. num_expected_ = 0;
  1113. expected_metadata_sequence_[num_expected_++] = &application1_;
  1114. expected_metadata_sequence_[num_expected_++] = &application2_;
  1115. if(!seekable_stream_decoder_test_respond_(decoder, &decoder_client_data))
  1116. return false;
  1117. /*
  1118.  * ignore all, respond APPLICATION id of app#1
  1119.  */
  1120. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_ignore_all()... ");
  1121. if(!OggFLAC__seekable_stream_decoder_set_metadata_ignore_all(decoder))
  1122. return die_ss_("returned false", decoder);
  1123. printf("OKn");
  1124. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_respond_application(of app block #1)... ");
  1125. if(!OggFLAC__seekable_stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id))
  1126. return die_ss_("returned false", decoder);
  1127. printf("OKn");
  1128. num_expected_ = 0;
  1129. expected_metadata_sequence_[num_expected_++] = &application1_;
  1130. if(!seekable_stream_decoder_test_respond_(decoder, &decoder_client_data))
  1131. return false;
  1132. /*
  1133.  * ignore all, respond APPLICATION id of app#1 & app#2
  1134.  */
  1135. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_ignore_all()... ");
  1136. if(!OggFLAC__seekable_stream_decoder_set_metadata_ignore_all(decoder))
  1137. return die_ss_("returned false", decoder);
  1138. printf("OKn");
  1139. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_respond_application(of app block #1)... ");
  1140. if(!OggFLAC__seekable_stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id))
  1141. return die_ss_("returned false", decoder);
  1142. printf("OKn");
  1143. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_respond_application(of app block #2)... ");
  1144. if(!OggFLAC__seekable_stream_decoder_set_metadata_respond_application(decoder, application2_.data.application.id))
  1145. return die_ss_("returned false", decoder);
  1146. printf("OKn");
  1147. num_expected_ = 0;
  1148. expected_metadata_sequence_[num_expected_++] = &application1_;
  1149. expected_metadata_sequence_[num_expected_++] = &application2_;
  1150. if(!seekable_stream_decoder_test_respond_(decoder, &decoder_client_data))
  1151. return false;
  1152. /*
  1153.  * respond all, ignore APPLICATION, respond APPLICATION id of app#1
  1154.  */
  1155. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_respond_all()... ");
  1156. if(!OggFLAC__seekable_stream_decoder_set_metadata_respond_all(decoder))
  1157. return die_ss_("returned false", decoder);
  1158. printf("OKn");
  1159. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_ignore(APPLICATION)... ");
  1160. if(!OggFLAC__seekable_stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_APPLICATION))
  1161. return die_ss_("returned false", decoder);
  1162. printf("OKn");
  1163. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_respond_application(of app block #1)... ");
  1164. if(!OggFLAC__seekable_stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id))
  1165. return die_ss_("returned false", decoder);
  1166. printf("OKn");
  1167. num_expected_ = 0;
  1168. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1169. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1170. expected_metadata_sequence_[num_expected_++] = &padding_;
  1171. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1172. expected_metadata_sequence_[num_expected_++] = &application1_;
  1173. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1174. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1175. if(!seekable_stream_decoder_test_respond_(decoder, &decoder_client_data))
  1176. return false;
  1177. /*
  1178.  * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
  1179.  */
  1180. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_ignore_all()... ");
  1181. if(!OggFLAC__seekable_stream_decoder_set_metadata_ignore_all(decoder))
  1182. return die_ss_("returned false", decoder);
  1183. printf("OKn");
  1184. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_respond(APPLICATION)... ");
  1185. if(!OggFLAC__seekable_stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_APPLICATION))
  1186. return die_ss_("returned false", decoder);
  1187. printf("OKn");
  1188. printf("testing OggFLAC__seekable_stream_decoder_set_metadata_ignore_application(of app block #1)... ");
  1189. if(!OggFLAC__seekable_stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id))
  1190. return die_ss_("returned false", decoder);
  1191. printf("OKn");
  1192. num_expected_ = 0;
  1193. expected_metadata_sequence_[num_expected_++] = &application2_;
  1194. if(!seekable_stream_decoder_test_respond_(decoder, &decoder_client_data))
  1195. return false;
  1196. /* done, now leave the sequence the way we found it... */
  1197. num_expected_ = 0;
  1198. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1199. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1200. expected_metadata_sequence_[num_expected_++] = &padding_;
  1201. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1202. expected_metadata_sequence_[num_expected_++] = &application1_;
  1203. expected_metadata_sequence_[num_expected_++] = &application2_;
  1204. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1205. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1206. printf("testing OggFLAC__seekable_stream_decoder_delete()... ");
  1207. OggFLAC__seekable_stream_decoder_delete(decoder);
  1208. printf("OKn");
  1209. fclose(decoder_client_data.file);
  1210. printf("nPASSED!n");
  1211. return true;
  1212. }
  1213. static FLAC__StreamDecoderWriteStatus file_decoder_write_callback_(const OggFLAC__FileDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  1214. {
  1215. (void)decoder;
  1216. return stream_decoder_write_callback_(0, frame, buffer, client_data);
  1217. }
  1218. static void file_decoder_metadata_callback_(const OggFLAC__FileDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  1219. {
  1220. (void)decoder;
  1221. stream_decoder_metadata_callback_(0, metadata, client_data);
  1222. }
  1223. static void file_decoder_error_callback_(const OggFLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  1224. {
  1225. (void)decoder;
  1226. stream_decoder_error_callback_(0, status, client_data);
  1227. }
  1228. static FLAC__bool file_decoder_test_respond_(OggFLAC__FileDecoder *decoder, file_decoder_client_data_struct *dcd)
  1229. {
  1230. if(!OggFLAC__file_decoder_set_write_callback(decoder, file_decoder_write_callback_))
  1231. return die_f_("at OggFLAC__file_decoder_set_write_callback(), returned false", decoder);
  1232. if(!OggFLAC__file_decoder_set_metadata_callback(decoder, file_decoder_metadata_callback_))
  1233. return die_f_("at OggFLAC__file_decoder_set_metadata_callback(), returned false", decoder);
  1234. if(!OggFLAC__file_decoder_set_error_callback(decoder, file_decoder_error_callback_))
  1235. return die_f_("at OggFLAC__file_decoder_set_error_callback(), returned false", decoder);
  1236. if(!OggFLAC__file_decoder_set_client_data(decoder, dcd))
  1237. return die_f_("at OggFLAC__file_decoder_set_client_data(), returned false", decoder);
  1238. if(!OggFLAC__file_decoder_set_filename(decoder, oggflacfilename_))
  1239. return die_f_("at OggFLAC__file_decoder_set_filename(), returned false", decoder);
  1240. if(!OggFLAC__file_decoder_set_md5_checking(decoder, true))
  1241. return die_f_("at OggFLAC__file_decoder_set_md5_checking(), returned false", decoder);
  1242. printf("testing OggFLAC__file_decoder_init()... ");
  1243. if(OggFLAC__file_decoder_init(decoder) != OggFLAC__FILE_DECODER_OK)
  1244. return die_f_(0, decoder);
  1245. printf("OKn");
  1246. dcd->current_metadata_number = 0;
  1247. printf("testing OggFLAC__file_decoder_process_until_end_of_file()... ");
  1248. if(!OggFLAC__file_decoder_process_until_end_of_file(decoder))
  1249. return die_f_("returned false", decoder);
  1250. printf("OKn");
  1251. printf("testing OggFLAC__file_decoder_finish()... ");
  1252. (void) OggFLAC__file_decoder_finish(decoder);
  1253. printf("OKn");
  1254. return true;
  1255. }
  1256. static FLAC__bool test_file_decoder()
  1257. {
  1258. OggFLAC__FileDecoder *decoder;
  1259. OggFLAC__FileDecoderState state;
  1260. OggFLAC__SeekableStreamDecoderState ssstate;
  1261. OggFLAC__StreamDecoderState sstate;
  1262. FLAC__StreamDecoderState fstate;
  1263. seekable_stream_decoder_client_data_struct decoder_client_data;
  1264. printf("n+++ libOggFLAC unit test: OggFLAC__FileDecodernn");
  1265. printf("testing OggFLAC__file_decoder_new()... ");
  1266. decoder = OggFLAC__file_decoder_new();
  1267. if(0 == decoder) {
  1268. printf("FAILED, returned NULLn");
  1269. return false;
  1270. }
  1271. printf("OKn");
  1272. printf("testing OggFLAC__file_decoder_delete()... ");
  1273. OggFLAC__file_decoder_delete(decoder);
  1274. printf("OKn");
  1275. printf("testing OggFLAC__file_decoder_new()... ");
  1276. decoder = OggFLAC__file_decoder_new();
  1277. if(0 == decoder) {
  1278. printf("FAILED, returned NULLn");
  1279. return false;
  1280. }
  1281. printf("OKn");
  1282. printf("testing OggFLAC__file_decoder_init()... ");
  1283. if(OggFLAC__file_decoder_init(decoder) == OggFLAC__FILE_DECODER_OK)
  1284. return die_f_(0, decoder);
  1285. printf("OKn");
  1286. printf("testing OggFLAC__file_decoder_delete()... ");
  1287. OggFLAC__file_decoder_delete(decoder);
  1288. printf("OKn");
  1289. num_expected_ = 0;
  1290. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1291. printf("testing OggFLAC__file_decoder_new()... ");
  1292. decoder = OggFLAC__file_decoder_new();
  1293. if(0 == decoder) {
  1294. printf("FAILED, returned NULLn");
  1295. return false;
  1296. }
  1297. printf("OKn");
  1298. printf("testing OggFLAC__file_decoder_set_serial_number()... ");
  1299. if(!OggFLAC__file_decoder_set_serial_number(decoder, file_utils__serial_number))
  1300. return die_f_("returned false", decoder);
  1301. printf("OKn");
  1302. printf("testing OggFLAC__file_decoder_set_write_callback()... ");
  1303. if(!OggFLAC__file_decoder_set_write_callback(decoder, file_decoder_write_callback_))
  1304. return die_f_("returned false", decoder);
  1305. printf("OKn");
  1306. printf("testing OggFLAC__file_decoder_set_metadata_callback()... ");
  1307. if(!OggFLAC__file_decoder_set_metadata_callback(decoder, file_decoder_metadata_callback_))
  1308. return die_f_("returned false", decoder);
  1309. printf("OKn");
  1310. printf("testing OggFLAC__file_decoder_set_error_callback()... ");
  1311. if(!OggFLAC__file_decoder_set_error_callback(decoder, file_decoder_error_callback_))
  1312. return die_f_("returned false", decoder);
  1313. printf("OKn");
  1314. printf("testing OggFLAC__file_decoder_set_client_data()... ");
  1315. if(!OggFLAC__file_decoder_set_client_data(decoder, &decoder_client_data))
  1316. return die_f_("returned false", decoder);
  1317. printf("OKn");
  1318. printf("testing OggFLAC__file_decoder_set_filename()... ");
  1319. if(!OggFLAC__file_decoder_set_filename(decoder, oggflacfilename_))
  1320. return die_f_("returned false", decoder);
  1321. printf("OKn");
  1322. printf("testing OggFLAC__file_decoder_set_md5_checking()... ");
  1323. if(!OggFLAC__file_decoder_set_md5_checking(decoder, true))
  1324. return die_f_("returned false", decoder);
  1325. printf("OKn");
  1326. printf("testing OggFLAC__file_decoder_init()... ");
  1327. if(OggFLAC__file_decoder_init(decoder) != OggFLAC__FILE_DECODER_OK)
  1328. return die_f_(0, decoder);
  1329. printf("OKn");
  1330. printf("testing OggFLAC__file_decoder_get_state()... ");
  1331. state = OggFLAC__file_decoder_get_state(decoder);
  1332. printf("returned state = %u (%s)... OKn", state, OggFLAC__FileDecoderStateString[state]);
  1333. printf("testing OggFLAC__file_decoder_get_seekable_stream_decoder_state()... ");
  1334. ssstate = OggFLAC__file_decoder_get_seekable_stream_decoder_state(decoder);
  1335. printf("returned state = %u (%s)... OKn", ssstate, OggFLAC__SeekableStreamDecoderStateString[ssstate]);
  1336. printf("testing OggFLAC__file_decoder_get_stream_decoder_state()... ");
  1337. sstate = OggFLAC__file_decoder_get_stream_decoder_state(decoder);
  1338. printf("returned state = %u (%s)... OKn", sstate, OggFLAC__StreamDecoderStateString[sstate]);
  1339. printf("testing OggFLAC__file_decoder_get_FLAC_stream_decoder_state()... ");
  1340. fstate = OggFLAC__file_decoder_get_FLAC_stream_decoder_state(decoder);
  1341. printf("returned state = %u (%s)... OKn", fstate, FLAC__StreamDecoderStateString[fstate]);
  1342. decoder_client_data.current_metadata_number = 0;
  1343. decoder_client_data.ignore_errors = false;
  1344. decoder_client_data.error_occurred = false;
  1345. printf("testing OggFLAC__file_decoder_get_md5_checking()... ");
  1346. if(!OggFLAC__file_decoder_get_md5_checking(decoder)) {
  1347. printf("FAILED, returned false, expected truen");
  1348. return false;
  1349. }
  1350. printf("OKn");
  1351. printf("testing OggFLAC__file_decoder_process_until_end_of_metadata()... ");
  1352. if(!OggFLAC__file_decoder_process_until_end_of_metadata(decoder))
  1353. return die_f_("returned false", decoder);
  1354. printf("OKn");
  1355. printf("testing OggFLAC__file_decoder_process_single()... ");
  1356. if(!OggFLAC__file_decoder_process_single(decoder))
  1357. return die_f_("returned false", decoder);
  1358. printf("OKn");
  1359. printf("testing OggFLAC__file_decoder_seek_absolute()... ");
  1360. if(!OggFLAC__file_decoder_seek_absolute(decoder, 0))
  1361. return die_f_("returned false", decoder);
  1362. printf("OKn");
  1363. printf("testing OggFLAC__file_decoder_process_until_end_of_file()... ");
  1364. if(!OggFLAC__file_decoder_process_until_end_of_file(decoder))
  1365. return die_f_("returned false", decoder);
  1366. printf("OKn");
  1367. printf("testing OggFLAC__file_decoder_get_channels()... ");
  1368. {
  1369. unsigned channels = OggFLAC__file_decoder_get_channels(decoder);
  1370. if(channels != streaminfo_.data.stream_info.channels) {
  1371. printf("FAILED, returned %u, expected %un", channels, streaminfo_.data.stream_info.channels);
  1372. return false;
  1373. }
  1374. }
  1375. printf("OKn");
  1376. printf("testing OggFLAC__file_decoder_get_bits_per_sample()... ");
  1377. {
  1378. unsigned bits_per_sample = OggFLAC__file_decoder_get_bits_per_sample(decoder);
  1379. if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
  1380. printf("FAILED, returned %u, expected %un", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
  1381. return false;
  1382. }
  1383. }
  1384. printf("OKn");
  1385. printf("testing OggFLAC__file_decoder_get_sample_rate()... ");
  1386. {
  1387. unsigned sample_rate = OggFLAC__file_decoder_get_sample_rate(decoder);
  1388. if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
  1389. printf("FAILED, returned %u, expected %un", sample_rate, streaminfo_.data.stream_info.sample_rate);
  1390. return false;
  1391. }
  1392. }
  1393. printf("OKn");
  1394. printf("testing OggFLAC__file_decoder_get_blocksize()... ");
  1395. {
  1396. unsigned blocksize = OggFLAC__file_decoder_get_blocksize(decoder);
  1397. /* value could be anything since we're at the last block, so accept any answer */
  1398. printf("returned %u... OKn", blocksize);
  1399. }
  1400. printf("testing OggFLAC__file_decoder_get_channel_assignment()... ");
  1401. {
  1402. FLAC__ChannelAssignment ca = OggFLAC__file_decoder_get_channel_assignment(decoder);
  1403. printf("returned %u (%s)... OKn", (unsigned)ca, FLAC__ChannelAssignmentString[ca]);
  1404. }
  1405. printf("testing OggFLAC__file_decoder_finish()... ");
  1406. (void) OggFLAC__file_decoder_finish(decoder);
  1407. printf("OKn");
  1408. /*
  1409.  * respond all
  1410.  */
  1411. printf("testing OggFLAC__file_decoder_set_metadata_respond_all()... ");
  1412. if(!OggFLAC__file_decoder_set_metadata_respond_all(decoder))
  1413. return die_f_("returned false", decoder);
  1414. printf("OKn");
  1415. num_expected_ = 0;
  1416. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1417. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1418. expected_metadata_sequence_[num_expected_++] = &padding_;
  1419. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1420. expected_metadata_sequence_[num_expected_++] = &application1_;
  1421. expected_metadata_sequence_[num_expected_++] = &application2_;
  1422. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1423. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1424. if(!file_decoder_test_respond_(decoder, &decoder_client_data))
  1425. return false;
  1426. /*
  1427.  * ignore all
  1428.  */
  1429. printf("testing OggFLAC__file_decoder_set_metadata_ignore_all()... ");
  1430. if(!OggFLAC__file_decoder_set_metadata_ignore_all(decoder))
  1431. return die_f_("returned false", decoder);
  1432. printf("OKn");
  1433. num_expected_ = 0;
  1434. if(!file_decoder_test_respond_(decoder, &decoder_client_data))
  1435. return false;
  1436. /*
  1437.  * respond all, ignore VORBIS_COMMENT
  1438.  */
  1439. printf("testing OggFLAC__file_decoder_set_metadata_respond_all()... ");
  1440. if(!OggFLAC__file_decoder_set_metadata_respond_all(decoder))
  1441. return die_f_("returned false", decoder);
  1442. printf("OKn");
  1443. printf("testing OggFLAC__file_decoder_set_metadata_ignore(VORBIS_COMMENT)... ");
  1444. if(!OggFLAC__file_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT))
  1445. return die_f_("returned false", decoder);
  1446. printf("OKn");
  1447. num_expected_ = 0;
  1448. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1449. expected_metadata_sequence_[num_expected_++] = &padding_;
  1450. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1451. expected_metadata_sequence_[num_expected_++] = &application1_;
  1452. expected_metadata_sequence_[num_expected_++] = &application2_;
  1453. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1454. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1455. if(!file_decoder_test_respond_(decoder, &decoder_client_data))
  1456. return false;
  1457. /*
  1458.  * respond all, ignore APPLICATION
  1459.  */
  1460. printf("testing OggFLAC__file_decoder_set_metadata_respond_all()... ");
  1461. if(!OggFLAC__file_decoder_set_metadata_respond_all(decoder))
  1462. return die_f_("returned false", decoder);
  1463. printf("OKn");
  1464. printf("testing OggFLAC__file_decoder_set_metadata_ignore(APPLICATION)... ");
  1465. if(!OggFLAC__file_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_APPLICATION))
  1466. return die_f_("returned false", decoder);
  1467. printf("OKn");
  1468. num_expected_ = 0;
  1469. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1470. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1471. expected_metadata_sequence_[num_expected_++] = &padding_;
  1472. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1473. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1474. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1475. if(!file_decoder_test_respond_(decoder, &decoder_client_data))
  1476. return false;
  1477. /*
  1478.  * respond all, ignore APPLICATION id of app#1
  1479.  */
  1480. printf("testing OggFLAC__file_decoder_set_metadata_respond_all()... ");
  1481. if(!OggFLAC__file_decoder_set_metadata_respond_all(decoder))
  1482. return die_f_("returned false", decoder);
  1483. printf("OKn");
  1484. printf("testing OggFLAC__file_decoder_set_metadata_ignore_application(of app block #1)... ");
  1485. if(!OggFLAC__file_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id))
  1486. return die_f_("returned false", decoder);
  1487. printf("OKn");
  1488. num_expected_ = 0;
  1489. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1490. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1491. expected_metadata_sequence_[num_expected_++] = &padding_;
  1492. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1493. expected_metadata_sequence_[num_expected_++] = &application2_;
  1494. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1495. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1496. if(!file_decoder_test_respond_(decoder, &decoder_client_data))
  1497. return false;
  1498. /*
  1499.  * respond all, ignore APPLICATION id of app#1 & app#2
  1500.  */
  1501. printf("testing OggFLAC__file_decoder_set_metadata_respond_all()... ");
  1502. if(!OggFLAC__file_decoder_set_metadata_respond_all(decoder))
  1503. return die_f_("returned false", decoder);
  1504. printf("OKn");
  1505. printf("testing OggFLAC__file_decoder_set_metadata_ignore_application(of app block #1)... ");
  1506. if(!OggFLAC__file_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id))
  1507. return die_f_("returned false", decoder);
  1508. printf("OKn");
  1509. printf("testing OggFLAC__file_decoder_set_metadata_ignore_application(of app block #2)... ");
  1510. if(!OggFLAC__file_decoder_set_metadata_ignore_application(decoder, application2_.data.application.id))
  1511. return die_f_("returned false", decoder);
  1512. printf("OKn");
  1513. num_expected_ = 0;
  1514. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1515. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1516. expected_metadata_sequence_[num_expected_++] = &padding_;
  1517. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1518. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1519. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1520. if(!file_decoder_test_respond_(decoder, &decoder_client_data))
  1521. return false;
  1522. /*
  1523.  * ignore all, respond VORBIS_COMMENT
  1524.  */
  1525. printf("testing OggFLAC__file_decoder_set_metadata_ignore_all()... ");
  1526. if(!OggFLAC__file_decoder_set_metadata_ignore_all(decoder))
  1527. return die_f_("returned false", decoder);
  1528. printf("OKn");
  1529. printf("testing OggFLAC__file_decoder_set_metadata_respond(VORBIS_COMMENT)... ");
  1530. if(!OggFLAC__file_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT))
  1531. return die_f_("returned false", decoder);
  1532. printf("OKn");
  1533. num_expected_ = 0;
  1534. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1535. if(!file_decoder_test_respond_(decoder, &decoder_client_data))
  1536. return false;
  1537. /*
  1538.  * ignore all, respond APPLICATION
  1539.  */
  1540. printf("testing OggFLAC__file_decoder_set_metadata_ignore_all()... ");
  1541. if(!OggFLAC__file_decoder_set_metadata_ignore_all(decoder))
  1542. return die_f_("returned false", decoder);
  1543. printf("OKn");
  1544. printf("testing OggFLAC__file_decoder_set_metadata_respond(APPLICATION)... ");
  1545. if(!OggFLAC__file_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_APPLICATION))
  1546. return die_f_("returned false", decoder);
  1547. printf("OKn");
  1548. num_expected_ = 0;
  1549. expected_metadata_sequence_[num_expected_++] = &application1_;
  1550. expected_metadata_sequence_[num_expected_++] = &application2_;
  1551. if(!file_decoder_test_respond_(decoder, &decoder_client_data))
  1552. return false;
  1553. /*
  1554.  * ignore all, respond APPLICATION id of app#1
  1555.  */
  1556. printf("testing OggFLAC__file_decoder_set_metadata_ignore_all()... ");
  1557. if(!OggFLAC__file_decoder_set_metadata_ignore_all(decoder))
  1558. return die_f_("returned false", decoder);
  1559. printf("OKn");
  1560. printf("testing OggFLAC__file_decoder_set_metadata_respond_application(of app block #1)... ");
  1561. if(!OggFLAC__file_decoder_set_metadata_respond_application(decoder, application1_.data.application.id))
  1562. return die_f_("returned false", decoder);
  1563. printf("OKn");
  1564. num_expected_ = 0;
  1565. expected_metadata_sequence_[num_expected_++] = &application1_;
  1566. if(!file_decoder_test_respond_(decoder, &decoder_client_data))
  1567. return false;
  1568. /*
  1569.  * ignore all, respond APPLICATION id of app#1 & app#2
  1570.  */
  1571. printf("testing OggFLAC__file_decoder_set_metadata_ignore_all()... ");
  1572. if(!OggFLAC__file_decoder_set_metadata_ignore_all(decoder))
  1573. return die_f_("returned false", decoder);
  1574. printf("OKn");
  1575. printf("testing OggFLAC__file_decoder_set_metadata_respond_application(of app block #1)... ");
  1576. if(!OggFLAC__file_decoder_set_metadata_respond_application(decoder, application1_.data.application.id))
  1577. return die_f_("returned false", decoder);
  1578. printf("OKn");
  1579. printf("testing OggFLAC__file_decoder_set_metadata_respond_application(of app block #2)... ");
  1580. if(!OggFLAC__file_decoder_set_metadata_respond_application(decoder, application2_.data.application.id))
  1581. return die_f_("returned false", decoder);
  1582. printf("OKn");
  1583. num_expected_ = 0;
  1584. expected_metadata_sequence_[num_expected_++] = &application1_;
  1585. expected_metadata_sequence_[num_expected_++] = &application2_;
  1586. if(!file_decoder_test_respond_(decoder, &decoder_client_data))
  1587. return false;
  1588. /*
  1589.  * respond all, ignore APPLICATION, respond APPLICATION id of app#1
  1590.  */
  1591. printf("testing OggFLAC__file_decoder_set_metadata_respond_all()... ");
  1592. if(!OggFLAC__file_decoder_set_metadata_respond_all(decoder))
  1593. return die_f_("returned false", decoder);
  1594. printf("OKn");
  1595. printf("testing OggFLAC__file_decoder_set_metadata_ignore(APPLICATION)... ");
  1596. if(!OggFLAC__file_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_APPLICATION))
  1597. return die_f_("returned false", decoder);
  1598. printf("OKn");
  1599. printf("testing OggFLAC__file_decoder_set_metadata_respond_application(of app block #1)... ");
  1600. if(!OggFLAC__file_decoder_set_metadata_respond_application(decoder, application1_.data.application.id))
  1601. return die_f_("returned false", decoder);
  1602. printf("OKn");
  1603. num_expected_ = 0;
  1604. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1605. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1606. expected_metadata_sequence_[num_expected_++] = &padding_;
  1607. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1608. expected_metadata_sequence_[num_expected_++] = &application1_;
  1609. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1610. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1611. if(!file_decoder_test_respond_(decoder, &decoder_client_data))
  1612. return false;
  1613. /*
  1614.  * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
  1615.  */
  1616. printf("testing OggFLAC__file_decoder_set_metadata_ignore_all()... ");
  1617. if(!OggFLAC__file_decoder_set_metadata_ignore_all(decoder))
  1618. return die_f_("returned false", decoder);
  1619. printf("OKn");
  1620. printf("testing OggFLAC__file_decoder_set_metadata_respond(APPLICATION)... ");
  1621. if(!OggFLAC__file_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_APPLICATION))
  1622. return die_f_("returned false", decoder);
  1623. printf("OKn");
  1624. printf("testing OggFLAC__file_decoder_set_metadata_ignore_application(of app block #1)... ");
  1625. if(!OggFLAC__file_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id))
  1626. return die_f_("returned false", decoder);
  1627. printf("OKn");
  1628. num_expected_ = 0;
  1629. expected_metadata_sequence_[num_expected_++] = &application2_;
  1630. if(!file_decoder_test_respond_(decoder, &decoder_client_data))
  1631. return false;
  1632. /* done, now leave the sequence the way we found it... */
  1633. num_expected_ = 0;
  1634. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1635. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1636. expected_metadata_sequence_[num_expected_++] = &padding_;
  1637. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1638. expected_metadata_sequence_[num_expected_++] = &application1_;
  1639. expected_metadata_sequence_[num_expected_++] = &application2_;
  1640. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1641. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1642. printf("testing OggFLAC__file_decoder_delete()... ");
  1643. OggFLAC__file_decoder_delete(decoder);
  1644. printf("OKn");
  1645. printf("nPASSED!n");
  1646. return true;
  1647. }
  1648. FLAC__bool test_decoders()
  1649. {
  1650. init_metadata_blocks_();
  1651. if(!generate_file_())
  1652. return false;
  1653. if(!test_stream_decoder())
  1654. return false;
  1655. if(!test_seekable_stream_decoder())
  1656. return false;
  1657. if(!test_file_decoder())
  1658. return false;
  1659. (void) grabbag__file_remove_file(oggflacfilename_);
  1660. free_metadata_blocks_();
  1661. return true;
  1662. }