Clean up libardour tests a bit.
[ardour.git] / libs / ardour / test / audio_region_test.cc
1 /*
2     Copyright (C) 2012 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (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., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include "pbd/filesystem.h"
20 #include "pbd/compose.h"
21 #include "ardour/playlist_factory.h"
22 #include "ardour/source_factory.h"
23 #include "ardour/region.h"
24 #include "ardour/region_factory.h"
25 #include "ardour/sndfilesource.h"
26 #include "ardour/audioregion.h"
27 #include "ardour/audioplaylist.h"
28 #include "audio_region_test.h"
29 #include "test_globals.h"
30
31 using namespace std;
32 using namespace PBD;
33 using namespace ARDOUR;
34
35 void
36 AudioRegionTest::setUp ()
37 {
38         TestNeedingSession::setUp ();
39
40         /* This is important, otherwise createWritable will mark the source immutable (hence unwritable) */
41         unlink ("libs/ardour/test/test.wav");
42         string const test_wav_path = "libs/ardour/test/test.wav";
43         _playlist = PlaylistFactory::create (DataType::AUDIO, *_session, "test");
44         _audio_playlist = boost::dynamic_pointer_cast<AudioPlaylist> (_playlist);
45         _source = SourceFactory::createWritable (DataType::AUDIO, *_session, test_wav_path, "", false, Fs);
46
47         /* Write a staircase to the source */
48
49         boost::shared_ptr<SndFileSource> s = boost::dynamic_pointer_cast<SndFileSource> (_source);
50         assert (s);
51
52         int const signal_length = 4096;
53         
54         Sample staircase[signal_length];
55         for (int i = 0; i < signal_length; ++i) {
56                 staircase[i] = i;
57         }
58
59         s->write (staircase, signal_length);
60         
61         PropertyList plist;
62         plist.add (Properties::start, 0);
63         plist.add (Properties::length, 100);
64         for (int i = 0; i < 16; ++i) {
65                 _r[i] = RegionFactory::create (_source, plist);
66                 _ar[i] = boost::dynamic_pointer_cast<AudioRegion> (_r[i]);
67                 _ar[i]->set_name (string_compose ("ar%1", i));
68         }
69 }
70
71 void
72 AudioRegionTest::tearDown ()
73 {
74         _playlist.reset ();
75         _audio_playlist.reset ();
76         _source.reset ();
77         for (int i = 0; i < 16; ++i) {
78                 _r[i].reset ();
79                 _ar[i].reset ();
80         }
81
82         TestNeedingSession::tearDown ();
83 }
84
85