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

« back to all changes in this revision

Viewing changes to test/unit/classification_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/classification.hpp>
 
9
#include <tut/tut.hpp>
 
10
#include <bitset>
 
11
#include <sstream>
 
12
#include <stdexcept>
 
13
#include <string>
 
14
#include "common.hpp"
 
15
 
 
16
namespace tut
 
17
 
18
    struct lasclassification_data
 
19
    {
 
20
        typedef liblas::Classification::bitset_type bitset_type;
 
21
        liblas::Classification m_default;
 
22
    };
 
23
 
 
24
    typedef test_group<lasclassification_data> tg;
 
25
    typedef tg::object to;
 
26
 
 
27
    tg test_group_lasclassification("liblas::Classification");
 
28
 
 
29
    template<>
 
30
    template<>
 
31
    void to::test<1>()
 
32
    {
 
33
        ensure_equals(m_default, bitset_type(0));
 
34
        ensure_equals(m_default.GetClass(), 0);
 
35
        ensure_not(m_default.IsSynthetic());
 
36
        ensure_not(m_default.IsKeyPoint());
 
37
        ensure_not(m_default.IsWithheld());
 
38
    }
 
39
 
 
40
    template<>
 
41
    template<>
 
42
    void to::test<2>()
 
43
    {
 
44
        liblas::Classification c0(0);
 
45
 
 
46
        ensure_equals(c0, m_default);
 
47
        ensure_equals(c0, bitset_type(0));
 
48
        ensure_equals(c0.GetClass(), 0);
 
49
        ensure_not(c0.IsSynthetic());
 
50
        ensure_not(c0.IsKeyPoint());
 
51
        ensure_not(c0.IsWithheld());
 
52
    }
 
53
 
 
54
    template<>
 
55
    template<>
 
56
    void to::test<3>()
 
57
    {
 
58
        liblas::Classification c31(0x1F);
 
59
 
 
60
        ensure_not(c31 == m_default);
 
61
        ensure_equals(c31.GetClass(), 31);
 
62
        ensure_not(c31.IsSynthetic());
 
63
        ensure_not(c31.IsKeyPoint());
 
64
        ensure_not(c31.IsWithheld());
 
65
    }
 
66
 
 
67
    template<>
 
68
    template<>
 
69
    void to::test<4>()
 
70
    {
 
71
        liblas::Classification c255(255);
 
72
        ensure_equals(c255, bitset_type(255));
 
73
        ensure_equals(c255.GetClass(), 31);
 
74
        ensure(c255.IsSynthetic());
 
75
        ensure(c255.IsKeyPoint());
 
76
        ensure(c255.IsWithheld());
 
77
    }
 
78
 
 
79
    template<>
 
80
    template<>
 
81
    void to::test<5>()
 
82
    {
 
83
        liblas::Classification c(31, false, false, false);
 
84
     
 
85
        ensure_equals(c.GetClass(), 31);
 
86
        ensure_not(c.IsSynthetic());
 
87
        ensure_not(c.IsKeyPoint());
 
88
        ensure_not(c.IsWithheld());
 
89
        ensure_equals(c, bitset_type(std::string("00011111")));
 
90
    }
 
91
 
 
92
    template<>
 
93
    template<>
 
94
    void to::test<6>()
 
95
    {
 
96
        liblas::Classification c(7, true, false, true);
 
97
     
 
98
        ensure_equals(c.GetClass(), 7);
 
99
        ensure_not(c.IsKeyPoint());
 
100
        ensure(c.IsWithheld());
 
101
        ensure(c.IsSynthetic());
 
102
        ensure_equals(c, bitset_type(std::string("10100111")));
 
103
    }
 
104
 
 
105
    template<>
 
106
    template<>
 
107
    void to::test<7>()
 
108
    {
 
109
        try
 
110
        {
 
111
            liblas::Classification c(255, true, true, true);
 
112
 
 
113
            fail("std::out_of_range not thrown but expected");
 
114
        }
 
115
        catch (std::out_of_range const& e)
 
116
        {
 
117
            ensure(e.what(), true);
 
118
        }
 
119
        catch (...)
 
120
        {
 
121
            fail("unhandled exception expected");
 
122
        }
 
123
    }
 
124
 
 
125
    template<>
 
126
    template<>
 
127
    void to::test<8>()
 
128
    {
 
129
        liblas::Classification cpy(m_default);
 
130
     
 
131
        ensure_equals(cpy, m_default);
 
132
    }
 
133
 
 
134
    template<>
 
135
    template<>
 
136
    void to::test<9>()
 
137
    {
 
138
        liblas::Classification c(7, true, false, true);
 
139
        liblas::Classification cpy(c);
 
140
     
 
141
        ensure_equals(cpy.GetClass(), 7);
 
142
        ensure_not(cpy.IsKeyPoint());
 
143
        ensure(cpy.IsWithheld());
 
144
        ensure(cpy.IsSynthetic());
 
145
        ensure_equals(cpy, bitset_type(std::string("10100111")));
 
146
        ensure_equals(cpy, c);
 
147
    }
 
148
 
 
149
    template<>
 
150
    template<>
 
151
    void to::test<10>()
 
152
    {
 
153
        liblas::Classification cpy;
 
154
        cpy = m_default;
 
155
     
 
156
        ensure_equals(cpy, m_default);
 
157
    }
 
158
 
 
159
    template<>
 
160
    template<>
 
161
    void to::test<11>()
 
162
    {
 
163
        liblas::Classification c(7, true, false, true);
 
164
        liblas::Classification cpy = c;
 
165
     
 
166
        ensure_equals(cpy.GetClass(), 7);
 
167
        ensure_not(cpy.IsKeyPoint());
 
168
        ensure(cpy.IsWithheld());
 
169
        ensure(cpy.IsSynthetic());
 
170
        ensure_equals(cpy, bitset_type(std::string("10100111")));
 
171
        ensure_equals(cpy, c);
 
172
    }
 
173
 
 
174
 
 
175
    template<>
 
176
    template<>
 
177
    void to::test<12>()
 
178
    {
 
179
        liblas::Classification c;
 
180
 
 
181
        c.SetClass(0);
 
182
        ensure_equals(c.GetClass(), 0);
 
183
 
 
184
        c.SetClass(31);
 
185
        ensure_equals(c.GetClass(), 31);
 
186
 
 
187
        ensure(c != m_default);
 
188
    }
 
189
 
 
190
    template<>
 
191
    template<>
 
192
    void to::test<13>()
 
193
    {
 
194
        liblas::Classification c;
 
195
 
 
196
        c.SetSynthetic(true);
 
197
        ensure(c.IsSynthetic());
 
198
        ensure(c != m_default);
 
199
 
 
200
        c.SetSynthetic(false);
 
201
        ensure_not(c.IsSynthetic());
 
202
        ensure_equals(c, m_default);
 
203
 
 
204
        c.SetSynthetic(true);
 
205
        ensure(c.IsSynthetic());
 
206
        ensure(c != m_default);
 
207
 
 
208
        c.SetSynthetic(false);
 
209
        ensure_not(c.IsSynthetic());
 
210
        ensure_equals(c, m_default);
 
211
 
 
212
        ensure_equals(c.GetClass(), 0);
 
213
    }
 
214
 
 
215
    template<>
 
216
    template<>
 
217
    void to::test<14>()
 
218
    {
 
219
        liblas::Classification c;
 
220
 
 
221
        c.SetKeyPoint(true);
 
222
        ensure(c.IsKeyPoint());
 
223
        ensure(c != m_default);
 
224
 
 
225
        c.SetKeyPoint(false);
 
226
        ensure_not(c.IsKeyPoint());
 
227
        ensure_equals(c, m_default);
 
228
 
 
229
        c.SetKeyPoint(true);
 
230
        ensure(c.IsKeyPoint());
 
231
        ensure(c != m_default);
 
232
 
 
233
        c.SetKeyPoint(false);
 
234
        ensure_not(c.IsKeyPoint());
 
235
        ensure_equals(c, m_default);
 
236
 
 
237
        ensure_equals(c.GetClass(), 0);
 
238
    }
 
239
 
 
240
    template<>
 
241
    template<>
 
242
    void to::test<15>()
 
243
    {
 
244
        liblas::Classification c;
 
245
 
 
246
        c.SetWithheld(true);
 
247
        ensure(c.IsWithheld());
 
248
        ensure(c != m_default);
 
249
 
 
250
        c.SetWithheld(false);
 
251
        ensure_not(c.IsWithheld());
 
252
        ensure_equals(c, m_default);
 
253
 
 
254
        c.SetWithheld(true);
 
255
        ensure(c.IsWithheld());
 
256
        ensure(c != m_default);
 
257
 
 
258
        c.SetWithheld(false);
 
259
        ensure_not(c.IsWithheld());
 
260
        ensure_equals(c, m_default);
 
261
 
 
262
        ensure_equals(c.GetClass(), 0);
 
263
    }
 
264
 
 
265
    template<>
 
266
    template<>
 
267
    void to::test<16>()
 
268
    {
 
269
        liblas::Classification c;
 
270
 
 
271
        c.SetKeyPoint(true);
 
272
        ensure(c.IsKeyPoint());
 
273
        ensure(c != m_default);
 
274
 
 
275
        c.SetWithheld(true);
 
276
        ensure(c.IsWithheld());
 
277
        ensure(c.IsKeyPoint());
 
278
        ensure(c != m_default);
 
279
        
 
280
        c.SetSynthetic(true);
 
281
        ensure(c.IsWithheld());
 
282
        ensure(c.IsKeyPoint());
 
283
        ensure(c.IsSynthetic());
 
284
        ensure(c != m_default);
 
285
 
 
286
        ensure_equals(c.GetClass(), 0);
 
287
    }
 
288
 
 
289
    template<>
 
290
    template<>
 
291
    void to::test<17>()
 
292
    {
 
293
        liblas::Classification c;
 
294
 
 
295
        c.SetKeyPoint(true);
 
296
        c.SetSynthetic(true);
 
297
        c.SetWithheld(true);
 
298
        ensure(c.IsWithheld());
 
299
        ensure(c.IsKeyPoint());
 
300
        ensure(c.IsSynthetic());
 
301
        ensure_not(c == m_default);
 
302
        ensure_equals(c.GetClass(), 0);
 
303
 
 
304
        c.SetKeyPoint(false);
 
305
        c.SetSynthetic(false);
 
306
        c.SetWithheld(false);
 
307
        ensure_not(c.IsWithheld());
 
308
        ensure_not(c.IsKeyPoint());
 
309
        ensure_not(c.IsSynthetic());
 
310
        ensure_equals(c.GetClass(), 0);
 
311
 
 
312
        liblas::Classification::bitset_type bits1(c);
 
313
        liblas::Classification::bitset_type bits2(m_default);
 
314
        ensure_equals(c, m_default);
 
315
    }
 
316
 
 
317
    template<>
 
318
    template<>
 
319
    void to::test<18>()
 
320
    {
 
321
        liblas::Classification c;
 
322
 
 
323
        c.SetKeyPoint(true);
 
324
        c.SetClass(1);
 
325
        c.SetSynthetic(true);
 
326
        c.SetWithheld(true);
 
327
        ensure(c.IsWithheld());
 
328
        ensure(c.IsKeyPoint());
 
329
        ensure(c.IsSynthetic());
 
330
        ensure_equals(c.GetClass(), 1);
 
331
        ensure_not(c == m_default);
 
332
        
 
333
        c.SetKeyPoint(false);
 
334
        c.SetSynthetic(false);
 
335
        c.SetClass(0);
 
336
        c.SetWithheld(false);
 
337
        ensure_not(c.IsWithheld());
 
338
        ensure_not(c.IsKeyPoint());
 
339
        ensure_not(c.IsSynthetic());
 
340
        ensure_equals(c.GetClass(), 0);
 
341
 
 
342
        liblas::Classification::bitset_type bits1(c);
 
343
        liblas::Classification::bitset_type bits2(m_default);
 
344
        ensure_equals(c, m_default);
 
345
    }
 
346
 
 
347
    template<>
 
348
    template<>
 
349
    void to::test<19>()
 
350
    {
 
351
        std::string const sbits("00000000");
 
352
 
 
353
        liblas::Classification c;
 
354
 
 
355
        std::ostringstream oss;
 
356
        oss << c;
 
357
        ensure_equals(oss.str(), sbits);
 
358
    }
 
359
 
 
360
    template<>
 
361
    template<>
 
362
    void to::test<20>()
 
363
    {
 
364
        std::string const sbits("00000011");
 
365
 
 
366
        liblas::Classification c;
 
367
        c.SetClass(3);
 
368
 
 
369
        std::ostringstream oss;
 
370
        oss << c;
 
371
        ensure_equals(oss.str(), sbits);
 
372
    }
 
373
 
 
374
    template<>
 
375
    template<>
 
376
    void to::test<21>()
 
377
    {
 
378
        std::string const sbits("10000001");
 
379
 
 
380
        liblas::Classification c;
 
381
        
 
382
        c.SetWithheld(true);
 
383
        c.SetClass(1);
 
384
 
 
385
        std::ostringstream oss;
 
386
        oss << c;
 
387
        ensure_equals(oss.str(), sbits);
 
388
    }
 
389
 
 
390
    template<>
 
391
    template<>
 
392
    void to::test<22>()
 
393
    {
 
394
        std::string const sbits("10110000");
 
395
 
 
396
        liblas::Classification c;
 
397
        
 
398
        c.SetClass(16);
 
399
        c.SetSynthetic(true);
 
400
        c.SetKeyPoint(false);
 
401
        c.SetWithheld(true);
 
402
 
 
403
        std::ostringstream oss;
 
404
        oss << c;
 
405
        ensure_equals(oss.str(), sbits);
 
406
    }
 
407
 
 
408
    template<>
 
409
    template<>
 
410
    void to::test<23>()
 
411
    {
 
412
        std::string const sbits("00000000");
 
413
        liblas::Classification::bitset_type bits(sbits);
 
414
        
 
415
        liblas::Classification c(bits);
 
416
        ensure_equals(c, bits);
 
417
 
 
418
        std::ostringstream oss;
 
419
        oss << c;
 
420
        ensure_equals(oss.str(), sbits);
 
421
    }
 
422
 
 
423
    template<>
 
424
    template<>
 
425
    void to::test<24>()
 
426
    {
 
427
        std::string const sbits("00000011");
 
428
        liblas::Classification::bitset_type bits(sbits);
 
429
 
 
430
        liblas::Classification c(bits);
 
431
        ensure_equals(c, bits);
 
432
 
 
433
        std::ostringstream oss;
 
434
        oss << c;
 
435
        ensure_equals(oss.str(), sbits);
 
436
    }
 
437
 
 
438
    template<>
 
439
    template<>
 
440
    void to::test<25>()
 
441
    {
 
442
        std::string const sbits("10000001");
 
443
        liblas::Classification::bitset_type bits(sbits);
 
444
 
 
445
        liblas::Classification c(bits);
 
446
        ensure_equals(c, bits);
 
447
 
 
448
        std::ostringstream oss;
 
449
        oss << c;
 
450
        ensure_equals(oss.str(), sbits);
 
451
    }
 
452
 
 
453
    template<>
 
454
    template<>
 
455
    void to::test<26>()
 
456
    {
 
457
        std::string const sbits("10110000");
 
458
        liblas::Classification::bitset_type bits(sbits);
 
459
 
 
460
        liblas::Classification c(bits);
 
461
        ensure_equals(c, bits);
 
462
 
 
463
        std::ostringstream oss;
 
464
        oss << c;
 
465
        ensure_equals(oss.str(), sbits);
 
466
    }
 
467
 
 
468
    template<>
 
469
    template<>
 
470
    void to::test<27>()
 
471
    {
 
472
        std::string const cn("Created, never classified");
 
473
        ensure_equals(m_default.GetClassName(), cn);
 
474
    }
 
475
 
 
476
    template<>
 
477
    template<>
 
478
    void to::test<28>()
 
479
    {
 
480
        std::string const cn("Low Point (noise)");
 
481
        m_default.SetClass(7);
 
482
        ensure_equals(m_default.GetClassName(), cn);
 
483
    }
 
484
 
 
485
    template<>
 
486
    template<>
 
487
    void to::test<29>()
 
488
    {
 
489
        std::string const cn("Reserved for ASPRS Definition");
 
490
        m_default.SetClass(31);
 
491
        ensure_equals(m_default.GetClassName(), cn);
 
492
    }
 
493
 
 
494
    template<>
 
495
    template<>
 
496
    void to::test<30>()
 
497
    {
 
498
        try
 
499
        {
 
500
            m_default.SetClass(32);
 
501
            fail("std::out_of_range not thrown but expected");
 
502
        }
 
503
        catch (std::out_of_range const& e)
 
504
        {
 
505
            ensure(e.what(), true);
 
506
        }
 
507
        catch (...)
 
508
        {
 
509
            fail("unhandled exception expected");
 
510
        }
 
511
    }
 
512
}