Open Source Tomb Raider Engine
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Sound.cpp 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*!
  2. * \file test/Sound.cpp
  3. * \brief This is the audio manager Unit Test
  4. *
  5. * \author Mongoose
  6. * \author xythobuz
  7. */
  8. #include <stdio.h>
  9. #include <unistd.h>
  10. #include <Sound.h>
  11. #include "greatest.h"
  12. #define TESTFILE "../../data/sample.wav"
  13. Sound sound;
  14. bool inited = false;
  15. GREATEST_MAIN_DEFS();
  16. TEST initSound() {
  17. int ret;
  18. if ((ret = sound.init()) != 0) {
  19. printf("Couldn't initialize Sound (%d)!", ret);
  20. FAIL();
  21. }
  22. inited = true;
  23. PASS();
  24. }
  25. TEST playFile() {
  26. int id, ret;
  27. ASSERT_EQm("Sound not initialized!", inited, true);
  28. if ((ret = sound.addFile(TESTFILE, &id, sound.SoundFlagsNone)) != 0) {
  29. printf("Couldn't add file (%d)!", ret);
  30. FAIL();
  31. }
  32. sound.play(id);
  33. sleep(2);
  34. PASS();
  35. }
  36. TEST loadFile() {
  37. int id, ret;
  38. unsigned int l;
  39. unsigned char *buf;
  40. FILE *f;
  41. ASSERT_EQm("Sound not initialized!", inited, true);
  42. if (!(f = fopen(TESTFILE, "rb"))) {
  43. printf("Couldn't open %s!", TESTFILE);
  44. FAIL();
  45. }
  46. fseek(f, 0, SEEK_END);
  47. l = ftell(f);
  48. fseek(f, 0, SEEK_SET);
  49. buf = new unsigned char[l];
  50. fread(buf, l, 1, f);
  51. fclose(f);
  52. if ((ret = sound.addWave(buf, l, &id, sound.SoundFlagsNone)) != 0) {
  53. printf("Couldn't add buffer (%d)!", ret);
  54. FAIL();
  55. }
  56. sound.play(id);
  57. delete [] buf;
  58. sleep(2);
  59. PASS();
  60. }
  61. SUITE(soundSuite) {
  62. RUN_TEST(initSound);
  63. RUN_TEST(playFile);
  64. RUN_TEST(loadFile);
  65. }
  66. int main(int argc, char *argv[]) {
  67. GREATEST_MAIN_BEGIN();
  68. RUN_SUITE(soundSuite);
  69. GREATEST_MAIN_END();
  70. }