Unit test for internal failures.
parent
b1ed751b83
commit
19cdfd12df
|
@ -279,3 +279,105 @@ TEST_F(ImporterTest, SearchFileHeaderForTokenTest) {
|
|||
//DefaultIOSystem ioSystem;
|
||||
// BaseImporter::SearchFileHeaderForToken( &ioSystem, assetPath, Token, 2 )
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
// Description for an importer which fails in specific ways.
|
||||
aiImporterDesc s_failingImporterDescription = {
|
||||
"Failing importer",
|
||||
"assimp team",
|
||||
"",
|
||||
"",
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
"fail"
|
||||
};
|
||||
|
||||
// This importer fails in specific ways.
|
||||
class FailingImporter : public Assimp::BaseImporter {
|
||||
public:
|
||||
virtual ~FailingImporter() = default;
|
||||
virtual bool CanRead( const std::string&, Assimp::IOSystem*, bool ) const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual const aiImporterDesc* GetInfo() const { return &s_failingImporterDescription; }
|
||||
|
||||
virtual void InternReadFile( const std::string& pFile, aiScene*, Assimp::IOSystem* ) override
|
||||
{
|
||||
if (pFile == "deadlyImportError.fail")
|
||||
{
|
||||
throw DeadlyImportError("Deadly import error test");
|
||||
}
|
||||
else if (pFile == "stdException.fail")
|
||||
{
|
||||
throw std::exception("std::exception test");
|
||||
}
|
||||
else if (pFile == "unexpectedException.fail")
|
||||
{
|
||||
throw 5;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
TEST_F(ImporterTest, deadlyImportError)
|
||||
{
|
||||
pImp->RegisterLoader(new FailingImporter);
|
||||
pImp->SetIOHandler(new TestIOSystem);
|
||||
const aiScene* scene = pImp->ReadFile("deadlyImportError.fail", 0);
|
||||
EXPECT_EQ(scene, nullptr);
|
||||
EXPECT_STREQ(pImp->GetErrorString(), "Deadly import error test");
|
||||
EXPECT_EQ(pImp->GetInternalException(), std::exception_ptr());
|
||||
}
|
||||
|
||||
TEST_F(ImporterTest, stdException)
|
||||
{
|
||||
pImp->RegisterLoader(new FailingImporter);
|
||||
pImp->SetIOHandler(new TestIOSystem);
|
||||
const aiScene* scene = pImp->ReadFile("stdException.fail", 0);
|
||||
EXPECT_EQ(scene, nullptr);
|
||||
EXPECT_STREQ(pImp->GetErrorString(), "Internal error");
|
||||
EXPECT_NE(pImp->GetInternalException(), std::exception_ptr());
|
||||
try
|
||||
{
|
||||
std::rethrow_exception(pImp->GetInternalException());
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
EXPECT_STREQ(e.what(), "std::exception test");
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(ImporterTest, unexpectedException)
|
||||
{
|
||||
pImp->RegisterLoader(new FailingImporter);
|
||||
pImp->SetIOHandler(new TestIOSystem);
|
||||
const aiScene* scene = pImp->ReadFile("unexpectedException.fail", 0);
|
||||
|
||||
EXPECT_EQ(scene, nullptr);
|
||||
EXPECT_STREQ(pImp->GetErrorString(), "Internal error");
|
||||
ASSERT_NE(pImp->GetInternalException(), std::exception_ptr());
|
||||
try
|
||||
{
|
||||
std::rethrow_exception(pImp->GetInternalException());
|
||||
}
|
||||
catch(int x)
|
||||
{
|
||||
EXPECT_EQ(x, 5);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue