-
Notifications
You must be signed in to change notification settings - Fork 432
/
XMLSchemaTest.cpp
163 lines (117 loc) · 5.06 KB
/
XMLSchemaTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/******************************************************************************
* Copyright (c) 2011, Michael P. Gerlek (mpg@flaxen.com)
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following
* conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided
* with the distribution.
* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the
* names of its contributors may be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
****************************************************************************/
#include <boost/test/unit_test.hpp>
#include <boost/cstdint.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <pdal/XMLSchema.hpp>
#include <pdal/Metadata.hpp>
#include <pdal/drivers/faux/Reader.hpp>
#include <pdal/drivers/faux/Writer.hpp>
#include <pdal/drivers/las/Reader.hpp>
#include <pdal/StageIterator.hpp>
#include <pdal/FileUtils.hpp>
#include "Support.hpp"
#include "TestConfig.hpp"
#include <fstream>
using namespace pdal;
std::string ReadXML(std::string filename)
{
std::istream* infile = FileUtils::openFile(filename);
std::ifstream::pos_type size;
// char* data;
std::vector<char> data;
if (infile->good())
{
infile->seekg(0, std::ios::end);
size = infile->tellg();
data.resize(static_cast<std::vector<char>::size_type>(size));
// data = new char [size];
infile->seekg(0, std::ios::beg);
infile->read(&data.front(), size);
// infile->close();
// delete[] data;
delete infile;
return std::string(&data[0], data.size());
// return data;
}
else
{
throw pdal_error("unable to open file!");
// return data;
}
}
BOOST_AUTO_TEST_SUITE(XMLSchemaTest)
BOOST_AUTO_TEST_CASE(test_schema_read)
{
// std::istream* xml_stream = Utils::openFile(TestConfig::g_data_path+"schemas/8-dimension-schema.xml");
// std::istream* xsd_stream = Utils::openFile(TestConfig::g_data_path+"/schemas/LAS.xsd");
std::string xml = ReadXML(TestConfig::g_data_path+"../../schemas/8-dimension-schema.xml");
std::string xsd = ReadXML(TestConfig::g_data_path+"../../schemas/LAS.xsd");
pdal::schema::Reader reader(xml, xsd);
pdal::Schema schema = reader.getSchema();
pdal::Metadata m1("m1");
pdal::Metadata m2("m2");
pdal::Metadata m1prime("m1");
m1.setValue<boost::uint32_t>(1u);
m2.setValue<boost::int32_t>(1);
m1prime.setValue<std::string>("Some other metadata");
pdal::Metadata b;
b.addMetadata(m1.getName(), m1);
pdal::Metadata m3(m1);
BOOST_CHECK_EQUAL(m3.getValue<boost::uint32_t>(), 1u);
m3.setValue<boost::int64_t>(64);
BOOST_CHECK_EQUAL(m3.getValue<boost::int64_t>(), 64);
b.addMetadata("uuid", boost::uuids::nil_uuid());
pdal::schema::Writer writer(schema);
writer.setMetadata(b.toPTree());
std::string xml_output = writer.getXML();
pdal::schema::Reader reader2(xml_output, xsd);
pdal::Schema schema2 = reader2.getSchema();
schema::index_by_index const& dims1 = schema.getDimensions().get<schema::index>();
schema::index_by_index const& dims2 = schema2.getDimensions().get<schema::index>();
// const std::vector<pdal::Dimension>& dims1 = schema.getDimensions();
// const std::vector<pdal::Dimension>& dims2 = schema2.getDimensions();
BOOST_CHECK_EQUAL(dims1.size(), dims2.size());
for (boost::uint32_t i = 0; i < dims2.size(); ++i)
{
pdal::Dimension const& dim1 = dims1[i];
pdal::Dimension const& dim2 = dims2[i];
BOOST_CHECK_EQUAL(dim1.getName(), dim2.getName());
BOOST_CHECK_EQUAL(dim1.getInterpretation(), dim2.getInterpretation());
BOOST_CHECK_EQUAL(dim1.getByteSize(), dim2.getByteSize());
BOOST_CHECK_EQUAL(dim1.getDescription(), dim2.getDescription());
}
}
BOOST_AUTO_TEST_SUITE_END()