Add test file for glTF mesh loading

This commit is contained in:
JosiahWI 2022-10-16 21:48:29 -05:00
parent 4860523223
commit 21ce3d9657
No known key found for this signature in database
GPG Key ID: C7BB8573A4ABC4B9
8 changed files with 18117 additions and 0 deletions

View File

@ -38,6 +38,7 @@ if(NOT CMAKE_BUILD_TYPE)
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
add_subdirectory(source/lib/catch2)
add_subdirectory(source/lib/tinygltf)
add_subdirectory(source/Irrlicht)

View File

@ -321,6 +321,8 @@ if(WIN32)
set_target_properties(IrrlichtMt PROPERTIES PREFIX "") # for DLL name
endif()
add_subdirectory(tests)
# Installation of library
if(ANDROID)
set(INSTALL_TARGETS IrrlichtMt native_app_glue)

View File

@ -0,0 +1,21 @@
add_executable(tests
inMemoryFile.cpp inMemoryFile.h
testCGLTFMeshFileLoader.cpp
)
set_target_properties(tests PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)
target_compile_options(tests
PRIVATE
"$<$<CXX_COMPILER_ID:GNU>:-Wall>"
)
target_link_libraries(tests
PRIVATE
Catch2::Catch
IrrlichtMt::IrrlichtMt
)

View File

@ -0,0 +1,54 @@
#include "inMemoryFile.h"
#include <irrlicht.h>
#include <ios>
namespace irr
{
namespace io
{
InMemoryFile::InMemoryFile(const io::path& filename, const std::string& s)
: m_filename { filename }
, m_sstream { s }
{
}
std::size_t InMemoryFile::read(void* buffer, std::size_t sizeToRead)
{
m_sstream.read(reinterpret_cast<char*>(buffer), sizeToRead);
return m_sstream.gcount();
}
bool InMemoryFile::seek(long finalPos, bool relativeMovement)
{
if (relativeMovement) {
m_sstream.seekg(finalPos, std::ios::beg);
} else {
m_sstream.seekg(finalPos);
}
return m_sstream.fail();
}
long InMemoryFile::getSize() const
{
return m_sstream.str().size();
}
long InMemoryFile::getPos() const
{
return m_sstream.tellg();
}
const io::path& InMemoryFile::getFileName() const
{
return m_filename;
}
} // namespace irr
} // namespace io

View File

@ -0,0 +1,32 @@
#include <irrlicht.h>
#include <cstddef>
#include <sstream>
#include <string>
namespace irr
{
namespace io
{
class InMemoryFile: public IReadFile
{
public:
InMemoryFile(const io::path& filename, const std::string& s);
std::size_t read(void* buffer, std::size_t sizeToRead) override;
bool seek(long finalPos, bool relativeMovement=false) override;
long getSize() const override;
long getPos() const override;
const io::path& getFileName() const override;
private:
io::path m_filename;
mutable std::stringstream m_sstream;
};
} // namespace io
} // namespace irr

View File

@ -0,0 +1,18 @@
#include "inMemoryFile.h"
#define CATCH_CONFIG_MAIN
#include <catch.hpp>
#include <irrlicht.h>
TEST_CASE("load empty gltf file") {
irr::IrrlichtDevice* device { irr::createDevice(irr::video::EDT_NULL) };
irr::scene::ISceneManager* smgr { device->getSceneManager() };
irr::io::InMemoryFile filebuf{"test.gltf", ""};
auto* mesh { smgr->getMesh(&filebuf) };
REQUIRE(mesh == nullptr);
device->drop();
}

View File

@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.5)
project(Catch2
LANGUAGES CXX
)
add_library(Catch2 INTERFACE)
add_library(Catch2::Catch ALIAS Catch2)
target_include_directories(Catch2
INTERFACE
"${PROJECT_SOURCE_DIR}"
)

17976
source/lib/catch2/catch.hpp Normal file

File diff suppressed because it is too large Load Diff