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

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

Issue 2852533004: Implementing Binary glTF reader for the VR controller model (Closed)
Patch Set: Avoiding auto Created 3 years, 7 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 class GltfParserTest : public testing::Test { 20 class DataDrivenTest : public testing::Test {
21 protected: 21 protected:
22 static void SetUpTestCase() { test::RegisterPathProvider(); } 22 static void SetUpTestCase() { test::RegisterPathProvider(); }
23 23
24 void SetUp() override { PathService::Get(test::DIR_TEST_DATA, &data_dir_); } 24 void SetUp() override { PathService::Get(test::DIR_TEST_DATA, &data_dir_); }
25 25
26 base::FilePath data_dir_; 26 base::FilePath data_dir_;
27 };
27 28
29 class GltfParserTest : public DataDrivenTest {
30 protected:
28 std::unique_ptr<base::DictionaryValue> Deserialize( 31 std::unique_ptr<base::DictionaryValue> Deserialize(
29 const base::FilePath& gltf_path); 32 const base::FilePath& gltf_path);
30 }; 33 };
31 34
35 class BinaryGltfParserTest : public DataDrivenTest {};
36
32 std::unique_ptr<base::DictionaryValue> GltfParserTest::Deserialize( 37 std::unique_ptr<base::DictionaryValue> GltfParserTest::Deserialize(
33 const base::FilePath& gltf_path) { 38 const base::FilePath& gltf_path) {
34 int error_code; 39 int error_code;
35 std::string error_msg; 40 std::string error_msg;
36 JSONFileValueDeserializer json_deserializer(gltf_path); 41 JSONFileValueDeserializer json_deserializer(gltf_path);
37 auto asset_value = json_deserializer.Deserialize(&error_code, &error_msg); 42 auto asset_value = json_deserializer.Deserialize(&error_code, &error_msg);
38 EXPECT_NE(nullptr, asset_value); 43 EXPECT_NE(nullptr, asset_value);
39 base::DictionaryValue* asset; 44 base::DictionaryValue* asset;
40 EXPECT_TRUE(asset_value->GetAsDictionary(&asset)); 45 EXPECT_TRUE(asset_value->GetAsDictionary(&asset));
41 asset_value.release(); 46 asset_value.release();
42 return std::unique_ptr<base::DictionaryValue>(asset); 47 return std::unique_ptr<base::DictionaryValue>(asset);
43 } 48 }
44 49
45 TEST_F(GltfParserTest, Parse) { 50 TEST_F(GltfParserTest, Parse) {
46 auto asset = Deserialize(data_dir_.Append("sample_inline.gltf")); 51 auto asset = Deserialize(data_dir_.Append("sample_inline.gltf"));
47 GltfParser parser; 52 GltfParser parser;
48 std::vector<std::unique_ptr<gltf::Buffer>> buffers; 53 std::vector<std::unique_ptr<gltf::Buffer>> buffers;
49 54
50 auto gltf_model = parser.Parse(*asset, &buffers); 55 std::unique_ptr<gltf::Asset> gltf_model = parser.Parse(*asset, &buffers);
51 EXPECT_TRUE(gltf_model); 56 EXPECT_TRUE(gltf_model);
52 EXPECT_EQ(1u, buffers.size()); 57 EXPECT_EQ(1u, buffers.size());
53 58
54 const gltf::Buffer* buffer = buffers[0].get(); 59 const gltf::Buffer* buffer = buffers[0].get();
55 EXPECT_EQ("HELLO WORLD!", *buffer); 60 EXPECT_EQ("HELLO WORLD!", *buffer);
56 EXPECT_EQ(12u, buffer->length()); 61 EXPECT_EQ(12u, buffer->length());
57 62
58 const gltf::BufferView* buffer_view = gltf_model->GetBufferView(0); 63 const gltf::BufferView* buffer_view = gltf_model->GetBufferView(0);
59 EXPECT_NE(nullptr, buffer_view); 64 EXPECT_NE(nullptr, buffer_view);
60 EXPECT_EQ(nullptr, gltf_model->GetBufferView(1)); 65 EXPECT_EQ(nullptr, gltf_model->GetBufferView(1));
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 std::unique_ptr<base::Value> value; 137 std::unique_ptr<base::Value> value;
133 asset->Remove("buffers.dummyBuffer.uri", &value); 138 asset->Remove("buffers.dummyBuffer.uri", &value);
134 EXPECT_EQ(nullptr, parser.Parse(*asset, &buffers)); 139 EXPECT_EQ(nullptr, parser.Parse(*asset, &buffers));
135 } 140 }
136 141
137 TEST_F(GltfParserTest, ParseExternal) { 142 TEST_F(GltfParserTest, ParseExternal) {
138 auto gltf_path = data_dir_.Append("sample_external.gltf"); 143 auto gltf_path = data_dir_.Append("sample_external.gltf");
139 GltfParser parser; 144 GltfParser parser;
140 std::vector<std::unique_ptr<gltf::Buffer>> buffers; 145 std::vector<std::unique_ptr<gltf::Buffer>> buffers;
141 146
142 auto gltf_model = parser.Parse(gltf_path, &buffers); 147 std::unique_ptr<gltf::Asset> gltf_model = parser.Parse(gltf_path, &buffers);
143 EXPECT_NE(nullptr, gltf_model); 148 EXPECT_NE(nullptr, gltf_model);
144 EXPECT_EQ(1u, buffers.size()); 149 EXPECT_EQ(1u, buffers.size());
145 const gltf::Buffer* buffer = buffers[0].get(); 150 const gltf::Buffer* buffer = buffers[0].get();
146 EXPECT_NE(nullptr, buffer); 151 EXPECT_NE(nullptr, buffer);
147 EXPECT_EQ("HELLO WORLD!", *buffer); 152 EXPECT_EQ("HELLO WORLD!", *buffer);
148 EXPECT_EQ(12u, buffer->length()); 153 EXPECT_EQ(12u, buffer->length());
149 } 154 }
150 155
151 TEST_F(GltfParserTest, ParseExternalNoPath) { 156 TEST_F(GltfParserTest, ParseExternalNoPath) {
152 auto asset = Deserialize(data_dir_.Append("sample_external.gltf")); 157 auto asset = Deserialize(data_dir_.Append("sample_external.gltf"));
153 GltfParser parser; 158 GltfParser parser;
154 std::vector<std::unique_ptr<gltf::Buffer>> buffers; 159 std::vector<std::unique_ptr<gltf::Buffer>> buffers;
155 160
156 // Parsing fails when no path is provided. 161 // Parsing fails when no path is provided.
157 EXPECT_EQ(nullptr, parser.Parse(*asset, &buffers)); 162 EXPECT_EQ(nullptr, parser.Parse(*asset, &buffers));
158 } 163 }
159 164
165 TEST_F(BinaryGltfParserTest, ParseBinary) {
166 std::string data;
167 EXPECT_TRUE(base::ReadFileToString(data_dir_.Append("sample.glb"), &data));
168 base::StringPiece glb_data(data);
169 std::vector<std::unique_ptr<gltf::Buffer>> buffers;
170 std::unique_ptr<gltf::Asset> asset =
171 BinaryGltfParser::Parse(glb_data, &buffers);
172 EXPECT_TRUE(asset);
173 EXPECT_EQ(1u, buffers.size());
174 const gltf::BufferView* buffer_view = asset->GetBufferView(0);
175 EXPECT_TRUE(buffer_view);
176 EXPECT_EQ(0, buffer_view->buffer);
177 }
178
160 } // namespace vr_shell 179 } // 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.glb » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698