mirror of
https://github.com/minetest/irrlicht.git
synced 2024-11-13 05:50:26 +01:00
Add test file for glTF mesh loading
This commit is contained in:
parent
bde174d1a0
commit
92862a3a2d
|
@ -35,9 +35,10 @@ endif()
|
|||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
enable_testing()
|
||||
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(src/lib/catch2)
|
||||
add_subdirectory(src/lib/tinygltf)
|
||||
add_subdirectory(src/Irrlicht)
|
||||
add_subdirectory(test)
|
||||
|
||||
option(BUILD_EXAMPLES "Build example applications" FALSE)
|
||||
|
|
21
source/Irrlicht/tests/CMakeLists.txt
Normal file
21
source/Irrlicht/tests/CMakeLists.txt
Normal 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
|
||||
)
|
54
source/Irrlicht/tests/inMemoryFile.cpp
Normal file
54
source/Irrlicht/tests/inMemoryFile.cpp
Normal 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
|
||||
|
32
source/Irrlicht/tests/inMemoryFile.h
Normal file
32
source/Irrlicht/tests/inMemoryFile.h
Normal 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
|
||||
|
18
source/Irrlicht/tests/testCGLTFMeshFileLoader.cpp
Normal file
18
source/Irrlicht/tests/testCGLTFMeshFileLoader.cpp
Normal 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();
|
||||
}
|
||||
|
13
source/lib/catch2/CMakeLists.txt
Normal file
13
source/lib/catch2/CMakeLists.txt
Normal 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
17976
source/lib/catch2/catch.hpp
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -575,6 +575,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 tinygltf native_app_glue)
|
||||
|
|
Loading…
Reference in New Issue
Block a user