mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-14 09:16:07 +08:00
added tests to cover empty, empty buffer, and single byte buffer cases
This commit is contained in:
parent
c670f08a3b
commit
6b7ec9f494
378
tests/issue-261.gltf
Normal file
378
tests/issue-261.gltf
Normal file
@ -0,0 +1,378 @@
|
||||
{
|
||||
"accessors": [
|
||||
{
|
||||
"bufferView": 0,
|
||||
"componentType": 5126,
|
||||
"count": 8,
|
||||
"max": [
|
||||
0.5,
|
||||
0.5,
|
||||
0.5
|
||||
],
|
||||
"min": [
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5
|
||||
],
|
||||
"type": "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView": 1,
|
||||
"componentType": 5125,
|
||||
"count": 36,
|
||||
"type": "SCALAR"
|
||||
}
|
||||
],
|
||||
"asset": {
|
||||
"copyright": "NVIDIA Corporation",
|
||||
"generator": "Iray glTF plugin",
|
||||
"version": "2.0"
|
||||
},
|
||||
"bufferViews": [
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteLength": 96,
|
||||
"byteStride": 12,
|
||||
"target": 34962
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteLength": 144,
|
||||
"byteOffset": 96,
|
||||
"target": 34963
|
||||
}
|
||||
],
|
||||
"buffers": [
|
||||
{
|
||||
"byteLength": 240,
|
||||
"uri": "data:application/octet-stream;base64,AAAAvwAAAL8AAAC/AAAAvwAAAL8AAAA/AAAAvwAAAD8AAAC/AAAAvwAAAD8AAAA/AAAAPwAAAL8AAAC/AAAAPwAAAL8AAAA/AAAAPwAAAD8AAAC/AAAAPwAAAD8AAAA/AAAAAAEAAAADAAAAAAAAAAMAAAACAAAAAQAAAAUAAAAHAAAAAQAAAAcAAAADAAAABQAAAAQAAAAGAAAABQAAAAYAAAAHAAAABAAAAAAAAAACAAAABAAAAAIAAAAGAAAABAAAAAUAAAABAAAABAAAAAEAAAAAAAAAAgAAAAMAAAAHAAAAAgAAAAcAAAAGAAAA"
|
||||
}
|
||||
],
|
||||
"cameras": [
|
||||
{
|
||||
"extensions": {
|
||||
"NV_Iray": {
|
||||
"mip_burn_highlights": 0.699999988079071,
|
||||
"mip_burn_highlights_per_component": false,
|
||||
"mip_camera_shutter": 4.0,
|
||||
"mip_cm2_factor": 1.0,
|
||||
"mip_crush_blacks": 0.5,
|
||||
"mip_f_number": 1.0,
|
||||
"mip_film_iso": 100.0,
|
||||
"mip_gamma": 2.200000047683716,
|
||||
"mip_saturation": 1.0,
|
||||
"mip_vignetting": 0.00019999999494757503,
|
||||
"mip_whitepoint": [
|
||||
1.0,
|
||||
1.0,
|
||||
1.0,
|
||||
1.0
|
||||
],
|
||||
"tm_enable_tonemapper": true,
|
||||
"tm_tonemapper": "mia_exposure_photographic"
|
||||
}
|
||||
},
|
||||
"extras": {
|
||||
"resolution": [
|
||||
640,
|
||||
480
|
||||
]
|
||||
},
|
||||
"name": "default",
|
||||
"perspective": {
|
||||
"aspectRatio": 1.3333333730697632,
|
||||
"yfov": 0.9272952079772949,
|
||||
"zfar": 1000.0,
|
||||
"znear": 0.1
|
||||
},
|
||||
"type": "perspective"
|
||||
}
|
||||
],
|
||||
"extensions": {
|
||||
"KHR_lights_punctual": {
|
||||
"lights": [
|
||||
{
|
||||
"color": [
|
||||
1.0,
|
||||
1.0,
|
||||
1.0
|
||||
],
|
||||
"intensity": 1000.0,
|
||||
"name": "light",
|
||||
"type": "point"
|
||||
}
|
||||
]
|
||||
},
|
||||
"NV_MDL": {
|
||||
"modules": [
|
||||
"mdl::base",
|
||||
"mdl::nvidia::core_definitions",
|
||||
"mdl::state"
|
||||
],
|
||||
"shaders": [
|
||||
{
|
||||
"definition": "mdl::base::environment_spherical(texture_2d)",
|
||||
"name": "env_shd"
|
||||
},
|
||||
{
|
||||
"arguments": {
|
||||
"base_color": [
|
||||
0.0055217444896698,
|
||||
0.36859095096588135,
|
||||
0.0041161770932376385
|
||||
],
|
||||
"normal=": 2
|
||||
},
|
||||
"definition": "mdl::nvidia::core_definitions::flex_material",
|
||||
"name": "cube_instance_material"
|
||||
},
|
||||
{
|
||||
"definition": "mdl::state::normal()",
|
||||
"name": "mdl::state::normal_341"
|
||||
},
|
||||
{
|
||||
"arguments": {
|
||||
"base_color": [
|
||||
0.0055217444896698,
|
||||
0.36859095096588135,
|
||||
0.0041161770932376385
|
||||
],
|
||||
"normal=": 4
|
||||
},
|
||||
"definition": "mdl::nvidia::core_definitions::flex_material",
|
||||
"name": "cube_instance_material"
|
||||
},
|
||||
{
|
||||
"definition": "mdl::state::normal()",
|
||||
"name": "mdl::state::normal_341"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"extensionsUsed": [
|
||||
"NV_MDL",
|
||||
"NV_Iray",
|
||||
"KHR_lights_punctual"
|
||||
],
|
||||
"materials": [
|
||||
{
|
||||
"doubleSided": true,
|
||||
"extras": {
|
||||
"mdl_shader": 1
|
||||
},
|
||||
"name": "cube_instance_material",
|
||||
"pbrMetallicRoughness": {
|
||||
"baseColorFactor": [
|
||||
0.0055217444896698,
|
||||
0.36859095096588135,
|
||||
0.0041161770932376385,
|
||||
1.0
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"meshes": [
|
||||
{
|
||||
"name": "cube",
|
||||
"primitives": [
|
||||
{
|
||||
"attributes": {
|
||||
"POSITION": 0
|
||||
},
|
||||
"indices": 1,
|
||||
"material": 0,
|
||||
"mode": 4
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"nodes": [
|
||||
{
|
||||
"camera": 0,
|
||||
"extensions": {
|
||||
"NV_Iray": {
|
||||
"iview:fkey": -1,
|
||||
"iview:fov": 53.130104064941406,
|
||||
"iview:interest": [
|
||||
0.1342654824256897,
|
||||
-0.14356137812137604,
|
||||
0.037264324724674225
|
||||
],
|
||||
"iview:position": [
|
||||
0.9729073643684387,
|
||||
1.2592438459396362,
|
||||
2.4199187755584717
|
||||
],
|
||||
"iview:roll": 0.0,
|
||||
"iview:up": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
]
|
||||
}
|
||||
},
|
||||
"matrix": [
|
||||
0.9432751389105357,
|
||||
-1.1769874756875739e-16,
|
||||
-0.3320120665176343,
|
||||
0.0,
|
||||
-0.16119596696756341,
|
||||
0.8742297945345237,
|
||||
-0.45797175303889276,
|
||||
0.0,
|
||||
0.290254840694694,
|
||||
0.48551237507207207,
|
||||
0.8246392308792816,
|
||||
0.0,
|
||||
0.9729073377709113,
|
||||
1.2592438262175363,
|
||||
2.419918748461627,
|
||||
1.0
|
||||
],
|
||||
"name": "CamInst"
|
||||
},
|
||||
{
|
||||
"extensions": {
|
||||
"NV_Iray": {
|
||||
"caustic": true,
|
||||
"caustic_cast": true,
|
||||
"caustic_recv": true,
|
||||
"face_back": true,
|
||||
"face_front": true,
|
||||
"finalgather": true,
|
||||
"finalgather_cast": true,
|
||||
"finalgather_recv": true,
|
||||
"globillum": true,
|
||||
"globillum_cast": true,
|
||||
"globillum_recv": true,
|
||||
"material=": 3,
|
||||
"pickable": true,
|
||||
"reflection_cast": true,
|
||||
"reflection_recv": true,
|
||||
"refraction_cast": true,
|
||||
"refraction_recv": true,
|
||||
"shadow_cast": true,
|
||||
"shadow_recv": true,
|
||||
"transparency_cast": true,
|
||||
"transparency_recv": true,
|
||||
"visible": true
|
||||
}
|
||||
},
|
||||
"mesh": 0,
|
||||
"name": "cube_instance"
|
||||
},
|
||||
{
|
||||
"extensions": {
|
||||
"KHR_lights_punctual": {
|
||||
"light": 0
|
||||
},
|
||||
"NV_Iray": {
|
||||
"shadow_cast": true,
|
||||
"visible": false
|
||||
}
|
||||
},
|
||||
"matrix": [
|
||||
0.6988062355563571,
|
||||
-7.76042172309776e-17,
|
||||
-0.7153110128800992,
|
||||
-0.0,
|
||||
-0.4276881690736487,
|
||||
0.8015668284138362,
|
||||
-0.41781987700564616,
|
||||
-0.0,
|
||||
0.57336957992379,
|
||||
0.5979051928078428,
|
||||
0.5601398979107212,
|
||||
0.0,
|
||||
2.3640632834071384,
|
||||
2.465226204472449,
|
||||
2.309515908392224,
|
||||
1.0
|
||||
],
|
||||
"name": "light_inst"
|
||||
}
|
||||
],
|
||||
"scene": 0,
|
||||
"scenes": [
|
||||
{
|
||||
"extensions": {
|
||||
"NV_Iray": {
|
||||
"CP_canny_threshold1": 40,
|
||||
"CP_canny_threshold2": 120,
|
||||
"CP_color_quantization": 8,
|
||||
"IVP_color": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0
|
||||
],
|
||||
"TM_drago_bias": 0.8500000238418579,
|
||||
"TM_drago_gamma2": 2.200000047683716,
|
||||
"TM_drago_saturation": 1.0,
|
||||
"TM_durand_contrast": 4.0,
|
||||
"TM_durand_gamma": 2.200000047683716,
|
||||
"TM_durand_saturation": 1.0,
|
||||
"TM_durand_sigma_color": 2.0,
|
||||
"TM_durand_sigma_space": 2.0,
|
||||
"TM_linear_gamma": 2.200000047683716,
|
||||
"TM_reinhard_color_adapt": 0.8999999761581421,
|
||||
"TM_reinhard_gamma": 1.0,
|
||||
"TM_reinhard_intensity": 0.0,
|
||||
"TM_reinhard_light_adapt": 1.0,
|
||||
"TM_reye_Ywhite": 1000000.0,
|
||||
"TM_reye_bsize": 2,
|
||||
"TM_reye_bthres": 3.0,
|
||||
"TM_reye_gamma": 2.200000047683716,
|
||||
"TM_reye_key": 0.5,
|
||||
"TM_reye_saturation": 1.0,
|
||||
"TM_reye_whitebalance": [
|
||||
1.0,
|
||||
0.9965101480484009,
|
||||
0.9805564880371094,
|
||||
0.0
|
||||
],
|
||||
"environment_dome_depth": 200.0,
|
||||
"environment_dome_height": 200.0,
|
||||
"environment_dome_mode": "infinite",
|
||||
"environment_dome_position": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"environment_dome_radius": 100.0,
|
||||
"environment_dome_rotation_angle": 0.0,
|
||||
"environment_dome_width": 200.0,
|
||||
"environment_function=": 0,
|
||||
"environment_function_intensity": 1.9900000095367432,
|
||||
"iray_instancing": "off",
|
||||
"iview::inline_color": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0
|
||||
],
|
||||
"iview::inline_width": 1.0,
|
||||
"iview::magnifier_size": 300,
|
||||
"iview::offset": 10.0,
|
||||
"iview::outline_color": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0
|
||||
],
|
||||
"iview::outline_width": 2.0,
|
||||
"iview::overview": true,
|
||||
"iview::zoom_factor": 1.0,
|
||||
"samples": 4.0,
|
||||
"shadow_cast": true,
|
||||
"shadow_recv": true
|
||||
}
|
||||
},
|
||||
"nodes": [
|
||||
0,
|
||||
1,
|
||||
2
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
220
tests/tester.cc
220
tests/tester.cc
@ -6,39 +6,37 @@
|
||||
// Nlohmann json(include ../json.hpp)
|
||||
#include "json.hpp"
|
||||
|
||||
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
|
||||
#include "catch.hpp"
|
||||
|
||||
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do
|
||||
// this in one cpp file
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
||||
static JsonDocument JsonConstruct(const char* str)
|
||||
{
|
||||
#include "catch.hpp"
|
||||
|
||||
static JsonDocument JsonConstruct(const char* str) {
|
||||
JsonDocument doc;
|
||||
JsonParse(doc, str, strlen(str));
|
||||
return doc;
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("parse-error", "[parse]") {
|
||||
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
|
||||
bool ret = ctx.LoadASCIIFromString(&model, &err, &warn, "bora", static_cast<int>(strlen("bora")), /* basedir*/ "");
|
||||
bool ret = ctx.LoadASCIIFromString(&model, &err, &warn, "bora",
|
||||
static_cast<int>(strlen("bora")),
|
||||
/* basedir*/ "");
|
||||
|
||||
REQUIRE(false == ret);
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("datauri-in-glb", "[issue-79]") {
|
||||
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
@ -53,13 +51,13 @@ TEST_CASE("datauri-in-glb", "[issue-79]") {
|
||||
}
|
||||
|
||||
TEST_CASE("extension-with-empty-object", "[issue-97]") {
|
||||
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
|
||||
bool ret = ctx.LoadASCIIFromFile(&model, &err, &warn, "../models/Extensions-issue97/test.gltf");
|
||||
bool ret = ctx.LoadASCIIFromFile(&model, &err, &warn,
|
||||
"../models/Extensions-issue97/test.gltf");
|
||||
if (!err.empty()) {
|
||||
std::cerr << err << std::endl;
|
||||
}
|
||||
@ -93,17 +91,17 @@ TEST_CASE("extension-with-empty-object", "[issue-97]") {
|
||||
REQUIRE(m.materials[0].extensions.size() == 1);
|
||||
REQUIRE(m.materials[0].extensions.count("VENDOR_material_some_ext") == 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("extension-overwrite", "[issue-261]") {
|
||||
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
|
||||
bool ret = ctx.LoadASCIIFromFile(&model, &err, &warn, "../models/Extensions-overwrite-issue261/issue-261.gltf");
|
||||
bool ret = ctx.LoadASCIIFromFile(
|
||||
&model, &err, &warn,
|
||||
"../models/Extensions-overwrite-issue261/issue-261.gltf");
|
||||
if (!err.empty()) {
|
||||
std::cerr << err << std::endl;
|
||||
}
|
||||
@ -112,9 +110,12 @@ TEST_CASE("extension-overwrite", "[issue-261]") {
|
||||
REQUIRE(model.extensionsUsed.size() == 3);
|
||||
{
|
||||
bool has_ext_lights = false;
|
||||
has_ext_lights |= (model.extensionsUsed[0].compare("KHR_lights_punctual") == 0);
|
||||
has_ext_lights |= (model.extensionsUsed[1].compare("KHR_lights_punctual") == 0);
|
||||
has_ext_lights |= (model.extensionsUsed[2].compare("KHR_lights_punctual") == 0);
|
||||
has_ext_lights |=
|
||||
(model.extensionsUsed[0].compare("KHR_lights_punctual") == 0);
|
||||
has_ext_lights |=
|
||||
(model.extensionsUsed[1].compare("KHR_lights_punctual") == 0);
|
||||
has_ext_lights |=
|
||||
(model.extensionsUsed[2].compare("KHR_lights_punctual") == 0);
|
||||
|
||||
REQUIRE(true == has_ext_lights);
|
||||
}
|
||||
@ -144,9 +145,7 @@ TEST_CASE("extension-overwrite", "[issue-261]") {
|
||||
REQUIRE(m.extensions.size() == 2);
|
||||
REQUIRE(m.extensions.count("NV_MDL"));
|
||||
REQUIRE(m.extensions.count("KHR_lights_punctual"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("invalid-primitive-indices", "[bounds-checking]") {
|
||||
@ -201,10 +200,13 @@ TEST_CASE("glb-invalid-length", "[bounds-checking]") {
|
||||
|
||||
// This glb has a much longer length than the provided data and should fail
|
||||
// initial range checks.
|
||||
const unsigned char glb_invalid_length[] = "glTF"
|
||||
"\x20\x00\x00\x00" "\x6c\x66\x00\x00" //
|
||||
// | version | length |
|
||||
"\x02\x00\x00\x00" "\x4a\x53\x4f\x4e{}"; //
|
||||
const unsigned char glb_invalid_length[] =
|
||||
"glTF"
|
||||
"\x20\x00\x00\x00"
|
||||
"\x6c\x66\x00\x00" //
|
||||
// | version | length |
|
||||
"\x02\x00\x00\x00"
|
||||
"\x4a\x53\x4f\x4e{}"; //
|
||||
// | model length | model format |
|
||||
|
||||
bool ret = ctx.LoadBinaryFromMemory(&model, &err, &warn, glb_invalid_length,
|
||||
@ -231,13 +233,13 @@ TEST_CASE("parse-integer", "[bounds-checking]") {
|
||||
SECTION("parses valid numbers") {
|
||||
std::string err;
|
||||
int result = 123;
|
||||
CHECK(tinygltf::ParseIntegerProperty(&result, &err, JsonConstruct("{\"zero\" : 0}"), "zero",
|
||||
true));
|
||||
CHECK(tinygltf::ParseIntegerProperty(
|
||||
&result, &err, JsonConstruct("{\"zero\" : 0}"), "zero", true));
|
||||
REQUIRE(err == "");
|
||||
REQUIRE(result == 0);
|
||||
|
||||
CHECK(tinygltf::ParseIntegerProperty(&result, &err, JsonConstruct("{\"int\": -1234}"), "int",
|
||||
true));
|
||||
CHECK(tinygltf::ParseIntegerProperty(
|
||||
&result, &err, JsonConstruct("{\"int\": -1234}"), "int", true));
|
||||
REQUIRE(err == "");
|
||||
REQUIRE(result == -1234);
|
||||
}
|
||||
@ -245,7 +247,8 @@ TEST_CASE("parse-integer", "[bounds-checking]") {
|
||||
SECTION("detects missing properties") {
|
||||
std::string err;
|
||||
int result = -1;
|
||||
CHECK_FALSE(tinygltf::ParseIntegerProperty(&result, &err, JsonConstruct(""), "int", true));
|
||||
CHECK_FALSE(tinygltf::ParseIntegerProperty(&result, &err, JsonConstruct(""),
|
||||
"int", true));
|
||||
REQUIRE_THAT(err, Catch::Contains("'int' property is missing"));
|
||||
REQUIRE(result == -1);
|
||||
}
|
||||
@ -253,8 +256,8 @@ TEST_CASE("parse-integer", "[bounds-checking]") {
|
||||
SECTION("handled missing but not required properties") {
|
||||
std::string err;
|
||||
int result = -1;
|
||||
CHECK_FALSE(
|
||||
tinygltf::ParseIntegerProperty(&result, &err, JsonConstruct(""), "int", false));
|
||||
CHECK_FALSE(tinygltf::ParseIntegerProperty(&result, &err, JsonConstruct(""),
|
||||
"int", false));
|
||||
REQUIRE(err == "");
|
||||
REQUIRE(result == -1);
|
||||
}
|
||||
@ -263,14 +266,14 @@ TEST_CASE("parse-integer", "[bounds-checking]") {
|
||||
std::string err;
|
||||
int result = -1;
|
||||
|
||||
CHECK_FALSE(tinygltf::ParseIntegerProperty(&result, &err, JsonConstruct("{\"int\": 0.5}"),
|
||||
"int", true));
|
||||
CHECK_FALSE(tinygltf::ParseIntegerProperty(
|
||||
&result, &err, JsonConstruct("{\"int\": 0.5}"), "int", true));
|
||||
REQUIRE_THAT(err, Catch::Contains("not an integer type"));
|
||||
|
||||
// Excessively large values and NaN aren't allowed either.
|
||||
err.clear();
|
||||
CHECK_FALSE(tinygltf::ParseIntegerProperty(&result, &err, JsonConstruct("{\"int\": 1e300}"),
|
||||
"int", true));
|
||||
CHECK_FALSE(tinygltf::ParseIntegerProperty(
|
||||
&result, &err, JsonConstruct("{\"int\": 1e300}"), "int", true));
|
||||
REQUIRE_THAT(err, Catch::Contains("not an integer type"));
|
||||
|
||||
err.clear();
|
||||
@ -278,9 +281,8 @@ TEST_CASE("parse-integer", "[bounds-checking]") {
|
||||
JsonDocument o;
|
||||
double nan = std::numeric_limits<double>::quiet_NaN();
|
||||
tinygltf::JsonAddMember(o, "int", json(nan));
|
||||
CHECK_FALSE(tinygltf::ParseIntegerProperty(
|
||||
&result, &err, o,
|
||||
"int", true));
|
||||
CHECK_FALSE(
|
||||
tinygltf::ParseIntegerProperty(&result, &err, o, "int", true));
|
||||
REQUIRE_THAT(err, Catch::Contains("not an integer type"));
|
||||
}
|
||||
}
|
||||
@ -304,19 +306,19 @@ TEST_CASE("parse-unsigned", "[bounds-checking]") {
|
||||
std::string err;
|
||||
size_t result = -1;
|
||||
|
||||
CHECK_FALSE(tinygltf::ParseUnsignedProperty(&result, &err, JsonConstruct("{\"int\": -1234}"),
|
||||
"int", true));
|
||||
CHECK_FALSE(tinygltf::ParseUnsignedProperty(
|
||||
&result, &err, JsonConstruct("{\"int\": -1234}"), "int", true));
|
||||
REQUIRE_THAT(err, Catch::Contains("not a positive integer"));
|
||||
|
||||
err.clear();
|
||||
CHECK_FALSE(tinygltf::ParseUnsignedProperty(&result, &err, JsonConstruct("{\"int\": 0.5}"),
|
||||
"int", true));
|
||||
CHECK_FALSE(tinygltf::ParseUnsignedProperty(
|
||||
&result, &err, JsonConstruct("{\"int\": 0.5}"), "int", true));
|
||||
REQUIRE_THAT(err, Catch::Contains("not a positive integer"));
|
||||
|
||||
// Excessively large values and NaN aren't allowed either.
|
||||
err.clear();
|
||||
CHECK_FALSE(tinygltf::ParseUnsignedProperty(&result, &err, JsonConstruct("{\"int\": 1e300}"),
|
||||
"int", true));
|
||||
CHECK_FALSE(tinygltf::ParseUnsignedProperty(
|
||||
&result, &err, JsonConstruct("{\"int\": 1e300}"), "int", true));
|
||||
REQUIRE_THAT(err, Catch::Contains("not a positive integer"));
|
||||
|
||||
err.clear();
|
||||
@ -324,9 +326,8 @@ TEST_CASE("parse-unsigned", "[bounds-checking]") {
|
||||
JsonDocument o;
|
||||
double nan = std::numeric_limits<double>::quiet_NaN();
|
||||
tinygltf::JsonAddMember(o, "int", json(nan));
|
||||
CHECK_FALSE(tinygltf::ParseUnsignedProperty(
|
||||
&result, &err, o,
|
||||
"int", true));
|
||||
CHECK_FALSE(
|
||||
tinygltf::ParseUnsignedProperty(&result, &err, o, "int", true));
|
||||
REQUIRE_THAT(err, Catch::Contains("not a positive integer"));
|
||||
}
|
||||
}
|
||||
@ -336,8 +337,8 @@ TEST_CASE("parse-integer-array", "[bounds-checking]") {
|
||||
SECTION("parses valid integers") {
|
||||
std::string err;
|
||||
std::vector<int> result;
|
||||
CHECK(tinygltf::ParseIntegerArrayProperty(&result, &err,
|
||||
JsonConstruct("{\"x\": [-1, 2, 3]}"), "x", true));
|
||||
CHECK(tinygltf::ParseIntegerArrayProperty(
|
||||
&result, &err, JsonConstruct("{\"x\": [-1, 2, 3]}"), "x", true));
|
||||
REQUIRE(err == "");
|
||||
REQUIRE(result.size() == 3);
|
||||
REQUIRE(result[0] == -1);
|
||||
@ -362,22 +363,27 @@ TEST_CASE("pbr-khr-texture-transform", "[material]") {
|
||||
|
||||
// Loading is expected to fail, but not crash.
|
||||
bool ret = ctx.LoadASCIIFromFile(
|
||||
&model, &err, &warn,
|
||||
"../models/Cube-texture-ext/Cube-textransform.gltf");
|
||||
&model, &err, &warn, "../models/Cube-texture-ext/Cube-textransform.gltf");
|
||||
REQUIRE(ret == true);
|
||||
|
||||
REQUIRE(model.materials.size() == 2);
|
||||
REQUIRE(model.materials[0].emissiveTexture.extensions.count("KHR_texture_transform") == 1);
|
||||
REQUIRE(model.materials[0].emissiveTexture.extensions["KHR_texture_transform"].IsObject());
|
||||
REQUIRE(model.materials[0].emissiveTexture.extensions.count(
|
||||
"KHR_texture_transform") == 1);
|
||||
REQUIRE(model.materials[0]
|
||||
.emissiveTexture.extensions["KHR_texture_transform"]
|
||||
.IsObject());
|
||||
|
||||
tinygltf::Value::Object &texform = model.materials[0].emissiveTexture.extensions["KHR_texture_transform"].Get<tinygltf::Value::Object>();
|
||||
tinygltf::Value::Object& texform =
|
||||
model.materials[0]
|
||||
.emissiveTexture.extensions["KHR_texture_transform"]
|
||||
.Get<tinygltf::Value::Object>();
|
||||
|
||||
REQUIRE(texform.count("scale"));
|
||||
|
||||
REQUIRE(texform["scale"].IsArray());
|
||||
|
||||
// Note: It looks json.hpp parse integer JSON number as integer, not floating point.
|
||||
// IsNumber return true either value is int or floating point.
|
||||
// Note: It looks json.hpp parse integer JSON number as integer, not floating
|
||||
// point. IsNumber return true either value is int or floating point.
|
||||
REQUIRE(texform["scale"].Get(0).IsNumber());
|
||||
REQUIRE(texform["scale"].Get(1).IsNumber());
|
||||
|
||||
@ -387,18 +393,18 @@ TEST_CASE("pbr-khr-texture-transform", "[material]") {
|
||||
|
||||
REQUIRE(scale[0] == Approx(1.0));
|
||||
REQUIRE(scale[1] == Approx(-1.0));
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("image-uri-spaces", "[issue-236]") {
|
||||
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
|
||||
// Test image file with single spaces.
|
||||
bool ret = ctx.LoadASCIIFromFile(&model, &err, &warn, "../models/CubeImageUriSpaces/CubeImageUriSpaces.gltf");
|
||||
bool ret = ctx.LoadASCIIFromFile(
|
||||
&model, &err, &warn,
|
||||
"../models/CubeImageUriSpaces/CubeImageUriSpaces.gltf");
|
||||
if (!err.empty()) {
|
||||
std::cerr << err << std::endl;
|
||||
}
|
||||
@ -407,7 +413,9 @@ TEST_CASE("image-uri-spaces", "[issue-236]") {
|
||||
|
||||
// Test image file with a beginning space, trailing space, and greater than
|
||||
// one consecutive spaces.
|
||||
ret = ctx.LoadASCIIFromFile(&model, &err, &warn, "../models/CubeImageUriSpaces/CubeImageUriMultipleSpaces.gltf");
|
||||
ret = ctx.LoadASCIIFromFile(
|
||||
&model, &err, &warn,
|
||||
"../models/CubeImageUriSpaces/CubeImageUriMultipleSpaces.gltf");
|
||||
if (!err.empty()) {
|
||||
std::cerr << err << std::endl;
|
||||
}
|
||||
@ -416,11 +424,11 @@ TEST_CASE("image-uri-spaces", "[issue-236]") {
|
||||
}
|
||||
|
||||
TEST_CASE("serialize-empty-material", "[issue-294]") {
|
||||
|
||||
tinygltf::Model m;
|
||||
|
||||
tinygltf::Material mat;
|
||||
mat.pbrMetallicRoughness.baseColorFactor = {1.0f, 1.0f, 1.0f, 1.0f}; // default baseColorFactor
|
||||
mat.pbrMetallicRoughness.baseColorFactor = {1.0f, 1.0f, 1.0f,
|
||||
1.0f}; // default baseColorFactor
|
||||
m.materials.push_back(mat);
|
||||
|
||||
std::stringstream os;
|
||||
@ -433,24 +441,23 @@ TEST_CASE("serialize-empty-material", "[issue-294]") {
|
||||
|
||||
REQUIRE(1 == j["materials"].size());
|
||||
REQUIRE(j["materials"][0].is_object());
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("empty-skeleton-id", "[issue-321]") {
|
||||
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
|
||||
bool ret = ctx.LoadASCIIFromFile(&model, &err, &warn, "../models/regression/unassigned-skeleton.gltf");
|
||||
bool ret = ctx.LoadASCIIFromFile(
|
||||
&model, &err, &warn, "../models/regression/unassigned-skeleton.gltf");
|
||||
if (!err.empty()) {
|
||||
std::cerr << err << std::endl;
|
||||
}
|
||||
REQUIRE(true == ret);
|
||||
|
||||
REQUIRE(model.skins.size() == 1);
|
||||
REQUIRE(model.skins[0].skeleton == -1); // unassigned
|
||||
REQUIRE(model.skins[0].skeleton == -1); // unassigned
|
||||
|
||||
std::stringstream os;
|
||||
|
||||
@ -463,15 +470,85 @@ TEST_CASE("empty-skeleton-id", "[issue-321]") {
|
||||
REQUIRE(1 == j["skins"].size());
|
||||
REQUIRE(j["skins"][0].is_object());
|
||||
REQUIRE(j["skins"][0].count("skeleton") == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("empty-bin-buffer", "[issue-382]") {
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
|
||||
tinygltf::Model model_empty;
|
||||
std::stringstream stream;
|
||||
bool ret = ctx.WriteGltfSceneToStream(&model_empty, stream, false, true);
|
||||
REQUIRE(ret == true);
|
||||
std::string str = stream.str();
|
||||
const unsigned char* bytes = (unsigned char*)str.data();
|
||||
ret = ctx.LoadBinaryFromMemory(&model, &err, &warn, bytes, str.size());
|
||||
if (!err.empty()) {
|
||||
std::cerr << err << std::endl;
|
||||
}
|
||||
REQUIRE(true == ret);
|
||||
|
||||
tinygltf::Model model_empty_buffer;
|
||||
model_empty_buffer.buffers.push_back(tinygltf::Buffer());
|
||||
stream = std::stringstream();
|
||||
ret = ctx.WriteGltfSceneToStream(&model_empty_buffer, stream, false, true);
|
||||
REQUIRE(ret == true);
|
||||
str = stream.str();
|
||||
bytes = (unsigned char*)str.data();
|
||||
ret = ctx.LoadBinaryFromMemory(&model, &err, &warn, bytes, str.size());
|
||||
if (err.empty()) {
|
||||
std::cerr << "there should have been an error reported" << std::endl;
|
||||
}
|
||||
REQUIRE(false == ret);
|
||||
|
||||
tinygltf::Model model_single_byte_buffer;
|
||||
tinygltf::Buffer buffer;
|
||||
buffer.data.push_back(0);
|
||||
model_single_byte_buffer.buffers.push_back(buffer);
|
||||
stream = std::stringstream();
|
||||
ret = ctx.WriteGltfSceneToStream(&model_single_byte_buffer, stream, false,
|
||||
true);
|
||||
REQUIRE(ret == true);
|
||||
str = stream.str();
|
||||
bytes = (unsigned char*)str.data();
|
||||
ret = ctx.LoadBinaryFromMemory(&model_single_byte_buffer, &err, &warn, bytes,
|
||||
str.size());
|
||||
if (err.empty()) {
|
||||
std::cerr << "there should have been an error reported" << std::endl;
|
||||
}
|
||||
REQUIRE(false == ret);
|
||||
|
||||
// bool ret = ctx.LoadBinaryFromFile(
|
||||
// &model, &err, &warn, "../models/EmptyBinChunk-issue382/empty.glb");
|
||||
// if (!err.empty()) {
|
||||
// std::cerr << err << std::endl;
|
||||
// }
|
||||
// REQUIRE(true == ret);
|
||||
|
||||
// ret = ctx.LoadBinaryFromFile(
|
||||
// &model, &err, &warn,
|
||||
// "../models/EmptyBinChunk-issue382/empty_buffer.glb");
|
||||
// if (err.empty()) {
|
||||
// std::cerr << "there should have been an error reported" << std::endl;
|
||||
// }
|
||||
// REQUIRE(false == ret);
|
||||
|
||||
// ret = ctx.LoadBinaryFromFile(
|
||||
// &model, &err, &warn,
|
||||
// "../models/EmptyBinChunk-issue382/single_byte_buffer.glb");
|
||||
// if (err.empty()) {
|
||||
// std::cerr << "there should have been an error reported" << std::endl;
|
||||
// }
|
||||
// REQUIRE(false == ret);
|
||||
}
|
||||
|
||||
#ifndef TINYGLTF_NO_FS
|
||||
TEST_CASE("expandpath-utf-8", "[pr-226]") {
|
||||
std::string s1 = "\xe5\xaf\xb9"; // utf-8 string
|
||||
|
||||
std::string s1 = "\xe5\xaf\xb9"; // utf-8 string
|
||||
|
||||
std::string ret = tinygltf::ExpandFilePath(s1, /* userdata */nullptr);
|
||||
std::string ret = tinygltf::ExpandFilePath(s1, /* userdata */ nullptr);
|
||||
|
||||
// expected: E5 AF B9
|
||||
REQUIRE(3 == ret.size());
|
||||
@ -479,6 +556,5 @@ TEST_CASE("expandpath-utf-8", "[pr-226]") {
|
||||
REQUIRE(0xe5 == static_cast<uint8_t>(ret[0]));
|
||||
REQUIRE(0xaf == static_cast<uint8_t>(ret[1]));
|
||||
REQUIRE(0xb9 == static_cast<uint8_t>(ret[2]));
|
||||
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user