Lightmetrica  0.0.1.50dbee3 (yosakoi)
 All Classes Functions Variables Typedefs Enumerations Enumerator
stub.asset.h
1 /*
2  Lightmetrica : A research-oriented renderer
3 
4  Copyright (c) 2014 Hisanari Otsu
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 #ifndef LIB_LIGHTMETRICA_TEST_STUB_ASSET_H
22 #define LIB_LIGHTMETRICA_TEST_STUB_ASSET_H
23 
24 #include "common.h"
25 #include <lightmetrica/asset.h>
26 #include <lightmetrica/assets.h>
27 #include <lightmetrica/confignode.h>
28 
29 LM_NAMESPACE_BEGIN
30 LM_TEST_NAMESPACE_BEGIN
31 
32 class StubAsset : public Asset
33 {
34 public:
35 
36  LM_ASSET_INTERFACE_DEF("stub_asset", "stub_assets");
37  LM_ASSET_NO_DEPENDENCIES();
38 
39 };
40 
42 {
43 public:
44 
45  LM_COMPONENT_IMPL_DEF("success");
46  virtual bool Load( const ConfigNode& node, const Assets& assets ) { return true; }
47 
48 };
49 
51 {
52 public:
53 
54  LM_COMPONENT_IMPL_DEF("fail_on_create");
55  virtual bool Load( const ConfigNode& node, const Assets& assets ) { return false; }
56 
57 };
58 
59 // --------------------------------------------------------------------------------
60 
61 class StubAsset_A : public Asset
62 {
63 public:
64 
65  LM_ASSET_INTERFACE_DEF("stub_asset_a", "stub_assets_a");
66  LM_ASSET_NO_DEPENDENCIES();
67 
68 };
69 
71 {
72 public:
73 
74  LM_COMPONENT_IMPL_DEF("a");
75  virtual bool Load( const ConfigNode& node, const Assets& assets )
76  {
77  return true;
78  }
79 
80 };
81 
82 class StubAsset_B : public Asset
83 {
84 public:
85 
86  LM_ASSET_INTERFACE_DEF("stub_asset_b", "stub_assets_b");
87  LM_ASSET_DEPENDENCIES("stub_asset_a");
88 
89 };
90 
92 {
93 public:
94 
95  LM_COMPONENT_IMPL_DEF("b");
96  virtual bool Load( const ConfigNode& node, const Assets& assets )
97  {
98  ConfigNode child;
99  Asset* p;
100 
101  // Check if 'stub_asset_a' (whose ID is expected to be set to 'a') is properly loaded
102  child = node.Child("stub_asset_a");
103  EXPECT_FALSE(child.Empty());
104  p = assets.ResolveReferenceToAsset(child, "stub_asset_a");
105  EXPECT_NE(nullptr, p);
106 
107  return p != nullptr;
108  }
109 
110 };
111 
112 class StubAsset_C : public Asset
113 {
114 public:
115 
116  LM_ASSET_INTERFACE_DEF("stub_asset_c", "stub_assets_c");
117  LM_ASSET_DEPENDENCIES("stub_asset_a", "stub_asset_b");
118 
119 };
120 
122 {
123 public:
124 
125  LM_COMPONENT_IMPL_DEF("c");
126  virtual bool Load( const ConfigNode& node, const Assets& assets )
127  {
128  ConfigNode child;
129  Asset* p;
130 
131  child = node.Child("stub_asset_a");
132  EXPECT_FALSE(child.Empty());
133  p = assets.ResolveReferenceToAsset(child, "stub_asset_a");
134  EXPECT_NE(nullptr, p);
135 
136  child = node.Child("stub_asset_b");
137  EXPECT_FALSE(child.Empty());
138  p = assets.ResolveReferenceToAsset(child, "stub_asset_b");
139  EXPECT_NE(nullptr, p);
140 
141  return p != nullptr;
142  }
143 
144 };
145 
146 class StubAsset_D : public Asset
147 {
148 public:
149 
150  LM_ASSET_INTERFACE_DEF("stub_asset_d", "stub_assets_d");
151  LM_ASSET_DEPENDENCIES("stub_asset_a", "stub_asset_b", "stub_asset_c");
152 
153 };
154 
156 {
157 public:
158 
159  LM_COMPONENT_IMPL_DEF("d");
160  virtual bool Load( const ConfigNode& node, const Assets& assets )
161  {
162  ConfigNode child;
163  Asset* p;
164 
165  child = node.Child("stub_asset_a");
166  EXPECT_FALSE(child.Empty());
167  p = assets.ResolveReferenceToAsset(child, "stub_asset_a");
168  EXPECT_NE(nullptr, p);
169 
170  child = node.Child("stub_asset_b");
171  EXPECT_FALSE(child.Empty());
172  p = assets.ResolveReferenceToAsset(child, "stub_asset_b");
173  EXPECT_NE(nullptr, p);
174 
175  child = node.Child("stub_asset_c");
176  EXPECT_FALSE(child.Empty());
177  p = assets.ResolveReferenceToAsset(child, "stub_asset_c");
178  EXPECT_NE(nullptr, p);
179 
180  return p != nullptr;
181  }
182 
183 };
184 
185 // --------------------------------------------------------------------------------
186 
187 class StubAsset_E : public Asset
188 {
189 public:
190 
191  LM_ASSET_INTERFACE_DEF("stub_asset_e", "stub_assets_e");
192  LM_ASSET_DEPENDENCIES("stub_asset_f");
193 
194 };
195 
197 {
198 public:
199 
200  LM_COMPONENT_IMPL_DEF("e");
201  virtual bool Load( const ConfigNode& node, const Assets& assets ) { return true; }
202 
203 };
204 
205 class StubAsset_F : public Asset
206 {
207 public:
208 
209  LM_ASSET_INTERFACE_DEF("stub_asset_f", "stub_assets_f");
210  LM_ASSET_DEPENDENCIES("stub_asset_e");
211 
212 };
213 
215 {
216 public:
217 
218  LM_COMPONENT_IMPL_DEF("e");
219  virtual bool Load( const ConfigNode& node, const Assets& assets ) { return true; }
220 
221 };
222 
223 LM_TEST_NAMESPACE_END
224 LM_NAMESPACE_END
225 
226 #endif // LIB_LIGHTMETRICA_TEST_STUB_ASSET_H
bool Empty() const
Definition: confignode.cpp:90
Definition: stub.asset.h:91
Definition: stub.asset.h:205
Definition: stub.asset.h:61
Definition: stub.asset.h:41
virtual bool Load(const ConfigNode &node, const Assets &assets)
Definition: stub.asset.h:160
virtual bool Load(const ConfigNode &node, const Assets &assets)
Definition: stub.asset.h:46
Definition: stub.asset.h:187
Definition: stub.asset.h:32
Definition: assets.h:39
LM_PUBLIC_API Asset * ResolveReferenceToAsset(const ConfigNode &node, const std::string &type) const
Definition: assets.cpp:279
Definition: stub.asset.h:196
Definition: stub.asset.h:146
Definition: stub.asset.h:50
virtual bool Load(const ConfigNode &node, const Assets &assets)
Definition: stub.asset.h:96
virtual bool Load(const ConfigNode &node, const Assets &assets)
Definition: stub.asset.h:219
virtual bool Load(const ConfigNode &node, const Assets &assets)
Definition: stub.asset.h:126
virtual bool Load(const ConfigNode &node, const Assets &assets)
Definition: stub.asset.h:55
Definition: stub.asset.h:112
Definition: asset.h:35
Definition: confignode.h:37
virtual bool Load(const ConfigNode &node, const Assets &assets)
Definition: stub.asset.h:75
Definition: stub.asset.h:121
Definition: stub.asset.h:214
ConfigNode Child(const std::string &name) const
Definition: confignode.cpp:95
Definition: stub.asset.h:70
Definition: stub.asset.h:82
virtual bool Load(const ConfigNode &node, const Assets &assets)
Definition: stub.asset.h:201
Definition: stub.asset.h:155