1 /* 2 * Copyright (c) 2016 Vivid Solutions. 3 * 4 * All rights reserved. This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * and Eclipse Distribution License v. 1.0 which accompanies this distribution. 7 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html 8 * and the Eclipse Distribution License is available at 9 * 10 * http://www.eclipse.org/org/documents/edl-v10.php. 11 */ 12 package org.locationtech.jts.io.oracle; 13 14 import java.sql.SQLException; 15 16 import org.locationtech.jts.generator.*; 17 import org.locationtech.jts.geom.*; 18 import org.locationtech.jts.io.oracle.OraReader; 19 import org.locationtech.jts.io.oracle.OraWriter; 20 21 import oracle.sql.STRUCT; 22 23 24 /** 25 * 26 * Does round trip testing by creating the oracle object, then decoding it. 27 * 28 * These tests do not include insert / delete / select operations. 29 * 30 * NOTE: This test does require a precision to be used during the comparison, 31 * as points are rounded somewhat when creating the oracle struct. 32 * (One less decimal than a java double). 33 * 34 * @author David Zwiers, Vivid Solutions. 35 */ 36 public class StaticMultiLineStringTest extends ConnectedTestCase { 37 38 /** 39 * @param arg 40 */ StaticMultiLineStringTest(String arg)41 public StaticMultiLineStringTest(String arg) { 42 super(arg); 43 } 44 45 /** 46 * Round Trip test for a single line string 47 * @throws SQLException 48 */ testSingleMultiLineStringRoundTrip()49 public void testSingleMultiLineStringRoundTrip() throws SQLException{ 50 LineStringGenerator pgc = new LineStringGenerator(); 51 pgc.setGeometryFactory(geometryFactory); 52 pgc.setNumberPoints(10); 53 MultiGenerator pg = new MultiGenerator(pgc); 54 pg.setBoundingBox(new Envelope(0,10,0,10)); 55 pg.setNumberGeometries(3); 56 pg.setGeometryFactory(geometryFactory); 57 58 MultiLineString pt = (MultiLineString) pg.create(); 59 60 OraWriter ow = new OraWriter(); 61 STRUCT st = ow.write(pt, getConnection()); 62 63 OraReader or = new OraReader(); 64 MultiLineString pt2 = (MultiLineString) or.read(st); 65 66 // System.out.println((pt==null?"NULL":pt.toString())); 67 // System.out.println((pt2==null?"NULL":pt2.toString())); 68 assertTrue("The input MultiLineString is not the same as the output MultiLineString",pt.equals(pt2)); 69 } 70 71 /** 72 * Round Trip test for a 100 non overlapping line strings 73 * @throws SQLException 74 */ testGridMultiLineStringsRoundTrip()75 public void testGridMultiLineStringsRoundTrip() throws SQLException{ 76 GridGenerator grid = new GridGenerator(); 77 grid.setGeometryFactory(geometryFactory); 78 grid.setBoundingBox(new Envelope(0,10,0,10)); 79 grid.setNumberColumns(10); 80 grid.setNumberRows(10); 81 82 MultiLineString[] pt = new MultiLineString[100]; 83 STRUCT[] st = new STRUCT[100]; 84 85 LineStringGenerator pgc = new LineStringGenerator(); 86 pgc.setGeometryFactory(geometryFactory); 87 pgc.setNumberPoints(10); 88 MultiGenerator pg = new MultiGenerator(pgc); 89 pg.setBoundingBox(new Envelope(0,10,0,10)); 90 pg.setNumberGeometries(3); 91 pg.setGeometryFactory(geometryFactory); 92 93 OraWriter ow = new OraWriter(); 94 95 int i=0; 96 while(grid.canCreate() && i<100){ 97 pg.setBoundingBox(grid.createEnv()); 98 pt[i] = (MultiLineString) pg.create(); 99 st[i] = ow.write(pt[i], getConnection()); 100 i++; 101 } 102 103 OraReader or = new OraReader(); 104 i=0; 105 while(i<100 && pt[i] != null){ 106 MultiLineString pt2 = (MultiLineString) or.read(st[i]); 107 // System.out.println((pt[i]==null?"NULL":pt[i].toString())); 108 // System.out.println((pt2==null?"NULL":pt2.toString())); 109 assertTrue("The input MultiLineString is not the same as the output MultiLineString",pt[i].equals(pt2)); 110 i++; 111 } 112 } 113 114 /** 115 * Round Trip test for a 8 overlapping line strings (4 distinct line strings) 116 * @throws SQLException 117 */ testOverlappingMultiLineStringsRoundTrip()118 public void testOverlappingMultiLineStringsRoundTrip() throws SQLException{ 119 GridGenerator grid = new GridGenerator(); 120 grid.setGeometryFactory(geometryFactory); 121 grid.setBoundingBox(new Envelope(0,10,0,10)); 122 grid.setNumberColumns(2); 123 grid.setNumberRows(2); 124 125 MultiLineString[] pt = new MultiLineString[4]; 126 STRUCT[] st = new STRUCT[8]; 127 128 LineStringGenerator pgc = new LineStringGenerator(); 129 pgc.setGeometryFactory(geometryFactory); 130 pgc.setNumberPoints(10); 131 MultiGenerator pg = new MultiGenerator(pgc); 132 pg.setBoundingBox(new Envelope(0,10,0,10)); 133 pg.setNumberGeometries(3); 134 pg.setGeometryFactory(geometryFactory); 135 136 OraWriter ow = new OraWriter(); 137 138 int i=0; 139 while(grid.canCreate() && i<8){ 140 pg.setBoundingBox(grid.createEnv()); 141 pt[i] = (MultiLineString) pg.create(); 142 st[i] = ow.write(pt[i], getConnection()); 143 i++; 144 } 145 for(int j=0;j<4;j++){ 146 if(pt[j]!=null) 147 st[i++] = ow.write(pt[j], getConnection()); 148 } 149 150 OraReader or = new OraReader(); 151 i=0; 152 while(i<8 && pt[i%4] != null){ 153 MultiLineString pt2 = (MultiLineString) or.read(st[i]); 154 // System.out.println((pt==null?"NULL":pt[i%4].toString())); 155 // System.out.println((pt2==null?"NULL":pt2.toString())); 156 assertTrue("The input MultiLineString is not the same as the output MultiLineString",pt[i%4].equals(pt2)); 157 i++; 158 } 159 } 160 161 /** 162 * Round Trip test for a single line string with lotsa points 163 * @throws SQLException 164 */ testSingleMultiLineStringManyPointRoundTrip()165 public void testSingleMultiLineStringManyPointRoundTrip() throws SQLException{ 166 167 LineStringGenerator pgc = new LineStringGenerator(); 168 pgc.setGeometryFactory(geometryFactory); 169 pgc.setNumberPoints(1000); 170 pgc.setGenerationAlgorithm(LineStringGenerator.HORZ); 171 MultiGenerator pg = new MultiGenerator(pgc); 172 pg.setBoundingBox(new Envelope(0,10,0,10)); 173 pg.setNumberGeometries(3); 174 pg.setGeometryFactory(geometryFactory); 175 176 MultiLineString pt = (MultiLineString) pg.create(); 177 // System.out.println((pt==null?"NULL":pt.toString())); 178 179 OraWriter ow = new OraWriter(); 180 STRUCT st = ow.write(pt, getConnection()); 181 182 OraReader or = new OraReader(); 183 MultiLineString pt2 = (MultiLineString) or.read(st); 184 185 // System.out.println((pt==null?"NULL":pt.toString())); 186 // System.out.println((pt2==null?"NULL":pt2.toString())); 187 assertTrue("The input MultiLineString is not the same as the output MultiLineString",pt.equals(pt2)); 188 } 189 } 190