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 StaticLineStringTest extends ConnectedTestCase { 37 38 /** 39 * @param arg 40 */ StaticLineStringTest(String arg)41 public StaticLineStringTest(String arg) { 42 super(arg); 43 } 44 45 /** 46 * Round Trip test for a single line string 47 * @throws SQLException 48 */ testSingleLineStringRoundTrip()49 public void testSingleLineStringRoundTrip() throws SQLException{ 50 LineStringGenerator pg = new LineStringGenerator(); 51 pg.setGeometryFactory(geometryFactory); 52 pg.setBoundingBox(new Envelope(0,10,0,10)); 53 pg.setNumberPoints(10); 54 55 LineString pt = (LineString) pg.create(); 56 57 OraWriter ow = new OraWriter(); 58 STRUCT st = ow.write(pt, getConnection()); 59 60 OraReader or = new OraReader(); 61 LineString pt2 = (LineString) or.read(st); 62 63 // System.out.println((pt==null?"NULL":pt.toString())); 64 // System.out.println((pt2==null?"NULL":pt2.toString())); 65 assertTrue("The input LineString is not the same as the output LineString",pt.equals(pt2)); 66 } 67 68 /** 69 * Round Trip test for a 100 non overlapping line strings 70 * @throws SQLException 71 */ testGridLineStringsRoundTrip()72 public void testGridLineStringsRoundTrip() throws SQLException{ 73 GridGenerator grid = new GridGenerator(); 74 grid.setGeometryFactory(geometryFactory); 75 grid.setBoundingBox(new Envelope(0,10,0,10)); 76 grid.setNumberColumns(10); 77 grid.setNumberRows(10); 78 79 LineString[] pt = new LineString[100]; 80 STRUCT[] st = new STRUCT[100]; 81 82 LineStringGenerator pg = new LineStringGenerator(); 83 pg.setGeometryFactory(geometryFactory); 84 pg.setNumberPoints(10); 85 OraWriter ow = new OraWriter(); 86 87 int i=0; 88 while(grid.canCreate() && i<100){ 89 pg.setBoundingBox(grid.createEnv()); 90 pt[i] = (LineString) pg.create(); 91 st[i] = ow.write(pt[i], getConnection()); 92 i++; 93 } 94 95 OraReader or = new OraReader(); 96 i=0; 97 while(i<100 && pt[i] != null){ 98 LineString pt2 = (LineString) or.read(st[i]); 99 // System.out.println((pt[i]==null?"NULL":pt[i].toString())); 100 // System.out.println((pt2==null?"NULL":pt2.toString())); 101 assertTrue("The input LineString is not the same as the output LineString",pt[i].equals(pt2)); 102 i++; 103 } 104 } 105 106 /** 107 * Round Trip test for a 8 overlapping line strings (4 distinct line strings) 108 * @throws SQLException 109 */ testOverlappingLineStringsRoundTrip()110 public void testOverlappingLineStringsRoundTrip() throws SQLException{ 111 GridGenerator grid = new GridGenerator(); 112 grid.setGeometryFactory(geometryFactory); 113 grid.setBoundingBox(new Envelope(0,10,0,10)); 114 grid.setNumberColumns(2); 115 grid.setNumberRows(2); 116 117 LineString[] pt = new LineString[4]; 118 STRUCT[] st = new STRUCT[8]; 119 120 LineStringGenerator pg = new LineStringGenerator(); 121 pg.setGeometryFactory(geometryFactory); 122 pg.setNumberPoints(10); 123 OraWriter ow = new OraWriter(); 124 125 int i=0; 126 while(grid.canCreate() && i<8){ 127 pg.setBoundingBox(grid.createEnv()); 128 pt[i] = (LineString) pg.create(); 129 st[i] = ow.write(pt[i], getConnection()); 130 i++; 131 } 132 for(int j=0;j<4;j++){ 133 if(pt[j]!=null) 134 st[i++] = ow.write(pt[j], getConnection()); 135 } 136 137 OraReader or = new OraReader(); 138 i=0; 139 while(i<8 && pt[i%4] != null){ 140 LineString pt2 = (LineString) or.read(st[i]); 141 // System.out.println((pt==null?"NULL":pt[i%4].toString())); 142 // System.out.println((pt2==null?"NULL":pt2.toString())); 143 assertTrue("The input LineString is not the same as the output LineString",pt[i%4].equals(pt2)); 144 i++; 145 } 146 } 147 148 /** 149 * Round Trip test for a single line string with lotsa points 150 * @throws SQLException 151 */ testSingleLineStringManyPointRoundTrip()152 public void testSingleLineStringManyPointRoundTrip() throws SQLException{ 153 LineStringGenerator pg = new LineStringGenerator(); 154 pg.setGeometryFactory(geometryFactory); 155 pg.setBoundingBox(new Envelope(0,10,0,10)); 156 pg.setGenerationAlgorithm(LineStringGenerator.HORZ); 157 pg.setNumberPoints(1000); 158 159 LineString pt = (LineString) pg.create(); 160 // System.out.println((pt==null?"NULL":pt.toString())); 161 162 OraWriter ow = new OraWriter(); 163 STRUCT st = ow.write(pt, getConnection()); 164 165 OraReader or = new OraReader(); 166 LineString pt2 = (LineString) or.read(st); 167 168 // System.out.println((pt==null?"NULL":pt.toString())); 169 // System.out.println((pt2==null?"NULL":pt2.toString())); 170 assertTrue("The input LineString is not the same as the output LineString",pt.equals(pt2)); 171 } 172 } 173