GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
draco_test_utils.h
Go to the documentation of this file.
1// Copyright 2016 The Draco Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15#ifndef DRACO_CORE_DRACO_TEST_UTILS_H_
16#define DRACO_CORE_DRACO_TEST_UTILS_H_
17
18#include <ostream>
19#include <sstream>
20#include <streambuf>
21
24#include "draco/io/mesh_io.h"
25#include "draco/io/point_cloud_io.h"
26
27#ifdef DRACO_TRANSCODER_SUPPORTED
28#include "draco/io/scene_io.h"
29#endif
30
31namespace draco {
32
33// Returns test temporary directory.
34std::string GetTestTempDir();
35
36// Returns the full path to a given file system entry, such as test file or test
37// directory.
38std::string GetTestFileFullPath(const std::string &entry_name);
39
40// Returns the full path to a given temporary file (a location where tests store
41// generated files).
42std::string GetTestTempFileFullPath(const std::string &file_name);
43
44// Generates a new golden file and saves it into the correct folder.
45// Returns false if the file couldn't be created.
46bool GenerateGoldenFile(const std::string &golden_file_name, const void *data,
47 int data_size);
48
49// Compare a golden file content with the input data.
50// Function will log the first byte position where the data differ.
51// Returns false if there are any differences.
52bool CompareGoldenFile(const std::string &golden_file_name, const void *data,
53 int data_size);
54
55// Loads a mesh / point cloud specified by a |file_name| that is going to be
56// automatically converted to the correct path available to the testing
57// instance.
58inline std::unique_ptr<Mesh> ReadMeshFromTestFile(
59 const std::string &file_name) {
60 const std::string path = GetTestFileFullPath(file_name);
61 return ReadMeshFromFile(path).value();
62}
63inline std::unique_ptr<Mesh> ReadMeshFromTestFile(const std::string &file_name,
64 bool use_metadata) {
65 const std::string path = GetTestFileFullPath(file_name);
66 return ReadMeshFromFile(path, use_metadata).value();
67}
68inline std::unique_ptr<Mesh> ReadMeshFromTestFile(const std::string &file_name,
69 const Options &options) {
70 const std::string path = GetTestFileFullPath(file_name);
71 return ReadMeshFromFile(path, options).value();
72}
73
74inline std::unique_ptr<PointCloud> ReadPointCloudFromTestFile(
75 const std::string &file_name) {
76 const std::string path = GetTestFileFullPath(file_name);
77 return ReadPointCloudFromFile(path).value();
78}
79
80#ifdef DRACO_TRANSCODER_SUPPORTED
81inline std::unique_ptr<Scene> ReadSceneFromTestFile(
82 const std::string &file_name) {
83 const std::string path = GetTestFileFullPath(file_name);
84 return ReadSceneFromFile(path).value();
85}
86
87// Loads geometry specified by a |file_name| that is going to be automatically
88// converted to the correct path available to the testing instance. Supported
89// geometry types are Mesh and Scene.
90template <typename T>
91std::unique_ptr<T> ReadGeometryFromTestFile(const std::string &file_name);
92
93#endif // DRACO_TRANSCODER_SUPPORTED
94
95// Utility class for redirection and capture of stderr/stdout.
97 public:
98 explicit CaptureStream(std::ostream &stream)
99 : old_buffer_(stream.rdbuf(buffer_.rdbuf())), stream_(stream) {}
100
102
103 std::string GetStringAndRelease() {
104 Reset();
105 return buffer_.str();
106 }
107
108 void Reset() {
109 if (old_buffer_) {
110 stream_.rdbuf(old_buffer_);
111 old_buffer_ = nullptr;
112 }
113 }
114
115 private:
116 std::ostringstream buffer_;
117 std::streambuf *old_buffer_ = nullptr;
118 std::ostream &stream_;
119};
120
121// Evaluates an expression that returns draco::Status. If the status is not OK,
122// the macro asserts and logs the error message.
123#define DRACO_ASSERT_OK(expression) \
124 { \
125 const draco::Status _local_status = (expression); \
126 ASSERT_TRUE(_local_status.ok()) << _local_status.error_msg_string(); \
127 }
128
129// In case StatusOr<T> is ok(), this macro assigns value stored in StatusOr<T>
130// to |lhs|, otherwise it asserts and logs the error message.
131//
132// DRACO_ASSIGN_OR_ASSERT(lhs, expression)
133//
134#define DRACO_ASSIGN_OR_ASSERT(lhs, expression) \
135 DRACO_ASSIGN_OR_ASSERT_IMPL_(DRACO_MACROS_IMPL_CONCAT_(_statusor, __LINE__), \
136 lhs, expression, _status)
137
138// The actual implementation of the above macro.
139#define DRACO_ASSIGN_OR_ASSERT_IMPL_(statusor, lhs, expression, error_expr) \
140 auto statusor = (expression); \
141 ASSERT_TRUE(statusor.ok()) << statusor.status().error_msg_string(); \
142 lhs = std::move(statusor).value();
143
144} // namespace draco
145
146#endif // DRACO_CORE_DRACO_TEST_UTILS_H_
CaptureStream(std::ostream &stream)
Definition draco_test_utils.h:98
std::string GetStringAndRelease()
Definition draco_test_utils.h:103
~CaptureStream()
Definition draco_test_utils.h:101
void Reset()
Definition draco_test_utils.h:108
Definition options.h:30
lazy data
Definition meshpage.php:1583
< h2 > I want smooth transition from jpg png webp to the engine</h2 > There s few options
Definition meshpage.php:1181
Definition attribute_octahedron_transform.cc:21
bool GenerateGoldenFile(const std::string &golden_file_name, const void *data, int data_size)
Definition draco_test_utils.cc:40
bool CompareGoldenFile(const std::string &golden_file_name, const void *data, int data_size)
Definition draco_test_utils.cc:46
std::string GetTestTempDir()
Definition draco_test_utils.cc:30
std::unique_ptr< Mesh > ReadMeshFromTestFile(const std::string &file_name)
Definition draco_test_utils.h:58
std::unique_ptr< PointCloud > ReadPointCloudFromTestFile(const std::string &file_name)
Definition draco_test_utils.h:74
std::string GetTestFileFullPath(const std::string &file_name)
Definition draco_test_utils.cc:32
std::string GetTestTempFileFullPath(const std::string &file_name)
Definition draco_test_utils.cc:36