-
Notifications
You must be signed in to change notification settings - Fork 619
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for the Header class. (#1577)
These are intended to exercise methods that are currently not covered by other tests according to the coverage report. Signed-off-by: Ben Grimes <[email protected]>
- Loading branch information
Showing
4 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// Copyright (c) Contributors to the OpenEXR Project. | ||
// | ||
|
||
#ifdef NDEBUG | ||
# undef NDEBUG | ||
#endif | ||
|
||
#include <ImfBoxAttribute.h> | ||
#include <ImfHeader.h> | ||
|
||
#include <exception> | ||
#include <iostream> | ||
#include <string> | ||
|
||
#include <assert.h> | ||
|
||
using namespace IEX_NAMESPACE; | ||
using namespace IMATH_NAMESPACE; | ||
using namespace OPENEXR_IMF_NAMESPACE; | ||
using namespace std; | ||
|
||
template<typename Header> | ||
struct Test | ||
{ | ||
void testFind(const string& name) | ||
{ | ||
Header header; | ||
auto iterator = header.find(name); | ||
assert(iterator != header.end()); | ||
} | ||
|
||
void testSubscript(const string& name) | ||
{ | ||
Header header; | ||
auto& comparand = header.find("displayWindow").attribute(); | ||
auto& attribute = header[name]; | ||
assert(&attribute == &comparand); | ||
} | ||
|
||
void testIterators(const string& name) | ||
{ | ||
Header header; | ||
|
||
auto& comparand = header.find("displayWindow").attribute(); | ||
|
||
for (auto iterator = header.begin(); iterator != header.end(); ++iterator) | ||
{ | ||
if (iterator.name() == name) | ||
{ | ||
assert(&iterator.attribute() == &comparand); | ||
return; | ||
} | ||
} | ||
|
||
assert (false); | ||
} | ||
}; | ||
|
||
void testEraseAttribute(const string& name) | ||
{ | ||
Header header; | ||
assert(header.find(name) != header.end()); | ||
header.erase(name); | ||
assert(header.find(name) == header.end()); | ||
} | ||
|
||
void testEraseAttributeThrowsWithEmptyString() | ||
{ | ||
Header header; | ||
|
||
try | ||
{ | ||
header.erase(""); | ||
assert (false); | ||
} | ||
catch (const ArgExc&) | ||
{ | ||
assert (true); | ||
} | ||
} | ||
|
||
void testHeader (const string& tempDir) | ||
{ | ||
try | ||
{ | ||
{ | ||
Test<Header> headerTest; | ||
headerTest.testFind("displayWindow"); | ||
headerTest.testSubscript("displayWindow"); | ||
headerTest.testIterators("displayWindow"); | ||
} | ||
{ | ||
Test<const Header> headerTest; | ||
headerTest.testFind("displayWindow"); | ||
headerTest.testSubscript("displayWindow"); | ||
headerTest.testIterators("displayWindow"); | ||
} | ||
testEraseAttribute("displayWindow"); | ||
testEraseAttributeThrowsWithEmptyString(); | ||
cout << "ok\n" << endl; | ||
} | ||
catch (const exception& e) | ||
{ | ||
cerr << "ERROR -- caught exception: " << e.what () << endl; | ||
assert (false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// Copyright (c) Contributors to the OpenEXR Project. | ||
// | ||
|
||
#include <string> | ||
|
||
void testHeader (const std::string& tempDir); |