Home | History | Annotate | Download | only in tests
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef PAPPI_TESTS_TEST_AUDIO_H_
      6 #define PAPPI_TESTS_TEST_AUDIO_H_
      7 
      8 #include <string>
      9 
     10 #include "ppapi/c/ppb_audio.h"
     11 #include "ppapi/c/ppb_audio_config.h"
     12 #include "ppapi/c/ppb_core.h"
     13 #include "ppapi/tests/test_case.h"
     14 
     15 class TestAudio : public TestCase {
     16  public:
     17   explicit TestAudio(TestingInstance* instance);
     18   ~TestAudio();
     19 
     20   // TestCase implementation.
     21   virtual bool Init();
     22   virtual void RunTests(const std::string& filter);
     23 
     24  private:
     25   std::string TestCreation();
     26   std::string TestDestroyNoStop();
     27   std::string TestFailures();
     28   std::string TestAudioCallback1();
     29   std::string TestAudioCallback2();
     30   std::string TestAudioCallback3();
     31   std::string TestAudioCallback4();
     32 
     33 #if defined(__native_client__)
     34   std::string TestAudioThreadCreatorIsRequired();
     35   std::string TestAudioThreadCreatorIsCalled();
     36 #endif
     37 
     38   // Calls |audio_callback_method_| (where |user_data| is "this").
     39   static void AudioCallbackTrampoline(void* sample_buffer,
     40                                       uint32_t buffer_size_in_bytes,
     41                                       PP_TimeDelta latency,
     42                                       void* user_data);
     43   static void AudioCallbackTrampoline1_0(void* sample_buffer,
     44                                          uint32_t buffer_size_in_bytes,
     45                                          void* user_data);
     46 
     47   typedef void (TestAudio::*AudioCallbackMethod)(void* sample_buffer,
     48                                                  uint32_t buffer_size_in_bytes,
     49                                                  PP_TimeDelta latency);
     50 
     51   // Method called by |AudioCallbackTrampoline()|. Set only when the callback
     52   // can't be running (before |StartPlayback()|, after |StopPlayback()| or
     53   // releasing the last reference to the audio resource).
     54   AudioCallbackMethod audio_callback_method_;
     55 
     56   // An |AudioCallbackMethod| that just clears |sample_buffer|.
     57   void AudioCallbackTrivial(void* sample_buffer,
     58                             uint32_t buffer_size_in_bytes,
     59                             PP_TimeDelta latency);
     60 
     61   // |AudioCallbackMethod| used by |TestAudioCallbackN()|.
     62   void AudioCallbackTest(void* sample_buffer,
     63                          uint32_t buffer_size_in_bytes,
     64                          PP_TimeDelta latency);
     65 
     66   PP_Resource CreateAudioConfig(PP_AudioSampleRate sample_rate,
     67                                 uint32_t requested_sample_frame_count);
     68 
     69   // Used by |TestAudioCallbackN()|.
     70   NestedEvent audio_callback_event_;
     71 
     72   bool test_done_;
     73 
     74   // Raw C-level interfaces, set in |Init()|; do not modify them elsewhere.
     75   const PPB_Audio_1_1* audio_interface_;
     76   const PPB_Audio_1_0* audio_interface_1_0_;
     77   const PPB_AudioConfig* audio_config_interface_;
     78   const PPB_Core* core_interface_;
     79 };
     80 
     81 #endif  // PAPPI_TESTS_TEST_AUDIO_H_
     82