From 8f27e65bddd7d4b8515ce620fb485fdd78fcdf89 Mon Sep 17 00:00:00 2001 From: Constantin Jucovschi Date: Fri, 24 Apr 2009 07:20:22 -0400 Subject: Initial commit --- java/rasj/test/TestMArray.java | 904 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 904 insertions(+) create mode 100644 java/rasj/test/TestMArray.java (limited to 'java/rasj/test/TestMArray.java') diff --git a/java/rasj/test/TestMArray.java b/java/rasj/test/TestMArray.java new file mode 100644 index 0000000..e8f817f --- /dev/null +++ b/java/rasj/test/TestMArray.java @@ -0,0 +1,904 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see . +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see +* or contact Peter Baumann via . +*/ +/** *********************************************************** + *
+ *
+ * PURPOSE: class for testing special MArrays
+ *
+ *
+ * COMMENTS:
+ * - adapt to general testbed structure
+ * 
+ *********************************************************** */ + +import java.io.*; +import java.net.*; +import rasj.clientcommhttp.*; +import rasj.odmg.*; +import org.odmg.*; +import rasj.*; +import java.util.*; + +/** + * class for testing special MArrays + * for testing please enable test data output in toString method of RASGMArray + * @version $$ + */ +public class TestMArray +{ + /** + * constants used in this test + **/ + // prefixes for test output + static final String PREFIX_PROGRAM = "+++ +++ +++ "; + static final String PREFIX_TESTSET = "+++ +++ "; + static final String PREFIX_TESTCASE = "+++ "; + + static final String DEFAULT_HOST = "localhost"; + static final String DEFAULT_BASE = "RASBASE"; + static final String DEFAULT_COLL = "test"; + /** + * std error tag printed if a test fails + **/ + static final String ERROR_TAG = "ERROR: "; + + /** + * main program for testing + * on error, an exception is thrown (java main() knows no exit status) + **/ + public static void main(String[] args) + { + String serv = DEFAULT_HOST; + String base = DEFAULT_BASE; + String coll = DEFAULT_COLL; + boolean wrongUsage = false; // error in cmd line params? + + for (int i=args.length-1; i>=0; i--) + { + if (args[i].equals("--server")) + serv = args[i+1]; + else if (args[i].equals("--database")) + base = args[i+1]; + else if (args[i].equals("--collname")) + coll = args[i+1]; + else + wrongUsage = true; + } + + if (wrongUsage) + { + System.out.println( "Usage: TestMArray [--server s] [--database d] [--collname c]" ); + System.out.println( "defaults: s=" + DEFAULT_HOST + ", d=" + DEFAULT_BASE + ", c=" + DEFAULT_COLL ); + return; + } + + System.out.println( "rasdaman system test v5.1revC: testing class MArray." ); + System.out.println( PREFIX_PROGRAM + "system test started, using server" + serv + ", database " + base + ", collection" + coll ); + + // -- START test cases ------------------------------------------------- + TestMArray marrayTest = new TestMArray(serv); + // -- END test cases --------------------------------------------------- + + System.out.println( PREFIX_PROGRAM + "system test done." ); + return; + } // main() + + public TestMArray(String server) + { + DBag resultBag = null; + Object result = null; + Transaction myTa = null; + Database myDb = null; + OQLQuery myQu = null; + + boolean equal = false; + + try + { + System.out.println("### Testing MArrays: ..."); + Implementation myApp = new RasImplementation("http://"+server+":7001"); + myDb = myApp.newDatabase(); + + System.out.println("Opening database ..."); + myDb.open("RASBASE", Database.OPEN_READ_WRITE); + myTa = myApp.newTransaction(); + + int width, height, len; + width = 18; + height = 18; + len = (width+1)*(height+1); + RasMInterval domain = new RasMInterval("[0:"+width+",0:"+height+"]"); + RasMInterval domain2 = new RasMInterval("[1:3,1:3]"); + RasStorageLayout stl = new RasStorageLayout(); + stl.setTileSize(128); + + + /** + * test the GMArray + */ + System.out.println("\n\n### Testing GMArray with OID: ################################################"); + myQu = myApp.newOQLQuery(); + + myQu.create("drop collection test"); + myTa.begin(); + try + { + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection dropped"); + } + catch(ODMGException e) + { + myTa.abort(); + System.err.println("Collection test does not exist: " + e.getMessage()); + } + + myQu.create("create collection test GreySet"); + RasGMArray mddConst = new RasGMArray(domain, 1, stl); + //RasGMArray mddConst = new RasGMArray(domain, 1); + byte[] data = new byte[len]; + mddConst.setObjectTypeName("GreyImage"); + + // test: get new OID from the server for GMArray and insert + System.out.println("new OID from server: " + myApp.getObjectId(mddConst)); + + for(int j = 0; j < data.length; j++) + data[j] = (byte)j; + + mddConst.setArray(data); + /* + System.out.println("\nbyte array: "); + for(int j=0; j