File: WKBWriterTest.cpp

package info (click to toggle)
geos 3.4.2-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 16,572 kB
  • ctags: 13,989
  • sloc: cpp: 97,030; xml: 32,337; sh: 10,379; ansic: 3,726; php: 1,831; makefile: 1,619; ruby: 1,295; python: 928
file content (163 lines) | stat: -rw-r--r-- 4,390 bytes parent folder | download | duplicates (2)
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
// 
// Test Suite for geos::io::WKBWriter

// tut
#include <tut.hpp>
// geos
#include <geos/io/WKBReader.h>
#include <geos/io/WKBWriter.h>
#include <geos/io/WKTReader.h>
#include <geos/io/WKTWriter.h>
#include <geos/geom/PrecisionModel.h>
#include <geos/geom/GeometryFactory.h>
#include <geos/geom/Geometry.h>
// std
#include <sstream>
#include <string>
#include <memory>
#include <cmath>

namespace tut
{
	//
	// Test Group
	//

	// dummy data, not used
	struct test_wkbwriter_data
	{
		geos::geom::PrecisionModel pm;
		geos::geom::GeometryFactory gf;
		geos::io::WKTReader wktreader;
		geos::io::WKTWriter wktwriter;
		geos::io::WKBReader wkbreader;
		geos::io::WKBWriter wkbwriter;

		test_wkbwriter_data()
			:
			pm(1000.0),
			gf(&pm),
      wktreader(&gf),
      wkbreader(gf)
		{}

	};

	typedef test_group<test_wkbwriter_data> group;
	typedef group::object object;

	group test_wkbwriter_group("geos::io::WKBWriter");


	//
	// Test Cases
	//

	// 1 - Test writing a 2D geometry with the WKBWriter in 3D output dimension.
	template<>
	template<>
	void object::test<1>()
	{         
            geos::geom::Geometry *geom = wktreader.read("POINT(-117 33)");
			std::stringstream result_stream;

            wkbwriter.setOutputDimension( 3 );
            wkbwriter.write( *geom, result_stream );
            delete geom;
            geom = NULL;

            ensure( result_stream.str().length() == 21 );

            result_stream.seekg( 0 );
            geom = wkbreader.read( result_stream );

            ensure( geom != NULL );

            ensure( geom->getCoordinateDimension() == 2 );
            ensure( geom->getCoordinate()->x == -117.0 );
            ensure( geom->getCoordinate()->y == 33.0 );
            ensure( ISNAN(geom->getCoordinate()->z) != 0 );

            delete geom;
    }

	// 2 - Test writing a 3D geometry with the WKBWriter in 3D output dimension.
	template<>
	template<>
	void object::test<2>()
	{         
            geos::geom::Geometry *geom = wktreader.read("POINT(-117 33 11)");
			std::stringstream result_stream;

            wkbwriter.setOutputDimension( 3 );
            wkbwriter.write( *geom, result_stream );
            delete geom;
            geom = NULL;

            ensure( result_stream.str().length() == 29 );

            result_stream.seekg( 0 );
            geom = wkbreader.read( result_stream );

            ensure( geom->getCoordinateDimension() == 3 );
            ensure( geom->getCoordinate()->x == -117.0 );
            ensure( geom->getCoordinate()->y == 33.0 );
            ensure( geom->getCoordinate()->z == 11.0 );

            delete geom;
    }

	// 3 - Test writing a 3D geometry with the WKBWriter in 2D output dimension.
	template<>
	template<>
	void object::test<3>()
	{         
            geos::geom::Geometry *geom = wktreader.read("POINT(-117 33 11)");
			std::stringstream result_stream;

            wkbwriter.setOutputDimension( 2 );
            wkbwriter.write( *geom, result_stream );
            delete geom;
            geom = NULL;

            ensure( result_stream.str().length() == 21 );

            result_stream.seekg( 0 );
            geom = wkbreader.read( result_stream );

            ensure( geom->getCoordinateDimension() == 2 );
            ensure( geom->getCoordinate()->x == -117.0 );
            ensure( geom->getCoordinate()->y == 33.0 );
            ensure( ISNAN(geom->getCoordinate()->z) != 0);

            delete geom;
    }

	// 4 - Test that SRID is output only once
  // See http://trac.osgeo.org/geos/ticket/583
	template<>
	template<>
	void object::test<4>()
	{         
    typedef geos::geom::Geometry Geom;
    typedef std::vector<Geom *> GeomVect;
    GeomVect *geoms = new GeomVect;
    geoms->push_back( wktreader.read("POLYGON((0 0,1 0,1 1,0 1,0 0))") );
    geoms->back()->setSRID(4326);
    Geom *geom = gf.createGeometryCollection(geoms);
    std::stringstream result_stream;

    wkbwriter.setOutputDimension( 2 );
    wkbwriter.setByteOrder( 1 );
    wkbwriter.setIncludeSRID( 1 );
    wkbwriter.writeHEX( *geom, result_stream );
    delete geom;

    std::string actual = result_stream.str();
    ensure_equals( actual, "0107000000010000000103000000010000000500000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F000000000000F03F0000000000000000000000000000F03F00000000000000000000000000000000");

  }


} // namespace tut