| OLD | NEW |
| 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 DataDrivenTest : public testing::Test { | 20 class GltfParserTest : 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 }; | |
| 28 | 27 |
| 29 class GltfParserTest : public DataDrivenTest { | |
| 30 protected: | |
| 31 std::unique_ptr<base::DictionaryValue> Deserialize( | 28 std::unique_ptr<base::DictionaryValue> Deserialize( |
| 32 const base::FilePath& gltf_path); | 29 const base::FilePath& gltf_path); |
| 33 }; | 30 }; |
| 34 | 31 |
| 35 class BinaryGltfParserTest : public DataDrivenTest { | |
| 36 protected: | |
| 37 base::StringPiece Read(const base::FilePath& path); | |
| 38 }; | |
| 39 | |
| 40 std::unique_ptr<base::DictionaryValue> GltfParserTest::Deserialize( | 32 std::unique_ptr<base::DictionaryValue> GltfParserTest::Deserialize( |
| 41 const base::FilePath& gltf_path) { | 33 const base::FilePath& gltf_path) { |
| 42 int error_code; | 34 int error_code; |
| 43 std::string error_msg; | 35 std::string error_msg; |
| 44 JSONFileValueDeserializer json_deserializer(gltf_path); | 36 JSONFileValueDeserializer json_deserializer(gltf_path); |
| 45 auto asset_value = json_deserializer.Deserialize(&error_code, &error_msg); | 37 auto asset_value = json_deserializer.Deserialize(&error_code, &error_msg); |
| 46 EXPECT_NE(nullptr, asset_value); | 38 EXPECT_NE(nullptr, asset_value); |
| 47 base::DictionaryValue* asset; | 39 base::DictionaryValue* asset; |
| 48 EXPECT_TRUE(asset_value->GetAsDictionary(&asset)); | 40 EXPECT_TRUE(asset_value->GetAsDictionary(&asset)); |
| 49 asset_value.release(); | 41 asset_value.release(); |
| 50 return std::unique_ptr<base::DictionaryValue>(asset); | 42 return std::unique_ptr<base::DictionaryValue>(asset); |
| 51 } | 43 } |
| 52 | 44 |
| 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 | |
| 59 TEST_F(GltfParserTest, Parse) { | 45 TEST_F(GltfParserTest, Parse) { |
| 60 auto asset = Deserialize(data_dir_.Append("sample_inline.gltf")); | 46 auto asset = Deserialize(data_dir_.Append("sample_inline.gltf")); |
| 61 GltfParser parser; | 47 GltfParser parser; |
| 62 std::vector<std::unique_ptr<gltf::Buffer>> buffers; | 48 std::vector<std::unique_ptr<gltf::Buffer>> buffers; |
| 63 | 49 |
| 64 auto gltf_model = parser.Parse(*asset, &buffers); | 50 auto gltf_model = parser.Parse(*asset, &buffers); |
| 65 EXPECT_TRUE(gltf_model); | 51 EXPECT_TRUE(gltf_model); |
| 66 EXPECT_EQ(1u, buffers.size()); | 52 EXPECT_EQ(1u, buffers.size()); |
| 67 | 53 |
| 68 const gltf::Buffer* buffer = buffers[0].get(); | 54 const gltf::Buffer* buffer = buffers[0].get(); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 | 150 |
| 165 TEST_F(GltfParserTest, ParseExternalNoPath) { | 151 TEST_F(GltfParserTest, ParseExternalNoPath) { |
| 166 auto asset = Deserialize(data_dir_.Append("sample_external.gltf")); | 152 auto asset = Deserialize(data_dir_.Append("sample_external.gltf")); |
| 167 GltfParser parser; | 153 GltfParser parser; |
| 168 std::vector<std::unique_ptr<gltf::Buffer>> buffers; | 154 std::vector<std::unique_ptr<gltf::Buffer>> buffers; |
| 169 | 155 |
| 170 // Parsing fails when no path is provided. | 156 // Parsing fails when no path is provided. |
| 171 EXPECT_EQ(nullptr, parser.Parse(*asset, &buffers)); | 157 EXPECT_EQ(nullptr, parser.Parse(*asset, &buffers)); |
| 172 } | 158 } |
| 173 | 159 |
| 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 | |
| 185 } // namespace vr_shell | 160 } // namespace vr_shell |
| OLD | NEW |