globally change all use of "frame" to refer to audio into "sample".
[ardour.git] / libs / audiographer / tests / sndfile / tmp_file_test.cc
1 #include "tests/utils.h"
2 #include "audiographer/sndfile/tmp_file_sync.h"
3
4 using namespace AudioGrapher;
5
6 class TmpFileTest : public CppUnit::TestFixture
7 {
8   CPPUNIT_TEST_SUITE (TmpFileTest);
9   CPPUNIT_TEST (testProcess);
10   CPPUNIT_TEST_SUITE_END ();
11
12   public:
13         void setUp()
14         {
15                 samples = 128;
16                 random_data = TestUtils::init_random_data(samples);
17         }
18
19         void tearDown()
20         {
21                 delete [] random_data;
22         }
23
24         void testProcess()
25         {
26                 uint32_t channels = 2;
27                 file.reset (new TmpFileSync<float>(SF_FORMAT_WAV | SF_FORMAT_FLOAT, channels, 44100));
28                 AllocatingProcessContext<float> c (random_data, samples, channels);
29                 c.set_flag (ProcessContext<float>::EndOfInput);
30                 file->process (c);
31
32                 TypeUtils<float>::zero_fill (c.data (), c.samples());
33
34                 file->seek (0, SEEK_SET);
35                 file->read (c);
36                 CPPUNIT_ASSERT (TestUtils::array_equals (random_data, c.data(), c.samples()));
37         }
38
39   private:
40         boost::shared_ptr<TmpFileSync<float> > file;
41
42         float * random_data;
43         samplecnt_t samples;
44 };
45
46 CPPUNIT_TEST_SUITE_REGISTRATION (TmpFileTest);
47