| 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 <audiofile.h> |
| 21 |
#include <gtest/gtest.h> |
| 22 |
#include <stdint.h> |
| 23 |
#include <stdlib.h> |
| 24 |
#include <unistd.h> |
| 25 |
|
| 26 |
#include "TestUtilities.h" |
| 27 |
|
| 28 |
TEST(SampleFormat, NullArguments) |
| 29 |
{ |
| 30 |
std::string testFileName; |
| 31 |
ASSERT_TRUE(createTemporaryFile("SampleFormat", &testFileName)); |
| 32 |
|
| 33 |
AFfilesetup setup = afNewFileSetup(); |
| 34 |
afInitFileFormat(setup, AF_FILE_AIFFC); |
| 35 |
afInitSampleFormat(setup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16); |
| 36 |
afInitChannels(setup, AF_DEFAULT_TRACK, 1); |
| 37 |
|
| 38 |
AFfilehandle file = afOpenFile(testFileName.c_str(), "w", setup); |
| 39 |
ASSERT_TRUE(file); |
| 40 |
afFreeFileSetup(setup); |
| 41 |
|
| 42 |
int sampleFormat, sampleWidth; |
| 43 |
afGetSampleFormat(file, AF_DEFAULT_TRACK, &sampleFormat, &sampleWidth); |
| 44 |
ASSERT_EQ(sampleFormat, AF_SAMPFMT_TWOSCOMP); |
| 45 |
ASSERT_EQ(sampleWidth, 16); |
| 46 |
|
| 47 |
sampleFormat = -1; |
| 48 |
afGetSampleFormat(file, AF_DEFAULT_TRACK, NULL, &sampleWidth); |
| 49 |
ASSERT_EQ(sampleFormat, -1); |
| 50 |
ASSERT_EQ(sampleWidth, 16); |
| 51 |
|
| 52 |
sampleWidth = -1; |
| 53 |
afGetSampleFormat(file, AF_DEFAULT_TRACK, &sampleFormat, NULL); |
| 54 |
ASSERT_EQ(sampleFormat, AF_SAMPFMT_TWOSCOMP); |
| 55 |
ASSERT_EQ(sampleWidth, -1); |
| 56 |
|
| 57 |
afGetVirtualSampleFormat(file, AF_DEFAULT_TRACK, &sampleFormat, &sampleWidth); |
| 58 |
ASSERT_EQ(sampleFormat, AF_SAMPFMT_TWOSCOMP); |
| 59 |
ASSERT_EQ(sampleWidth, 16); |
| 60 |
|
| 61 |
sampleFormat = -1; |
| 62 |
afGetVirtualSampleFormat(file, AF_DEFAULT_TRACK, NULL, &sampleWidth); |
| 63 |
ASSERT_EQ(sampleFormat, -1); |
| 64 |
ASSERT_EQ(sampleWidth, 16); |
| 65 |
|
| 66 |
sampleWidth = -1; |
| 67 |
afGetVirtualSampleFormat(file, AF_DEFAULT_TRACK, &sampleFormat, NULL); |
| 68 |
ASSERT_EQ(sampleFormat, AF_SAMPFMT_TWOSCOMP); |
| 69 |
ASSERT_EQ(sampleWidth, -1); |
| 70 |
|
| 71 |
ASSERT_EQ(afCloseFile(file), 0); |
| 72 |
|
| 73 |
ASSERT_EQ(::unlink(testFileName.c_str()), 0); |
| 74 |
} |
| 75 |
|
| 76 |
int main(int argc, char **argv) |
| 77 |
{ |
| 78 |
::testing::InitGoogleTest(&argc, argv); |
| 79 |
return RUN_ALL_TESTS(); |
| 80 |
} |