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

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. extern "C" {
  20. #include "file_utils.h"
  21. #include "metadata_utils.h"
  22. }
  23. #include "FLAC/assert.h"
  24. #include "FLAC/metadata.h" // for ::FLAC__metadata_object_is_equal()
  25. #include "OggFLAC++/decoder.h"
  26. #include "share/grabbag.h"
  27. #include <errno.h>
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #ifdef _MSC_VER
  32. // warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning)
  33. #pragma warning ( disable : 4800 )
  34. #endif
  35. static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, unknown_;
  36. static ::FLAC__StreamMetadata *expected_metadata_sequence_[8];
  37. static unsigned num_expected_;
  38. static const char *oggflacfilename_ = "metadata.ogg";
  39. static unsigned oggflacfilesize_;
  40. static bool die_(const char *msg)
  41. {
  42. printf("ERROR: %sn", msg);
  43. return false;
  44. }
  45. static void init_metadata_blocks_()
  46. {
  47. mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
  48. }
  49. static void free_metadata_blocks_()
  50. {
  51. mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
  52. }
  53. static bool generate_file_()
  54. {
  55. printf("nngenerating Ogg FLAC file for decoder tests...n");
  56. num_expected_ = 0;
  57. expected_metadata_sequence_[num_expected_++] = &padding_;
  58. expected_metadata_sequence_[num_expected_++] = &seektable_;
  59. expected_metadata_sequence_[num_expected_++] = &application1_;
  60. expected_metadata_sequence_[num_expected_++] = &application2_;
  61. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  62. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  63. expected_metadata_sequence_[num_expected_++] = &unknown_;
  64. /* WATCHOUT: the encoder should move the VORBIS_COMMENT block to the front, right after STREAMINFO */
  65. if(!file_utils__generate_oggflacfile(oggflacfilename_, &oggflacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_))
  66. return die_("creating the encoded file");
  67. return true;
  68. }
  69. class DecoderCommon {
  70. public:
  71. FILE *file_;
  72. unsigned current_metadata_number_;
  73. bool ignore_errors_;
  74. bool error_occurred_;
  75. DecoderCommon(): file_(0), current_metadata_number_(0), ignore_errors_(false), error_occurred_(false) { }
  76. ::FLAC__StreamDecoderReadStatus common_read_callback_(FLAC__byte buffer[], unsigned *bytes);
  77. ::FLAC__StreamDecoderWriteStatus common_write_callback_(const ::FLAC__Frame *frame);
  78. void common_metadata_callback_(const ::FLAC__StreamMetadata *metadata);
  79. void common_error_callback_(::FLAC__StreamDecoderErrorStatus status);
  80. };
  81. ::FLAC__StreamDecoderReadStatus DecoderCommon::common_read_callback_(FLAC__byte buffer[], unsigned *bytes)
  82. {
  83. if(error_occurred_)
  84. return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  85. if(feof(file_)) {
  86. *bytes = 0;
  87. return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  88. }
  89. else if(*bytes > 0) {
  90. *bytes = ::fread(buffer, 1, *bytes, file_);
  91. if(*bytes == 0) {
  92. if(feof(file_))
  93. return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  94. else
  95. return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  96. }
  97. else {
  98. return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  99. }
  100. }
  101. else
  102. return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
  103. }
  104. ::FLAC__StreamDecoderWriteStatus DecoderCommon::common_write_callback_(const ::FLAC__Frame *frame)
  105. {
  106. if(error_occurred_)
  107. return ::FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  108. if(
  109. (frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER && frame->header.number.frame_number == 0) ||
  110. (frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER && frame->header.number.sample_number == 0)
  111. ) {
  112. printf("content... ");
  113. fflush(stdout);
  114. }
  115. return ::FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  116. }
  117. void DecoderCommon::common_metadata_callback_(const ::FLAC__StreamMetadata *metadata)
  118. {
  119. if(error_occurred_)
  120. return;
  121. printf("%d... ", current_metadata_number_);
  122. fflush(stdout);
  123. if(current_metadata_number_ >= num_expected_) {
  124. (void)die_("got more metadata blocks than expected");
  125. error_occurred_ = true;
  126. }
  127. else {
  128. if(!::FLAC__metadata_object_is_equal(expected_metadata_sequence_[current_metadata_number_], metadata)) {
  129. (void)die_("metadata block mismatch");
  130. error_occurred_ = true;
  131. }
  132. }
  133. current_metadata_number_++;
  134. }
  135. void DecoderCommon::common_error_callback_(::FLAC__StreamDecoderErrorStatus status)
  136. {
  137. if(!ignore_errors_) {
  138. printf("ERROR: got error callback: err = %u (%s)n", (unsigned)status, ::FLAC__StreamDecoderErrorStatusString[status]);
  139. error_occurred_ = true;
  140. }
  141. }
  142. class StreamDecoder : public OggFLAC::Decoder::Stream, public DecoderCommon {
  143. public:
  144. StreamDecoder(): OggFLAC::Decoder::Stream(), DecoderCommon() { }
  145. ~StreamDecoder() { }
  146. // from OggFLAC::Decoder::Stream
  147. ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes);
  148. ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
  149. void metadata_callback(const ::FLAC__StreamMetadata *metadata);
  150. void error_callback(::FLAC__StreamDecoderErrorStatus status);
  151. bool die(const char *msg = 0) const;
  152. bool test_respond();
  153. };
  154. ::FLAC__StreamDecoderReadStatus StreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
  155. {
  156. return common_read_callback_(buffer, bytes);
  157. }
  158. ::FLAC__StreamDecoderWriteStatus StreamDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
  159. {
  160. (void)buffer;
  161. return common_write_callback_(frame);
  162. }
  163. void StreamDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
  164. {
  165. common_metadata_callback_(metadata);
  166. }
  167. void StreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
  168. {
  169. common_error_callback_(status);
  170. }
  171. bool StreamDecoder::die(const char *msg) const
  172. {
  173. State state = get_state();
  174. if(msg)
  175. printf("FAILED, %s", msg);
  176. else
  177. printf("FAILED");
  178. printf(", state = %u (%s)n", (unsigned)((::OggFLAC__StreamDecoderState)state), state.as_cstring());
  179. return false;
  180. }
  181. bool StreamDecoder::test_respond()
  182. {
  183. printf("testing init()... ");
  184. if(init() != ::OggFLAC__STREAM_DECODER_OK)
  185. return die();
  186. printf("OKn");
  187. current_metadata_number_ = 0;
  188. if(::fseek(file_, 0, SEEK_SET) < 0) {
  189. printf("FAILED rewinding input, errno = %dn", errno);
  190. return false;
  191. }
  192. printf("testing process_until_end_of_stream()... ");
  193. if(!process_until_end_of_stream()) {
  194. State state = get_state();
  195. printf("FAILED, returned false, state = %u (%s)n", (unsigned)((::OggFLAC__StreamDecoderState)state), state.as_cstring());
  196. return false;
  197. }
  198. printf("OKn");
  199. printf("testing finish()... ");
  200. finish();
  201. printf("OKn");
  202. return true;
  203. }
  204. static bool test_stream_decoder()
  205. {
  206. StreamDecoder *decoder;
  207. printf("n+++ libOggFLAC++ unit test: OggFLAC::Decoder::Streamnn");
  208. //
  209. // test new -> delete
  210. //
  211. printf("allocating decoder instance... ");
  212. decoder = new StreamDecoder();
  213. if(0 == decoder) {
  214. printf("FAILED, new returned NULLn");
  215. return false;
  216. }
  217. printf("OKn");
  218. printf("testing is_valid()... ");
  219. if(!decoder->is_valid()) {
  220. printf("FAILED, returned falsen");
  221. return false;
  222. }
  223. printf("OKn");
  224. printf("freeing decoder instance... ");
  225. delete decoder;
  226. printf("OKn");
  227. //
  228. // test new -> init -> delete
  229. //
  230. printf("allocating decoder instance... ");
  231. decoder = new StreamDecoder();
  232. if(0 == decoder) {
  233. printf("FAILED, new returned NULLn");
  234. return false;
  235. }
  236. printf("OKn");
  237. printf("testing is_valid()... ");
  238. if(!decoder->is_valid()) {
  239. printf("FAILED, returned falsen");
  240. return false;
  241. }
  242. printf("OKn");
  243. printf("testing init()... ");
  244. if(decoder->init() != ::OggFLAC__STREAM_DECODER_OK)
  245. return decoder->die();
  246. printf("OKn");
  247. printf("freeing decoder instance... ");
  248. delete decoder;
  249. printf("OKn");
  250. //
  251. // test normal usage
  252. //
  253. num_expected_ = 0;
  254. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  255. printf("allocating decoder instance... ");
  256. decoder = new StreamDecoder();
  257. if(0 == decoder) {
  258. printf("FAILED, new returned NULLn");
  259. return false;
  260. }
  261. printf("OKn");
  262. printf("testing is_valid()... ");
  263. if(!decoder->is_valid()) {
  264. printf("FAILED, returned falsen");
  265. return false;
  266. }
  267. printf("OKn");
  268. printf("testing set_serial_number()... ");
  269. if(!decoder->set_serial_number(file_utils__serial_number))
  270. return decoder->die("returned false");
  271. printf("OKn");
  272. printf("testing init()... ");
  273. if(decoder->init() != ::OggFLAC__STREAM_DECODER_OK)
  274. return decoder->die();
  275. printf("OKn");
  276. printf("testing get_state()... ");
  277. OggFLAC::Decoder::Stream::State state = decoder->get_state();
  278. printf("returned state = %u (%s)... OKn", (unsigned)((::OggFLAC__StreamDecoderState)state), state.as_cstring());
  279. printf("testing get_FLAC_stream_decoder_state()... ");
  280. FLAC::Decoder::Stream::State state_ = decoder->get_FLAC_stream_decoder_state();
  281. printf("returned state = %u (%s)... OKn", (unsigned)((::FLAC__StreamDecoderState)state_), state_.as_cstring());
  282. decoder->current_metadata_number_ = 0;
  283. decoder->ignore_errors_ = false;
  284. decoder->error_occurred_ = false;
  285. printf("opening Ogg FLAC file... ");
  286. decoder->file_ = ::fopen(oggflacfilename_, "rb");
  287. if(0 == decoder->file_) {
  288. printf("ERRORn");
  289. return false;
  290. }
  291. printf("OKn");
  292. printf("testing process_until_end_of_metadata()... ");
  293. if(!decoder->process_until_end_of_metadata())
  294. return decoder->die("returned false");
  295. printf("OKn");
  296. printf("testing process_single()... ");
  297. if(!decoder->process_single())
  298. return decoder->die("returned false");
  299. printf("OKn");
  300. printf("testing flush()... ");
  301. if(!decoder->flush())
  302. return decoder->die("returned false");
  303. printf("OKn");
  304. decoder->ignore_errors_ = true;
  305. printf("testing process_single()... ");
  306. if(!decoder->process_single())
  307. return decoder->die("returned false");
  308. printf("OKn");
  309. decoder->ignore_errors_ = false;
  310. printf("testing process_until_end_of_stream()... ");
  311. if(!decoder->process_until_end_of_stream())
  312. return decoder->die("returned false");
  313. printf("OKn");
  314. printf("testing get_channels()... ");
  315. {
  316. unsigned channels = decoder->get_channels();
  317. if(channels != streaminfo_.data.stream_info.channels) {
  318. printf("FAILED, returned %u, expected %un", channels, streaminfo_.data.stream_info.channels);
  319. return false;
  320. }
  321. }
  322. printf("OKn");
  323. printf("testing get_bits_per_sample()... ");
  324. {
  325. unsigned bits_per_sample = decoder->get_bits_per_sample();
  326. if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
  327. printf("FAILED, returned %u, expected %un", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
  328. return false;
  329. }
  330. }
  331. printf("OKn");
  332. printf("testing get_sample_rate()... ");
  333. {
  334. unsigned sample_rate = decoder->get_sample_rate();
  335. if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
  336. printf("FAILED, returned %u, expected %un", sample_rate, streaminfo_.data.stream_info.sample_rate);
  337. return false;
  338. }
  339. }
  340. printf("OKn");
  341. printf("testing get_blocksize()... ");
  342. {
  343. unsigned blocksize = decoder->get_blocksize();
  344. /* value could be anything since we're at the last block, so accept any answer */
  345. printf("returned %u... OKn", blocksize);
  346. }
  347. printf("testing get_channel_assignment()... ");
  348. {
  349. ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
  350. printf("returned %u (%s)... OKn", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
  351. }
  352. printf("testing reset()... ");
  353. if(!decoder->reset())
  354. return decoder->die("returned false");
  355. printf("OKn");
  356. decoder->current_metadata_number_ = 0;
  357. printf("rewinding input... ");
  358. if(::fseek(decoder->file_, 0, SEEK_SET) < 0) {
  359. printf("FAILED, errno = %dn", errno);
  360. return false;
  361. }
  362. printf("OKn");
  363. printf("testing process_until_end_of_stream()... ");
  364. if(!decoder->process_until_end_of_stream())
  365. return decoder->die("returned false");
  366. printf("OKn");
  367. printf("testing finish()... ");
  368. decoder->finish();
  369. printf("OKn");
  370. /*
  371.  * respond all
  372.  */
  373. printf("testing set_metadata_respond_all()... ");
  374. if(!decoder->set_metadata_respond_all()) {
  375. printf("FAILED, returned falsen");
  376. return false;
  377. }
  378. printf("OKn");
  379. num_expected_ = 0;
  380. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  381. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  382. expected_metadata_sequence_[num_expected_++] = &padding_;
  383. expected_metadata_sequence_[num_expected_++] = &seektable_;
  384. expected_metadata_sequence_[num_expected_++] = &application1_;
  385. expected_metadata_sequence_[num_expected_++] = &application2_;
  386. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  387. expected_metadata_sequence_[num_expected_++] = &unknown_;
  388. if(!decoder->test_respond())
  389. return false;
  390. /*
  391.  * ignore all
  392.  */
  393. printf("testing set_metadata_ignore_all()... ");
  394. if(!decoder->set_metadata_ignore_all()) {
  395. printf("FAILED, returned falsen");
  396. return false;
  397. }
  398. printf("OKn");
  399. num_expected_ = 0;
  400. if(!decoder->test_respond())
  401. return false;
  402. /*
  403.  * respond all, ignore VORBIS_COMMENT
  404.  */
  405. printf("testing set_metadata_respond_all()... ");
  406. if(!decoder->set_metadata_respond_all()) {
  407. printf("FAILED, returned falsen");
  408. return false;
  409. }
  410. printf("OKn");
  411. printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
  412. if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
  413. printf("FAILED, returned falsen");
  414. return false;
  415. }
  416. printf("OKn");
  417. num_expected_ = 0;
  418. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  419. expected_metadata_sequence_[num_expected_++] = &padding_;
  420. expected_metadata_sequence_[num_expected_++] = &seektable_;
  421. expected_metadata_sequence_[num_expected_++] = &application1_;
  422. expected_metadata_sequence_[num_expected_++] = &application2_;
  423. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  424. expected_metadata_sequence_[num_expected_++] = &unknown_;
  425. if(!decoder->test_respond())
  426. return false;
  427. /*
  428.  * respond all, ignore APPLICATION
  429.  */
  430. printf("testing set_metadata_respond_all()... ");
  431. if(!decoder->set_metadata_respond_all()) {
  432. printf("FAILED, returned falsen");
  433. return false;
  434. }
  435. printf("OKn");
  436. printf("testing set_metadata_ignore(APPLICATION)... ");
  437. if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
  438. printf("FAILED, returned falsen");
  439. return false;
  440. }
  441. printf("OKn");
  442. num_expected_ = 0;
  443. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  444. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  445. expected_metadata_sequence_[num_expected_++] = &padding_;
  446. expected_metadata_sequence_[num_expected_++] = &seektable_;
  447. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  448. expected_metadata_sequence_[num_expected_++] = &unknown_;
  449. if(!decoder->test_respond())
  450. return false;
  451. /*
  452.  * respond all, ignore APPLICATION id of app#1
  453.  */
  454. printf("testing set_metadata_respond_all()... ");
  455. if(!decoder->set_metadata_respond_all()) {
  456. printf("FAILED, returned falsen");
  457. return false;
  458. }
  459. printf("OKn");
  460. printf("testing set_metadata_ignore_application(of app block #1)... ");
  461. if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
  462. printf("FAILED, returned falsen");
  463. return false;
  464. }
  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_++] = &application2_;
  472. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  473. expected_metadata_sequence_[num_expected_++] = &unknown_;
  474. if(!decoder->test_respond())
  475. return false;
  476. /*
  477.  * respond all, ignore APPLICATION id of app#1 & app#2
  478.  */
  479. printf("testing set_metadata_respond_all()... ");
  480. if(!decoder->set_metadata_respond_all()) {
  481. printf("FAILED, returned falsen");
  482. return false;
  483. }
  484. printf("OKn");
  485. printf("testing set_metadata_ignore_application(of app block #1)... ");
  486. if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
  487. printf("FAILED, returned falsen");
  488. return false;
  489. }
  490. printf("OKn");
  491. printf("testing set_metadata_ignore_application(of app block #2)... ");
  492. if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
  493. printf("FAILED, returned falsen");
  494. return false;
  495. }
  496. printf("OKn");
  497. num_expected_ = 0;
  498. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  499. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  500. expected_metadata_sequence_[num_expected_++] = &padding_;
  501. expected_metadata_sequence_[num_expected_++] = &seektable_;
  502. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  503. expected_metadata_sequence_[num_expected_++] = &unknown_;
  504. if(!decoder->test_respond())
  505. return false;
  506. /*
  507.  * ignore all, respond VORBIS_COMMENT
  508.  */
  509. printf("testing set_metadata_ignore_all()... ");
  510. if(!decoder->set_metadata_ignore_all()) {
  511. printf("FAILED, returned falsen");
  512. return false;
  513. }
  514. printf("OKn");
  515. printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
  516. if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
  517. printf("FAILED, returned falsen");
  518. return false;
  519. }
  520. printf("OKn");
  521. num_expected_ = 0;
  522. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  523. if(!decoder->test_respond())
  524. return false;
  525. /*
  526.  * ignore all, respond APPLICATION
  527.  */
  528. printf("testing set_metadata_ignore_all()... ");
  529. if(!decoder->set_metadata_ignore_all()) {
  530. printf("FAILED, returned falsen");
  531. return false;
  532. }
  533. printf("OKn");
  534. printf("testing set_metadata_respond(APPLICATION)... ");
  535. if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
  536. printf("FAILED, returned falsen");
  537. return false;
  538. }
  539. printf("OKn");
  540. num_expected_ = 0;
  541. expected_metadata_sequence_[num_expected_++] = &application1_;
  542. expected_metadata_sequence_[num_expected_++] = &application2_;
  543. if(!decoder->test_respond())
  544. return false;
  545. /*
  546.  * ignore all, respond APPLICATION id of app#1
  547.  */
  548. printf("testing set_metadata_ignore_all()... ");
  549. if(!decoder->set_metadata_ignore_all()) {
  550. printf("FAILED, returned falsen");
  551. return false;
  552. }
  553. printf("OKn");
  554. printf("testing set_metadata_respond_application(of app block #1)... ");
  555. if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
  556. printf("FAILED, returned falsen");
  557. return false;
  558. }
  559. printf("OKn");
  560. num_expected_ = 0;
  561. expected_metadata_sequence_[num_expected_++] = &application1_;
  562. if(!decoder->test_respond())
  563. return false;
  564. /*
  565.  * ignore all, respond APPLICATION id of app#1 & app#2
  566.  */
  567. printf("testing set_metadata_ignore_all()... ");
  568. if(!decoder->set_metadata_ignore_all()) {
  569. printf("FAILED, returned falsen");
  570. return false;
  571. }
  572. printf("OKn");
  573. printf("testing set_metadata_respond_application(of app block #1)... ");
  574. if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
  575. printf("FAILED, returned falsen");
  576. return false;
  577. }
  578. printf("OKn");
  579. printf("testing set_metadata_respond_application(of app block #2)... ");
  580. if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
  581. printf("FAILED, returned falsen");
  582. return false;
  583. }
  584. printf("OKn");
  585. num_expected_ = 0;
  586. expected_metadata_sequence_[num_expected_++] = &application1_;
  587. expected_metadata_sequence_[num_expected_++] = &application2_;
  588. if(!decoder->test_respond())
  589. return false;
  590. /*
  591.  * respond all, ignore APPLICATION, respond APPLICATION id of app#1
  592.  */
  593. printf("testing set_metadata_respond_all()... ");
  594. if(!decoder->set_metadata_respond_all()) {
  595. printf("FAILED, returned falsen");
  596. return false;
  597. }
  598. printf("OKn");
  599. printf("testing set_metadata_ignore(APPLICATION)... ");
  600. if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
  601. printf("FAILED, returned falsen");
  602. return false;
  603. }
  604. printf("OKn");
  605. printf("testing set_metadata_respond_application(of app block #1)... ");
  606. if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
  607. printf("FAILED, returned falsen");
  608. return false;
  609. }
  610. printf("OKn");
  611. num_expected_ = 0;
  612. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  613. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  614. expected_metadata_sequence_[num_expected_++] = &padding_;
  615. expected_metadata_sequence_[num_expected_++] = &seektable_;
  616. expected_metadata_sequence_[num_expected_++] = &application1_;
  617. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  618. expected_metadata_sequence_[num_expected_++] = &unknown_;
  619. if(!decoder->test_respond())
  620. return false;
  621. /*
  622.  * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
  623.  */
  624. printf("testing set_metadata_ignore_all()... ");
  625. if(!decoder->set_metadata_ignore_all()) {
  626. printf("FAILED, returned falsen");
  627. return false;
  628. }
  629. printf("OKn");
  630. printf("testing set_metadata_respond(APPLICATION)... ");
  631. if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
  632. printf("FAILED, returned falsen");
  633. return false;
  634. }
  635. printf("OKn");
  636. printf("testing set_metadata_ignore_application(of app block #1)... ");
  637. if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
  638. printf("FAILED, returned falsen");
  639. return false;
  640. }
  641. printf("OKn");
  642. num_expected_ = 0;
  643. expected_metadata_sequence_[num_expected_++] = &application2_;
  644. if(!decoder->test_respond())
  645. return false;
  646. /* done, now leave the sequence the way we found it... */
  647. num_expected_ = 0;
  648. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  649. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  650. expected_metadata_sequence_[num_expected_++] = &padding_;
  651. expected_metadata_sequence_[num_expected_++] = &seektable_;
  652. expected_metadata_sequence_[num_expected_++] = &application1_;
  653. expected_metadata_sequence_[num_expected_++] = &application2_;
  654. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  655. expected_metadata_sequence_[num_expected_++] = &unknown_;
  656. ::fclose(decoder->file_);
  657. printf("freeing decoder instance... ");
  658. delete decoder;
  659. printf("OKn");
  660. printf("nPASSED!n");
  661. return true;
  662. }
  663. class SeekableStreamDecoder : public OggFLAC::Decoder::SeekableStream, public DecoderCommon {
  664. public:
  665. SeekableStreamDecoder(): OggFLAC::Decoder::SeekableStream(), DecoderCommon() { }
  666. ~SeekableStreamDecoder() { }
  667. // from OggFLAC::Decoder::SeekableStream
  668. ::OggFLAC__SeekableStreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes);
  669. ::OggFLAC__SeekableStreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
  670. ::OggFLAC__SeekableStreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
  671. ::OggFLAC__SeekableStreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length);
  672. bool eof_callback();
  673. ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
  674. void metadata_callback(const ::FLAC__StreamMetadata *metadata);
  675. void error_callback(::FLAC__StreamDecoderErrorStatus status);
  676. bool die(const char *msg = 0) const;
  677. bool test_respond();
  678. };
  679. ::OggFLAC__SeekableStreamDecoderReadStatus SeekableStreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
  680. {
  681. switch(common_read_callback_(buffer, bytes)) {
  682. case ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
  683. case ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
  684. return ::OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;
  685. case ::FLAC__STREAM_DECODER_READ_STATUS_ABORT:
  686. return ::OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
  687. default:
  688. FLAC__ASSERT(0);
  689. return ::OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
  690. }
  691. }
  692. ::OggFLAC__SeekableStreamDecoderSeekStatus SeekableStreamDecoder::seek_callback(FLAC__uint64 absolute_byte_offset)
  693. {
  694. if(error_occurred_)
  695. return ::OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
  696. if(::fseek(file_, (long)absolute_byte_offset, SEEK_SET) < 0) {
  697. error_occurred_ = true;
  698. return ::OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
  699. }
  700. return ::OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;
  701. }
  702. ::OggFLAC__SeekableStreamDecoderTellStatus SeekableStreamDecoder::tell_callback(FLAC__uint64 *absolute_byte_offset)
  703. {
  704. if(error_occurred_)
  705. return ::OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
  706. long offset = ::ftell(file_);
  707. *absolute_byte_offset = (FLAC__uint64)offset;
  708. if(offset < 0) {
  709. error_occurred_ = true;
  710. return ::OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
  711. }
  712. return ::OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK;
  713. }
  714. ::OggFLAC__SeekableStreamDecoderLengthStatus SeekableStreamDecoder::length_callback(FLAC__uint64 *stream_length)
  715. {
  716. if(error_occurred_)
  717. return ::OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR;
  718. *stream_length = (FLAC__uint64)oggflacfilesize_;
  719. return ::OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK;
  720. }
  721. bool SeekableStreamDecoder::eof_callback()
  722. {
  723. if(error_occurred_)
  724. return true;
  725. return (bool)feof(file_);
  726. }
  727. ::FLAC__StreamDecoderWriteStatus SeekableStreamDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
  728. {
  729. (void)buffer;
  730. return common_write_callback_(frame);
  731. }
  732. void SeekableStreamDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
  733. {
  734. common_metadata_callback_(metadata);
  735. }
  736. void SeekableStreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
  737. {
  738. common_error_callback_(status);
  739. }
  740. bool SeekableStreamDecoder::die(const char *msg) const
  741. {
  742. State state = get_state();
  743. if(msg)
  744. printf("FAILED, %s", msg);
  745. else
  746. printf("FAILED");
  747. printf(", state = %u (%s)n", (unsigned)((::OggFLAC__SeekableStreamDecoderState)state), state.as_cstring());
  748. if(state == ::OggFLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR) {
  749. OggFLAC::Decoder::Stream::State state_ = get_stream_decoder_state();
  750. printf("      stream decoder state = %u (%s)n", (unsigned)((::OggFLAC__StreamDecoderState)state_), state_.as_cstring());
  751. if(state_ == ::OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR) {
  752. FLAC::Decoder::Stream::State state__ = get_FLAC_stream_decoder_state();
  753. printf("      FLAC stream decoder state = %u (%s)n", (unsigned)((::FLAC__StreamDecoderState)state__), state__.as_cstring());
  754. }
  755. }
  756. return false;
  757. }
  758. bool SeekableStreamDecoder::test_respond()
  759. {
  760. if(!set_md5_checking(true)) {
  761. printf("FAILED at set_md5_checking(), returned falsen");
  762. return false;
  763. }
  764. printf("testing init()... ");
  765. if(init() != ::OggFLAC__SEEKABLE_STREAM_DECODER_OK)
  766. return die();
  767. printf("OKn");
  768. current_metadata_number_ = 0;
  769. if(::fseek(file_, 0, SEEK_SET) < 0) {
  770. printf("FAILED rewinding input, errno = %dn", errno);
  771. return false;
  772. }
  773. printf("testing process_until_end_of_stream()... ");
  774. if(!process_until_end_of_stream()) {
  775. State state = get_state();
  776. printf("FAILED, returned false, state = %u (%s)n", (unsigned)((::OggFLAC__SeekableStreamDecoderState)state), state.as_cstring());
  777. return false;
  778. }
  779. printf("OKn");
  780. printf("testing finish()... ");
  781. finish();
  782. printf("OKn");
  783. return true;
  784. }
  785. static bool test_seekable_stream_decoder()
  786. {
  787. SeekableStreamDecoder *decoder;
  788. printf("n+++ libOggFLAC++ unit test: OggFLAC::Decoder::SeekableStreamnn");
  789. //
  790. // test new -> delete
  791. //
  792. printf("allocating decoder instance... ");
  793. decoder = new SeekableStreamDecoder();
  794. if(0 == decoder) {
  795. printf("FAILED, new returned NULLn");
  796. return false;
  797. }
  798. printf("OKn");
  799. printf("testing is_valid()... ");
  800. if(!decoder->is_valid()) {
  801. printf("FAILED, returned falsen");
  802. return false;
  803. }
  804. printf("OKn");
  805. printf("freeing decoder instance... ");
  806. delete decoder;
  807. printf("OKn");
  808. //
  809. // test new -> init -> delete
  810. //
  811. printf("allocating decoder instance... ");
  812. decoder = new SeekableStreamDecoder();
  813. if(0 == decoder) {
  814. printf("FAILED, new returned NULLn");
  815. return false;
  816. }
  817. printf("OKn");
  818. printf("testing is_valid()... ");
  819. if(!decoder->is_valid()) {
  820. printf("FAILED, returned falsen");
  821. return false;
  822. }
  823. printf("OKn");
  824. printf("testing init()... ");
  825. if(decoder->init() != ::OggFLAC__SEEKABLE_STREAM_DECODER_OK)
  826. return decoder->die();
  827. printf("OKn");
  828. printf("freeing decoder instance... ");
  829. delete decoder;
  830. printf("OKn");
  831. //
  832. // test normal usage
  833. //
  834. num_expected_ = 0;
  835. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  836. printf("allocating decoder instance... ");
  837. decoder = new SeekableStreamDecoder();
  838. if(0 == decoder) {
  839. printf("FAILED, new returned NULLn");
  840. return false;
  841. }
  842. printf("OKn");
  843. printf("testing is_valid()... ");
  844. if(!decoder->is_valid()) {
  845. printf("FAILED, returned falsen");
  846. return false;
  847. }
  848. printf("OKn");
  849. printf("testing set_md5_checking()... ");
  850. if(!decoder->set_md5_checking(true)) {
  851. printf("FAILED, returned falsen");
  852. return false;
  853. }
  854. printf("OKn");
  855. printf("testing set_serial_number()... ");
  856. if(!decoder->set_serial_number(file_utils__serial_number))
  857. return decoder->die("returned false");
  858. printf("OKn");
  859. printf("testing init()... ");
  860. if(decoder->init() != ::OggFLAC__SEEKABLE_STREAM_DECODER_OK)
  861. return decoder->die();
  862. printf("OKn");
  863. printf("testing get_state()... ");
  864. OggFLAC::Decoder::SeekableStream::State state = decoder->get_state();
  865. printf("returned state = %u (%s)... OKn", (unsigned)((::OggFLAC__SeekableStreamDecoderState)state), state.as_cstring());
  866. printf("testing get_stream_decoder_state()... ");
  867. OggFLAC::Decoder::Stream::State state_ = decoder->get_stream_decoder_state();
  868. printf("returned state = %u (%s)... OKn", (unsigned)((::OggFLAC__StreamDecoderState)state_), state_.as_cstring());
  869. printf("testing get_FLAC_stream_decoder_state()... ");
  870. FLAC::Decoder::Stream::State state__ = decoder->get_FLAC_stream_decoder_state();
  871. printf("returned state = %u (%s)... OKn", (unsigned)((::FLAC__StreamDecoderState)state__), state__.as_cstring());
  872. decoder->current_metadata_number_ = 0;
  873. decoder->ignore_errors_ = false;
  874. decoder->error_occurred_ = false;
  875. printf("opening Ogg FLAC file... ");
  876. decoder->file_ = ::fopen(oggflacfilename_, "rb");
  877. if(0 == decoder->file_) {
  878. printf("ERRORn");
  879. return false;
  880. }
  881. printf("OKn");
  882. printf("testing get_md5_checking()... ");
  883. if(!decoder->get_md5_checking()) {
  884. printf("FAILED, returned false, expected truen");
  885. return false;
  886. }
  887. printf("OKn");
  888. printf("testing process_until_end_of_metadata()... ");
  889. if(!decoder->process_until_end_of_metadata())
  890. return decoder->die("returned false");
  891. printf("OKn");
  892. printf("testing process_single()... ");
  893. if(!decoder->process_single())
  894. return decoder->die("returned false");
  895. printf("OKn");
  896. printf("testing flush()... ");
  897. if(!decoder->flush())
  898. return decoder->die("returned false");
  899. printf("OKn");
  900. decoder->ignore_errors_ = true;
  901. printf("testing process_single()... ");
  902. if(!decoder->process_single())
  903. return decoder->die("returned false");
  904. printf("OKn");
  905. decoder->ignore_errors_ = false;
  906. printf("testing seek_absolute()... ");
  907. if(!decoder->seek_absolute(0))
  908. return decoder->die("returned false");
  909. printf("OKn");
  910. printf("testing process_until_end_of_stream()... ");
  911. if(!decoder->process_until_end_of_stream())
  912. return decoder->die("returned false");
  913. printf("OKn");
  914. printf("testing get_channels()... ");
  915. {
  916. unsigned channels = decoder->get_channels();
  917. if(channels != streaminfo_.data.stream_info.channels) {
  918. printf("FAILED, returned %u, expected %un", channels, streaminfo_.data.stream_info.channels);
  919. return false;
  920. }
  921. }
  922. printf("OKn");
  923. printf("testing get_bits_per_sample()... ");
  924. {
  925. unsigned bits_per_sample = decoder->get_bits_per_sample();
  926. if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
  927. printf("FAILED, returned %u, expected %un", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
  928. return false;
  929. }
  930. }
  931. printf("OKn");
  932. printf("testing get_sample_rate()... ");
  933. {
  934. unsigned sample_rate = decoder->get_sample_rate();
  935. if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
  936. printf("FAILED, returned %u, expected %un", sample_rate, streaminfo_.data.stream_info.sample_rate);
  937. return false;
  938. }
  939. }
  940. printf("OKn");
  941. printf("testing get_blocksize()... ");
  942. {
  943. unsigned blocksize = decoder->get_blocksize();
  944. /* value could be anything since we're at the last block, so accept any answer */
  945. printf("returned %u... OKn", blocksize);
  946. }
  947. printf("testing get_channel_assignment()... ");
  948. {
  949. ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
  950. printf("returned %u (%s)... OKn", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
  951. }
  952. printf("testing reset()... ");
  953. if(!decoder->reset())
  954. return decoder->die("returned false");
  955. printf("OKn");
  956. decoder->current_metadata_number_ = 0;
  957. printf("rewinding input... ");
  958. if(::fseek(decoder->file_, 0, SEEK_SET) < 0) {
  959. printf("FAILED, errno = %dn", errno);
  960. return false;
  961. }
  962. printf("OKn");
  963. printf("testing process_until_end_of_stream()... ");
  964. if(!decoder->process_until_end_of_stream())
  965. return decoder->die("returned false");
  966. printf("OKn");
  967. printf("testing finish()... ");
  968. decoder->finish();
  969. printf("OKn");
  970. /*
  971.  * respond all
  972.  */
  973. printf("testing set_metadata_respond_all()... ");
  974. if(!decoder->set_metadata_respond_all()) {
  975. printf("FAILED, returned falsen");
  976. return false;
  977. }
  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(!decoder->test_respond())
  989. return false;
  990. /*
  991.  * ignore all
  992.  */
  993. printf("testing set_metadata_ignore_all()... ");
  994. if(!decoder->set_metadata_ignore_all()) {
  995. printf("FAILED, returned falsen");
  996. return false;
  997. }
  998. printf("OKn");
  999. num_expected_ = 0;
  1000. if(!decoder->test_respond())
  1001. return false;
  1002. /*
  1003.  * respond all, ignore VORBIS_COMMENT
  1004.  */
  1005. printf("testing set_metadata_respond_all()... ");
  1006. if(!decoder->set_metadata_respond_all()) {
  1007. printf("FAILED, returned falsen");
  1008. return false;
  1009. }
  1010. printf("OKn");
  1011. printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
  1012. if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
  1013. printf("FAILED, returned falsen");
  1014. return false;
  1015. }
  1016. printf("OKn");
  1017. num_expected_ = 0;
  1018. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1019. expected_metadata_sequence_[num_expected_++] = &padding_;
  1020. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1021. expected_metadata_sequence_[num_expected_++] = &application1_;
  1022. expected_metadata_sequence_[num_expected_++] = &application2_;
  1023. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1024. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1025. if(!decoder->test_respond())
  1026. return false;
  1027. /*
  1028.  * respond all, ignore APPLICATION
  1029.  */
  1030. printf("testing set_metadata_respond_all()... ");
  1031. if(!decoder->set_metadata_respond_all()) {
  1032. printf("FAILED, returned falsen");
  1033. return false;
  1034. }
  1035. printf("OKn");
  1036. printf("testing set_metadata_ignore(APPLICATION)... ");
  1037. if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
  1038. printf("FAILED, returned falsen");
  1039. return false;
  1040. }
  1041. printf("OKn");
  1042. num_expected_ = 0;
  1043. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1044. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1045. expected_metadata_sequence_[num_expected_++] = &padding_;
  1046. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1047. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1048. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1049. if(!decoder->test_respond())
  1050. return false;
  1051. /*
  1052.  * respond all, ignore APPLICATION id of app#1
  1053.  */
  1054. printf("testing set_metadata_respond_all()... ");
  1055. if(!decoder->set_metadata_respond_all()) {
  1056. printf("FAILED, returned falsen");
  1057. return false;
  1058. }
  1059. printf("OKn");
  1060. printf("testing set_metadata_ignore_application(of app block #1)... ");
  1061. if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
  1062. printf("FAILED, returned falsen");
  1063. return false;
  1064. }
  1065. printf("OKn");
  1066. num_expected_ = 0;
  1067. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1068. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1069. expected_metadata_sequence_[num_expected_++] = &padding_;
  1070. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1071. expected_metadata_sequence_[num_expected_++] = &application2_;
  1072. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1073. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1074. if(!decoder->test_respond())
  1075. return false;
  1076. /*
  1077.  * respond all, ignore APPLICATION id of app#1 & app#2
  1078.  */
  1079. printf("testing set_metadata_respond_all()... ");
  1080. if(!decoder->set_metadata_respond_all()) {
  1081. printf("FAILED, returned falsen");
  1082. return false;
  1083. }
  1084. printf("OKn");
  1085. printf("testing set_metadata_ignore_application(of app block #1)... ");
  1086. if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
  1087. printf("FAILED, returned falsen");
  1088. return false;
  1089. }
  1090. printf("OKn");
  1091. printf("testing set_metadata_ignore_application(of app block #2)... ");
  1092. if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
  1093. printf("FAILED, returned falsen");
  1094. return false;
  1095. }
  1096. printf("OKn");
  1097. num_expected_ = 0;
  1098. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1099. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1100. expected_metadata_sequence_[num_expected_++] = &padding_;
  1101. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1102. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1103. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1104. if(!decoder->test_respond())
  1105. return false;
  1106. /*
  1107.  * ignore all, respond VORBIS_COMMENT
  1108.  */
  1109. printf("testing set_metadata_ignore_all()... ");
  1110. if(!decoder->set_metadata_ignore_all()) {
  1111. printf("FAILED, returned falsen");
  1112. return false;
  1113. }
  1114. printf("OKn");
  1115. printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
  1116. if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
  1117. printf("FAILED, returned falsen");
  1118. return false;
  1119. }
  1120. printf("OKn");
  1121. num_expected_ = 0;
  1122. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1123. if(!decoder->test_respond())
  1124. return false;
  1125. /*
  1126.  * ignore all, respond APPLICATION
  1127.  */
  1128. printf("testing set_metadata_ignore_all()... ");
  1129. if(!decoder->set_metadata_ignore_all()) {
  1130. printf("FAILED, returned falsen");
  1131. return false;
  1132. }
  1133. printf("OKn");
  1134. printf("testing set_metadata_respond(APPLICATION)... ");
  1135. if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
  1136. printf("FAILED, returned falsen");
  1137. return false;
  1138. }
  1139. printf("OKn");
  1140. num_expected_ = 0;
  1141. expected_metadata_sequence_[num_expected_++] = &application1_;
  1142. expected_metadata_sequence_[num_expected_++] = &application2_;
  1143. if(!decoder->test_respond())
  1144. return false;
  1145. /*
  1146.  * ignore all, respond APPLICATION id of app#1
  1147.  */
  1148. printf("testing set_metadata_ignore_all()... ");
  1149. if(!decoder->set_metadata_ignore_all()) {
  1150. printf("FAILED, returned falsen");
  1151. return false;
  1152. }
  1153. printf("OKn");
  1154. printf("testing set_metadata_respond_application(of app block #1)... ");
  1155. if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
  1156. printf("FAILED, returned falsen");
  1157. return false;
  1158. }
  1159. printf("OKn");
  1160. num_expected_ = 0;
  1161. expected_metadata_sequence_[num_expected_++] = &application1_;
  1162. if(!decoder->test_respond())
  1163. return false;
  1164. /*
  1165.  * ignore all, respond APPLICATION id of app#1 & app#2
  1166.  */
  1167. printf("testing set_metadata_ignore_all()... ");
  1168. if(!decoder->set_metadata_ignore_all()) {
  1169. printf("FAILED, returned falsen");
  1170. return false;
  1171. }
  1172. printf("OKn");
  1173. printf("testing set_metadata_respond_application(of app block #1)... ");
  1174. if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
  1175. printf("FAILED, returned falsen");
  1176. return false;
  1177. }
  1178. printf("OKn");
  1179. printf("testing set_metadata_respond_application(of app block #2)... ");
  1180. if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
  1181. printf("FAILED, returned falsen");
  1182. return false;
  1183. }
  1184. printf("OKn");
  1185. num_expected_ = 0;
  1186. expected_metadata_sequence_[num_expected_++] = &application1_;
  1187. expected_metadata_sequence_[num_expected_++] = &application2_;
  1188. if(!decoder->test_respond())
  1189. return false;
  1190. /*
  1191.  * respond all, ignore APPLICATION, respond APPLICATION id of app#1
  1192.  */
  1193. printf("testing set_metadata_respond_all()... ");
  1194. if(!decoder->set_metadata_respond_all()) {
  1195. printf("FAILED, returned falsen");
  1196. return false;
  1197. }
  1198. printf("OKn");
  1199. printf("testing set_metadata_ignore(APPLICATION)... ");
  1200. if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
  1201. printf("FAILED, returned falsen");
  1202. return false;
  1203. }
  1204. printf("OKn");
  1205. printf("testing set_metadata_respond_application(of app block #1)... ");
  1206. if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
  1207. printf("FAILED, returned falsen");
  1208. return false;
  1209. }
  1210. printf("OKn");
  1211. num_expected_ = 0;
  1212. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1213. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1214. expected_metadata_sequence_[num_expected_++] = &padding_;
  1215. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1216. expected_metadata_sequence_[num_expected_++] = &application1_;
  1217. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1218. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1219. if(!decoder->test_respond())
  1220. return false;
  1221. /*
  1222.  * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
  1223.  */
  1224. printf("testing set_metadata_ignore_all()... ");
  1225. if(!decoder->set_metadata_ignore_all()) {
  1226. printf("FAILED, returned falsen");
  1227. return false;
  1228. }
  1229. printf("OKn");
  1230. printf("testing set_metadata_respond(APPLICATION)... ");
  1231. if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
  1232. printf("FAILED, returned falsen");
  1233. return false;
  1234. }
  1235. printf("OKn");
  1236. printf("testing set_metadata_ignore_application(of app block #1)... ");
  1237. if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
  1238. printf("FAILED, returned falsen");
  1239. return false;
  1240. }
  1241. printf("OKn");
  1242. num_expected_ = 0;
  1243. expected_metadata_sequence_[num_expected_++] = &application2_;
  1244. if(!decoder->test_respond())
  1245. return false;
  1246. /* done, now leave the sequence the way we found it... */
  1247. num_expected_ = 0;
  1248. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1249. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1250. expected_metadata_sequence_[num_expected_++] = &padding_;
  1251. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1252. expected_metadata_sequence_[num_expected_++] = &application1_;
  1253. expected_metadata_sequence_[num_expected_++] = &application2_;
  1254. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1255. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1256. ::fclose(decoder->file_);
  1257. printf("freeing decoder instance... ");
  1258. delete decoder;
  1259. printf("OKn");
  1260. printf("nPASSED!n");
  1261. return true;
  1262. }
  1263. class FileDecoder : public OggFLAC::Decoder::File, public DecoderCommon {
  1264. public:
  1265. FileDecoder(): OggFLAC::Decoder::File(), DecoderCommon() { }
  1266. ~FileDecoder() { }
  1267. // from OggFLAC::Decoder::File
  1268. ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
  1269. void metadata_callback(const ::FLAC__StreamMetadata *metadata);
  1270. void error_callback(::FLAC__StreamDecoderErrorStatus status);
  1271. bool die(const char *msg = 0) const;
  1272. bool test_respond();
  1273. };
  1274. ::FLAC__StreamDecoderWriteStatus FileDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
  1275. {
  1276. (void)buffer;
  1277. return common_write_callback_(frame);
  1278. }
  1279. void FileDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
  1280. {
  1281. common_metadata_callback_(metadata);
  1282. }
  1283. void FileDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
  1284. {
  1285. common_error_callback_(status);
  1286. }
  1287. bool FileDecoder::die(const char *msg) const
  1288. {
  1289. State state = get_state();
  1290. if(msg)
  1291. printf("FAILED, %s", msg);
  1292. else
  1293. printf("FAILED");
  1294. printf(", state = %u (%s)n", (unsigned)((::OggFLAC__FileDecoderState)state), state.as_cstring());
  1295. if(state == ::OggFLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR) {
  1296. OggFLAC::Decoder::SeekableStream::State state_ = get_seekable_stream_decoder_state();
  1297. printf("      seekable stream decoder state = %u (%s)n", (unsigned)((::OggFLAC__SeekableStreamDecoderState)state_), state_.as_cstring());
  1298. if(state_ == ::OggFLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR) {
  1299. OggFLAC::Decoder::Stream::State state__ = get_stream_decoder_state();
  1300. printf("      stream decoder state = %u (%s)n", (unsigned)((::OggFLAC__StreamDecoderState)state__), state__.as_cstring());
  1301. if(state__ == ::OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR) {
  1302. FLAC::Decoder::Stream::State state___ = get_FLAC_stream_decoder_state();
  1303. printf("      FLAC stream decoder state = %u (%s)n", (unsigned)((::FLAC__StreamDecoderState)state___), state___.as_cstring());
  1304. }
  1305. }
  1306. }
  1307. return false;
  1308. }
  1309. bool FileDecoder::test_respond()
  1310. {
  1311. if(!set_filename(oggflacfilename_)) {
  1312. printf("FAILED at set_filename(), returned falsen");
  1313. return false;
  1314. }
  1315. if(!set_md5_checking(true)) {
  1316. printf("FAILED at set_md5_checking(), returned falsen");
  1317. return false;
  1318. }
  1319. printf("testing init()... ");
  1320. if(init() != ::OggFLAC__FILE_DECODER_OK)
  1321. return die();
  1322. printf("OKn");
  1323. current_metadata_number_ = 0;
  1324. printf("testing process_until_end_of_file()... ");
  1325. if(!process_until_end_of_file()) {
  1326. State state = get_state();
  1327. printf("FAILED, returned false, state = %u (%s)n", (unsigned)((::OggFLAC__FileDecoderState)state), state.as_cstring());
  1328. return false;
  1329. }
  1330. printf("OKn");
  1331. printf("testing finish()... ");
  1332. finish();
  1333. printf("OKn");
  1334. return true;
  1335. }
  1336. static bool test_file_decoder()
  1337. {
  1338. FileDecoder *decoder;
  1339. printf("n+++ libOggFLAC++ unit test: OggFLAC::Decoder::Filenn");
  1340. //
  1341. // test new -> delete
  1342. //
  1343. printf("allocating decoder instance... ");
  1344. decoder = new FileDecoder();
  1345. if(0 == decoder) {
  1346. printf("FAILED, new returned NULLn");
  1347. return false;
  1348. }
  1349. printf("OKn");
  1350. printf("testing is_valid()... ");
  1351. if(!decoder->is_valid()) {
  1352. printf("FAILED, returned falsen");
  1353. return false;
  1354. }
  1355. printf("OKn");
  1356. printf("freeing decoder instance... ");
  1357. delete decoder;
  1358. printf("OKn");
  1359. //
  1360. // test new -> init -> delete
  1361. //
  1362. printf("allocating decoder instance... ");
  1363. decoder = new FileDecoder();
  1364. if(0 == decoder) {
  1365. printf("FAILED, new returned NULLn");
  1366. return false;
  1367. }
  1368. printf("OKn");
  1369. printf("testing is_valid()... ");
  1370. if(!decoder->is_valid()) {
  1371. printf("FAILED, returned falsen");
  1372. return false;
  1373. }
  1374. printf("OKn");
  1375. printf("testing init()... ");
  1376. if(decoder->init() != ::OggFLAC__FILE_DECODER_OK)
  1377. return decoder->die();
  1378. printf("OKn");
  1379. printf("freeing decoder instance... ");
  1380. delete decoder;
  1381. printf("OKn");
  1382. //
  1383. // test normal usage
  1384. //
  1385. num_expected_ = 0;
  1386. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1387. printf("allocating decoder instance... ");
  1388. decoder = new FileDecoder();
  1389. if(0 == decoder) {
  1390. printf("FAILED, new returned NULLn");
  1391. return false;
  1392. }
  1393. printf("OKn");
  1394. printf("testing is_valid()... ");
  1395. if(!decoder->is_valid()) {
  1396. printf("FAILED, returned falsen");
  1397. return false;
  1398. }
  1399. printf("OKn");
  1400. printf("testing set_filename()... ");
  1401. if(!decoder->set_filename(oggflacfilename_)) {
  1402. printf("FAILED, returned falsen");
  1403. return false;
  1404. }
  1405. printf("OKn");
  1406. printf("testing set_md5_checking()... ");
  1407. if(!decoder->set_md5_checking(true)) {
  1408. printf("FAILED, returned falsen");
  1409. return false;
  1410. }
  1411. printf("OKn");
  1412. printf("testing set_serial_number()... ");
  1413. if(!decoder->set_serial_number(file_utils__serial_number))
  1414. return decoder->die("returned false");
  1415. printf("OKn");
  1416. printf("testing init()... ");
  1417. if(decoder->init() != ::OggFLAC__FILE_DECODER_OK)
  1418. return decoder->die();
  1419. printf("OKn");
  1420. printf("testing get_state()... ");
  1421. OggFLAC::Decoder::File::State state = decoder->get_state();
  1422. printf("returned state = %u (%s)... OKn", (unsigned)((::OggFLAC__FileDecoderState)state), state.as_cstring());
  1423. printf("testing get_seekable_stream_decoder_state()... ");
  1424. OggFLAC::Decoder::SeekableStream::State state_ = decoder->get_seekable_stream_decoder_state();
  1425. printf("returned state = %u (%s)... OKn", (unsigned)((::OggFLAC__SeekableStreamDecoderState)state_), state_.as_cstring());
  1426. printf("testing get_stream_decoder_state()... ");
  1427. OggFLAC::Decoder::Stream::State state__ = decoder->get_stream_decoder_state();
  1428. printf("returned state = %u (%s)... OKn", (unsigned)((::OggFLAC__StreamDecoderState)state__), state__.as_cstring());
  1429. printf("testing get_FLAC_stream_decoder_state()... ");
  1430. FLAC::Decoder::Stream::State state___ = decoder->get_FLAC_stream_decoder_state();
  1431. printf("returned state = %u (%s)... OKn", (unsigned)((::FLAC__StreamDecoderState)state___), state___.as_cstring());
  1432. decoder->current_metadata_number_ = 0;
  1433. decoder->ignore_errors_ = false;
  1434. decoder->error_occurred_ = false;
  1435. printf("testing get_md5_checking()... ");
  1436. if(!decoder->get_md5_checking()) {
  1437. printf("FAILED, returned false, expected truen");
  1438. return false;
  1439. }
  1440. printf("OKn");
  1441. printf("testing process_until_end_of_metadata()... ");
  1442. if(!decoder->process_until_end_of_metadata())
  1443. return decoder->die("returned false");
  1444. printf("OKn");
  1445. printf("testing process_single()... ");
  1446. if(!decoder->process_single())
  1447. return decoder->die("returned false");
  1448. printf("OKn");
  1449. printf("testing seek_absolute()... ");
  1450. if(!decoder->seek_absolute(0))
  1451. return decoder->die("returned false");
  1452. printf("OKn");
  1453. printf("testing process_until_end_of_file()... ");
  1454. if(!decoder->process_until_end_of_file())
  1455. return decoder->die("returned false");
  1456. printf("OKn");
  1457. printf("testing get_channels()... ");
  1458. {
  1459. unsigned channels = decoder->get_channels();
  1460. if(channels != streaminfo_.data.stream_info.channels) {
  1461. printf("FAILED, returned %u, expected %un", channels, streaminfo_.data.stream_info.channels);
  1462. return false;
  1463. }
  1464. }
  1465. printf("OKn");
  1466. printf("testing get_bits_per_sample()... ");
  1467. {
  1468. unsigned bits_per_sample = decoder->get_bits_per_sample();
  1469. if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
  1470. printf("FAILED, returned %u, expected %un", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
  1471. return false;
  1472. }
  1473. }
  1474. printf("OKn");
  1475. printf("testing get_sample_rate()... ");
  1476. {
  1477. unsigned sample_rate = decoder->get_sample_rate();
  1478. if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
  1479. printf("FAILED, returned %u, expected %un", sample_rate, streaminfo_.data.stream_info.sample_rate);
  1480. return false;
  1481. }
  1482. }
  1483. printf("OKn");
  1484. printf("testing get_blocksize()... ");
  1485. {
  1486. unsigned blocksize = decoder->get_blocksize();
  1487. /* value could be anything since we're at the last block, so accept any answer */
  1488. printf("returned %u... OKn", blocksize);
  1489. }
  1490. printf("testing get_channel_assignment()... ");
  1491. {
  1492. ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
  1493. printf("returned %u (%s)... OKn", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
  1494. }
  1495. printf("testing finish()... ");
  1496. decoder->finish();
  1497. printf("OKn");
  1498. /*
  1499.  * respond all
  1500.  */
  1501. printf("testing set_metadata_respond_all()... ");
  1502. if(!decoder->set_metadata_respond_all()) {
  1503. printf("FAILED, returned falsen");
  1504. return false;
  1505. }
  1506. printf("OKn");
  1507. num_expected_ = 0;
  1508. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1509. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1510. expected_metadata_sequence_[num_expected_++] = &padding_;
  1511. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1512. expected_metadata_sequence_[num_expected_++] = &application1_;
  1513. expected_metadata_sequence_[num_expected_++] = &application2_;
  1514. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1515. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1516. if(!decoder->test_respond())
  1517. return false;
  1518. /*
  1519.  * ignore all
  1520.  */
  1521. printf("testing set_metadata_ignore_all()... ");
  1522. if(!decoder->set_metadata_ignore_all()) {
  1523. printf("FAILED, returned falsen");
  1524. return false;
  1525. }
  1526. printf("OKn");
  1527. num_expected_ = 0;
  1528. if(!decoder->test_respond())
  1529. return false;
  1530. /*
  1531.  * respond all, ignore VORBIS_COMMENT
  1532.  */
  1533. printf("testing set_metadata_respond_all()... ");
  1534. if(!decoder->set_metadata_respond_all()) {
  1535. printf("FAILED, returned falsen");
  1536. return false;
  1537. }
  1538. printf("OKn");
  1539. printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
  1540. if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
  1541. printf("FAILED, returned falsen");
  1542. return false;
  1543. }
  1544. printf("OKn");
  1545. num_expected_ = 0;
  1546. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1547. expected_metadata_sequence_[num_expected_++] = &padding_;
  1548. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1549. expected_metadata_sequence_[num_expected_++] = &application1_;
  1550. expected_metadata_sequence_[num_expected_++] = &application2_;
  1551. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1552. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1553. if(!decoder->test_respond())
  1554. return false;
  1555. /*
  1556.  * respond all, ignore APPLICATION
  1557.  */
  1558. printf("testing set_metadata_respond_all()... ");
  1559. if(!decoder->set_metadata_respond_all()) {
  1560. printf("FAILED, returned falsen");
  1561. return false;
  1562. }
  1563. printf("OKn");
  1564. printf("testing set_metadata_ignore(APPLICATION)... ");
  1565. if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
  1566. printf("FAILED, returned falsen");
  1567. return false;
  1568. }
  1569. printf("OKn");
  1570. num_expected_ = 0;
  1571. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1572. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1573. expected_metadata_sequence_[num_expected_++] = &padding_;
  1574. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1575. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1576. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1577. if(!decoder->test_respond())
  1578. return false;
  1579. /*
  1580.  * respond all, ignore APPLICATION id of app#1
  1581.  */
  1582. printf("testing set_metadata_respond_all()... ");
  1583. if(!decoder->set_metadata_respond_all()) {
  1584. printf("FAILED, returned falsen");
  1585. return false;
  1586. }
  1587. printf("OKn");
  1588. printf("testing set_metadata_ignore_application(of app block #1)... ");
  1589. if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
  1590. printf("FAILED, returned falsen");
  1591. return false;
  1592. }
  1593. printf("OKn");
  1594. num_expected_ = 0;
  1595. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1596. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1597. expected_metadata_sequence_[num_expected_++] = &padding_;
  1598. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1599. expected_metadata_sequence_[num_expected_++] = &application2_;
  1600. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1601. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1602. if(!decoder->test_respond())
  1603. return false;
  1604. /*
  1605.  * respond all, ignore APPLICATION id of app#1 & app#2
  1606.  */
  1607. printf("testing set_metadata_respond_all()... ");
  1608. if(!decoder->set_metadata_respond_all()) {
  1609. printf("FAILED, returned falsen");
  1610. return false;
  1611. }
  1612. printf("OKn");
  1613. printf("testing set_metadata_ignore_application(of app block #1)... ");
  1614. if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
  1615. printf("FAILED, returned falsen");
  1616. return false;
  1617. }
  1618. printf("OKn");
  1619. printf("testing set_metadata_ignore_application(of app block #2)... ");
  1620. if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
  1621. printf("FAILED, returned falsen");
  1622. return false;
  1623. }
  1624. printf("OKn");
  1625. num_expected_ = 0;
  1626. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1627. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1628. expected_metadata_sequence_[num_expected_++] = &padding_;
  1629. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1630. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1631. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1632. if(!decoder->test_respond())
  1633. return false;
  1634. /*
  1635.  * ignore all, respond VORBIS_COMMENT
  1636.  */
  1637. printf("testing set_metadata_ignore_all()... ");
  1638. if(!decoder->set_metadata_ignore_all()) {
  1639. printf("FAILED, returned falsen");
  1640. return false;
  1641. }
  1642. printf("OKn");
  1643. printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
  1644. if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
  1645. printf("FAILED, returned falsen");
  1646. return false;
  1647. }
  1648. printf("OKn");
  1649. num_expected_ = 0;
  1650. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1651. if(!decoder->test_respond())
  1652. return false;
  1653. /*
  1654.  * ignore all, respond APPLICATION
  1655.  */
  1656. printf("testing set_metadata_ignore_all()... ");
  1657. if(!decoder->set_metadata_ignore_all()) {
  1658. printf("FAILED, returned falsen");
  1659. return false;
  1660. }
  1661. printf("OKn");
  1662. printf("testing set_metadata_respond(APPLICATION)... ");
  1663. if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
  1664. printf("FAILED, returned falsen");
  1665. return false;
  1666. }
  1667. printf("OKn");
  1668. num_expected_ = 0;
  1669. expected_metadata_sequence_[num_expected_++] = &application1_;
  1670. expected_metadata_sequence_[num_expected_++] = &application2_;
  1671. if(!decoder->test_respond())
  1672. return false;
  1673. /*
  1674.  * ignore all, respond APPLICATION id of app#1
  1675.  */
  1676. printf("testing set_metadata_ignore_all()... ");
  1677. if(!decoder->set_metadata_ignore_all()) {
  1678. printf("FAILED, returned falsen");
  1679. return false;
  1680. }
  1681. printf("OKn");
  1682. printf("testing set_metadata_respond_application(of app block #1)... ");
  1683. if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
  1684. printf("FAILED, returned falsen");
  1685. return false;
  1686. }
  1687. printf("OKn");
  1688. num_expected_ = 0;
  1689. expected_metadata_sequence_[num_expected_++] = &application1_;
  1690. if(!decoder->test_respond())
  1691. return false;
  1692. /*
  1693.  * ignore all, respond APPLICATION id of app#1 & app#2
  1694.  */
  1695. printf("testing set_metadata_ignore_all()... ");
  1696. if(!decoder->set_metadata_ignore_all()) {
  1697. printf("FAILED, returned falsen");
  1698. return false;
  1699. }
  1700. printf("OKn");
  1701. printf("testing set_metadata_respond_application(of app block #1)... ");
  1702. if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
  1703. printf("FAILED, returned falsen");
  1704. return false;
  1705. }
  1706. printf("OKn");
  1707. printf("testing set_metadata_respond_application(of app block #2)... ");
  1708. if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
  1709. printf("FAILED, returned falsen");
  1710. return false;
  1711. }
  1712. printf("OKn");
  1713. num_expected_ = 0;
  1714. expected_metadata_sequence_[num_expected_++] = &application1_;
  1715. expected_metadata_sequence_[num_expected_++] = &application2_;
  1716. if(!decoder->test_respond())
  1717. return false;
  1718. /*
  1719.  * respond all, ignore APPLICATION, respond APPLICATION id of app#1
  1720.  */
  1721. printf("testing set_metadata_respond_all()... ");
  1722. if(!decoder->set_metadata_respond_all()) {
  1723. printf("FAILED, returned falsen");
  1724. return false;
  1725. }
  1726. printf("OKn");
  1727. printf("testing set_metadata_ignore(APPLICATION)... ");
  1728. if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
  1729. printf("FAILED, returned falsen");
  1730. return false;
  1731. }
  1732. printf("OKn");
  1733. printf("testing set_metadata_respond_application(of app block #1)... ");
  1734. if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
  1735. printf("FAILED, returned falsen");
  1736. return false;
  1737. }
  1738. printf("OKn");
  1739. num_expected_ = 0;
  1740. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1741. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1742. expected_metadata_sequence_[num_expected_++] = &padding_;
  1743. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1744. expected_metadata_sequence_[num_expected_++] = &application1_;
  1745. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1746. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1747. if(!decoder->test_respond())
  1748. return false;
  1749. /*
  1750.  * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
  1751.  */
  1752. printf("testing set_metadata_ignore_all()... ");
  1753. if(!decoder->set_metadata_ignore_all()) {
  1754. printf("FAILED, returned falsen");
  1755. return false;
  1756. }
  1757. printf("OKn");
  1758. printf("testing set_metadata_respond(APPLICATION)... ");
  1759. if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
  1760. printf("FAILED, returned falsen");
  1761. return false;
  1762. }
  1763. printf("OKn");
  1764. printf("testing set_metadata_ignore_application(of app block #1)... ");
  1765. if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
  1766. printf("FAILED, returned falsen");
  1767. return false;
  1768. }
  1769. printf("OKn");
  1770. num_expected_ = 0;
  1771. expected_metadata_sequence_[num_expected_++] = &application2_;
  1772. if(!decoder->test_respond())
  1773. return false;
  1774. /* done, now leave the sequence the way we found it... */
  1775. num_expected_ = 0;
  1776. expected_metadata_sequence_[num_expected_++] = &streaminfo_;
  1777. expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
  1778. expected_metadata_sequence_[num_expected_++] = &padding_;
  1779. expected_metadata_sequence_[num_expected_++] = &seektable_;
  1780. expected_metadata_sequence_[num_expected_++] = &application1_;
  1781. expected_metadata_sequence_[num_expected_++] = &application2_;
  1782. expected_metadata_sequence_[num_expected_++] = &cuesheet_;
  1783. expected_metadata_sequence_[num_expected_++] = &unknown_;
  1784. printf("freeing decoder instance... ");
  1785. delete decoder;
  1786. printf("OKn");
  1787. printf("nPASSED!n");
  1788. return true;
  1789. }
  1790. bool test_decoders()
  1791. {
  1792. init_metadata_blocks_();
  1793. if(!generate_file_())
  1794. return false;
  1795. if(!test_stream_decoder())
  1796. return false;
  1797. if(!test_seekable_stream_decoder())
  1798. return false;
  1799. if(!test_file_decoder())
  1800. return false;
  1801. (void) grabbag__file_remove_file(oggflacfilename_);
  1802. free_metadata_blocks_();
  1803. return true;
  1804. }