| 1 |
/* |
| 2 |
Audio File Library |
| 3 |
Copyright (C) 2013 Michael Pruett <[email protected]> |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or modify |
| 6 |
it under the terms of the GNU General Public License as published by |
| 7 |
the Free Software Foundation; either version 2 of the License, or |
| 8 |
(at your option) any later version. |
| 9 |
|
| 10 |
This program is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
GNU General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public License along |
| 16 |
with this program; if not, write to the Free Software Foundation, Inc., |
| 17 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <gtest/gtest.h> |
| 21 |
#include <audiofile.h> |
| 22 |
#include <stdlib.h> |
| 23 |
|
| 24 |
#include "TestUtilities.h" |
| 25 |
|
| 26 |
static void testInstrumentParameters(int fileFormat) |
| 27 |
{ |
| 28 |
std::string testFileName; |
| 29 |
ASSERT_TRUE(createTemporaryFile("Instrument", &testFileName)); |
| 30 |
|
| 31 |
AFfilesetup setup = afNewFileSetup(); |
| 32 |
afInitFileFormat(setup, fileFormat); |
| 33 |
int instrumentIDs[] = {AF_DEFAULT_INST}; |
| 34 |
int numInstruments = sizeof (instrumentIDs) / sizeof (int); |
| 35 |
afInitInstIDs(setup, instrumentIDs, numInstruments); |
| 36 |
|
| 37 |
AFfilehandle file = afOpenFile(testFileName.c_str(), "w", setup); |
| 38 |
ASSERT_TRUE(file); |
| 39 |
|
| 40 |
afFreeFileSetup(setup); |
| 41 |
|
| 42 |
afSetInstParamLong(file, AF_DEFAULT_INST, AF_INST_MIDI_BASENOTE, 50); |
| 43 |
afSetInstParamLong(file, AF_DEFAULT_INST, AF_INST_NUMCENTS_DETUNE, -30); |
| 44 |
afSetInstParamLong(file, AF_DEFAULT_INST, AF_INST_MIDI_LOVELOCITY, 22); |
| 45 |
afSetInstParamLong(file, AF_DEFAULT_INST, AF_INST_MIDI_HIVELOCITY, 111); |
| 46 |
|
| 47 |
ASSERT_EQ(0, afCloseFile(file)); |
| 48 |
|
| 49 |
file = afOpenFile(testFileName.c_str(), "r", NULL); |
| 50 |
ASSERT_TRUE(file); |
| 51 |
ASSERT_EQ(fileFormat, afGetFileFormat(file, NULL)); |
| 52 |
|
| 53 |
ASSERT_EQ(1, afGetInstIDs(file, NULL)); |
| 54 |
int readInstrumentIDs[1] = {0}; |
| 55 |
ASSERT_EQ(1, afGetInstIDs(file, readInstrumentIDs)); |
| 56 |
ASSERT_EQ(AF_DEFAULT_INST, readInstrumentIDs[0]); |
| 57 |
|
| 58 |
EXPECT_EQ(50, |
| 59 |
afGetInstParamLong(file, AF_DEFAULT_INST, AF_INST_MIDI_BASENOTE)); |
| 60 |
EXPECT_EQ(-30, |
| 61 |
afGetInstParamLong(file, AF_DEFAULT_INST, AF_INST_NUMCENTS_DETUNE)); |
| 62 |
EXPECT_EQ(22, |
| 63 |
afGetInstParamLong(file, AF_DEFAULT_INST, AF_INST_MIDI_LOVELOCITY)); |
| 64 |
EXPECT_EQ(111, |
| 65 |
afGetInstParamLong(file, AF_DEFAULT_INST, AF_INST_MIDI_HIVELOCITY)); |
| 66 |
|
| 67 |
ASSERT_EQ(0, afCloseFile(file)); |
| 68 |
ASSERT_EQ(0, ::unlink(testFileName.c_str())); |
| 69 |
} |
| 70 |
|
| 71 |
TEST(Instrument, AIFF) { testInstrumentParameters(AF_FILE_AIFF); } |
| 72 |
TEST(Instrument, AIFFC) { testInstrumentParameters(AF_FILE_AIFFC); } |
| 73 |
|
| 74 |
int main(int argc, char **argv) |
| 75 |
{ |
| 76 |
::testing::InitGoogleTest(&argc, argv); |
| 77 |
return RUN_ALL_TESTS(); |
| 78 |
} |