summaryrefslogtreecommitdiff
path: root/libs/audiographer/tests/sndfile/tmp_file_test.cc
blob: 9748623f3756ad1e1302917bc1da712a72cc873b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "tests/utils.h"
#include "audiographer/sndfile/tmp_file_sync.h"

using namespace AudioGrapher;

class TmpFileTest : public CppUnit::TestFixture
{
  CPPUNIT_TEST_SUITE (TmpFileTest);
  CPPUNIT_TEST (testProcess);
  CPPUNIT_TEST_SUITE_END ();

  public:
	void setUp()
	{
		frames = 128;
		random_data = TestUtils::init_random_data(frames);
	}

	void tearDown()
	{
		delete [] random_data;
	}

	void testProcess()
	{
		uint32_t channels = 2;
		file.reset (new TmpFileSync<float>(SF_FORMAT_WAV | SF_FORMAT_FLOAT, channels, 44100));
		AllocatingProcessContext<float> c (random_data, frames, channels);
		c.set_flag (ProcessContext<float>::EndOfInput);
		file->process (c);

		TypeUtils<float>::zero_fill (c.data (), c.frames());

		file->seek (0, SEEK_SET);
		file->read (c);
		CPPUNIT_ASSERT (TestUtils::array_equals (random_data, c.data(), c.frames()));
	}

  private:
	boost::shared_ptr<TmpFileSync<float> > file;

	float * random_data;
	framecnt_t frames;
};

CPPUNIT_TEST_SUITE_REGISTRATION (TmpFileTest);