~ubuntu-branches/ubuntu/trusty/liblas/trusty-proposed

« back to all changes in this revision

Viewing changes to test/unit/header_test.cpp

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2014-01-05 17:00:29 UTC
  • mfrom: (7.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140105170029-ddtp0j63x5jvck2u
Tags: 1.7.0+dfsg-2
Fixed missing linking of system boost component.
(closes: #733282)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// $Id$
 
2
//
 
3
// (C) Copyright Mateusz Loskot 2008, mateusz@loskot.net
 
4
// Distributed under the BSD License
 
5
// (See accompanying file LICENSE.txt or copy at
 
6
// http://www.opensource.org/licenses/bsd-license.php)
 
7
//
 
8
#include <liblas/liblas.hpp>
 
9
#include <tut/tut.hpp>
 
10
#include <string>
 
11
#include <stdexcept>
 
12
#include "common.hpp"
 
13
 
 
14
namespace tut
 
15
 
16
    struct lasheader_data
 
17
    {
 
18
        liblas::Header m_default;
 
19
    };
 
20
 
 
21
    typedef test_group<lasheader_data> tg;
 
22
    typedef tg::object to;
 
23
 
 
24
    tg test_group_lasheader("liblas::Header");
 
25
 
 
26
    // Test default constructor
 
27
    template<>
 
28
    template<>
 
29
    void to::test<1>()
 
30
    {
 
31
        test_default_header(m_default);
 
32
    }
 
33
 
 
34
    // Test copy constructor
 
35
    template<>
 
36
    template<>
 
37
    void to::test<2>()
 
38
    {
 
39
        using liblas::Header;
 
40
        
 
41
        Header copy_of_default(m_default);
 
42
        test_default_header(copy_of_default);
 
43
 
 
44
        std::string sig("LASF and garbage");
 
45
 
 
46
        Header h1;
 
47
        
 
48
        h1.SetFileSignature(sig);
 
49
        ensure_not(h1.GetFileSignature() == sig);
 
50
        ensure_equals(h1.GetFileSignature().size(), std::string::size_type(4));
 
51
        ensure_equals(h1.GetFileSignature(), Header::FileSignature);
 
52
 
 
53
        Header h2(h1);
 
54
 
 
55
        ensure_not(h2.GetFileSignature() == sig);
 
56
        ensure_equals(h2.GetFileSignature().size(), std::string::size_type(4));
 
57
        ensure_equals(h2.GetFileSignature(), Header::FileSignature);
 
58
    }
 
59
 
 
60
 
 
61
    // Test assignment operator
 
62
    template<>
 
63
    template<>
 
64
    void to::test<3>()
 
65
    {
 
66
        using liblas::Header;
 
67
        
 
68
        Header copy_of_default;
 
69
        copy_of_default = m_default;
 
70
        test_default_header(copy_of_default);
 
71
 
 
72
    }
 
73
 
 
74
    // Test Get/SetFileSignature
 
75
    template<>
 
76
    template<>
 
77
    void to::test<4>()
 
78
    {
 
79
        using liblas::Header;
 
80
 
 
81
        std::string sig("LASF and garbage");
 
82
 
 
83
        Header h1;
 
84
        h1.SetFileSignature(sig);
 
85
 
 
86
        ensure_not(h1.GetFileSignature() == sig);
 
87
        ensure_equals(h1.GetFileSignature().size(), std::string::size_type(4));
 
88
        ensure_equals(h1.GetFileSignature(), Header::FileSignature);
 
89
 
 
90
        Header h2;
 
91
        h2 = h1;
 
92
 
 
93
        ensure_not(h2.GetFileSignature() == sig);
 
94
        ensure_equals(h2.GetFileSignature().size(), std::string::size_type(4));
 
95
        ensure_equals(h2.GetFileSignature(), Header::FileSignature);
 
96
    }
 
97
 
 
98
    // Test Get/SetFileSourceId
 
99
    template<>
 
100
    template<>
 
101
    void to::test<5>()
 
102
    {
 
103
        using liblas::Header;
 
104
        using boost::uint16_t;
 
105
 
 
106
        uint16_t const id1 = 1;
 
107
        uint16_t const id2 = 65535;
 
108
        uint16_t const overflowed = 0;
 
109
 
 
110
        Header h1;
 
111
        h1.SetFileSourceId(id1);
 
112
        ensure_equals(h1.GetFileSourceId(), id1);
 
113
        h1.SetFileSourceId(id2);
 
114
        ensure_equals(h1.GetFileSourceId(), id2);
 
115
 
 
116
#ifdef _MSC_VER
 
117
# pragma warning(push)
 
118
# pragma warning(disable: 4305) //  truncation from 'int' to 'boost::uint16_t'
 
119
# pragma warning(disable: 4309) // conditional expression is constant.
 
120
#endif
 
121
        // Unsigned overflow
 
122
        // Likely compiler warning: truncation from int to boost::uint16_t
 
123
        h1.SetFileSourceId(id2 + 1);
 
124
        ensure_equals(h1.GetFileSourceId(), overflowed);
 
125
 
 
126
#ifdef _MSC_VER
 
127
# pragma warning(push)
 
128
#endif
 
129
    }
 
130
 
 
131
    // Test GetReserved
 
132
    template<>
 
133
    template<>
 
134
    void to::test<6>()
 
135
    {
 
136
        liblas::Header h;
 
137
        ensure_equals(h.GetReserved(), 0);
 
138
        h.SetReserved(1);
 
139
        ensure_equals(h.GetReserved(), 1);
 
140
    }
 
141
 
 
142
    // Test Set/GetProjectId
 
143
    template<>
 
144
    template<>
 
145
    void to::test<7>()
 
146
    {
 
147
        std::string strid("030B4A82-1B7C-11CF-9D53-00AA003C9CB6");
 
148
        liblas::guid id(strid.c_str());
 
149
 
 
150
        liblas::Header h;
 
151
        h.SetProjectId(id);
 
152
        
 
153
        ensure_not(h.GetProjectId().is_null());
 
154
        ensure_equals(h.GetProjectId(), id);
 
155
    }
 
156
 
 
157
    // Test handling minor/major version
 
158
    template<>
 
159
    template<>
 
160
    void to::test<8>()
 
161
    {
 
162
        liblas::Header h;
 
163
 
 
164
        h.SetVersionMajor(1);
 
165
        h.SetVersionMinor(0);
 
166
        ensure_equals(h.GetVersionMajor(), 1);
 
167
        ensure_equals(h.GetVersionMinor(), 0);
 
168
 
 
169
        h.SetVersionMajor(1);
 
170
        h.SetVersionMinor(1);
 
171
        ensure_equals(h.GetVersionMajor(), 1);
 
172
        ensure_equals(h.GetVersionMinor(), 1);
 
173
 
 
174
        try
 
175
        {
 
176
            h.SetVersionMajor(2);
 
177
            ensure("std::out_of_range was not thrown", false);
 
178
        }
 
179
        catch (std::out_of_range const& e)
 
180
        {
 
181
            ensure(e.what(), true);
 
182
        }
 
183
 
 
184
        try
 
185
        {
 
186
            h.SetVersionMinor(4);
 
187
            ensure("std::out_of_range was not thrown", false);
 
188
        }
 
189
        catch (std::out_of_range const& e)
 
190
        {
 
191
            ensure(e.what(), true);
 
192
        }
 
193
    }
 
194
 
 
195
    // Test Get/SetSystemId
 
196
    template<>
 
197
    template<>
 
198
    void to::test<9>()
 
199
    {
 
200
        using liblas::Header;
 
201
 
 
202
        std::string sysid1("Short Sys Id"); // 12 bytes
 
203
        std::string::size_type const len1 = sysid1.size();
 
204
        std::string sysid2("Long System Identifier - XXX YYY"); // 32 bytes
 
205
        std::string::size_type const len2 = sysid2.size();
 
206
 
 
207
        Header h;
 
208
 
 
209
        h.SetSystemId(sysid1);
 
210
        ensure_equals(h.GetSystemId(), sysid1);
 
211
        ensure_equals(h.GetSystemId().size(), len1);
 
212
        ensure_equals(h.GetSystemId(true).size(), std::string::size_type(32));
 
213
 
 
214
        h.SetSystemId(sysid2);
 
215
        ensure_equals(h.GetSystemId(), sysid2);
 
216
        ensure_equals(h.GetSystemId().size(), len2);
 
217
        ensure_equals(h.GetSystemId(true).size(), std::string::size_type(32));
 
218
    }
 
219
 
 
220
    // Test Get/SetSoftwareId
 
221
    template<>
 
222
    template<>
 
223
    void to::test<10>()
 
224
    {
 
225
        using liblas::Header;
 
226
 
 
227
        std::string softid1("Short Soft Id"); // 13 bytes
 
228
        std::string::size_type const len1 = softid1.size();
 
229
        std::string softid2("Long Software Identifier - XX YY"); // 32 bytes
 
230
        std::string::size_type const len2 = softid2.size();
 
231
 
 
232
        Header h;
 
233
        h.SetSoftwareId(softid1);
 
234
        ensure_equals(h.GetSoftwareId(), softid1);
 
235
        ensure_equals(h.GetSoftwareId().size(), len1);
 
236
        ensure_equals(h.GetSoftwareId(true).size(), std::string::size_type(32));
 
237
 
 
238
        h.SetSoftwareId(softid2);
 
239
        ensure_equals(h.GetSoftwareId(), softid2);
 
240
        ensure_equals(h.GetSoftwareId().size(), len2);
 
241
        ensure_equals(h.GetSoftwareId(true).size(), std::string::size_type(32));
 
242
    }
 
243
 
 
244
    // Test GetPointRecordsByReturnCount
 
245
    template<>
 
246
    template<>
 
247
    void to::test<11>()
 
248
    {
 
249
        typedef ::liblas::Header::RecordsByReturnArray::size_type size_type;
 
250
        typedef ::boost::uint32_t count_type;
 
251
 
 
252
        liblas::Header h;
 
253
        // NOTE: The committee in its infinite stupidity decided to increase the size of this array to 7 at 1.3.
 
254
        ensure(h.GetPointRecordsByReturnCount().size() >= 5);
 
255
        ensure(h.GetPointRecordsByReturnCount().size() <= 7);
 
256
 
 
257
        h.SetPointRecordsByReturnCount(0, 100);
 
258
        ensure(h.GetPointRecordsByReturnCount().size() >= 5);
 
259
        ensure(h.GetPointRecordsByReturnCount().size() <= 7);
 
260
        ensure_equals(h.GetPointRecordsByReturnCount().at(0), count_type(100));
 
261
 
 
262
        h.SetPointRecordsByReturnCount(1, 101);
 
263
        ensure(h.GetPointRecordsByReturnCount().size() >= 5);
 
264
        ensure(h.GetPointRecordsByReturnCount().size() <= 7);
 
265
        ensure_equals(h.GetPointRecordsByReturnCount().at(1), count_type(101));
 
266
 
 
267
        h.SetPointRecordsByReturnCount(2, 102);
 
268
        ensure(h.GetPointRecordsByReturnCount().size() >= 5);
 
269
        ensure(h.GetPointRecordsByReturnCount().size() <= 7);
 
270
        ensure_equals(h.GetPointRecordsByReturnCount().at(2), count_type(102));
 
271
 
 
272
        h.SetPointRecordsByReturnCount(3, 103);
 
273
        ensure(h.GetPointRecordsByReturnCount().size() >= 5);
 
274
        ensure(h.GetPointRecordsByReturnCount().size() <= 7);
 
275
        ensure_equals(h.GetPointRecordsByReturnCount().at(3), count_type(103));
 
276
 
 
277
        h.SetPointRecordsByReturnCount(4, 104);
 
278
        ensure(h.GetPointRecordsByReturnCount().size() >= 5);
 
279
        ensure(h.GetPointRecordsByReturnCount().size() <= 7);
 
280
        ensure_equals(h.GetPointRecordsByReturnCount().at(4), count_type(104));
 
281
 
 
282
        try
 
283
        {
 
284
            // 8 is out of range
 
285
            h.SetPointRecordsByReturnCount(8, 500);
 
286
            ensure("std::out_of_range not thrown", false);
 
287
        }
 
288
        catch (std::out_of_range const& e)
 
289
        {
 
290
            ensure(e.what(), true);
 
291
        }
 
292
    }
 
293
 
 
294
    // Test GetSRS
 
295
    template<>
 
296
    template<>
 
297
    void to::test<12>()
 
298
    {
 
299
        liblas::Header h;
 
300
        liblas::SpatialReference srs = h.GetSRS();
 
301
 
 
302
        ensure_equals(srs.GetProj4(), "");
 
303
        ensure_equals(srs.GetWKT(), "");
 
304
 
 
305
    }
 
306
}
 
307