OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/android/vr_shell/gltf_parser.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" |
| 11 #include "base/json/json_file_value_serializer.h" |
| 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/path_service.h" |
| 14 #include "base/values.h" |
| 15 #include "chrome/browser/android/vr_shell/test/paths.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 |
| 18 namespace vr_shell { |
| 19 |
| 20 TEST(GltfParser, Parse) { |
| 21 test::RegisterPathProvider(); |
| 22 base::FilePath gltf_path; |
| 23 PathService::Get(test::DIR_TEST_DATA, &gltf_path); |
| 24 gltf_path = gltf_path.Append("sample_inline.gltf"); |
| 25 |
| 26 int error_code; |
| 27 std::string error_msg; |
| 28 JSONFileValueDeserializer json_deserializer(gltf_path); |
| 29 auto asset_value = json_deserializer.Deserialize(&error_code, &error_msg); |
| 30 EXPECT_NE(nullptr, asset_value); |
| 31 base::DictionaryValue* asset; |
| 32 EXPECT_TRUE(asset_value->GetAsDictionary(&asset)); |
| 33 |
| 34 GltfParser parser; |
| 35 auto gltf_model = parser.Parse(*asset); |
| 36 EXPECT_TRUE(gltf_model); |
| 37 |
| 38 const gltf::Buffer* buffer = gltf_model->GetBuffer(0); |
| 39 EXPECT_NE(nullptr, buffer); |
| 40 EXPECT_EQ(nullptr, gltf_model->GetBuffer(1)); |
| 41 EXPECT_EQ("HELLO WORLD!", *buffer); |
| 42 EXPECT_EQ(12u, buffer->length()); |
| 43 |
| 44 const gltf::BufferView* buffer_view = gltf_model->GetBufferView(0); |
| 45 EXPECT_NE(nullptr, buffer_view); |
| 46 EXPECT_EQ(nullptr, gltf_model->GetBufferView(1)); |
| 47 EXPECT_EQ(buffer, buffer_view->buffer); |
| 48 EXPECT_EQ(20, buffer_view->byte_length); |
| 49 EXPECT_EQ(10, buffer_view->byte_offset); |
| 50 EXPECT_EQ(1, buffer_view->target); |
| 51 |
| 52 const gltf::Accessor* accessor = gltf_model->GetAccessor(0); |
| 53 EXPECT_NE(nullptr, accessor); |
| 54 EXPECT_EQ(nullptr, gltf_model->GetAccessor(1)); |
| 55 EXPECT_EQ(buffer_view, accessor->buffer_view); |
| 56 EXPECT_EQ(10, accessor->byte_offset); |
| 57 EXPECT_EQ(16, accessor->byte_stride); |
| 58 EXPECT_EQ(5, accessor->component_type); |
| 59 EXPECT_EQ(24, accessor->count); |
| 60 EXPECT_EQ(gltf::VEC3, accessor->type); |
| 61 |
| 62 const gltf::Mesh* mesh = gltf_model->GetMesh(0); |
| 63 EXPECT_NE(nullptr, mesh); |
| 64 EXPECT_EQ(nullptr, gltf_model->GetAccessor(1)); |
| 65 EXPECT_EQ(1u, mesh->primitives.size()); |
| 66 gltf::Mesh::Primitive* primitive = mesh->primitives[0].get(); |
| 67 EXPECT_EQ(1u, primitive->attributes.size()); |
| 68 auto attr_it = primitive->attributes.begin(); |
| 69 EXPECT_EQ("POSITION", attr_it->first); |
| 70 EXPECT_EQ(accessor, attr_it->second); |
| 71 EXPECT_EQ(accessor, primitive->indices); |
| 72 EXPECT_EQ(4, primitive->mode); |
| 73 |
| 74 const gltf::Node* node_1 = gltf_model->GetNode(0); |
| 75 const gltf::Node* node_2 = gltf_model->GetNode(1); |
| 76 EXPECT_NE(nullptr, node_1); |
| 77 EXPECT_NE(nullptr, node_2); |
| 78 EXPECT_EQ(nullptr, gltf_model->GetNode(2)); |
| 79 EXPECT_EQ(1u, node_1->children.size()); |
| 80 EXPECT_EQ(0u, node_1->meshes.size()); |
| 81 EXPECT_EQ(node_2, node_1->children[0]); |
| 82 EXPECT_EQ(0u, node_2->children.size()); |
| 83 EXPECT_EQ(1u, node_2->meshes.size()); |
| 84 EXPECT_EQ(mesh, node_2->meshes[0]); |
| 85 |
| 86 const gltf::Scene* scene = gltf_model->GetScene(0); |
| 87 EXPECT_NE(nullptr, scene); |
| 88 EXPECT_EQ(nullptr, gltf_model->GetNode(2)); |
| 89 EXPECT_EQ(1u, scene->nodes.size()); |
| 90 EXPECT_EQ(node_1, scene->nodes[0]); |
| 91 |
| 92 EXPECT_EQ(scene, gltf_model->GetMainScene()); |
| 93 } |
| 94 |
| 95 } // namespace vr_shell |
OLD | NEW |