diff --git a/.gitignore b/.gitignore index 879c4cd..2fdbb60 100644 --- a/.gitignore +++ b/.gitignore @@ -68,4 +68,11 @@ loader_example tests/tester tests/tester_noexcept tests/issue-97.gltf +tests/issue-261.gltf +# unignore +!./Makefile +!examples/build-gltf/Makefile +!examples/raytrace/cornellbox_suzanne.obj +!tests/Makefile +!tools/windows/premake5.exe \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index ba27550..0000000 --- a/Makefile +++ /dev/null @@ -1,13 +0,0 @@ - -# Use this for strict compilation check(will work on clang 3.8+) -#EXTRA_CXXFLAGS := -fsanitize=address -Wall -Werror -Weverything -Wno-c++11-long-long -Wno-c++98-compat - -# With draco -# EXTRA_CXXFLAGS := -I../draco/src/ -I../draco/build -DTINYGLTF_ENABLE_DRACO -L../draco/build -# EXTRA_LINKFLAGS := -L../draco/build/ -ldracodec -ldraco - -all: - clang++ $(EXTRA_CXXFLAGS) -std=c++11 -g -O0 -o loader_example loader_example.cc $(EXTRA_LINKFLAGS) - -lint: - deps/cpplint.py tiny_gltf.h diff --git a/tests/issue-261.gltf b/tests/issue-261.gltf deleted file mode 100644 index d1c5ca7..0000000 --- a/tests/issue-261.gltf +++ /dev/null @@ -1,378 +0,0 @@ -{ - "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 - ] - } - ] -} diff --git a/tests/tester.cc b/tests/tester.cc index c06aab4..0be911e 100644 --- a/tests/tester.cc +++ b/tests/tester.cc @@ -6,37 +6,39 @@ // 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 -#include -#include -#include -#include -#include - +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file #include "catch.hpp" -static JsonDocument JsonConstruct(const char* str) { +#include +#include +#include +#include +#include +#include + +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(strlen("bora")), - /* basedir*/ ""); + bool ret = ctx.LoadASCIIFromString(&model, &err, &warn, "bora", static_cast(strlen("bora")), /* basedir*/ ""); REQUIRE(false == ret); + } TEST_CASE("datauri-in-glb", "[issue-79]") { + tinygltf::Model model; tinygltf::TinyGLTF ctx; std::string err; @@ -51,13 +53,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; } @@ -91,17 +93,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; } @@ -110,12 +112,9 @@ 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); } @@ -145,7 +144,9 @@ 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]") { @@ -200,13 +201,10 @@ 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, @@ -233,13 +231,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); } @@ -247,8 +245,7 @@ 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); } @@ -256,8 +253,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); } @@ -266,14 +263,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(); @@ -281,8 +278,9 @@ TEST_CASE("parse-integer", "[bounds-checking]") { JsonDocument o; double nan = std::numeric_limits::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")); } } @@ -306,19 +304,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(); @@ -326,8 +324,9 @@ TEST_CASE("parse-unsigned", "[bounds-checking]") { JsonDocument o; double nan = std::numeric_limits::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")); } } @@ -337,8 +336,8 @@ TEST_CASE("parse-integer-array", "[bounds-checking]") { SECTION("parses valid integers") { std::string err; std::vector 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); @@ -363,27 +362,22 @@ 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 &texform = model.materials[0].emissiveTexture.extensions["KHR_texture_transform"].Get(); 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()); @@ -393,18 +387,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; } @@ -413,9 +407,7 @@ 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; } @@ -424,11 +416,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; @@ -441,23 +433,24 @@ 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; @@ -470,8 +463,26 @@ 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); + } +#ifndef TINYGLTF_NO_FS +TEST_CASE("expandpath-utf-8", "[pr-226]") { + + std::string s1 = "\xe5\xaf\xb9"; // utf-8 string + + std::string ret = tinygltf::ExpandFilePath(s1, /* userdata */nullptr); + + // expected: E5 AF B9 + REQUIRE(3 == ret.size()); + + REQUIRE(0xe5 == static_cast(ret[0])); + REQUIRE(0xaf == static_cast(ret[1])); + REQUIRE(0xb9 == static_cast(ret[2])); + +} +#endif + TEST_CASE("empty-bin-buffer", "[issue-382]") { tinygltf::Model model; tinygltf::TinyGLTF ctx; @@ -519,42 +530,4 @@ TEST_CASE("empty-bin-buffer", "[issue-382]") { 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 ret = tinygltf::ExpandFilePath(s1, /* userdata */ nullptr); - - // expected: E5 AF B9 - REQUIRE(3 == ret.size()); - - REQUIRE(0xe5 == static_cast(ret[0])); - REQUIRE(0xaf == static_cast(ret[1])); - REQUIRE(0xb9 == static_cast(ret[2])); -} -#endif +} \ No newline at end of file diff --git a/tiny_gltf.h b/tiny_gltf.h index 0971c18..c43d7ac 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -7894,4 +7894,4 @@ bool TinyGLTF::WriteGltfSceneToFile(Model *model, const std::string &filename, #pragma clang diagnostic pop #endif -#endif // TINYGLTF_IMPLEMENTATION +#endif // TINYGLTF_IMPLEMENTATION \ No newline at end of file