Index: chrome/browser/android/vr_shell/gltf_parser_unittest.cc |
diff --git a/chrome/browser/android/vr_shell/gltf_parser_unittest.cc b/chrome/browser/android/vr_shell/gltf_parser_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..70ecc1d1a2efec8f8ec11a5b9fbef1b0e85d9f94 |
--- /dev/null |
+++ b/chrome/browser/android/vr_shell/gltf_parser_unittest.cc |
@@ -0,0 +1,145 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/android/vr_shell/gltf_parser.h" |
+ |
+#include <memory> |
+ |
+#include "base/memory/ptr_util.h" |
+#include "base/values.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace vr_shell { |
+ |
+TEST(GltfParser, Parse) { |
+ base::DictionaryValue asset; |
mthiesse
2017/03/21 20:24:38
I think rather than constructing a dictionary that
cjgrant
2017/03/21 20:38:02
I agree. The JSON would be easier to read, and ev
acondor_
2017/03/22 16:25:29
Done.
|
+ asset.SetString("asset.version", "1.0"); |
+ |
+ auto buffers = base::MakeUnique<base::DictionaryValue>(); |
+ auto buffer_dict = base::MakeUnique<base::DictionaryValue>(); |
+ buffer_dict->SetString( |
+ "uri", "data:application/octet-stream;base64,SEVMTE8gV09STEQh"); |
+ buffer_dict->SetInteger("byteLength", 12); |
+ buffers->Set("dummyBuffer", std::move(buffer_dict)); |
+ asset.Set("buffers", std::move(buffers)); |
+ |
+ auto buffer_views = base::MakeUnique<base::DictionaryValue>(); |
+ auto buffer_view_dict = base::MakeUnique<base::DictionaryValue>(); |
+ buffer_view_dict->SetString("buffer", "dummyBuffer"); |
+ buffer_view_dict->SetInteger("byteLength", 20); |
+ buffer_view_dict->SetInteger("byteOffset", 10); |
+ buffer_view_dict->SetInteger("target", 1); |
+ buffer_views->Set("dummyBufferView", std::move(buffer_view_dict)); |
+ asset.Set("bufferViews", std::move(buffer_views)); |
+ |
+ auto accessors = base::MakeUnique<base::DictionaryValue>(); |
+ auto accessor_dict = base::MakeUnique<base::DictionaryValue>(); |
+ accessor_dict->SetString("bufferView", "dummyBufferView"); |
+ accessor_dict->SetInteger("byteOffset", 10); |
+ accessor_dict->SetInteger("byteStride", 16); |
+ accessor_dict->SetInteger("componentType", 5); |
+ accessor_dict->SetInteger("count", 24); |
+ accessor_dict->SetString("type", "VEC3"); |
+ accessors->Set("dummyAccessor", std::move(accessor_dict)); |
+ asset.Set("accessors", std::move(accessors)); |
+ |
+ auto meshes = base::MakeUnique<base::DictionaryValue>(); |
+ auto mesh_dict = base::MakeUnique<base::DictionaryValue>(); |
+ auto primitive_list = base::MakeUnique<base::ListValue>(); |
+ auto primitive_dict = base::MakeUnique<base::DictionaryValue>(); |
+ auto attributes_dict = base::MakeUnique<base::DictionaryValue>(); |
+ attributes_dict->SetString("POSITION", "dummyAccessor"); |
+ primitive_dict->Set("attributes", std::move(attributes_dict)); |
+ primitive_dict->SetString("indices", "dummyAccessor"); |
+ primitive_dict->SetInteger("mode", 4); |
+ primitive_list->Append(std::move(primitive_dict)); |
+ mesh_dict->Set("primitives", std::move(primitive_list)); |
+ meshes->Set("dummyMesh", std::move(mesh_dict)); |
+ asset.Set("meshes", std::move(meshes)); |
+ |
+ auto nodes = base::MakeUnique<base::DictionaryValue>(); |
+ auto node_dict = base::MakeUnique<base::DictionaryValue>(); |
+ auto children_list = base::MakeUnique<base::ListValue>(); |
+ children_list->AppendString("dummyNode2"); |
+ node_dict->Set("children", std::move(children_list)); |
+ nodes->Set("dummyNode1", std::move(node_dict)); |
+ node_dict = base::MakeUnique<base::DictionaryValue>(); |
+ auto mesh_list = base::MakeUnique<base::ListValue>(); |
+ mesh_list->AppendString("dummyMesh"); |
+ node_dict->Set("meshes", std::move(mesh_list)); |
+ nodes->Set("dummyNode2", std::move(node_dict)); |
+ asset.Set("nodes", std::move(nodes)); |
+ |
+ auto scenes = base::MakeUnique<base::DictionaryValue>(); |
+ auto scene_dict = base::MakeUnique<base::DictionaryValue>(); |
+ auto node_list = base::MakeUnique<base::ListValue>(); |
+ node_list->AppendString("dummyNode1"); |
+ scene_dict->Set("nodes", std::move(node_list)); |
+ scenes->Set("dummyScene", std::move(scene_dict)); |
+ asset.Set("scenes", std::move(scenes)); |
+ |
+ asset.SetString("scene", "dummyScene"); |
+ |
+ GltfParser parser; |
+ auto gltf_model = parser.Parse(asset); |
+ EXPECT_TRUE(gltf_model); |
+ |
+ const gltf::Buffer* buffer = gltf_model->GetBuffer(0); |
+ EXPECT_NE(nullptr, buffer); |
+ EXPECT_EQ(nullptr, gltf_model->GetBuffer(1)); |
+ EXPECT_EQ("HELLO WORLD!", *buffer); |
+ EXPECT_EQ(12u, buffer->length()); |
+ |
+ const gltf::BufferView* buffer_view = gltf_model->GetBufferView(0); |
+ EXPECT_NE(nullptr, buffer_view); |
+ EXPECT_EQ(nullptr, gltf_model->GetBufferView(1)); |
+ EXPECT_EQ(buffer, buffer_view->buffer); |
+ EXPECT_EQ(20, buffer_view->byte_length); |
+ EXPECT_EQ(10, buffer_view->byte_offset); |
+ EXPECT_EQ(1, buffer_view->target); |
+ |
+ const gltf::Accessor* accessor = gltf_model->GetAccessor(0); |
+ EXPECT_NE(nullptr, accessor); |
+ EXPECT_EQ(nullptr, gltf_model->GetAccessor(1)); |
+ EXPECT_EQ(buffer_view, accessor->buffer_view); |
+ EXPECT_EQ(10, accessor->byte_offset); |
+ EXPECT_EQ(16, accessor->byte_stride); |
+ EXPECT_EQ(5, accessor->component_type); |
+ EXPECT_EQ(24, accessor->count); |
+ EXPECT_EQ(gltf::VEC3, accessor->type); |
+ |
+ const gltf::Mesh* mesh = gltf_model->GetMesh(0); |
+ EXPECT_NE(nullptr, mesh); |
+ EXPECT_EQ(nullptr, gltf_model->GetAccessor(1)); |
+ EXPECT_EQ(1u, mesh->primitives.size()); |
+ gltf::Mesh::Primitive* primitive = mesh->primitives[0].get(); |
+ EXPECT_EQ(1u, primitive->attributes.size()); |
+ auto attr_it = primitive->attributes.begin(); |
+ EXPECT_EQ("POSITION", attr_it->first); |
+ EXPECT_EQ(accessor, attr_it->second); |
+ EXPECT_EQ(accessor, primitive->indices); |
+ EXPECT_EQ(4, primitive->mode); |
+ |
+ const gltf::Node* node_1 = gltf_model->GetNode(0); |
+ const gltf::Node* node_2 = gltf_model->GetNode(1); |
+ EXPECT_NE(nullptr, node_1); |
+ EXPECT_NE(nullptr, node_2); |
+ EXPECT_EQ(nullptr, gltf_model->GetNode(2)); |
+ EXPECT_EQ(1u, node_1->children.size()); |
+ EXPECT_EQ(0u, node_1->meshes.size()); |
+ EXPECT_EQ(node_2, node_1->children[0]); |
+ EXPECT_EQ(0u, node_2->children.size()); |
+ EXPECT_EQ(1u, node_2->meshes.size()); |
+ EXPECT_EQ(mesh, node_2->meshes[0]); |
+ |
+ const gltf::Scene* scene = gltf_model->GetScene(0); |
+ EXPECT_NE(nullptr, scene); |
+ EXPECT_EQ(nullptr, gltf_model->GetNode(2)); |
+ EXPECT_EQ(1u, scene->nodes.size()); |
+ EXPECT_EQ(node_1, scene->nodes[0]); |
+ |
+ EXPECT_EQ(scene, gltf_model->GetMainScene()); |
+} |
+ |
+} // namespace vr_shell |