Lightmetrica  0.0.1.50dbee3 (yosakoi)
 All Classes Functions Variables Typedefs Enumerations Enumerator
stub.config.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_CONFIG_H
22 #define LIB_LIGHTMETRICA_TEST_STUB_CONFIG_H
23 
24 #include "common.h"
25 #include <lightmetrica/config.h>
26 #include <lightmetrica/confignode.h>
27 #include <lightmetrica/logger.h>
28 #include <pugixml.hpp>
29 #include <gtest/gtest.h>
30 
31 LM_NAMESPACE_BEGIN
32 LM_TEST_NAMESPACE_BEGIN
33 
34 class StubConfig : public Config
35 {
36 public:
37 
38  LM_COMPONENT_IMPL_DEF("stub");
39 
40 public:
41 
42  virtual bool Load( const std::string& path ) { return false; }
43  virtual bool Load( const std::string& path, const std::string& basePath ) { return false; }
44  virtual const ConfigNode Root() const { return ConfigNode(doc.root().internal_object(), this); }
45  virtual std::string BasePath() const { return ""; }
46 
47  virtual bool LoadFromString( const std::string& data, const std::string& basePath )
48  {
49  auto result = doc.load_buffer(static_cast<const void*>(data.c_str()), data.size());
50  if (!result) LM_LOG_ERROR(result.description());
51  return result;
52  }
53 
54 public:
55 
56  ConfigNode LoadFromStringAndGetFirstChild(const std::string& data)
57  {
58  EXPECT_TRUE(LoadFromString(data, ""));
59  return ConfigNode(doc.first_child().internal_object(), this);
60  }
61 
62 private:
63 
64  pugi::xml_document doc;
65 
66 };
67 
68 LM_TEST_NAMESPACE_END
69 LM_NAMESPACE_END
70 
71 #endif // LIB_LIGHTMETRICA_TEST_STUB_CONFIG_H
virtual bool LoadFromString(const std::string &data, const std::string &basePath)
Definition: stub.config.h:47
virtual const ConfigNode Root() const
Definition: stub.config.h:44
Definition: config.h:36
Definition: stub.config.h:34
virtual bool Load(const std::string &path, const std::string &basePath)
Definition: stub.config.h:43
virtual std::string BasePath() const
Definition: stub.config.h:45
virtual bool Load(const std::string &path)
Definition: stub.config.h:42
Definition: confignode.h:37