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

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

Issue 2775283004: Rendering Daydream controller in a fixed position. (Closed)
Patch Set: Moving code to more appropriate locations. Created 3 years, 8 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"
(...skipping 28 matching lines...) Expand all
39 EXPECT_NE(nullptr, asset_value); 39 EXPECT_NE(nullptr, asset_value);
40 base::DictionaryValue* asset; 40 base::DictionaryValue* asset;
41 EXPECT_TRUE(asset_value->GetAsDictionary(&asset)); 41 EXPECT_TRUE(asset_value->GetAsDictionary(&asset));
42 asset_value.release(); 42 asset_value.release();
43 return std::unique_ptr<base::DictionaryValue>(asset); 43 return std::unique_ptr<base::DictionaryValue>(asset);
44 } 44 }
45 45
46 TEST_F(GltfParserTest, Parse) { 46 TEST_F(GltfParserTest, Parse) {
47 auto asset = Deserialize(data_dir_.Append("sample_inline.gltf")); 47 auto asset = Deserialize(data_dir_.Append("sample_inline.gltf"));
48 GltfParser parser; 48 GltfParser parser;
49 std::vector<std::unique_ptr<gltf::Buffer>> buffers;
49 50
50 auto gltf_model = parser.Parse(*asset); 51 auto gltf_model = parser.Parse(*asset, &buffers);
51 EXPECT_TRUE(gltf_model); 52 EXPECT_TRUE(gltf_model);
53 EXPECT_EQ(1u, buffers.size());
52 54
53 const gltf::Buffer* buffer = gltf_model->GetBuffer(0); 55 const gltf::Buffer* buffer = buffers[0].get();
54 EXPECT_NE(nullptr, buffer);
55 EXPECT_EQ(nullptr, gltf_model->GetBuffer(1));
56 EXPECT_EQ("HELLO WORLD!", *buffer); 56 EXPECT_EQ("HELLO WORLD!", *buffer);
57 EXPECT_EQ(12u, buffer->length()); 57 EXPECT_EQ(12u, buffer->length());
58 58
59 const gltf::BufferView* buffer_view = gltf_model->GetBufferView(0); 59 const gltf::BufferView* buffer_view = gltf_model->GetBufferView(0);
60 EXPECT_NE(nullptr, buffer_view); 60 EXPECT_NE(nullptr, buffer_view);
61 EXPECT_EQ(nullptr, gltf_model->GetBufferView(1)); 61 EXPECT_EQ(nullptr, gltf_model->GetBufferView(1));
62 EXPECT_EQ(buffer, buffer_view->buffer); 62 EXPECT_EQ(0, buffer_view->buffer);
63 EXPECT_EQ(20, buffer_view->byte_length); 63 EXPECT_EQ(20, buffer_view->byte_length);
64 EXPECT_EQ(10, buffer_view->byte_offset); 64 EXPECT_EQ(10, buffer_view->byte_offset);
65 EXPECT_EQ(1, buffer_view->target); 65 EXPECT_EQ(1, buffer_view->target);
66 66
67 const gltf::Accessor* accessor = gltf_model->GetAccessor(0); 67 const gltf::Accessor* accessor = gltf_model->GetAccessor(0);
68 EXPECT_NE(nullptr, accessor); 68 EXPECT_NE(nullptr, accessor);
69 EXPECT_EQ(nullptr, gltf_model->GetAccessor(1)); 69 EXPECT_EQ(nullptr, gltf_model->GetAccessor(1));
70 EXPECT_EQ(buffer_view, accessor->buffer_view); 70 EXPECT_EQ(buffer_view, accessor->buffer_view);
71 EXPECT_EQ(10, accessor->byte_offset); 71 EXPECT_EQ(10, accessor->byte_offset);
72 EXPECT_EQ(16, accessor->byte_stride); 72 EXPECT_EQ(16, accessor->byte_stride);
(...skipping 30 matching lines...) Expand all
103 EXPECT_EQ(nullptr, gltf_model->GetNode(2)); 103 EXPECT_EQ(nullptr, gltf_model->GetNode(2));
104 EXPECT_EQ(1u, scene->nodes.size()); 104 EXPECT_EQ(1u, scene->nodes.size());
105 EXPECT_EQ(node_1, scene->nodes[0]); 105 EXPECT_EQ(node_1, scene->nodes[0]);
106 106
107 EXPECT_EQ(scene, gltf_model->GetMainScene()); 107 EXPECT_EQ(scene, gltf_model->GetMainScene());
108 } 108 }
109 109
110 TEST_F(GltfParserTest, ParseUnknownBuffer) { 110 TEST_F(GltfParserTest, ParseUnknownBuffer) {
111 auto asset = Deserialize(data_dir_.Append("sample_inline.gltf")); 111 auto asset = Deserialize(data_dir_.Append("sample_inline.gltf"));
112 GltfParser parser; 112 GltfParser parser;
113 std::vector<std::unique_ptr<gltf::Buffer>> buffers;
113 114
114 // Parsing succeeds. 115 // Parsing succeeds.
115 EXPECT_NE(nullptr, parser.Parse(*asset)); 116 EXPECT_NE(nullptr, parser.Parse(*asset, &buffers));
116 117
117 // Parsing fails when a referenced buffer is removed. 118 // Parsing fails when a referenced buffer is removed.
118 std::unique_ptr<base::Value> value; 119 std::unique_ptr<base::Value> value;
119 asset->Remove("buffers.dummyBuffer", &value); 120 asset->Remove("buffers.dummyBuffer", &value);
120 EXPECT_EQ(nullptr, parser.Parse(*asset)); 121 EXPECT_EQ(nullptr, parser.Parse(*asset, &buffers));
121 122
122 // Parsing fails when the buffer reinserted with a different ID. 123 // Parsing fails when the buffer is reinserted with a different ID.
123 asset->Set("buffers.anotherDummyBuffer", std::move(value)); 124 asset->Set("buffers.anotherDummyBuffer", std::move(value));
124 EXPECT_EQ(nullptr, parser.Parse(*asset)); 125 EXPECT_EQ(nullptr, parser.Parse(*asset, &buffers));
125 } 126 }
126 127
127 TEST_F(GltfParserTest, ParseMissingRequired) { 128 TEST_F(GltfParserTest, ParseMissingRequired) {
128 auto asset = Deserialize(data_dir_.Append("sample_inline.gltf")); 129 auto asset = Deserialize(data_dir_.Append("sample_inline.gltf"));
129 GltfParser parser; 130 GltfParser parser;
131 std::vector<std::unique_ptr<gltf::Buffer>> buffers;
130 132
131 std::unique_ptr<base::Value> value; 133 std::unique_ptr<base::Value> value;
132 asset->Remove("buffers.dummyBuffer.uri", &value); 134 asset->Remove("buffers.dummyBuffer.uri", &value);
133 EXPECT_EQ(nullptr, parser.Parse(*asset)); 135 EXPECT_EQ(nullptr, parser.Parse(*asset, &buffers));
134 } 136 }
135 137
136 TEST_F(GltfParserTest, ParseExternal) { 138 TEST_F(GltfParserTest, ParseExternal) {
137 auto gltf_path = data_dir_.Append("sample_external.gltf"); 139 auto gltf_path = data_dir_.Append("sample_external.gltf");
138 GltfParser parser; 140 GltfParser parser;
141 std::vector<std::unique_ptr<gltf::Buffer>> buffers;
139 142
140 auto gltf_model = parser.Parse(gltf_path); 143 auto gltf_model = parser.Parse(gltf_path, &buffers);
141 EXPECT_NE(nullptr, gltf_model); 144 EXPECT_NE(nullptr, gltf_model);
142 const gltf::Buffer* buffer = gltf_model->GetBuffer(0); 145 EXPECT_EQ(1u, buffers.size());
146 const gltf::Buffer* buffer = buffers[0].get();
143 EXPECT_NE(nullptr, buffer); 147 EXPECT_NE(nullptr, buffer);
144 EXPECT_EQ("HELLO WORLD!", *buffer); 148 EXPECT_EQ("HELLO WORLD!", *buffer);
145 EXPECT_EQ(12u, buffer->length()); 149 EXPECT_EQ(12u, buffer->length());
146 } 150 }
147 151
148 TEST_F(GltfParserTest, ParseExternalNoPath) { 152 TEST_F(GltfParserTest, ParseExternalNoPath) {
149 auto asset = Deserialize(data_dir_.Append("sample_external.gltf")); 153 auto asset = Deserialize(data_dir_.Append("sample_external.gltf"));
150 GltfParser parser; 154 GltfParser parser;
155 std::vector<std::unique_ptr<gltf::Buffer>> buffers;
151 156
152 // Parsing fails when no path is provided. 157 // Parsing fails when no path is provided.
153 EXPECT_EQ(nullptr, parser.Parse(*asset)); 158 EXPECT_EQ(nullptr, parser.Parse(*asset, &buffers));
154 } 159 }
155 160
156 } // namespace vr_shell 161 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/gltf_parser.cc ('k') | chrome/browser/android/vr_shell/vr_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698