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

« back to all changes in this revision

Viewing changes to csharp/NUnitTest/LASHeaderTest.cs

  • 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
/******************************************************************************
 
2
 * $Id$
 
3
 *
 
4
 * Project:  libLAS - http://liblas.org - A BSD library for LAS format data.
 
5
 * Purpose:  Test cases of LASHeader class, .NET/Mono bindings
 
6
 * Author:   Martin Vales, martin_gnu@mundo-r.com
 
7
 *
 
8
 ******************************************************************************
 
9
 * Copyright (c) 2008, Martin Vales
 
10
 *
 
11
 * All rights reserved.
 
12
 * 
 
13
 * Redistribution and use in source and binary forms, with or without 
 
14
 * modification, are permitted provided that the following 
 
15
 * conditions are met:
 
16
 * 
 
17
 *     * Redistributions of source code must retain the above copyright 
 
18
 *       notice, this list of conditions and the following disclaimer.
 
19
 *     * Redistributions in binary form must reproduce the above copyright 
 
20
 *       notice, this list of conditions and the following disclaimer in 
 
21
 *       the documentation and/or other materials provided 
 
22
 *       with the distribution.
 
23
 *     * Neither the name of the Martin Isenburg or Iowa Department 
 
24
 *       of Natural Resources nor the names of its contributors may be 
 
25
 *       used to endorse or promote products derived from this software 
 
26
 *       without specific prior written permission.
 
27
 * 
 
28
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 
29
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 
30
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 
31
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 
32
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
 
33
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 
34
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 
 
35
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 
36
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
 
37
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
 
38
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
 
39
 * OF SUCH DAMAGE.
 
40
 ****************************************************************************/
 
41
 
 
42
using System;
 
43
using System.Collections.Generic;
 
44
using System.Text;
 
45
using NUnit.Framework;
 
46
using LibLAS;
 
47
 
 
48
namespace NUnitTest
 
49
{
 
50
    [TestFixture]
 
51
    public class LASHeaderTest
 
52
    {
 
53
        [SetUp]
 
54
        protected void SetUp()
 
55
        {
 
56
        }
 
57
 
 
58
        [Test]
 
59
        public void CopyConstructor()
 
60
        {
 
61
            LASHeader header = new LASHeader();
 
62
            //  string sig = "LASF and garbage";
 
63
            //    header.FileSignature = sig;
 
64
            //    Assert.AreEqual(header.FileSignature.Length,4);
 
65
            //       LASHeader h1;
 
66
            Assert.AreEqual(1, 1);
 
67
            //h1.SetFileSignature(sig);
 
68
            //ensure_not(h1.GetFileSignature() == sig);
 
69
            //ensure_equals(h1.GetFileSignature().size(), 4);
 
70
            //ensure_equals(h1.GetFileSignature(), LASHeader::FileSignature);
 
71
 
 
72
            //LASHeader h2(h1);
 
73
 
 
74
            //ensure_not(h2.GetFileSignature() == sig);
 
75
            //ensure_equals(h2.GetFileSignature().size(), 4);
 
76
            //ensure_equals(h2.GetFileSignature(), LASHeader::FileSignature);
 
77
        }
 
78
 
 
79
        [Test]
 
80
        public void FileSignature()
 
81
        {
 
82
            LASHeader header = new LASHeader();
 
83
            // string sig = "LASF and garbage";
 
84
 
 
85
            Assert.AreEqual(header.FileSignature.Length, 4);
 
86
            Assert.AreEqual(header.FileSignature, "LASF");
 
87
 
 
88
            // I can not set FileSignature from c# API because i am a bad guy.
 
89
            //header.FileSignature = "LASF";
 
90
        }
 
91
 
 
92
        [Test]
 
93
        public void FileSourceId()
 
94
        {
 
95
            LASHeader h1 = new LASHeader();
 
96
 
 
97
            UInt16 id1 = 1;
 
98
            UInt16 id2 = 65535;
 
99
            UInt16 overflowed = 0;
 
100
 
 
101
            h1.FileSourceId = id1;
 
102
            Assert.AreEqual(h1.FileSourceId, id1);
 
103
            h1.FileSourceId = id2;
 
104
            Assert.AreEqual(h1.FileSourceId, id2);
 
105
 
 
106
            // Unsigned overflow
 
107
            // Likely compiler warning: truncation from int to liblas::uint16_t
 
108
            h1.FileSourceId = (ushort)(id2 + 1);
 
109
            Assert.AreEqual(h1.FileSourceId, overflowed);
 
110
        }
 
111
 
 
112
        [Test]
 
113
        public void Reserved()
 
114
        {
 
115
            LASHeader h = new LASHeader();
 
116
 
 
117
            Assert.AreEqual(h.Reserved, 0);
 
118
        }
 
119
 
 
120
        [Test]
 
121
        public void ProjectId()
 
122
        {
 
123
            LASHeader h = new LASHeader();
 
124
 
 
125
            //string strid="030B4A82-1B7C-11CF-9D53-00AA003C9CB6";
 
126
            //      Assert.AreEqual(h.Reserved, 0);
 
127
            //      liblas::guid id(strid.c_str());
 
128
            //      h.ProjectId=;
 
129
            //    std::string strid("030B4A82-1B7C-11CF-9D53-00AA003C9CB6");
 
130
            //liblas::guid id(strid.c_str());
 
131
 
 
132
            //liblas::LASHeader h;
 
133
            //h.SetProjectId(id);
 
134
 
 
135
            //ensure_not(h.GetProjectId().is_null());
 
136
            //ensure_equals(h.GetProjectId(), id);
 
137
        }
 
138
 
 
139
        [Test]
 
140
        public void MinorMajorVersion()
 
141
        {
 
142
            LASHeader h = new LASHeader();
 
143
            h.VersionMinor = 0;
 
144
            h.VersionMajor = 1;
 
145
            Assert.AreEqual(h.VersionMinor, 0);
 
146
            Assert.AreEqual(h.VersionMajor, 1);
 
147
 
 
148
            h.VersionMinor = 1;
 
149
            h.VersionMajor = 1;
 
150
            Assert.AreEqual(h.VersionMinor, 1);
 
151
            Assert.AreEqual(h.VersionMajor, 1);
 
152
 
 
153
            try
 
154
            {
 
155
                h.VersionMajor = 2;
 
156
                //don�t get the next line...
 
157
                Assert.AreEqual(2, 5);
 
158
            }
 
159
            catch (LASException e)
 
160
            {
 
161
                Assert.AreEqual(e.Message, "Exception in Set Header VersionMajor.");
 
162
            }
 
163
 
 
164
            try
 
165
            {
 
166
                h.VersionMinor = 2;
 
167
                //don�t get the next line...
 
168
                Assert.AreEqual(2, 5);
 
169
            }
 
170
            catch (LASException e)
 
171
            {
 
172
                Assert.AreEqual(e.Message, "Exception in Set Header VersionMinor.");
 
173
            }
 
174
        }
 
175
 
 
176
        [Test]
 
177
        public void SoftwareId()
 
178
        {
 
179
            LASHeader h = new LASHeader();
 
180
 
 
181
            string softid1 = "Short Soft Id"; // 13 bytes
 
182
            int len1 = softid1.Length;
 
183
            string softid2 = "Long Software Identifier - XX YY"; // 32 bytes
 
184
            int len2 = softid2.Length;
 
185
 
 
186
            h.SoftwareId = softid1;
 
187
            Assert.AreEqual(h.SoftwareId, softid1);
 
188
            Assert.AreEqual(h.SoftwareId.Length, len1);
 
189
            // Assert.AreEqual(h.GetSoftwareId(true).size(), 32);
 
190
 
 
191
            h.SoftwareId = softid2;
 
192
            Assert.AreEqual(h.SoftwareId, softid2);
 
193
            Assert.AreEqual(h.SoftwareId.Length, len2);
 
194
            // Assert.AreEqual(h.GetSoftwareId(true).size(), 32);
 
195
        }
 
196
 
 
197
        [Test]
 
198
        public void PointRecordsByReturnCount()
 
199
        {
 
200
            LASHeader h = new LASHeader();
 
201
            // Assert.AreEqual(h.GetPointRecordsByReturnCount(5),5);
 
202
 
 
203
            h.SetPointRecordsByReturnCount(0, 100);
 
204
            //ensure_equals(h.GetPointRecordsByReturnCount().size(), 5);
 
205
            Assert.AreEqual(h.GetPointRecordsByReturnCount(0), 100);
 
206
 
 
207
            h.SetPointRecordsByReturnCount(1, 101);
 
208
            //ensure_equals(h.GetPointRecordsByReturnCount().size(), 5);
 
209
            Assert.AreEqual(h.GetPointRecordsByReturnCount(1), 101);
 
210
 
 
211
            h.SetPointRecordsByReturnCount(2, 102);
 
212
            //ensure_equals(h.GetPointRecordsByReturnCount().size(), 5);
 
213
            Assert.AreEqual(h.GetPointRecordsByReturnCount(2), 102);
 
214
 
 
215
            h.SetPointRecordsByReturnCount(3, 103);
 
216
            //ensure_equals(h.GetPointRecordsByReturnCount().size(), 5);
 
217
            Assert.AreEqual(h.GetPointRecordsByReturnCount(3), 103);
 
218
 
 
219
            h.SetPointRecordsByReturnCount(4, 104);
 
220
            //ensure_equals(h.GetPointRecordsByReturnCount().size(), 5);
 
221
            Assert.AreEqual(h.GetPointRecordsByReturnCount(4), 104);
 
222
 
 
223
            try
 
224
            {
 
225
                // 5 is out of range
 
226
                h.SetPointRecordsByReturnCount(5, 500);
 
227
                //don�t get the next line...
 
228
                Assert.AreEqual(2, 5);
 
229
            }
 
230
            catch (LASException e)
 
231
            {
 
232
                Assert.AreEqual(e.Message, "Exception in Set Header SetPointRecordsByReturnCount.");
 
233
            }
 
234
        }
 
235
    }
 
236
}