File: GeometricTest.java

package info (click to toggle)
libpgjava 8.4-701-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,532 kB
  • ctags: 4,162
  • sloc: java: 33,948; xml: 3,158; makefile: 14; sh: 10
file content (115 lines) | stat: -rw-r--r-- 4,186 bytes parent folder | download
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
/*-------------------------------------------------------------------------
*
* Copyright (c) 2004-2008, PostgreSQL Global Development Group
*
* IDENTIFICATION
*   $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/GeometricTest.java,v 1.5 2008/01/08 06:56:31 jurka Exp $
*
*-------------------------------------------------------------------------
*/
package org.postgresql.test.jdbc2;

import org.postgresql.test.TestUtil;
import org.postgresql.util.PGobject;
import org.postgresql.geometric.*;
import junit.framework.TestCase;
import java.sql.*;

/*
 * Test case for geometric type I/O
 */
public class GeometricTest extends TestCase
{
    private Connection con;

    public GeometricTest(String name)
    {
        super(name);
    }

    // Set up the fixture for this testcase: a connection to a database with
    // a table for this test.
    protected void setUp() throws Exception
    {
        con = TestUtil.openDB();
        TestUtil.createTable(con,
                             "testgeometric",
                             "boxval box, circleval circle, lsegval lseg, pathval path, polygonval polygon, pointval point");
    }

    // Tear down the fixture for this test case.
    protected void tearDown() throws Exception
    {
        TestUtil.dropTable(con, "testgeometric");
        TestUtil.closeDB(con);
    }

    private void checkReadWrite(PGobject obj, String column) throws Exception {
        PreparedStatement insert = con.prepareStatement("INSERT INTO testgeometric(" + column + ") VALUES (?)");
        insert.setObject(1, obj);
        insert.executeUpdate();
        insert.close();

        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT " + column + " FROM testgeometric");
        assertTrue(rs.next());
        assertEquals(obj, rs.getObject(1));
        rs.close();

        stmt.executeUpdate("DELETE FROM testgeometric");
        stmt.close();
    }

    public void testPGbox() throws Exception {
        checkReadWrite(new PGbox(1.0, 2.0, 3.0, 4.0), "boxval");
        checkReadWrite(new PGbox( -1.0, 2.0, 3.0, 4.0), "boxval");
        checkReadWrite(new PGbox(1.0, -2.0, 3.0, 4.0), "boxval");
        checkReadWrite(new PGbox(1.0, 2.0, -3.0, 4.0), "boxval");
        checkReadWrite(new PGbox(1.0, 2.0, 3.0, -4.0), "boxval");
    }

    public void testPGcircle() throws Exception {
        checkReadWrite(new PGcircle(1.0, 2.0, 3.0), "circleval");
        checkReadWrite(new PGcircle( -1.0, 2.0, 3.0), "circleval");
        checkReadWrite(new PGcircle(1.0, -2.0, 3.0), "circleval");
    }

    public void testPGlseg() throws Exception {
        checkReadWrite(new PGlseg(1.0, 2.0, 3.0, 4.0), "lsegval");
        checkReadWrite(new PGlseg( -1.0, 2.0, 3.0, 4.0), "lsegval");
        checkReadWrite(new PGlseg(1.0, -2.0, 3.0, 4.0), "lsegval");
        checkReadWrite(new PGlseg(1.0, 2.0, -3.0, 4.0), "lsegval");
        checkReadWrite(new PGlseg(1.0, 2.0, 3.0, -4.0), "lsegval");
    }

    public void testPGpath() throws Exception {
        PGpoint[] points = new PGpoint[] {
                               new PGpoint(0.0, 0.0),
                               new PGpoint(0.0, 5.0),
                               new PGpoint(5.0, 5.0),
                               new PGpoint(5.0, -5.0),
                               new PGpoint( -5.0, -5.0),
                               new PGpoint( -5.0, 5.0),
                           };

        checkReadWrite(new PGpath(points, true), "pathval");
        checkReadWrite(new PGpath(points, false), "pathval");
    }

    public void testPGpolygon() throws Exception {
        PGpoint[] points = new PGpoint[] {
                               new PGpoint(0.0, 0.0),
                               new PGpoint(0.0, 5.0),
                               new PGpoint(5.0, 5.0),
                               new PGpoint(5.0, -5.0),
                               new PGpoint( -5.0, -5.0),
                               new PGpoint( -5.0, 5.0),
                           };

        checkReadWrite(new PGpolygon(points), "polygonval");
    }

    public void testPGpoint() throws Exception {
        checkReadWrite(new PGpoint(1.0, 2.0), "pointval");
    }
}