mirror of
https://github.com/syoyo/tinygltf.git
synced 2026-08-21 10:38:36 +00:00
Move tiny_gltf.h/.cc, tinygltf_json.h, json.hpp, stb_image*, loader_example.cc, examples/, wasm/, experimental/, legacy tests and fuzzers under attic/. TinyGLTF v3 C (tiny_gltf_v3.h/.c + tinygltf_json_c.h) is now the mainline: - CMakeLists.txt: v3 C tests only, installs only v3 files - tests/Makefile and Makefile: build/run the v3 C testers - test_runner.py: verifies v3 C tester output only (no v1 ground truth) - CI workflows: build and test v3 C only (GCC/Clang/MSVC/Meson/sanitizers) - README: v3 C quick start, testing, licenses; legacy moved to attic/
88 lines
3.0 KiB
C++
88 lines
3.0 KiB
C++
#ifdef VALIJSON_BUILD_CXX11_ADAPTERS
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <valijson/adapters/json11_adapter.hpp>
|
|
|
|
class TestJson11Adapter : public testing::Test
|
|
{
|
|
|
|
};
|
|
|
|
TEST_F(TestJson11Adapter, BasicArrayIteration)
|
|
{
|
|
const unsigned int numElements = 10;
|
|
|
|
// Create a Json11 document that consists of an array of numbers
|
|
json11::Json::array array;
|
|
for (unsigned int i = 0; i < numElements; i++) {
|
|
json11::Json value(static_cast<double>(i));
|
|
array.push_back(value);
|
|
}
|
|
json11::Json document(array);
|
|
|
|
// Ensure that wrapping the document preserves the array and does not allow
|
|
// it to be cast to other types
|
|
valijson::adapters::Json11Adapter adapter(document);
|
|
ASSERT_NO_THROW( adapter.getArray() );
|
|
ASSERT_ANY_THROW( adapter.getBool() );
|
|
ASSERT_ANY_THROW( adapter.getDouble() );
|
|
ASSERT_ANY_THROW( adapter.getObject() );
|
|
ASSERT_ANY_THROW( adapter.getString() );
|
|
|
|
// Ensure that the array contains the expected number of elements
|
|
EXPECT_EQ( numElements, adapter.getArray().size() );
|
|
|
|
// Ensure that the elements are returned in the order they were inserted
|
|
unsigned int expectedValue = 0;
|
|
for (const valijson::adapters::Json11Adapter value : adapter.getArray()) {
|
|
ASSERT_TRUE( value.isNumber() );
|
|
EXPECT_EQ( double(expectedValue), value.getDouble() );
|
|
expectedValue++;
|
|
}
|
|
|
|
// Ensure that the correct number of elements were iterated over
|
|
EXPECT_EQ(numElements, expectedValue);
|
|
}
|
|
|
|
TEST_F(TestJson11Adapter, BasicObjectIteration)
|
|
{
|
|
const unsigned int numElements = 10;
|
|
|
|
// Create a DropBoxJson11 document that consists of an object that maps numeric
|
|
// strings their corresponding numeric values
|
|
json11::Json::object object;
|
|
for (unsigned int i = 0; i < numElements; i++) {
|
|
std::string name(std::to_string(i));
|
|
object[name] = json11::Json(static_cast<double>(i));
|
|
}
|
|
json11::Json document(object);
|
|
|
|
// Ensure that wrapping the document preserves the object and does not
|
|
// allow it to be cast to other types
|
|
valijson::adapters::Json11Adapter adapter(document);
|
|
ASSERT_NO_THROW( adapter.getObject() );
|
|
ASSERT_ANY_THROW( adapter.getArray() );
|
|
ASSERT_ANY_THROW( adapter.getBool() );
|
|
ASSERT_ANY_THROW( adapter.getDouble() );
|
|
ASSERT_ANY_THROW( adapter.getString() );
|
|
|
|
// Ensure that the object contains the expected number of members
|
|
EXPECT_EQ( numElements, adapter.getObject().size() );
|
|
|
|
// Ensure that the members are returned in the order they were inserted
|
|
unsigned int expectedValue = 0;
|
|
for (const valijson::adapters::Json11Adapter::ObjectMember member : adapter.getObject()) {
|
|
ASSERT_TRUE( member.second.isNumber() );
|
|
EXPECT_EQ( std::to_string(expectedValue), member.first );
|
|
EXPECT_EQ( double(expectedValue), member.second.getDouble() );
|
|
expectedValue++;
|
|
}
|
|
|
|
// Ensure that the correct number of elements were iterated over
|
|
EXPECT_EQ( numElements, expectedValue );
|
|
}
|
|
|
|
#endif // VALIJSON_BUILD_CXX11_ADAPTERS
|
|
|