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

Windows CE

开发平台:

C/C++

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