Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: chrome/browser/android/vr_shell/gltf_parser_unittest.cc

Issue 2774653002: Support for parsing external file references in a glTF resource. (Closed)
Patch Set: Scoping Clean call. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/vr_shell/gltf_parser.h" 5 #include "chrome/browser/android/vr_shell/gltf_parser.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/json/json_file_value_serializer.h" 11 #include "base/json/json_file_value_serializer.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/android/vr_shell/test/paths.h" 15 #include "chrome/browser/android/vr_shell/test/paths.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 namespace vr_shell { 18 namespace vr_shell {
19 19
20 TEST(GltfParser, Parse) { 20 class GltfParserTest : public testing::Test {
21 test::RegisterPathProvider(); 21 protected:
22 base::FilePath gltf_path; 22 void SetUp() override {
23 PathService::Get(test::DIR_TEST_DATA, &gltf_path); 23 test::RegisterPathProvider();
24 gltf_path = gltf_path.Append("sample_inline.gltf"); 24 PathService::Get(test::DIR_TEST_DATA, &data_dir_);
25 }
25 26
27 base::FilePath data_dir_;
28
29 std::unique_ptr<base::DictionaryValue> Deserialize(
30 const base::FilePath& gltf_path);
31 };
32
33 std::unique_ptr<base::DictionaryValue> GltfParserTest::Deserialize(
34 const base::FilePath& gltf_path) {
26 int error_code; 35 int error_code;
27 std::string error_msg; 36 std::string error_msg;
28 JSONFileValueDeserializer json_deserializer(gltf_path); 37 JSONFileValueDeserializer json_deserializer(gltf_path);
29 auto asset_value = json_deserializer.Deserialize(&error_code, &error_msg); 38 auto asset_value = json_deserializer.Deserialize(&error_code, &error_msg);
30 EXPECT_NE(nullptr, asset_value); 39 EXPECT_NE(nullptr, asset_value);
31 base::DictionaryValue* asset; 40 base::DictionaryValue* asset;
32 EXPECT_TRUE(asset_value->GetAsDictionary(&asset)); 41 EXPECT_TRUE(asset_value->GetAsDictionary(&asset));
42 asset_value.release();
43 return std::unique_ptr<base::DictionaryValue>(asset);
44 }
33 45
46 TEST_F(GltfParserTest, Parse) {
47 auto asset = Deserialize(data_dir_.Append("sample_inline.gltf"));
34 GltfParser parser; 48 GltfParser parser;
49
35 auto gltf_model = parser.Parse(*asset); 50 auto gltf_model = parser.Parse(*asset);
36 EXPECT_TRUE(gltf_model); 51 EXPECT_TRUE(gltf_model);
37 52
38 const gltf::Buffer* buffer = gltf_model->GetBuffer(0); 53 const gltf::Buffer* buffer = gltf_model->GetBuffer(0);
39 EXPECT_NE(nullptr, buffer); 54 EXPECT_NE(nullptr, buffer);
40 EXPECT_EQ(nullptr, gltf_model->GetBuffer(1)); 55 EXPECT_EQ(nullptr, gltf_model->GetBuffer(1));
41 EXPECT_EQ("HELLO WORLD!", *buffer); 56 EXPECT_EQ("HELLO WORLD!", *buffer);
42 EXPECT_EQ(12u, buffer->length()); 57 EXPECT_EQ(12u, buffer->length());
43 58
44 const gltf::BufferView* buffer_view = gltf_model->GetBufferView(0); 59 const gltf::BufferView* buffer_view = gltf_model->GetBufferView(0);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 100
86 const gltf::Scene* scene = gltf_model->GetScene(0); 101 const gltf::Scene* scene = gltf_model->GetScene(0);
87 EXPECT_NE(nullptr, scene); 102 EXPECT_NE(nullptr, scene);
88 EXPECT_EQ(nullptr, gltf_model->GetNode(2)); 103 EXPECT_EQ(nullptr, gltf_model->GetNode(2));
89 EXPECT_EQ(1u, scene->nodes.size()); 104 EXPECT_EQ(1u, scene->nodes.size());
90 EXPECT_EQ(node_1, scene->nodes[0]); 105 EXPECT_EQ(node_1, scene->nodes[0]);
91 106
92 EXPECT_EQ(scene, gltf_model->GetMainScene()); 107 EXPECT_EQ(scene, gltf_model->GetMainScene());
93 } 108 }
94 109
110 TEST_F(GltfParserTest, ParseUnknownBuffer) {
111 auto asset = Deserialize(data_dir_.Append("sample_inline.gltf"));
112 GltfParser parser;
113
114 // Parsing succeeds.
115 EXPECT_NE(nullptr, parser.Parse(*asset));
116
117 // Parsing fails when a referenced buffer is removed.
118 std::unique_ptr<base::Value> value;
119 asset->Remove("buffers.dummyBuffer", &value);
120 EXPECT_EQ(nullptr, parser.Parse(*asset));
121
122 // Parsing fails when the buffer reinserted with a different ID.
123 asset->Set("buffers.anotherDummyBuffer", std::move(value));
124 EXPECT_EQ(nullptr, parser.Parse(*asset));
125 }
126
127 TEST_F(GltfParserTest, ParseMissingRequired) {
128 auto asset = Deserialize(data_dir_.Append("sample_inline.gltf"));
129 GltfParser parser;
130
131 std::unique_ptr<base::Value> value;
132 asset->Remove("buffers.dummyBuffer.uri", &value);
133 EXPECT_EQ(nullptr, parser.Parse(*asset));
134 }
135
136 TEST_F(GltfParserTest, ParseExternal) {
137 auto gltf_path = data_dir_.Append("sample_external.gltf");
138 GltfParser parser;
139
140 auto gltf_model = parser.Parse(gltf_path);
141 EXPECT_NE(nullptr, gltf_model);
142 const gltf::Buffer* buffer = gltf_model->GetBuffer(0);
143 EXPECT_NE(nullptr, buffer);
144 EXPECT_EQ("HELLO WORLD!", *buffer);
145 EXPECT_EQ(12u, buffer->length());
146 }
147
148 TEST_F(GltfParserTest, ParseExternalNoPath) {
149 auto asset = Deserialize(data_dir_.Append("sample_external.gltf"));
150 GltfParser parser;
151
152 // Parsing fails when no path is provided.
153 EXPECT_EQ(nullptr, parser.Parse(*asset));
154 }
155
95 } // namespace vr_shell 156 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/gltf_parser.cc ('k') | chrome/browser/android/vr_shell/test/data/sample.bin » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698