| 1 |
/* |
| 2 |
Copyright (C) 2011, Michael Pruett. All rights reserved. |
| 3 |
|
| 4 |
Redistribution and use in source and binary forms, with or without |
| 5 |
modification, are permitted provided that the following conditions |
| 6 |
are met: |
| 7 |
|
| 8 |
1. Redistributions of source code must retain the above copyright |
| 9 |
notice, this list of conditions and the following disclaimer. |
| 10 |
|
| 11 |
2. Redistributions in binary form must reproduce the above copyright |
| 12 |
notice, this list of conditions and the following disclaimer in the |
| 13 |
documentation and/or other materials provided with the distribution. |
| 14 |
|
| 15 |
3. The name of the author may not be used to endorse or promote products |
| 16 |
derived from this software without specific prior written permission. |
| 17 |
|
| 18 |
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 19 |
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 20 |
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 21 |
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 22 |
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 23 |
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 |
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 |
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 |
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 |
*/ |
| 29 |
|
| 30 |
#include <gtest/gtest.h> |
| 31 |
#include <audiofile.h> |
| 32 |
#include <stdint.h> |
| 33 |
#include <stdio.h> |
| 34 |
#include <string.h> |
| 35 |
#include <unistd.h> |
| 36 |
|
| 37 |
#include "TestUtilities.h" |
| 38 |
|
| 39 |
static void testAESSupported(int fileFormat) |
| 40 |
{ |
| 41 |
std::string testFileName; |
| 42 |
ASSERT_TRUE(createTemporaryFile("AES", &testFileName)); |
| 43 |
|
| 44 |
AFfilesetup setup = afNewFileSetup(); |
| 45 |
afInitFileFormat(setup, fileFormat); |
| 46 |
afInitAESChannelDataTo(setup, AF_DEFAULT_TRACK, true); |
| 47 |
|
| 48 |
AFfilehandle file = afOpenFile(testFileName.c_str(), "w", setup); |
| 49 |
ASSERT_TRUE(file); |
| 50 |
|
| 51 |
afFreeFileSetup(setup); |
| 52 |
|
| 53 |
unsigned char aesData[24]; |
| 54 |
for (int i=0; i<24; i++) |
| 55 |
aesData[i] = 3*i + 1; |
| 56 |
afSetAESChannelData(file, AF_DEFAULT_TRACK, aesData); |
| 57 |
|
| 58 |
afCloseFile(file); |
| 59 |
|
| 60 |
file = afOpenFile(testFileName.c_str(), "r", NULL); |
| 61 |
ASSERT_TRUE(file); |
| 62 |
|
| 63 |
unsigned char readAESData[24]; |
| 64 |
EXPECT_TRUE(afGetAESChannelData(file, AF_DEFAULT_TRACK, readAESData)); |
| 65 |
EXPECT_TRUE(!memcmp(aesData, readAESData, 24)); |
| 66 |
|
| 67 |
afCloseFile(file); |
| 68 |
|
| 69 |
ASSERT_EQ(::unlink(testFileName.c_str()), 0); |
| 70 |
} |
| 71 |
|
| 72 |
TEST(AES_Supported, AIFFC) { testAESSupported(AF_FILE_AIFFC); } |
| 73 |
TEST(AES_Supported, AIFF) { testAESSupported(AF_FILE_AIFF); } |
| 74 |
|
| 75 |
static void testAESUnsupported(int fileFormat) |
| 76 |
{ |
| 77 |
IgnoreErrors ignoreErrors; |
| 78 |
|
| 79 |
std::string testFileName; |
| 80 |
ASSERT_TRUE(createTemporaryFile("AES", &testFileName)); |
| 81 |
|
| 82 |
AFfilesetup setup = afNewFileSetup(); |
| 83 |
afInitFileFormat(setup, fileFormat); |
| 84 |
afInitAESChannelDataTo(setup, AF_DEFAULT_TRACK, true); |
| 85 |
|
| 86 |
AFfilehandle file = afOpenFile(testFileName.c_str(), "w", setup); |
| 87 |
ASSERT_FALSE(file); |
| 88 |
|
| 89 |
afFreeFileSetup(setup); |
| 90 |
|
| 91 |
ASSERT_EQ(::unlink(testFileName.c_str()), 0); |
| 92 |
} |
| 93 |
|
| 94 |
TEST(AES_Unsupported, Raw) { testAESUnsupported(AF_FILE_RAWDATA); } |
| 95 |
TEST(AES_Unsupported, NeXT) { testAESUnsupported(AF_FILE_NEXTSND); } |
| 96 |
TEST(AES_Unsupported, WAVE) { testAESUnsupported(AF_FILE_WAVE); } |
| 97 |
TEST(AES_Unsupported, IRCAM) { testAESUnsupported(AF_FILE_IRCAM); } |
| 98 |
TEST(AES_Unsupported, AVR) { testAESUnsupported(AF_FILE_AVR); } |
| 99 |
TEST(AES_Unsupported, IFF) { testAESUnsupported(AF_FILE_IFF_8SVX); } |
| 100 |
TEST(AES_Unsupported, SampleVision) { testAESUnsupported(AF_FILE_SAMPLEVISION); } |
| 101 |
TEST(AES_Unsupported, VOC) { testAESUnsupported(AF_FILE_VOC); } |
| 102 |
TEST(AES_Unsupported, NIST) { testAESUnsupported(AF_FILE_NIST_SPHERE); } |
| 103 |
TEST(AES_Unsupported, CAF) { testAESUnsupported(AF_FILE_CAF); } |
| 104 |
TEST(AES_Unsupported, FLAC) { testAESUnsupported(AF_FILE_FLAC); } |
| 105 |
|
| 106 |
int main(int argc, char **argv) |
| 107 |
{ |
| 108 |
::testing::InitGoogleTest(&argc, argv); |
| 109 |
return RUN_ALL_TESTS(); |
| 110 |
} |