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

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: Addressing suggestions. 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 protected:
37 base::StringPiece Read(const base::FilePath& path);
38 };
39
32 std::unique_ptr<base::DictionaryValue> GltfParserTest::Deserialize( 40 std::unique_ptr<base::DictionaryValue> GltfParserTest::Deserialize(
33 const base::FilePath& gltf_path) { 41 const base::FilePath& gltf_path) {
34 int error_code; 42 int error_code;
35 std::string error_msg; 43 std::string error_msg;
36 JSONFileValueDeserializer json_deserializer(gltf_path); 44 JSONFileValueDeserializer json_deserializer(gltf_path);
37 auto asset_value = json_deserializer.Deserialize(&error_code, &error_msg); 45 auto asset_value = json_deserializer.Deserialize(&error_code, &error_msg);
38 EXPECT_NE(nullptr, asset_value); 46 EXPECT_NE(nullptr, asset_value);
39 base::DictionaryValue* asset; 47 base::DictionaryValue* asset;
40 EXPECT_TRUE(asset_value->GetAsDictionary(&asset)); 48 EXPECT_TRUE(asset_value->GetAsDictionary(&asset));
41 asset_value.release(); 49 asset_value.release();
42 return std::unique_ptr<base::DictionaryValue>(asset); 50 return std::unique_ptr<base::DictionaryValue>(asset);
43 } 51 }
44 52
53 base::StringPiece BinaryGltfParserTest::Read(const base::FilePath& path) {
54 std::string data;
55 base::ReadFileToString(path, &data);
56 return base::StringPiece(data);
57 }
58
45 TEST_F(GltfParserTest, Parse) { 59 TEST_F(GltfParserTest, Parse) {
46 auto asset = Deserialize(data_dir_.Append("sample_inline.gltf")); 60 auto asset = Deserialize(data_dir_.Append("sample_inline.gltf"));
47 GltfParser parser; 61 GltfParser parser;
48 std::vector<std::unique_ptr<gltf::Buffer>> buffers; 62 std::vector<std::unique_ptr<gltf::Buffer>> buffers;
49 63
50 auto gltf_model = parser.Parse(*asset, &buffers); 64 auto gltf_model = parser.Parse(*asset, &buffers);
51 EXPECT_TRUE(gltf_model); 65 EXPECT_TRUE(gltf_model);
52 EXPECT_EQ(1u, buffers.size()); 66 EXPECT_EQ(1u, buffers.size());
53 67
54 const gltf::Buffer* buffer = buffers[0].get(); 68 const gltf::Buffer* buffer = buffers[0].get();
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 164
151 TEST_F(GltfParserTest, ParseExternalNoPath) { 165 TEST_F(GltfParserTest, ParseExternalNoPath) {
152 auto asset = Deserialize(data_dir_.Append("sample_external.gltf")); 166 auto asset = Deserialize(data_dir_.Append("sample_external.gltf"));
153 GltfParser parser; 167 GltfParser parser;
154 std::vector<std::unique_ptr<gltf::Buffer>> buffers; 168 std::vector<std::unique_ptr<gltf::Buffer>> buffers;
155 169
156 // Parsing fails when no path is provided. 170 // Parsing fails when no path is provided.
157 EXPECT_EQ(nullptr, parser.Parse(*asset, &buffers)); 171 EXPECT_EQ(nullptr, parser.Parse(*asset, &buffers));
158 } 172 }
159 173
174 TEST_F(BinaryGltfParserTest, ParseBinary) {
175 auto glb_data = Read(data_dir_.Append("sample.glb"));
176 std::vector<std::unique_ptr<gltf::Buffer>> buffers;
177 auto asset = BinaryGltfParser::Parse(glb_data, &buffers);
178 EXPECT_TRUE(asset);
179 EXPECT_EQ(1u, buffers.size());
180 const gltf::BufferView* buffer_view = asset->GetBufferView(0);
181 EXPECT_TRUE(buffer_view);
182 EXPECT_EQ(0, buffer_view->buffer);
183 }
184
160 } // namespace vr_shell 185 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698