0001: /*
0002: (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
0003: [See end of file]
0004: $Id: Regression.java,v 1.42 2008/02/13 07:54:03 chris-dollin Exp $
0005: */
0006:
0007: package com.hp.hpl.jena.regression;
0008:
0009: import com.hp.hpl.jena.rdf.model.impl.*;
0010: import com.hp.hpl.jena.rdf.model.*;
0011:
0012: import com.hp.hpl.jena.vocabulary.*;
0013: import com.hp.hpl.jena.shared.*;
0014: import com.hp.hpl.jena.graph.*;
0015:
0016: import java.net.*;
0017: import java.util.*;
0018: import java.io.*;
0019:
0020: import org.apache.commons.logging.Log;
0021: import org.apache.commons.logging.LogFactory;
0022:
0023: /** A common set of regression tests. [Now being factored out into the
0024: * NewRegression suite; kers.]
0025: *
0026: * @author bwm
0027: * @version Release='$Name: $' Revision='$Revision: 1.42 $' Date='$Date: 2008/02/13 07:54:03 $'
0028: */
0029: public class Regression extends Object {
0030:
0031: protected boolean errors = false;
0032:
0033: public static void doTest(Model m1, Model m2, Model m3, Model m4) {
0034: (new Regression()).test(m1, m2, m3, m4);
0035: }
0036:
0037: protected static Log logger = LogFactory.getLog(Regression.class);
0038:
0039: /** Run the whole batch of common tests on a model implementation
0040: * @param m an instance of the model to be tested
0041: */
0042: public void test(Model m1, Model m2, Model m3, Model m4) {
0043: try {
0044: StmtIterator iter = m1.listStatements();
0045: while (iter.hasNext()) {
0046: iter.nextStatement();
0047: iter.remove();
0048: }
0049:
0050: iter = m2.listStatements();
0051: while (iter.hasNext()) {
0052: iter.nextStatement();
0053: iter.remove();
0054: }
0055:
0056: iter = m3.listStatements();
0057: while (iter.hasNext()) {
0058: iter.nextStatement();
0059: iter.remove();
0060: }
0061:
0062: iter = m4.listStatements();
0063: while (iter.hasNext()) {
0064: iter.nextStatement();
0065: iter.remove();
0066: }
0067: } catch (Exception e) {
0068: System.out.println(e);
0069: errors = true;
0070: }
0071:
0072: test1(m1);
0073: test2(m1);
0074: test3(m1);
0075: test4(m1);
0076: test5(m1); // leaves m empty if successful
0077: test6(m1);
0078: test7(m1, m2);
0079: test8(m1);
0080: test9(m2);
0081: test10(m3);
0082: test11(m1, m2);
0083: test12(m1);
0084: test13(m1);
0085: test14(m1);
0086: test15(m1);
0087: test16(m1);
0088: test17(m1);
0089: test18(m4);
0090: test19(m2, m3);
0091: // test20(m4); reification is not working
0092: test97(m4);
0093: // test98(m1);
0094: }
0095:
0096: /** Test Literal creation methods
0097: * @param m the model implementation under test
0098: */
0099: public void test1(Model m) {
0100: Literal l;
0101: String test = "Test1";
0102: int n = 0;
0103: // System.out.println("Beginning " + test);
0104: try {
0105: {
0106: n = 100;
0107: n++;
0108: if (!m.createTypedLiteral(true).getBoolean())
0109: error(test, n);
0110: n++;
0111: if (m.createTypedLiteral(false).getBoolean())
0112: error(test, n);
0113: }
0114:
0115: {
0116: n = 200;
0117: byte tv = 0;
0118:
0119: l = m.createTypedLiteral(tv);
0120: n++;
0121: if (l.getByte() != tv)
0122: error(test, n);
0123: n++;
0124: if (l.getShort() != tv)
0125: error(test, n);
0126: n++;
0127: if (l.getInt() != tv)
0128: error(test, n);
0129: n++;
0130: if (l.getLong() != tv)
0131: error(test, n);
0132:
0133: tv = -1;
0134: l = m.createTypedLiteral(tv);
0135: n++;
0136: if (l.getByte() != tv)
0137: error(test, n);
0138: n++;
0139: if (l.getShort() != tv)
0140: error(test, n);
0141: n++;
0142: if (l.getInt() != tv)
0143: error(test, n);
0144: n++;
0145: if (l.getLong() != tv)
0146: error(test, n);
0147:
0148: tv = Byte.MIN_VALUE;
0149: l = m.createTypedLiteral(tv);
0150: n++;
0151: if (l.getByte() != tv)
0152: error(test, n);
0153: n++;
0154: if (l.getShort() != tv)
0155: error(test, n);
0156: n++;
0157: if (l.getInt() != tv)
0158: error(test, n);
0159: n++;
0160: if (l.getLong() != tv)
0161: error(test, n);
0162:
0163: tv = Byte.MAX_VALUE;
0164: l = m.createTypedLiteral(tv);
0165: n++;
0166: if (l.getByte() != tv)
0167: error(test, n);
0168: n++;
0169: if (l.getShort() != tv)
0170: error(test, n);
0171: n++;
0172: if (l.getInt() != tv)
0173: error(test, n);
0174: n++;
0175: if (l.getLong() != tv)
0176: error(test, n);
0177: }
0178:
0179: {
0180: n = 300;
0181: short tv;
0182:
0183: tv = 0;
0184: l = m.createTypedLiteral(tv);
0185: n++;
0186: if (l.getByte() != tv)
0187: error(test, n);
0188: n++;
0189: if (l.getShort() != tv)
0190: error(test, n);
0191: n++;
0192: if (l.getInt() != tv)
0193: error(test, n);
0194: n++;
0195: if (l.getLong() != tv)
0196: error(test, n);
0197:
0198: tv = -1;
0199: l = m.createTypedLiteral(tv);
0200: n++;
0201: if (l.getByte() != tv)
0202: error(test, n);
0203: n++;
0204: if (l.getShort() != tv)
0205: error(test, n);
0206: n++;
0207: if (l.getInt() != tv)
0208: error(test, n);
0209: n++;
0210: if (l.getLong() != tv)
0211: error(test, n);
0212:
0213: tv = Short.MIN_VALUE;
0214: l = m.createTypedLiteral(tv);
0215: try {
0216: n++;
0217: if (l.getByte() != tv)
0218: error(test, n);
0219: } catch (NumberFormatException e) {
0220: } catch (IllegalArgumentException e) {
0221: }
0222: n++;
0223: if (l.getShort() != tv)
0224: error(test, n);
0225: n++;
0226: if (l.getInt() != tv)
0227: error(test, n);
0228: n++;
0229: if (l.getLong() != tv)
0230: error(test, n);
0231:
0232: tv = Short.MAX_VALUE;
0233: l = m.createTypedLiteral(tv);
0234: try {
0235: n++;
0236: if (l.getByte() != tv)
0237: error(test, n);
0238: } catch (NumberFormatException e) {
0239: } catch (IllegalArgumentException e) {
0240: }
0241: n++;
0242: if (l.getShort() != tv)
0243: error(test, n);
0244: n++;
0245: if (l.getInt() != tv)
0246: error(test, n);
0247: n++;
0248: if (l.getLong() != tv)
0249: error(test, n);
0250: }
0251:
0252: {
0253: n = 400;
0254: int tv;
0255:
0256: tv = 0;
0257: l = m.createTypedLiteral(tv);
0258: n++;
0259: if (l.getByte() != tv)
0260: error(test, n);
0261: n++;
0262: if (l.getShort() != tv)
0263: error(test, n);
0264: n++;
0265: if (l.getInt() != tv)
0266: error(test, n);
0267: n++;
0268: if (l.getLong() != tv)
0269: error(test, n);
0270:
0271: tv = -1;
0272: l = m.createTypedLiteral(tv);
0273: n++;
0274: if (l.getByte() != tv)
0275: error(test, n);
0276: n++;
0277: if (l.getShort() != tv)
0278: error(test, n);
0279: n++;
0280: if (l.getInt() != tv)
0281: error(test, n);
0282: n++;
0283: if (l.getLong() != tv)
0284: error(test, n);
0285:
0286: tv = Integer.MIN_VALUE;
0287: l = m.createTypedLiteral(tv);
0288: try {
0289: n++;
0290: if (l.getByte() != tv)
0291: error(test, n);
0292: } catch (NumberFormatException e) {
0293: } catch (IllegalArgumentException e) {
0294: }
0295: try {
0296: n++;
0297: if (l.getShort() != tv)
0298: error(test, n);
0299: } catch (NumberFormatException e) {
0300: } catch (IllegalArgumentException e) {
0301: }
0302: n++;
0303: if (l.getInt() != tv)
0304: error(test, n);
0305: n++;
0306: if (l.getLong() != tv)
0307: error(test, n);
0308:
0309: tv = Integer.MAX_VALUE;
0310: l = m.createTypedLiteral(tv);
0311: try {
0312: n++;
0313: if (l.getByte() != tv)
0314: error(test, n);
0315: } catch (NumberFormatException e) {
0316: } catch (IllegalArgumentException e) {
0317: }
0318: try {
0319: n++;
0320: if (l.getShort() != tv)
0321: error(test, n);
0322: } catch (NumberFormatException e) {
0323: } catch (IllegalArgumentException e) {
0324: }
0325: n++;
0326: if (l.getInt() != tv)
0327: error(test, n);
0328: n++;
0329: if (l.getLong() != tv)
0330: error(test, n);
0331: }
0332:
0333: {
0334: n = 500;
0335: long tv;
0336:
0337: tv = 0;
0338: l = m.createTypedLiteral(tv);
0339: n++;
0340: if (l.getByte() != tv)
0341: error(test, n);
0342: n++;
0343: if (l.getShort() != tv)
0344: error(test, n);
0345: n++;
0346: if (l.getInt() != tv)
0347: error(test, n);
0348: n++;
0349: if (l.getLong() != tv)
0350: error(test, n);
0351:
0352: tv = -1;
0353: l = m.createTypedLiteral(tv);
0354: n++;
0355: if (l.getByte() != tv)
0356: error(test, n);
0357: n++;
0358: if (l.getShort() != tv)
0359: error(test, n);
0360: n++;
0361: if (l.getInt() != tv)
0362: error(test, n);
0363: n++;
0364: if (l.getLong() != tv)
0365: error(test, n);
0366:
0367: tv = Long.MIN_VALUE;
0368: l = m.createTypedLiteral(tv);
0369: try {
0370: n++;
0371: if (l.getByte() != tv)
0372: error(test, n);
0373: } catch (NumberFormatException e) {
0374: } catch (IllegalArgumentException e) {
0375: }
0376: try {
0377: n++;
0378: if (l.getShort() != tv)
0379: error(test, n);
0380: } catch (NumberFormatException e) {
0381: } catch (IllegalArgumentException e) {
0382: }
0383: try {
0384: n++;
0385: if (l.getInt() != tv)
0386: error(test, n);
0387: } catch (NumberFormatException e) {
0388: } catch (IllegalArgumentException e) {
0389: }
0390: n++;
0391: if (l.getLong() != tv)
0392: error(test, n);
0393:
0394: tv = Long.MAX_VALUE;
0395: l = m.createTypedLiteral(tv);
0396: try {
0397: n++;
0398: if (l.getByte() != tv)
0399: error(test, n);
0400: } catch (NumberFormatException e) {
0401: } catch (IllegalArgumentException e) {
0402: }
0403: try {
0404: n++;
0405: if (l.getShort() != tv)
0406: error(test, n);
0407: } catch (NumberFormatException e) {
0408: } catch (IllegalArgumentException e) {
0409: }
0410: try {
0411: n++;
0412: if (l.getInt() != tv)
0413: error(test, n);
0414: } catch (NumberFormatException e) {
0415: } catch (IllegalArgumentException e) {
0416: }
0417: n++;
0418: if (l.getLong() != tv)
0419: error(test, n);
0420: }
0421:
0422: {
0423: float tv;
0424: float maxerror = (float) 0.00005;
0425: n = 600;
0426:
0427: tv = (float) 0.0;
0428: l = m.createTypedLiteral(tv);
0429: n++;
0430: if (java.lang.Math.abs(l.getFloat() - tv) >= maxerror)
0431: error(test, n);
0432:
0433: tv = (float) -1.0;
0434: l = m.createTypedLiteral(tv);
0435: n++;
0436: if (java.lang.Math.abs(l.getFloat() - tv) >= maxerror)
0437: error(test, n);
0438:
0439: tv = (float) 12345.6789;
0440: l = m.createTypedLiteral(tv);
0441: n++;
0442: if (java.lang.Math.abs(l.getFloat() - tv) >= maxerror)
0443: error(test, n);
0444:
0445: tv = Float.MAX_VALUE;
0446: l = m.createTypedLiteral(tv);
0447: n++;
0448: if (java.lang.Math.abs(l.getFloat() - tv) >= maxerror)
0449: error(test, n);
0450:
0451: tv = Float.MIN_VALUE;
0452: l = m.createTypedLiteral(tv);
0453: n++;
0454: if (java.lang.Math.abs(l.getFloat() - tv) >= maxerror)
0455: error(test, n);
0456: }
0457: {
0458: double tv;
0459: double maxerror = (double) 0.000000005;
0460: n = 700;
0461:
0462: tv = (double) 0.0;
0463: l = m.createTypedLiteral(tv);
0464: n++;
0465: if (java.lang.Math.abs(l.getDouble() - tv) >= maxerror)
0466: error(test, n);
0467:
0468: tv = (double) -1.0;
0469: l = m.createTypedLiteral(tv);
0470: n++;
0471: if (java.lang.Math.abs(l.getDouble() - tv) >= maxerror)
0472: error(test, n);
0473:
0474: tv = (double) 12345.67890;
0475: l = m.createTypedLiteral(tv);
0476: n++;
0477: if (java.lang.Math.abs(l.getDouble() - tv) >= maxerror)
0478: error(test, n);
0479:
0480: tv = Double.MAX_VALUE;
0481: l = m.createTypedLiteral(tv);
0482: n++;
0483: if (java.lang.Math.abs(l.getDouble() - tv) >= maxerror)
0484: error(test, n);
0485:
0486: tv = Double.MIN_VALUE;
0487: l = m.createTypedLiteral(tv);
0488: n++;
0489: if (java.lang.Math.abs(l.getDouble() - tv) >= maxerror)
0490: error(test, n);
0491: }
0492:
0493: {
0494: char tv;
0495: n = 800;
0496:
0497: tv = 'A';
0498: n++;
0499: if (m.createTypedLiteral(tv).getChar() != tv)
0500: error(test, n);
0501:
0502: tv = 'a';
0503: n++;
0504: if (m.createTypedLiteral(tv).getChar() != tv)
0505: error(test, n);
0506:
0507: tv = '#';
0508: n++;
0509: if (m.createTypedLiteral(tv).getChar() != tv)
0510: error(test, n);
0511:
0512: tv = '@';
0513: n++;
0514: if (m.createTypedLiteral(tv).getChar() != tv)
0515: error(test, n);
0516: }
0517:
0518: {
0519: String language = "en";
0520: String tv;
0521: n = 900;
0522:
0523: tv = "";
0524: n++;
0525: if (!m.createLiteral(tv).getString().equals(tv))
0526: error(test, n);
0527:
0528: tv = "A test string";
0529: n++;
0530: if (!m.createLiteral(tv).getString().equals(tv))
0531: error(test, n);
0532:
0533: tv = "Another test string";
0534: n++;
0535: l = m.createLiteral(tv);
0536: n++;
0537: if (!l.getString().equals(tv))
0538: error(test, n);
0539: n++;
0540: if (!(l.getLanguage().equals("")))
0541: error(test, n);
0542: n++;
0543: l = m.createLiteral(tv, language);
0544: n++;
0545: if (!(l.getString().equals(tv)))
0546: error(test, n);
0547: n++;
0548: if (!(l.getLanguage().equals(language)))
0549: error(test, n);
0550: n++;
0551: if (!l.equals(m.createLiteral(tv, language)))
0552: error(test, n);
0553: n++;
0554: if (l.equals(m.createLiteral(tv)))
0555: error(test, n);
0556: }
0557:
0558: {
0559: LitTestObj tv;
0560: LitTestObjF factory = new LitTestObjF();
0561: n = 1000;
0562:
0563: tv = new LitTestObj(0);
0564: n++;
0565: if (!m.createTypedLiteral(tv).getObject(factory)
0566: .equals(tv))
0567: error(test, n);
0568:
0569: tv = new LitTestObj(12345);
0570: n++;
0571: if (!m.createTypedLiteral(tv).getObject(factory)
0572: .equals(tv))
0573: error(test, n);
0574:
0575: tv = new LitTestObj(-67890);
0576: n++;
0577: if (!m.createTypedLiteral(tv).getObject(factory)
0578: .equals(tv))
0579: error(test, n);
0580: }
0581: } catch (Exception e) {
0582: logger.error("test " + test + "[" + n + "]", e);
0583: errors = true;
0584: }
0585: // System.out.println("End of " + test);
0586: }
0587:
0588: /** Test Resource creation methods
0589: * @param m the model implementation under test
0590: */
0591: public void test2(Model m) {
0592: String test = "Test2";
0593: int n = 0;
0594: String uri;
0595: // System.out.println("Beginning " + test);
0596: try {
0597: {
0598: Resource r;
0599: n = 100;
0600:
0601: try {
0602: n = 110;
0603: n++;
0604: r = m.createResource();
0605: n++;
0606: if (!r.isAnon())
0607: error(test, n);
0608: n++;
0609: if (!(r.getURI() == null))
0610: error(test, n);
0611: n++;
0612: if (!(r.getNameSpace() == null))
0613: error(test, n);
0614: n++;
0615: if (!(r.getLocalName() == null))
0616: error(test, n);
0617: } catch (JenaException e) {
0618: error(test, n, e);
0619: }
0620:
0621: try {
0622: n = 120;
0623: n++;
0624: r = m.createResource((String) null);
0625: n++;
0626: if (!r.isAnon())
0627: error(test, n);
0628: n++;
0629: if (!(r.getURI() == null))
0630: error(test, n);
0631: } catch (JenaException e) {
0632: error(test, n, e);
0633: }
0634:
0635: try {
0636: n = 140;
0637: uri = "http://aldabaran.hpl.hp.com/foo";
0638: n++;
0639: r = m.createResource(uri);
0640: n++;
0641: if (!r.getURI().equals(uri))
0642: error(test, n);
0643: } catch (JenaException e) {
0644: error(test, n, e);
0645: }
0646:
0647: try {
0648: n = 150;
0649: n++;
0650: r = m.createResource(RDF.Property);
0651: n++;
0652: if (!r.isAnon())
0653: error(test, n);
0654: } catch (JenaException e) {
0655: error(test, n, e);
0656: }
0657:
0658: try {
0659: n = 160;
0660: uri = "http://aldabaran.hpl.hp.com/foo";
0661: n++;
0662: r = m.createResource(uri, RDF.Property);
0663: n++;
0664: if (!r.getURI().equals(uri))
0665: error(test, n);
0666: } catch (JenaException e) {
0667: error(test, n, e);
0668: }
0669:
0670: try {
0671: n = 170;
0672: n++;
0673: r = m.createResource(new ResTestObjF());
0674: n++;
0675: if (!r.isAnon())
0676: error(test, n);
0677: } catch (JenaException e) {
0678: error(test, n, e);
0679: }
0680:
0681: try {
0682: n = 180;
0683: uri = "http://aldabaran.hpl.hp.com/foo";
0684: n++;
0685: r = m.createResource(uri, new ResTestObjF());
0686: n++;
0687: if (!r.getURI().equals(uri))
0688: error(test, n);
0689: } catch (JenaException e) {
0690: error(test, n, e);
0691: }
0692: }
0693:
0694: {
0695: Property p;
0696: n = 200;
0697:
0698: try {
0699: n++;
0700: p = m.createProperty(null);
0701: error(test, n);
0702: } catch (InvalidPropertyURIException jx) {
0703: // as expected.
0704:
0705: }
0706:
0707: try {
0708: n++;
0709: p = m.createProperty("abc/def");
0710: n++;
0711: if (!p.getNameSpace().equals("abc/"))
0712: error(test, n);
0713: n++;
0714: if (!p.getLocalName().equals("def"))
0715: error(test, n);
0716: n++;
0717: if (!p.getURI().equals("abc/def"))
0718: error(test, n);
0719: } catch (JenaException e) {
0720: error(test, n, e);
0721: }
0722:
0723: try {
0724: n++;
0725: p = m.createProperty("abc/", "def");
0726: n++;
0727: if (!p.getNameSpace().equals("abc/"))
0728: error(test, n);
0729: n++;
0730: if (!p.getLocalName().equals("def"))
0731: error(test, n);
0732: n++;
0733: if (!p.getURI().equals("abc/def"))
0734: error(test, n);
0735: } catch (JenaException e) {
0736: error(test, n, e);
0737: }
0738:
0739: try {
0740: n++;
0741: p = m.createProperty(RDF.getURI() + "_345");
0742: n++;
0743: if (!p.getNameSpace().equals(RDF.getURI()))
0744: error(test, n);
0745: n++;
0746: if (!p.getLocalName().equals("_345"))
0747: error(test, n);
0748: n++;
0749: if (!p.getURI().equals(RDF.getURI() + "_345"))
0750: error(test, n);
0751: } catch (JenaException e) {
0752: error(test, n, e);
0753: }
0754:
0755: try {
0756: n++;
0757: p = m.createProperty(RDF.getURI(), "_345");
0758: n++;
0759: if (!p.getNameSpace().equals(RDF.getURI()))
0760: error(test, n);
0761: n++;
0762: if (!p.getLocalName().equals("_345"))
0763: error(test, n);
0764: n++;
0765: if (!p.getURI().equals(RDF.getURI() + "_345"))
0766: error(test, n);
0767: } catch (JenaException e) {
0768: error(test, n, e);
0769: }
0770:
0771: }
0772:
0773: {
0774: String subjURI = "http://aldabaran.hpl.hp.com/foo";
0775: String predURI = "http://aldabaran.hpl.hp.com/bar";
0776: Resource r = m.createResource(subjURI);
0777: Property p = m.createProperty(predURI);
0778: Statement s;
0779:
0780: n = 300;
0781:
0782: try {
0783: boolean tv = true;
0784: n = 310;
0785: n++;
0786: s = m.createLiteralStatement(r, p, tv);
0787: n++;
0788: if (!s.getSubject().getURI().equals(subjURI))
0789: error(test, n);
0790: n++;
0791: if (!s.getPredicate().getURI().equals(predURI))
0792: error(test, n);
0793: n++;
0794: if (!s.getBoolean())
0795: error(test, n);
0796: } catch (Exception e) {
0797: error(test, n, e);
0798: }
0799:
0800: try {
0801: byte tv = Byte.MAX_VALUE;
0802: n = 320;
0803: n++;
0804: s = m.createLiteralStatement(r, p, tv);
0805: n++;
0806: if (!s.getSubject().getURI().equals(subjURI))
0807: error(test, n);
0808: n++;
0809: if (!s.getPredicate().getURI().equals(predURI))
0810: error(test, n);
0811: n++;
0812: if (!(s.getByte() == tv))
0813: error(test, n);
0814: } catch (Exception e) {
0815: error(test, n, e);
0816: }
0817:
0818: try {
0819: short tv = Short.MAX_VALUE;
0820: n = 330;
0821: n++;
0822: s = m.createLiteralStatement(r, p, tv);
0823: n++;
0824: if (!s.getSubject().getURI().equals(subjURI))
0825: error(test, n);
0826: n++;
0827: if (!s.getPredicate().getURI().equals(predURI))
0828: error(test, n);
0829: n++;
0830: if (!(s.getShort() == tv))
0831: error(test, n);
0832: } catch (Exception e) {
0833: error(test, n, e);
0834: }
0835:
0836: try {
0837: int tv = Integer.MAX_VALUE;
0838: n = 340;
0839: n++;
0840: s = m.createLiteralStatement(r, p, tv);
0841: n++;
0842: if (!s.getSubject().getURI().equals(subjURI))
0843: error(test, n);
0844: n++;
0845: if (!s.getPredicate().getURI().equals(predURI))
0846: error(test, n);
0847: n++;
0848: if (!(s.getInt() == tv))
0849: error(test, n);
0850: } catch (Exception e) {
0851: error(test, n, e);
0852: }
0853:
0854: try {
0855: long tv = Long.MAX_VALUE;
0856: n = 350;
0857: n++;
0858: s = m.createLiteralStatement(r, p, tv);
0859: n++;
0860: if (!s.getSubject().getURI().equals(subjURI))
0861: error(test, n);
0862: n++;
0863: if (!s.getPredicate().getURI().equals(predURI))
0864: error(test, n);
0865: n++;
0866: if (!(s.getLong() == tv))
0867: error(test, n);
0868: } catch (Exception e) {
0869: error(test, n, e);
0870: }
0871:
0872: try {
0873: char tv = '$';
0874: n = 360;
0875: n++;
0876: s = m.createLiteralStatement(r, p, tv);
0877: n++;
0878: if (!s.getSubject().getURI().equals(subjURI))
0879: error(test, n);
0880: n++;
0881: if (!s.getPredicate().getURI().equals(predURI))
0882: error(test, n);
0883: n++;
0884: if (!(s.getChar() == tv))
0885: error(test, n);
0886: } catch (Exception e) {
0887: error(test, n, e);
0888: }
0889:
0890: try {
0891: float tv = (float) 123.456;
0892: n = 370;
0893: n++;
0894: s = m.createStatement(r, p, m
0895: .createTypedLiteral(tv));
0896: n++;
0897: if (!s.getSubject().getURI().equals(subjURI))
0898: error(test, n);
0899: n++;
0900: if (!s.getPredicate().getURI().equals(predURI))
0901: error(test, n);
0902: n++;
0903: if (!((s.getFloat() - tv) < 0.0005))
0904: error(test, n);
0905: } catch (Exception e) {
0906: error(test, n, e);
0907: }
0908:
0909: try {
0910: double tv = 12345.67890;
0911: n = 380;
0912: n++;
0913: s = m.createStatement(r, p, m
0914: .createTypedLiteral(tv));
0915: n++;
0916: if (!s.getSubject().getURI().equals(subjURI))
0917: error(test, n);
0918: n++;
0919: if (!s.getPredicate().getURI().equals(predURI))
0920: error(test, n);
0921: n++;
0922: if (!((s.getDouble() - tv) < 0.0000005))
0923: error(test, n);
0924: } catch (Exception e) {
0925: error(test, n, e);
0926: }
0927:
0928: try {
0929: String tv = "this is a test string";
0930: String lang = "en";
0931: n = 390;
0932: n++;
0933: s = m.createStatement(r, p, tv);
0934: n++;
0935: if (!s.getSubject().getURI().equals(subjURI))
0936: error(test, n);
0937: n++;
0938: if (!s.getPredicate().getURI().equals(predURI))
0939: error(test, n);
0940: n++;
0941: if (!s.getString().equals(tv))
0942: error(test, n);
0943: // n++; if (! s.getLiteral().equals(tv)) error(test,n);
0944: n++;
0945: s = m.createStatement(r, p, tv, lang);
0946: n++;
0947: if (!s.getLanguage().equals(lang))
0948: error(test, n);
0949: } catch (Exception e) {
0950: error(test, n, e);
0951: }
0952:
0953: try {
0954: LitTestObj tv = new LitTestObj(Long.MIN_VALUE);
0955: String lang = "fr";
0956: n = 400;
0957: n++;
0958: s = m.createLiteralStatement(r, p, tv);
0959: n++;
0960: if (!s.getSubject().getURI().equals(subjURI))
0961: error(test, n);
0962: n++;
0963: if (!s.getPredicate().getURI().equals(predURI))
0964: error(test, n);
0965: n++;
0966: if (!s.getObject(new LitTestObjF()).equals(tv))
0967: error(test, n);
0968: } catch (Exception e) {
0969: error(test, n, e);
0970: }
0971:
0972: try {
0973: Resource tv = m.createResource();
0974: n = 410;
0975: n++;
0976: s = m.createStatement(r, p, tv);
0977: n++;
0978: if (!s.getSubject().getURI().equals(subjURI))
0979: error(test, n);
0980: n++;
0981: if (!s.getPredicate().getURI().equals(predURI))
0982: error(test, n);
0983: n++;
0984: if (!s.getResource().equals(tv))
0985: error(test, n);
0986: } catch (Exception e) {
0987: error(test, n, e);
0988: }
0989:
0990: try {
0991: Literal tv = m.createTypedLiteral(true);
0992: n = 420;
0993: n++;
0994: s = m.createStatement(r, p, tv);
0995: n++;
0996: if (!s.getSubject().getURI().equals(subjURI))
0997: error(test, n);
0998: n++;
0999: if (!s.getPredicate().getURI().equals(predURI))
1000: error(test, n);
1001: n++;
1002: if (!s.getBoolean())
1003: error(test, n);
1004: } catch (Exception e) {
1005: error(test, n, e);
1006: }
1007: }
1008:
1009: {
1010: // test container creation
1011:
1012: try {
1013: Bag tv;
1014: n = 500;
1015: n++;
1016: tv = m.createBag();
1017: n++;
1018: if (!tv.isAnon())
1019: error(test, n);
1020: n++;
1021: if (!m.contains(tv, RDF.type, RDF.Bag))
1022: error(test, n);
1023:
1024: uri = "http://aldabaran/foo";
1025: n++;
1026: tv = m.createBag(uri);
1027: n++;
1028: if (!tv.getURI().equals(uri))
1029: error(test, n);
1030: n++;
1031: if (!m.contains(tv, RDF.type, RDF.Bag))
1032: error(test, n);
1033: } catch (Exception e) {
1034: error(test, n, e);
1035: }
1036:
1037: try {
1038: Alt tv;
1039: n = 510;
1040: n++;
1041: tv = m.createAlt();
1042: n++;
1043: if (!tv.isAnon())
1044: error(test, n);
1045: n++;
1046: if (!m.contains(tv, RDF.type, RDF.Alt))
1047: error(test, n);
1048:
1049: uri = "http://aldabaran/foo";
1050: n++;
1051: tv = m.createAlt(uri);
1052: n++;
1053: if (!tv.getURI().equals(uri))
1054: error(test, n);
1055: n++;
1056: if (!m.contains(tv, RDF.type, RDF.Alt))
1057: error(test, n);
1058: } catch (Exception e) {
1059: error(test, n, e);
1060: }
1061:
1062: try {
1063: Seq tv;
1064: n = 520;
1065: n++;
1066: tv = m.createSeq();
1067: n++;
1068: if (!tv.isAnon())
1069: error(test, n);
1070: n++;
1071: if (!m.contains(tv, RDF.type, RDF.Seq))
1072: error(test, n);
1073:
1074: uri = "http://aldabaran/foo";
1075: n++;
1076: tv = m.createSeq(uri);
1077: n++;
1078: if (!tv.getURI().equals(uri))
1079: error(test, n);
1080: n++;
1081: if (!m.contains(tv, RDF.type, RDF.Seq))
1082: error(test, n);
1083: } catch (Exception e) {
1084: error(test, n, e);
1085: }
1086: }
1087:
1088: } catch (Exception e) {
1089: logger.error("test " + test + "[" + n + "]", e);
1090: errors = true;
1091: }
1092: // System.out.println("End of " + test);
1093: }
1094:
1095: /** Test model add and contains methods
1096: * @param m the model implementation under test
1097: */
1098: public void test3(Model m) {
1099: String test = "Test3";
1100: int n = 0;
1101:
1102: try {
1103: boolean tvBoolean = true;
1104: byte tvByte = 1;
1105: short tvShort = 2;
1106: int tvInt = -1;
1107: long tvLong = -2;
1108: char tvChar = '!';
1109: float tvFloat = (float) 123.456;
1110: double tvDouble = -123.456;
1111: String tvString = "test string";
1112: String lang = "en";
1113: LitTestObj tvObject = new LitTestObj(12345);
1114: Literal tvLiteral = m.createLiteral("test string 2");
1115: Resource tvResource = m.createResource();
1116: Resource subject = m.createResource();
1117: // System.out.println("Beginning " + test);
1118:
1119: try {
1120: n = 100;
1121: n++;
1122: m.add(subject, RDF.value, tvResource);
1123: n++;
1124: if (!m.contains(subject, RDF.value, tvResource))
1125: error(test, n);
1126: } catch (Exception e) {
1127: error(test, n, e);
1128: }
1129:
1130: try {
1131: n = 110;
1132: n++;
1133: m.add(subject, RDF.value, tvLiteral);
1134: n++;
1135: if (!m.contains(subject, RDF.value, tvLiteral))
1136: error(test, n);
1137: } catch (Exception e) {
1138: error(test, n, e);
1139: }
1140:
1141: try {
1142: n = 120;
1143: n++;
1144: m.addLiteral(subject, RDF.value, tvByte);
1145: n++;
1146: if (!m.containsLiteral(subject, RDF.value, tvByte))
1147: error(test, n);
1148: } catch (Exception e) {
1149: error(test, n, e);
1150: }
1151:
1152: try {
1153: n = 130;
1154: n++;
1155: m.addLiteral(subject, RDF.value, tvShort);
1156: n++;
1157: if (!m.containsLiteral(subject, RDF.value, tvShort))
1158: error(test, n);
1159: } catch (Exception e) {
1160: error(test, n, e);
1161: }
1162:
1163: try {
1164: n = 140;
1165: n++;
1166: m.addLiteral(subject, RDF.value, tvInt);
1167: n++;
1168: if (!m.containsLiteral(subject, RDF.value, tvInt))
1169: error(test, n);
1170: } catch (Exception e) {
1171: error(test, n, e);
1172: }
1173:
1174: try {
1175: n = 150;
1176: n++;
1177: m.addLiteral(subject, RDF.value, tvLong);
1178: n++;
1179: if (!m.containsLiteral(subject, RDF.value, tvLong))
1180: error(test, n);
1181: } catch (Exception e) {
1182: error(test, n, e);
1183: }
1184:
1185: try {
1186: n = 160;
1187: n++;
1188: m.addLiteral(subject, RDF.value, tvChar);
1189: n++;
1190: if (!m.containsLiteral(subject, RDF.value, tvChar))
1191: error(test, n);
1192: } catch (Exception e) {
1193: error(test, n, e);
1194: }
1195:
1196: try {
1197: n = 170;
1198: n++;
1199: m.addLiteral(subject, RDF.value, tvFloat);
1200: n++;
1201: if (!m.containsLiteral(subject, RDF.value, tvFloat))
1202: error(test, n);
1203: } catch (Exception e) {
1204: error(test, n, e);
1205: }
1206:
1207: try {
1208: n = 180;
1209: n++;
1210: m.addLiteral(subject, RDF.value, tvDouble);
1211: n++;
1212: if (!m.containsLiteral(subject, RDF.value, tvDouble))
1213: error(test, n);
1214: } catch (Exception e) {
1215: error(test, n, e);
1216: }
1217:
1218: try {
1219: n = 190;
1220: n++;
1221: m.addLiteral(subject, RDF.value, tvObject);
1222: n++;
1223: if (!m.containsLiteral(subject, RDF.value, tvObject))
1224: error(test, n);
1225: } catch (Exception e) {
1226: error(test, n, e);
1227: }
1228:
1229: try {
1230: n = 200;
1231: n++;
1232: m.add(subject, RDF.value, tvString);
1233: n++;
1234: if (!m.contains(subject, RDF.value, tvString))
1235: error(test, n);
1236: n++;
1237: if (m.contains(subject, RDF.value, tvString, lang))
1238: error(test, n);
1239: n++;
1240: m.add(subject, RDF.value, tvString, lang);
1241: n++;
1242: if (!m.contains(subject, RDF.value, tvString, lang))
1243: error(test, n);
1244: } catch (Exception e) {
1245: error(test, n, e);
1246: }
1247:
1248: try {
1249: n = 210;
1250: n++;
1251: tvLiteral = m.createTypedLiteral(n);
1252: n++;
1253: Statement stmt = m.createStatement(subject, RDF.value,
1254: tvLiteral);
1255: n++;
1256: m.add(stmt);
1257: n++;
1258: if (!m.contains(stmt))
1259: error(test, n);
1260: n++;
1261: long size = m.size();
1262: n++;
1263: m.add(stmt);
1264: n++;
1265: if (!(m.size() == size))
1266: error(test, n);
1267: n++;
1268: if (!m.contains(subject, RDF.value))
1269: error(test, n);
1270: n++;
1271: if (m.contains(subject, RDF.subject))
1272: error(test, n);
1273: } catch (Exception e) {
1274: error(test, n, e);
1275: }
1276: } catch (Exception e) {
1277: logger.error("test " + test + "[" + n + "]", e);
1278: errors = true;
1279: }
1280: // System.out.println("End of " + test);
1281: }
1282:
1283: /** Test model get methods
1284: * @param m the model implementation under test
1285: */
1286: public void test4(Model m) {
1287: String test = "Test4";
1288: int n = 0;
1289:
1290: try {
1291: // System.out.println("Beginning " + test);
1292:
1293: try {
1294: Resource r;
1295: n = 110;
1296: String uri = "http://aldabaran.hpl.hp.com/rdf/test4/a"
1297: + Integer.toString(n);
1298: n++;
1299: r = m.getResource(uri);
1300: n++;
1301: if (!r.getURI().equals(uri))
1302: error(test, n);
1303: } catch (Exception e) {
1304: error(test, n, e);
1305: }
1306:
1307: try {
1308: Resource r;
1309: n = 120;
1310: String uri = "http://aldabaran.hpl.hp.com/rdf/test4/a"
1311: + Integer.toString(n);
1312: n++;
1313: r = m.getResource(uri, new ResTestObjF());
1314: n++;
1315: if (!r.getURI().equals(uri))
1316: error(test, n);
1317: } catch (Exception e) {
1318: error(test, n, e);
1319: }
1320:
1321: try {
1322: Property p;
1323: n = 130;
1324: String uri = "http://aldabaran.hpl.hp.com/rdf/test4/a"
1325: + Integer.toString(n);
1326: n++;
1327: p = m.getProperty(uri);
1328: n++;
1329: if (!p.getURI().equals(uri))
1330: error(test, n);
1331: } catch (Exception e) {
1332: error(test, n, e);
1333: }
1334:
1335: try {
1336: Property p;
1337: n = 140;
1338: String ns = "http://aldabaran.hpl.hp.com/rdf/test4/"
1339: + Integer.toString(n) + "/";
1340: String ln = "foo";
1341: n++;
1342: p = m.getProperty(ns, ln);
1343: n++;
1344: if (!p.getURI().equals(ns + ln))
1345: error(test, n);
1346: } catch (Exception e) {
1347: error(test, n, e);
1348: }
1349:
1350: try {
1351: Bag c;
1352: n = 150;
1353: String uri = "http://aldabaran.hpl.hp.com/rdf/test4/"
1354: + Integer.toString(n);
1355: n++;
1356: m.createBag(uri);
1357: n++;
1358: c = m.getBag(uri);
1359: n++;
1360: if (!c.getURI().equals(uri))
1361: error(test, n);
1362: n++;
1363: if (!m.contains(c, RDF.type, RDF.Bag))
1364: error(test, n);
1365: } catch (Exception e) {
1366: error(test, n, e);
1367: }
1368:
1369: try {
1370: Alt c;
1371: n = 160;
1372: String uri = "http://aldabaran.hpl.hp.com/rdf/test4/"
1373: + Integer.toString(n);
1374: n++;
1375: m.createAlt(uri);
1376: n++;
1377: c = m.getAlt(uri);
1378: c = m.getAlt(m.getResource(uri));
1379: n++;
1380: if (!c.getURI().equals(uri))
1381: error(test, n);
1382: n++;
1383: if (!m.contains(c, RDF.type, RDF.Alt))
1384: error(test, n);
1385: } catch (Exception e) {
1386: error(test, n, e);
1387: }
1388:
1389: try {
1390: Seq c;
1391: n = 170;
1392: String uri = "http://aldabaran.hpl.hp.com/rdf/test4/"
1393: + Integer.toString(n);
1394: n++;
1395: m.createSeq(uri);
1396: n++;
1397: c = m.getSeq(uri);
1398: n++;
1399: if (!c.getURI().equals(uri))
1400: error(test, n);
1401: n++;
1402: if (!m.contains(c, RDF.type, RDF.Seq))
1403: error(test, n);
1404: } catch (Exception e) {
1405: error(test, n, e);
1406: }
1407: } catch (Exception e) {
1408: logger.error("test " + test + "[" + n + "]", e);
1409: errors = true;
1410: }
1411: // System.out.println("End of " + test);
1412: }
1413:
1414: /** Empty the passed in model
1415: * @param m the model implementation under test
1416: */
1417: public void test5(Model m) {
1418: String test = "Test5";
1419: int n = 0;
1420:
1421: try {
1422: StmtIterator iter;
1423: // System.out.println("Beginning " + test);
1424:
1425: try {
1426: n = 100;
1427: n++;
1428: iter = m.listStatements();
1429: while (iter.hasNext()) {
1430: iter.nextStatement();
1431: n++;
1432: iter.remove();
1433: }
1434: n++;
1435: iter.close();
1436: n++;
1437: if (!(m.size() == 0))
1438: error(test, 999);
1439: } catch (Exception e) {
1440: error(test, n, e);
1441: }
1442: } catch (Exception e) {
1443: logger.error("test " + test + "[" + n + "]", e);
1444: }
1445: // System.out.println("End of " + test);
1446: }
1447:
1448: /** test model list methods
1449: * @param m the model implementation under test
1450: */
1451: public void test6(Model m) {
1452: String test = "Test6";
1453: int n = 0;
1454: int num = 5;
1455: int numStatements;
1456:
1457: // System.out.println("Beginning " + test);
1458:
1459: Resource subject[] = new Resource[num];
1460: Property predicate[] = new Property[num];
1461: Statement stmts[] = new Statement[num * num];
1462:
1463: String suri = "http://aldabaran/test6/s";
1464: String puri = "http://aldabaran/test6/";
1465:
1466: try {
1467:
1468: for (int i = 0; i < num; i++) {
1469: subject[i] = m.createResource(suri
1470: + Integer.toString(i));
1471: predicate[i] = m.createProperty(puri
1472: + Integer.toString(i), "p");
1473: }
1474:
1475: n = 50;
1476: if (m.size() != 0)
1477: error(test, n);
1478:
1479: for (int i = 0; i < num; i++) {
1480: for (int j = 0; j < num; j++) {
1481: Statement stmt = m.createStatement(subject[i],
1482: predicate[j], m.createTypedLiteral(i * num
1483: + j));
1484: m.add(stmt);
1485: m.add(stmt);
1486: stmts[i * num + j] = stmt;
1487: }
1488: }
1489:
1490: int numStmts = num * num;
1491: boolean stmtf[] = new boolean[numStmts];
1492: boolean subjf[] = new boolean[num];
1493: boolean predf[] = new boolean[num];
1494:
1495: n = 100;
1496: n++;
1497: if (m.size() != numStmts)
1498: error(test, n);
1499: for (int i = 0; i < numStmts; i++) {
1500: stmtf[i] = false;
1501: }
1502: for (int i = 0; i < num; i++) {
1503: subjf[i] = false;
1504: predf[i] = false;
1505: }
1506:
1507: boolean found = false;
1508: ResIterator rIter = m.listSubjects();
1509: while (rIter.hasNext()) {
1510: Resource subj = rIter.nextResource();
1511: found = false;
1512: for (int i = 0; i < num; i++) {
1513: if (subj.equals(subject[i])) {
1514: found = true;
1515: if (subjf[i])
1516: error(test, 110);
1517: subjf[i] = true;
1518: }
1519: }
1520: if (!found)
1521: error(test, 120);
1522: }
1523: for (int i = 0; i < num; i++) {
1524: if (!subjf[i])
1525: error(test, 120 + i);
1526: }
1527:
1528: // System.err.println( "WARNING: listNameSpace testing wonky for the moment" );
1529: // NsIterator nIter = m.listNameSpaces();
1530: // HashSet fromIterator = new HashSet();
1531: // HashSet fromPredicates = new HashSet();
1532: // while (nIter.hasNext()) fromIterator.add( nIter.next() );
1533: // for (int i = 0; i < num; i += 1) fromPredicates.add( predicate[i].getNameSpace() );
1534: // if (fromIterator.equals( fromPredicates ))
1535: // {}
1536: // else
1537: // {
1538: // System.err.println( "| oh dear." );
1539: // System.err.println( "| predicate namespaces: " + fromPredicates );
1540: // System.err.println( "| iterator namespaces: " + fromIterator );
1541: // }
1542:
1543: NsIterator nIter = m.listNameSpaces();
1544: while (nIter.hasNext()) {
1545: String ns = nIter.nextNs();
1546: found = false;
1547: for (int i = 0; i < num; i++) {
1548: if (ns.equals(predicate[i].getNameSpace())) {
1549: found = true;
1550: if (predf[i])
1551: error(test, 130);
1552: predf[i] = true;
1553: }
1554: }
1555: if (!found)
1556: error(test, 140);
1557: }
1558: for (int i = 0; i < num; i++) {
1559: if (!predf[i])
1560: error(test, 140 + i);
1561: }
1562:
1563: StmtIterator sIter = m.listStatements();
1564: while (sIter.hasNext()) {
1565: Statement stmt = sIter.nextStatement();
1566: found = false;
1567: for (int i = 0; i < numStmts; i++) {
1568: if (stmt.equals(stmts[i])) {
1569: found = true;
1570: if (stmtf[i])
1571: error(test, 150);
1572: stmtf[i] = true;
1573: }
1574: }
1575: if (!found)
1576: error(test, 160);
1577: }
1578: for (int i = 0; i < numStmts; i++) {
1579: if (!stmtf[i])
1580: error(test, 160 + i);
1581: }
1582:
1583: // SEE the tests in model.test: TestReifiedStatements and TestStatementResources
1584: // {
1585: // System.err.println( "WARNING: reification testing suppressed for the moment" );
1586: ///* Reification is not working properly
1587: //
1588: // for (int i=0; i<num; i++) {
1589: // stmtf[i] = false;
1590: // m.add(stmts[i], predicate[i], i);
1591: // }
1592: // sIter = m.listReifiedStatements();
1593: // while (sIter.hasNext()) {
1594: // Statement stmt = sIter.next();
1595: // found = false;
1596: // for (int i=0; i<num; i++) {
1597: // if (stmt.equals(stmts[i])) {
1598: // found = true;
1599: // if (stmtf[i]) error(test, 200);
1600: // stmtf[i] = true;
1601: // }
1602: // }
1603: // if (! found) error(test, 210);
1604: // }
1605: // for (int i=0; i<num; i++) {
1606: // if (! stmtf[i]) error(test, 220+i);
1607: // } */
1608: // }
1609:
1610: {
1611: NodeIterator iter;
1612: boolean[] object = new boolean[num * num];
1613: n = 300;
1614: for (int i = 0; i < (num * num); i++) {
1615: object[i] = false;
1616: }
1617: iter = m.listObjectsOfProperty(predicate[0]);
1618: while (iter.hasNext()) {
1619: Literal l = (Literal) iter.nextNode();
1620: int i = l.getInt();
1621: object[i] = true;
1622: }
1623: for (int i = 0; i < (num * num); i++) {
1624: if ((i % num) == 0) {
1625: if (!object[i])
1626: error(test, 300 + i);
1627: } else {
1628: if (object[i])
1629: error(test, 350 + i);
1630: }
1631: }
1632: }
1633:
1634: {
1635: NodeIterator iter;
1636: boolean[] object = new boolean[num];
1637: n = 400;
1638: Resource subj = m.createResource();
1639: for (int i = 0; i < num; i++) {
1640: m.addLiteral(subj, RDF.value, i);
1641: object[i] = false;
1642: }
1643:
1644: iter = m.listObjectsOfProperty(subj, RDF.value);
1645: while (iter.hasNext()) {
1646: int i = ((Literal) iter.nextNode()).getInt();
1647: object[i] = true;
1648: }
1649: for (int i = 0; i < (num); i++) {
1650: if (!object[i])
1651: error(test, n + i);
1652: }
1653: }
1654:
1655: {
1656: int count = 0;
1657: NodeIterator iter;
1658: n = 500;
1659: iter = m.listObjects();
1660: while (iter.hasNext()) {
1661: iter.nextNode();
1662: count++;
1663: }
1664: if (!(count == 25)) {
1665: System.err.println(">> count = " + count);
1666: error(test, n + count);
1667: }
1668: }
1669: } catch (Exception e) {
1670: logger.error("test " + test + "[" + n + "]", e);
1671: errors = true;
1672: throw new RuntimeException(e);
1673: }
1674: // System.out.println("End of " + test);
1675: }
1676:
1677: /** test add and remove sets and models
1678: * @param m the model implementation under test
1679: */
1680: public void test7(Model m1, Model m2) {
1681: String test = "Test7";
1682: int n = 0;
1683:
1684: try {
1685: StmtIterator iter;
1686: // System.out.println("Beginning " + test);
1687:
1688: try {
1689: n = 100;
1690: n++;
1691: iter = m1.listStatements();
1692: n++;
1693: m2.add(iter);
1694: iter.close();
1695: n++;
1696: if (!(m1.size() == m2.size()))
1697: error(test, n);
1698: n++;
1699: iter = m1.listStatements();
1700: n = 110;
1701: while (iter.hasNext()) {
1702: n++;
1703: if (!m2.contains(iter.nextStatement()))
1704: error(test, n);
1705: }
1706: n = 200;
1707: iter = m2.listStatements();
1708: while (iter.hasNext()) {
1709: n++;
1710: if (!m1.contains(iter.nextStatement()))
1711: error(test, n);
1712: }
1713: } catch (Exception e) {
1714: error(test, n, e);
1715: }
1716:
1717: try {
1718: n = 300;
1719: m1.add(m1.createResource(), RDF.value, m1
1720: .createResource());
1721: m1.add(m1.createResource(), RDF.value, m1
1722: .createResource());
1723: m1.add(m1.createResource(), RDF.value, m1
1724: .createResource());
1725: n++;
1726: iter = m1.listStatements();
1727: n++;
1728: m2.remove(iter.nextStatement());
1729: n++;
1730: m2.remove(iter);
1731: iter.close();
1732: n++;
1733: if (!(m2.size() == 0))
1734: error(test, n);
1735: } catch (Exception e) {
1736: error(test, n, e);
1737: }
1738:
1739: try {
1740: n = 400;
1741: n++;
1742: m2.add(m1);
1743: n++;
1744: if (!(m1.size() == m2.size()))
1745: error(test, n);
1746: n++;
1747: iter = m1.listStatements();
1748: n = 410;
1749: while (iter.hasNext()) {
1750: n++;
1751: if (!m2.contains(iter.nextStatement()))
1752: error(test, n);
1753: }
1754: n = 500;
1755: iter = m2.listStatements();
1756: while (iter.hasNext()) {
1757: n++;
1758: if (!m1.contains(iter.nextStatement()))
1759: error(test, n);
1760: }
1761: } catch (Exception e) {
1762: error(test, n, e);
1763: }
1764:
1765: try {
1766: n = 600;
1767: // System.err.println( "| m2.size() = " + m2.size() );
1768: n++;
1769: m2.remove(m1);
1770: n++;
1771: if (!(m2.size() == 0))
1772: error(test, n);
1773: // System.err.println( "| after: m2.size = " + m2.size() );
1774: } catch (Exception e) {
1775: error(test, n, e);
1776: }
1777: } catch (Exception e) {
1778: logger.error("test " + test + "[" + n + "]", e);
1779: errors = true;
1780: }
1781: // System.out.println("End of " + test);
1782: }
1783:
1784: /** test list subjects with methods
1785: * @param m the model implementation under test
1786: */
1787: public void test8(Model m) {
1788: String test = "Test8";
1789: int n = 0;
1790: int num = 5;
1791:
1792: Resource subject[] = new Resource[num];
1793: Property predicate[] = new Property[num];
1794: Vector stmtv = new Vector();
1795: Statement stmts[];
1796: Statement stmt;
1797:
1798: String suri = "http://aldabaran/test8/s";
1799: String puri = "http://aldabaran/test8/";
1800:
1801: boolean tvBoolean[] = { false, true };
1802: long tvLong[] = { 123, 321 };
1803: char tvChar[] = { '@', ';' };
1804: float tvFloat[] = { 456.789f, 789.456f };
1805: double tvDouble[] = { 123.456, 456.123 };
1806: String tvString[] = { "test8 testing string 1",
1807: "test8 testing string 2" };
1808: String lang[] = { "en", "fr" };
1809:
1810: boolean subjf[] = new boolean[num];
1811: boolean predf[] = new boolean[num];
1812:
1813: int numObj = 9;
1814: boolean objf[] = new boolean[numObj];
1815: RDFNode object[] = new RDFNode[numObj];
1816:
1817: // System.out.println("Beginning " + test);
1818:
1819: try {
1820: Literal tvLitObj[] = {
1821: m.createTypedLiteral(new LitTestObjF()),
1822: m.createTypedLiteral(new LitTestObjF()) };
1823: Resource tvResObj[] = {
1824: m.createResource(new ResTestObjF()),
1825: m.createResource(new ResTestObjF()) };
1826:
1827: for (int i = 0; i < num; i++) {
1828: subject[i] = m.createResource(suri
1829: + Integer.toString(i));
1830: predicate[i] = m.createProperty(puri
1831: + Integer.toString(i), "p");
1832: }
1833:
1834: for (int i = 0; i < num; i++) {
1835: m.addLiteral(subject[i], predicate[4], false);
1836: }
1837:
1838: for (int i = 0; i < 2; i++) {
1839: for (int j = 0; j < 2; j++) {
1840: stmt = m.createStatement(subject[i], predicate[j],
1841: m.createTypedLiteral(tvBoolean[j]));
1842: m.add(stmt);
1843: stmt = m.createLiteralStatement(subject[i],
1844: predicate[j], tvLong[j]);
1845: m.add(stmt);
1846: stmt = m.createLiteralStatement(subject[i],
1847: predicate[j], tvChar[j]);
1848: m.add(stmt);
1849:
1850: stmt = m.createStatement(subject[i], predicate[j],
1851: m.createTypedLiteral(tvFloat[j]));
1852: m.add(stmt);
1853: stmt = m.createStatement(subject[i], predicate[j],
1854: m.createTypedLiteral(tvDouble[j]));
1855: m.add(stmt);
1856:
1857: stmt = m.createStatement(subject[i], predicate[j],
1858: tvString[j]);
1859: m.add(stmt);
1860: stmt = m.createStatement(subject[i], predicate[j],
1861: tvString[j], lang[j]);
1862: m.add(stmt);
1863: stmt = m.createStatement(subject[i], predicate[j],
1864: tvLitObj[j]);
1865: m.add(stmt);
1866: stmt = m.createStatement(subject[i], predicate[j],
1867: tvResObj[j]);
1868: m.add(stmt);
1869: }
1870: }
1871: object[0] = m.createTypedLiteral(tvBoolean[1]);
1872: object[1] = m.createTypedLiteral(tvLong[1]);
1873: object[2] = m.createTypedLiteral(tvChar[1]);
1874: object[3] = m.createTypedLiteral(tvFloat[1]);
1875: object[4] = m.createTypedLiteral(tvDouble[1]);
1876: object[5] = m.createLiteral(tvString[1]);
1877: object[6] = m.createLiteral(tvString[1], lang[1]);
1878: object[7] = tvLitObj[1];
1879: object[8] = tvResObj[1];
1880:
1881: n = 100;
1882:
1883: n++;
1884: stmt = m.getRequiredProperty(subject[1], predicate[1]);
1885:
1886: n++;
1887: try {
1888: stmt = m.getRequiredProperty(subject[1], RDF.value);
1889: error(test, n);
1890: } catch (PropertyNotFoundException jx) {
1891: // as required
1892: }
1893:
1894: for (int i = 0; i < num; i++) {
1895: subjf[i] = false;
1896: }
1897: boolean found = false;
1898:
1899: ResIterator rIter = m
1900: .listResourcesWithProperty(predicate[4]);
1901: while (rIter.hasNext()) {
1902: Resource subj = rIter.nextResource();
1903: found = false;
1904: for (int i = 0; i < num; i++) {
1905: if (subj.equals(subject[i])) {
1906: found = true;
1907: if (subjf[i])
1908: error(test, 110);
1909: subjf[i] = true;
1910: }
1911: }
1912: if (!found)
1913: error(test, 120);
1914: }
1915: for (int i = 0; i < num; i++) {
1916: if (!subjf[i])
1917: error(test, 130 + i);
1918: }
1919:
1920: for (int i = 0; i < num; i++) {
1921: subjf[i] = false;
1922: }
1923: found = false;
1924: rIter = m.listResourcesWithProperty(predicate[0]);
1925: while (rIter.hasNext()) {
1926: Resource subj = rIter.nextResource();
1927: found = false;
1928: for (int i = 0; i < num; i++) {
1929: if (subj.equals(subject[i])) {
1930: found = true;
1931: if (subjf[i])
1932: error(test, 150);
1933: subjf[i] = true;
1934: }
1935: }
1936: if (!found)
1937: error(test, 160);
1938: }
1939: for (int i = 0; i < num; i++) {
1940: if (subjf[i]) {
1941: if (i > 1)
1942: error(test, 170 + i);
1943: } else {
1944: if (i < 2)
1945: error(test, 190 + i);
1946: }
1947: }
1948:
1949: n = 200;
1950: // System.out.println( "* -- n := " + n );
1951: for (int i = 0; i < num; i++) {
1952: subjf[i] = false;
1953: }
1954: found = false;
1955: rIter = m.listResourcesWithProperty(predicate[0], m
1956: .createTypedLiteral(tvBoolean[0]));
1957: while (rIter.hasNext()) {
1958: Resource subj = rIter.nextResource();
1959: found = false;
1960: for (int i = 0; i < num; i++) {
1961: if (subj.equals(subject[i])) {
1962: found = true;
1963: if (subjf[i])
1964: error(test, n + 10);
1965: subjf[i] = true;
1966: }
1967: }
1968: if (!found)
1969: error(test, n + 20);
1970: }
1971: for (int i = 0; i < num; i++) {
1972: if (subjf[i]) {
1973: if (i > 1)
1974: error(test, n + 30 + i);
1975: } else {
1976: if (i < 2)
1977: error(test, n + 40 + i);
1978: }
1979: }
1980:
1981: for (int i = 0; i < num; i++) {
1982: subjf[i] = false;
1983: }
1984: found = false;
1985: rIter = m.listResourcesWithProperty(predicate[0], m
1986: .createTypedLiteral(tvBoolean[1]));
1987: while (rIter.hasNext()) {
1988: Resource subj = rIter.nextResource();
1989: found = false;
1990: for (int i = 0; i < num; i++) {
1991: if (subj.equals(subject[i])) {
1992: found = true;
1993: if (subjf[i])
1994: error(test, n + 50);
1995: subjf[i] = true;
1996: }
1997: }
1998: if (!found)
1999: error(test, n + 60);
2000: }
2001: for (int i = 0; i < num; i++) {
2002: if (subjf[i])
2003: error(test, n + 70 + i);
2004: }
2005:
2006: n = 300;
2007: // System.out.println( "* -- n := " + n );
2008: for (int i = 0; i < num; i++) {
2009: subjf[i] = false;
2010: }
2011: found = false;
2012: rIter = m.listResourcesWithProperty(predicate[0],
2013: (byte) tvLong[0]);
2014: while (rIter.hasNext()) {
2015: Resource subj = rIter.nextResource();
2016: // System.out.println( "+ " + subj );
2017: found = false;
2018: for (int i = 0; i < num; i++) {
2019: if (subj.equals(subject[i])) {
2020: found = true;
2021: if (subjf[i])
2022: error(test, n + 10);
2023: subjf[i] = true;
2024: }
2025: }
2026: if (!found)
2027: error(test, n + 20);
2028: }
2029:
2030: for (int i = 0; i < num; i++) {
2031: if (subjf[i]) {
2032: if (i > 1)
2033: error(test, n + 30 + i);
2034: } else {
2035: if (i < 2)
2036: error(test, n + 40 + i);
2037: }
2038: }
2039:
2040: for (int i = 0; i < num; i++) {
2041: subjf[i] = false;
2042: }
2043: found = false;
2044: rIter = m.listResourcesWithProperty(predicate[0],
2045: (byte) tvLong[1]);
2046: while (rIter.hasNext()) {
2047: Resource subj = rIter.nextResource();
2048: found = false;
2049: for (int i = 0; i < num; i++) {
2050: if (subj.equals(subject[i])) {
2051: found = true;
2052: if (subjf[i])
2053: error(test, n + 50);
2054: subjf[i] = true;
2055: }
2056: }
2057: if (!found)
2058: error(test, n + 60);
2059: }
2060:
2061: for (int i = 0; i < num; i++) {
2062: if (subjf[i])
2063: error(test, n + 70 + i);
2064: }
2065:
2066: n = 400;
2067: // System.out.println( "* -- n := " + n );
2068: for (int i = 0; i < num; i++) {
2069: subjf[i] = false;
2070: }
2071: found = false;
2072: rIter = m.listResourcesWithProperty(predicate[0],
2073: (short) tvLong[0]);
2074: while (rIter.hasNext()) {
2075: Resource subj = rIter.nextResource();
2076: found = false;
2077: for (int i = 0; i < num; i++) {
2078: if (subj.equals(subject[i])) {
2079: found = true;
2080: if (subjf[i])
2081: error(test, n + 10);
2082: subjf[i] = true;
2083: }
2084: }
2085: if (!found)
2086: error(test, n + 20);
2087: }
2088: for (int i = 0; i < num; i++) {
2089: if (subjf[i]) {
2090: if (i > 1)
2091: error(test, n + 30 + i);
2092: } else {
2093: if (i < 2)
2094: error(test, n + 40 + i);
2095: }
2096: }
2097:
2098: for (int i = 0; i < num; i++) {
2099: subjf[i] = false;
2100: }
2101: found = false;
2102: rIter = m.listResourcesWithProperty(predicate[0],
2103: (short) tvLong[1]);
2104: while (rIter.hasNext()) {
2105: Resource subj = rIter.nextResource();
2106: found = false;
2107: for (int i = 0; i < num; i++) {
2108: if (subj.equals(subject[i])) {
2109: found = true;
2110: if (subjf[i])
2111: error(test, n + 50);
2112: subjf[i] = true;
2113: }
2114: }
2115: if (!found)
2116: error(test, n + 60);
2117: }
2118: for (int i = 0; i < num; i++) {
2119: if (subjf[i])
2120: error(test, n + 70 + i);
2121: }
2122:
2123: n = 500;
2124: // System.out.println( "* -- n := " + n );
2125: for (int i = 0; i < num; i++) {
2126: subjf[i] = false;
2127: }
2128: found = false;
2129: rIter = m.listResourcesWithProperty(predicate[0],
2130: (int) tvLong[0]);
2131: while (rIter.hasNext()) {
2132: Resource subj = rIter.nextResource();
2133: found = false;
2134: for (int i = 0; i < num; i++) {
2135: if (subj.equals(subject[i])) {
2136: found = true;
2137: if (subjf[i])
2138: error(test, n + 10);
2139: subjf[i] = true;
2140: }
2141: }
2142: if (!found)
2143: error(test, n + 20);
2144: }
2145: for (int i = 0; i < num; i++) {
2146: if (subjf[i]) {
2147: if (i > 1)
2148: error(test, n + 30 + i);
2149: } else {
2150: if (i < 2)
2151: error(test, n + 40 + i);
2152: }
2153: }
2154:
2155: for (int i = 0; i < num; i++) {
2156: subjf[i] = false;
2157: }
2158: found = false;
2159: rIter = m.listResourcesWithProperty(predicate[0],
2160: (int) tvLong[1]);
2161: while (rIter.hasNext()) {
2162: Resource subj = rIter.nextResource();
2163: found = false;
2164: for (int i = 0; i < num; i++) {
2165: if (subj.equals(subject[i])) {
2166: found = true;
2167: if (subjf[i])
2168: error(test, n + 50);
2169: subjf[i] = true;
2170: }
2171: }
2172: if (!found)
2173: error(test, n + 60);
2174: }
2175: for (int i = 0; i < num; i++) {
2176: if (subjf[i])
2177: error(test, n + 70 + i);
2178: }
2179:
2180: // System.out.println( "* -- n := " + n );
2181: n = 600;
2182: // System.out.println( "* -- n := " + n );
2183: for (int i = 0; i < num; i++) {
2184: subjf[i] = false;
2185: }
2186: found = false;
2187: rIter = m
2188: .listResourcesWithProperty(predicate[0], tvLong[0]);
2189: while (rIter.hasNext()) {
2190: Resource subj = rIter.nextResource();
2191: found = false;
2192: for (int i = 0; i < num; i++) {
2193: if (subj.equals(subject[i])) {
2194: found = true;
2195: if (subjf[i])
2196: error(test, n + 10);
2197: subjf[i] = true;
2198: }
2199: }
2200: if (!found)
2201: error(test, n + 20);
2202: }
2203: for (int i = 0; i < num; i++) {
2204: if (subjf[i]) {
2205: if (i > 1)
2206: error(test, n + 30 + i);
2207: } else {
2208: if (i < 2)
2209: error(test, n + 40 + i);
2210: }
2211: }
2212:
2213: for (int i = 0; i < num; i++) {
2214: subjf[i] = false;
2215: }
2216: found = false;
2217: rIter = m
2218: .listResourcesWithProperty(predicate[0], tvLong[1]);
2219: while (rIter.hasNext()) {
2220: Resource subj = rIter.nextResource();
2221: found = false;
2222: for (int i = 0; i < num; i++) {
2223: if (subj.equals(subject[i])) {
2224: found = true;
2225: if (subjf[i])
2226: error(test, n + 50);
2227: subjf[i] = true;
2228: }
2229: }
2230: if (!found)
2231: error(test, n + 60);
2232: }
2233: for (int i = 0; i < num; i++) {
2234: if (subjf[i])
2235: error(test, n + 70 + i);
2236: }
2237:
2238: n = 700;
2239: for (int i = 0; i < num; i++) {
2240: subjf[i] = false;
2241: }
2242: found = false;
2243: rIter = m
2244: .listResourcesWithProperty(predicate[0], tvChar[0]);
2245: while (rIter.hasNext()) {
2246: Resource subj = rIter.nextResource();
2247: found = false;
2248: for (int i = 0; i < num; i++) {
2249: if (subj.equals(subject[i])) {
2250: found = true;
2251: if (subjf[i])
2252: error(test, n + 10);
2253: subjf[i] = true;
2254: }
2255: }
2256: if (!found)
2257: error(test, n + 20);
2258: }
2259: for (int i = 0; i < num; i++) {
2260: if (subjf[i]) {
2261: if (i > 1)
2262: error(test, n + 30 + i);
2263: } else {
2264: if (i < 2)
2265: error(test, n + 40 + i);
2266: }
2267: }
2268:
2269: for (int i = 0; i < num; i++) {
2270: subjf[i] = false;
2271: }
2272: found = false;
2273: rIter = m
2274: .listResourcesWithProperty(predicate[0], tvChar[1]);
2275: while (rIter.hasNext()) {
2276: Resource subj = rIter.nextResource();
2277: found = false;
2278: for (int i = 0; i < num; i++) {
2279: if (subj.equals(subject[i])) {
2280: found = true;
2281: if (subjf[i])
2282: error(test, n + 50);
2283: subjf[i] = true;
2284: }
2285: }
2286: if (!found)
2287: error(test, n + 60);
2288: }
2289: for (int i = 0; i < num; i++) {
2290: if (subjf[i])
2291: error(test, n + 70 + i);
2292: }
2293:
2294: n = 800;
2295: // System.out.println( "* -- n := " + n );
2296: for (int i = 0; i < num; i++) {
2297: subjf[i] = false;
2298: }
2299: found = false;
2300: rIter = m.listResourcesWithProperty(predicate[0], m
2301: .createTypedLiteral(tvDouble[0]));
2302: while (rIter.hasNext()) {
2303: Resource subj = rIter.nextResource();
2304: found = false;
2305: for (int i = 0; i < num; i++) {
2306: if (subj.equals(subject[i])) {
2307: found = true;
2308: if (subjf[i])
2309: error(test, n + 10);
2310: subjf[i] = true;
2311: }
2312: }
2313: if (!found)
2314: error(test, n + 20);
2315: }
2316: for (int i = 0; i < num; i++) {
2317: if (subjf[i]) {
2318: if (i > 1)
2319: error(test, n + 30 + i);
2320: } else {
2321: if (i < 2)
2322: error(test, n + 40 + i);
2323: }
2324: }
2325:
2326: for (int i = 0; i < num; i++) {
2327: subjf[i] = false;
2328: }
2329: found = false;
2330: rIter = m.listResourcesWithProperty(predicate[0], m
2331: .createTypedLiteral(tvDouble[1]));
2332: while (rIter.hasNext()) {
2333: Resource subj = rIter.nextResource();
2334: found = false;
2335: for (int i = 0; i < num; i++) {
2336: if (subj.equals(subject[i])) {
2337: found = true;
2338: if (subjf[i])
2339: error(test, n + 50);
2340: subjf[i] = true;
2341: }
2342: }
2343: if (!found)
2344: error(test, n + 60);
2345: }
2346: for (int i = 0; i < num; i++) {
2347: if (subjf[i])
2348: error(test, n + 70 + i);
2349: }
2350:
2351: n = 900;
2352: // System.out.println( "* -- n := " + n );
2353: for (int i = 0; i < num; i++) {
2354: subjf[i] = false;
2355: }
2356: found = false;
2357: rIter = m.listResourcesWithProperty(predicate[0], m
2358: .createTypedLiteral(tvDouble[0]));
2359: while (rIter.hasNext()) {
2360: Resource subj = rIter.nextResource();
2361: found = false;
2362: for (int i = 0; i < num; i++) {
2363: if (subj.equals(subject[i])) {
2364: found = true;
2365: if (subjf[i])
2366: error(test, n + 10);
2367: subjf[i] = true;
2368: }
2369: }
2370: if (!found)
2371: error(test, n + 20);
2372: }
2373: for (int i = 0; i < num; i++) {
2374: if (subjf[i]) {
2375: if (i > 1)
2376: error(test, n + 30 + i);
2377: } else {
2378: if (i < 2)
2379: error(test, n + 40 + i);
2380: }
2381: }
2382:
2383: for (int i = 0; i < num; i++) {
2384: subjf[i] = false;
2385: }
2386: found = false;
2387: rIter = m.listResourcesWithProperty(predicate[0], m
2388: .createTypedLiteral(tvDouble[1]));
2389: while (rIter.hasNext()) {
2390: Resource subj = rIter.nextResource();
2391: found = false;
2392: for (int i = 0; i < num; i++) {
2393: if (subj.equals(subject[i])) {
2394: found = true;
2395: if (subjf[i])
2396: error(test, n + 50);
2397: subjf[i] = true;
2398: }
2399: }
2400: if (!found)
2401: error(test, n + 60);
2402: }
2403: for (int i = 0; i < num; i++) {
2404: if (subjf[i])
2405: error(test, n + 70 + i);
2406: }
2407:
2408: n = 1000;
2409: // System.out.println( "* -- n := " + n );
2410: for (int i = 0; i < num; i++) {
2411: subjf[i] = false;
2412: }
2413: found = false;
2414: rIter = m.listSubjectsWithProperty(predicate[0],
2415: tvString[0]);
2416: while (rIter.hasNext()) {
2417: Resource subj = rIter.nextResource();
2418: found = false;
2419: for (int i = 0; i < num; i++) {
2420: if (subj.equals(subject[i])) {
2421: found = true;
2422: if (subjf[i])
2423: error(test, n + 10);
2424: subjf[i] = true;
2425: }
2426: }
2427: if (!found)
2428: error(test, n + 20);
2429: }
2430: for (int i = 0; i < num; i++) {
2431: if (subjf[i]) {
2432: if (i > 1)
2433: error(test, n + 30 + i);
2434: } else {
2435: if (i < 2)
2436: error(test, n + 40 + i);
2437: }
2438: }
2439:
2440: for (int i = 0; i < num; i++) {
2441: subjf[i] = false;
2442: }
2443: found = false;
2444: rIter = m.listSubjectsWithProperty(predicate[0],
2445: tvString[1]);
2446: while (rIter.hasNext()) {
2447: Resource subj = rIter.nextResource();
2448: found = false;
2449: for (int i = 0; i < num; i++) {
2450: if (subj.equals(subject[i])) {
2451: found = true;
2452: if (subjf[i])
2453: error(test, n + 50);
2454: subjf[i] = true;
2455: }
2456: }
2457: if (!found)
2458: error(test, n + 60);
2459: }
2460: for (int i = 0; i < num; i++) {
2461: if (subjf[i])
2462: error(test, n + 70 + i);
2463: }
2464:
2465: n = 1100;
2466: // System.out.println( "* -- n := " + n );
2467: for (int i = 0; i < num; i++) {
2468: subjf[i] = false;
2469: }
2470: found = false;
2471: rIter = m.listSubjectsWithProperty(predicate[0],
2472: tvString[0], lang[0]);
2473: while (rIter.hasNext()) {
2474: Resource subj = rIter.nextResource();
2475: found = false;
2476: for (int i = 0; i < num; i++) {
2477: if (subj.equals(subject[i])) {
2478: found = true;
2479: if (subjf[i])
2480: error(test, n + 10);
2481: subjf[i] = true;
2482: }
2483: }
2484: if (!found)
2485: error(test, n + 20);
2486: }
2487: for (int i = 0; i < num; i++) {
2488: if (subjf[i]) {
2489: if (i > 1)
2490: error(test, n + 30 + i);
2491: } else {
2492: if (i < 2)
2493: error(test, n + 40 + i);
2494: }
2495: }
2496:
2497: for (int i = 0; i < num; i++) {
2498: subjf[i] = false;
2499: }
2500: found = false;
2501: rIter = m.listSubjectsWithProperty(predicate[0],
2502: tvString[1]);
2503: while (rIter.hasNext()) {
2504: Resource subj = rIter.nextResource();
2505: found = false;
2506: for (int i = 0; i < num; i++) {
2507: if (subj.equals(subject[i])) {
2508: found = true;
2509: if (subjf[i])
2510: error(test, n + 50);
2511: subjf[i] = true;
2512: }
2513: }
2514: if (!found)
2515: error(test, n + 60);
2516: }
2517: for (int i = 0; i < num; i++) {
2518: if (subjf[i])
2519: error(test, n + 70 + i);
2520: }
2521:
2522: n = 1200;
2523: // System.out.println( "* -- n := " + n );
2524: for (int i = 0; i < num; i++) {
2525: subjf[i] = false;
2526: }
2527: found = false;
2528: rIter = m.listResourcesWithProperty(predicate[0],
2529: tvLitObj[0]);
2530: while (rIter.hasNext()) {
2531: Resource subj = rIter.nextResource();
2532: found = false;
2533: for (int i = 0; i < num; i++) {
2534: if (subj.equals(subject[i])) {
2535: found = true;
2536: if (subjf[i])
2537: error(test, n + 10);
2538: subjf[i] = true;
2539: }
2540: }
2541: if (!found)
2542: error(test, n + 20);
2543: }
2544: for (int i = 0; i < num; i++) {
2545: if (subjf[i]) {
2546: if (i > 1)
2547: error(test, n + 30 + i);
2548: } else {
2549: if (i < 2)
2550: error(test, n + 40 + i);
2551: }
2552: }
2553:
2554: for (int i = 0; i < num; i++) {
2555: subjf[i] = false;
2556: }
2557: found = false;
2558: rIter = m.listResourcesWithProperty(predicate[0],
2559: tvLitObj[1]);
2560: while (rIter.hasNext()) {
2561: Resource subj = rIter.nextResource();
2562: found = false;
2563: for (int i = 0; i < num; i++) {
2564: if (subj.equals(subject[i])) {
2565: found = true;
2566: if (subjf[i])
2567: error(test, n + 50);
2568: subjf[i] = true;
2569: }
2570: }
2571: if (!found)
2572: error(test, n + 60);
2573: }
2574: for (int i = 0; i < num; i++) {
2575: if (subjf[i])
2576: error(test, n + 70 + i);
2577: }
2578:
2579: n = 1300;
2580: // System.out.println( "* -- n := " + n );
2581: for (int i = 0; i < num; i++) {
2582: subjf[i] = false;
2583: }
2584: found = false;
2585: rIter = m.listResourcesWithProperty(predicate[0],
2586: tvResObj[0]);
2587: while (rIter.hasNext()) {
2588: Resource subj = rIter.nextResource();
2589: found = false;
2590: for (int i = 0; i < num; i++) {
2591: if (subj.equals(subject[i])) {
2592: found = true;
2593: if (subjf[i])
2594: error(test, n + 10);
2595: subjf[i] = true;
2596: }
2597: }
2598: if (!found)
2599: error(test, n + 20);
2600: }
2601: for (int i = 0; i < num; i++) {
2602: if (subjf[i]) {
2603: if (i > 1)
2604: error(test, n + 30 + i);
2605: } else {
2606: if (i < 2)
2607: error(test, n + 40 + i);
2608: }
2609: }
2610:
2611: for (int i = 0; i < num; i++) {
2612: subjf[i] = false;
2613: }
2614: found = false;
2615: rIter = m.listResourcesWithProperty(predicate[0],
2616: tvResObj[1]);
2617: while (rIter.hasNext()) {
2618: Resource subj = rIter.nextResource();
2619: found = false;
2620: for (int i = 0; i < num; i++) {
2621: if (subj.equals(subject[i])) {
2622: found = true;
2623: if (subjf[i])
2624: error(test, n + 50);
2625: subjf[i] = true;
2626: }
2627: }
2628: if (!found)
2629: error(test, n + 60);
2630: }
2631: for (int i = 0; i < num; i++) {
2632: if (subjf[i])
2633: error(test, n + 70 + i);
2634: }
2635:
2636: n = 1400;
2637: // System.out.println( "* -- n := " + n );
2638: for (int i = 0; i < num; i++) {
2639: subjf[i] = false;
2640: }
2641: NodeIterator nIter = m.listObjectsOfProperty(predicate[1]);
2642: while (nIter.hasNext()) {
2643: RDFNode obj = nIter.nextNode();
2644: found = false;
2645: for (int i = 0; i < numObj; i++) {
2646: if (obj.equals(object[i])) {
2647: found = true;
2648: if (objf[i])
2649: error(test, n + 50);
2650: objf[i] = true;
2651: }
2652: }
2653: if (!found)
2654: error(test, n + 60);
2655: }
2656: for (int i = 0; i < numObj; i++) {
2657: if (!objf[i])
2658: error(test, n + 70 + i);
2659: }
2660:
2661: } catch (Exception e) {
2662: logger.error("test " + test + "[" + n + "]", e);
2663: errors = true;
2664: }
2665: // System.out.println("End of " + test);
2666: }
2667:
2668: /** test the list statements methods of model
2669: * @param m the model implementation under test
2670: */
2671: public void test9(Model m) {
2672: String test = "Test9";
2673: int n = 0;
2674: int num = 2;
2675:
2676: Resource subject[] = new Resource[num];
2677: Property predicate[] = new Property[num];
2678: Vector stmtv = new Vector();
2679: Statement stmts[];
2680: Statement stmt;
2681:
2682: String suri = "http://aldabaran/test9/s";
2683: String puri = "http://aldabaran/test9/";
2684:
2685: boolean tvBoolean[] = { false, true };
2686: long tvLong[] = { 123, 321 };
2687: char tvChar[] = { '@', ';' };
2688: double tvDouble[] = { 123.456, 456.123 };
2689: String tvString[] = { "test8 testing string 1",
2690: "test8 testing string 2" };
2691: String lang[] = { "en", "fr" };
2692:
2693: // System.out.println("Beginning " + test);
2694:
2695: try {
2696: Literal tvLitObj[] = {
2697: m.createTypedLiteral(new LitTestObjF()),
2698: m.createTypedLiteral(new LitTestObjF()) };
2699: Resource tvResObj[] = {
2700: m.createResource(new ResTestObjF()),
2701: m.createResource(new ResTestObjF()) };
2702:
2703: for (int i = 0; i < num; i++) {
2704: subject[i] = m.createResource(suri
2705: + Integer.toString(i));
2706: predicate[i] = m.createProperty(puri
2707: + Integer.toString(i), "p");
2708: }
2709:
2710: for (int i = 0; i < num; i++) {
2711: for (int j = 0; j < num; j++) {
2712: stmt = m.createLiteralStatement(subject[i],
2713: predicate[j], tvBoolean[j]);
2714: m.add(stmt);
2715: stmt = m.createLiteralStatement(subject[i],
2716: predicate[j], tvLong[j]);
2717: m.add(stmt);
2718: stmt = m.createLiteralStatement(subject[i],
2719: predicate[j], tvChar[j]);
2720: m.add(stmt);
2721: stmt = m.createStatement(subject[i], predicate[j],
2722: m.createTypedLiteral(tvDouble[j]));
2723: m.add(stmt);
2724: stmt = m.createStatement(subject[i], predicate[j],
2725: tvString[j]);
2726: m.add(stmt);
2727: stmt = m.createStatement(subject[i], predicate[j],
2728: tvString[j], lang[j]);
2729: m.add(stmt);
2730: stmt = m.createStatement(subject[i], predicate[j],
2731: tvLitObj[j]);
2732: m.add(stmt);
2733: stmt = m.createStatement(subject[i], predicate[j],
2734: tvResObj[j]);
2735: m.add(stmt);
2736: }
2737: }
2738:
2739: StmtIterator iter;
2740: n = 100;
2741: int count = 0;
2742: n++;
2743: iter = m.listStatements(new SimpleSelector(null, null,
2744: (RDFNode) null));
2745: while (iter.hasNext()) {
2746: iter.nextStatement();
2747: count++;
2748: }
2749: n++;
2750: iter.close();
2751: n++;
2752: if (!(count == num * num * 8)) {
2753: error(test, n);
2754: System.err.println(count);
2755: }
2756:
2757: n = 110;
2758: count = 0;
2759: n++;
2760: iter = m.listStatements(new SimpleSelector(subject[0],
2761: null, (RDFNode) null));
2762: while (iter.hasNext()) {
2763: stmt = iter.nextStatement();
2764: if (!stmt.getSubject().equals(subject[0]))
2765: error(test, n);
2766: count++;
2767: }
2768: n++;
2769: iter.close();
2770: n++;
2771: if (!(count == num * 8))
2772: error(test, n);
2773:
2774: n = 120;
2775: count = 0;
2776: n++;
2777: iter = m.listStatements(new SimpleSelector(null,
2778: predicate[1], (RDFNode) null));
2779: while (iter.hasNext()) {
2780: stmt = iter.nextStatement();
2781: if (!stmt.getPredicate().equals(predicate[1]))
2782: error(test, n);
2783: count++;
2784: }
2785: n++;
2786: iter.close();
2787: n++;
2788: if (!(count == num * 8))
2789: error(test, n);
2790:
2791: n = 130;
2792: count = 0;
2793: n++;
2794: iter = m.listStatements(new SimpleSelector(null, null,
2795: tvResObj[1]));
2796: while (iter.hasNext()) {
2797: stmt = iter.nextStatement();
2798: if (!stmt.getObject().equals(tvResObj[1]))
2799: error(test, n);
2800: count++;
2801: }
2802: n++;
2803: iter.close();
2804: n++;
2805: if (!(count == 2))
2806: error(test, n);
2807:
2808: n = 140;
2809: count = 0;
2810: n++;
2811: iter = m.listStatements(new SimpleSelector(null, null, m
2812: .createTypedLiteral(false)));
2813: while (iter.hasNext()) {
2814: stmt = iter.nextStatement();
2815: if (stmt.getBoolean())
2816: error(test, n);
2817: count++;
2818: }
2819: n++;
2820: iter.close();
2821: n++;
2822: if (!(count == 2))
2823: error(test, n);
2824:
2825: n = 150;
2826: count = 0;
2827: n++;
2828: iter = m.listStatements(new SimpleSelector(null, null,
2829: tvString[1], lang[1]));
2830: n++;
2831: while (iter.hasNext()) {
2832: stmt = iter.nextStatement();
2833: if (!stmt.getLanguage().equals(lang[1]))
2834: error(test, n);
2835: count++;
2836: }
2837: n++;
2838: iter.close();
2839: n++;
2840: if (!(count == 2))
2841: error(test, n);
2842:
2843: } catch (Exception e) {
2844: logger.error("test " + test + "[" + n + "]", e);
2845: errors = true;
2846: }
2847: // System.out.println("End of " + test);
2848: }
2849:
2850: /** test the query statements methods of model
2851: * @param m the model implementation under test
2852: */
2853: public void test10(Model m) {
2854: String test = "Test10";
2855: int n = 0;
2856: int num = 2;
2857:
2858: Resource subject[] = new Resource[num];
2859: Property predicate[] = new Property[num];
2860: Vector stmtv = new Vector();
2861: Statement stmts[];
2862: Statement stmt;
2863:
2864: String suri = "http://aldabaran/test10/s";
2865: String puri = "http://aldabaran/test10/";
2866:
2867: boolean tvBoolean[] = { false, true };
2868: long tvLong[] = { 123, 321 };
2869: char tvChar[] = { '@', ';' };
2870: double tvDouble[] = { 123.456, 456.123 };
2871: String tvString[] = { "test8 testing string 1",
2872: "test8 testing string 2" };
2873: String lang[] = { "en", "fr" };
2874:
2875: // System.out.println("Beginning " + test);
2876:
2877: try {
2878: Literal tvLitObj[] = {
2879: m.createTypedLiteral(new LitTestObj(1)),
2880: m.createTypedLiteral(new LitTestObj(2)) };
2881: Resource tvResObj[] = {
2882: m.createResource(new ResTestObjF()),
2883: m.createResource(new ResTestObjF()) };
2884:
2885: for (int i = 0; i < num; i++) {
2886: subject[i] = m.createResource(suri
2887: + Integer.toString(i));
2888: predicate[i] = m.createProperty(puri
2889: + Integer.toString(i), "p");
2890: }
2891:
2892: for (int i = 0; i < num; i++) {
2893: for (int j = 0; j < num; j++) {
2894: stmt = m.createLiteralStatement(subject[i],
2895: predicate[j], tvBoolean[j]);
2896: m.add(stmt);
2897: stmt = m.createLiteralStatement(subject[i],
2898: predicate[j], tvLong[j]);
2899: m.add(stmt);
2900: stmt = m.createLiteralStatement(subject[i],
2901: predicate[j], tvChar[j]);
2902: m.add(stmt);
2903: stmt = m.createStatement(subject[i], predicate[j],
2904: m.createTypedLiteral(tvDouble[j]));
2905: m.add(stmt);
2906: stmt = m.createStatement(subject[i], predicate[j],
2907: tvString[j]);
2908: m.add(stmt);
2909: stmt = m.createStatement(subject[i], predicate[j],
2910: tvString[j], lang[i]);
2911: m.add(stmt);
2912: stmt = m.createStatement(subject[i], predicate[j],
2913: tvLitObj[j]);
2914: m.add(stmt);
2915: stmt = m.createStatement(subject[i], predicate[j],
2916: tvResObj[j]);
2917: m.add(stmt);
2918: stmt = m.createStatement(subject[i], predicate[j],
2919: tvResObj[j]);
2920: m.add(stmt);
2921: }
2922: }
2923:
2924: Model mm;
2925: StmtIterator iter;
2926: n = 100;
2927: int count = 0;
2928: n++;
2929: mm = m
2930: .query(new SimpleSelector(null, null,
2931: (RDFNode) null));
2932: n++;
2933: iter = mm.listStatements();
2934: while (iter.hasNext()) {
2935: iter.nextStatement();
2936: count++;
2937: }
2938: n++;
2939: iter.close();
2940: n++;
2941: if (!(count == num * num * 8))
2942: error(test, n);
2943: n++;
2944: if (!(mm.size() == count))
2945: error(test, n);
2946:
2947: n = 110;
2948: count = 0;
2949: n++;
2950: mm = m.query(new SimpleSelector(subject[0], null,
2951: (RDFNode) null));
2952: n++;
2953: iter = mm.listStatements();
2954: while (iter.hasNext()) {
2955: stmt = iter.nextStatement();
2956: if (!stmt.getSubject().equals(subject[0]))
2957: error(test, n);
2958: count++;
2959: }
2960: n++;
2961: iter.close();
2962: n++;
2963: if (!(count == num * 8))
2964: error(test, n);
2965: n++;
2966: if (!(mm.size() == count))
2967: error(test, n);
2968:
2969: n = 120;
2970: count = 0;
2971: n++;
2972: mm = m.query(new SimpleSelector(null, predicate[1],
2973: (RDFNode) null));
2974: n++;
2975: iter = mm.listStatements();
2976: while (iter.hasNext()) {
2977: stmt = iter.nextStatement();
2978: if (!stmt.getPredicate().equals(predicate[1]))
2979: error(test, n);
2980: count++;
2981: }
2982: n++;
2983: iter.close();
2984: n++;
2985: if (!(count == num * 8))
2986: error(test, n);
2987: n++;
2988: if (!(mm.size() == count))
2989: error(test, n);
2990:
2991: n = 130;
2992: count = 0;
2993: n++;
2994: mm = m.query(new SimpleSelector(null, null, tvResObj[1]));
2995: n++;
2996: iter = mm.listStatements();
2997: while (iter.hasNext()) {
2998: stmt = iter.nextStatement();
2999: if (!stmt.getObject().equals(tvResObj[1]))
3000: error(test, n);
3001: count++;
3002: }
3003: n++;
3004: iter.close();
3005: n++;
3006: if (!(count == 2))
3007: error(test, n);
3008: n++;
3009: if (!(mm.size() == count))
3010: error(test, n);
3011:
3012: n = 140;
3013: count = 0;
3014: n++;
3015: mm = m.query(new SimpleSelector(null, null, m
3016: .createTypedLiteral(false)));
3017: n++;
3018: iter = mm.listStatements();
3019: while (iter.hasNext()) {
3020: stmt = iter.nextStatement();
3021: if (stmt.getBoolean())
3022: error(test, n);
3023: count++;
3024: }
3025: n++;
3026: iter.close();
3027: n++;
3028: if (!(count == 2))
3029: error(test, n);
3030: n++;
3031: if (!(mm.size() == count))
3032: error(test, n);
3033:
3034: n = 150;
3035: n++;
3036: mm = m.query(new SimpleSelector(null, null, tvString[1],
3037: lang[0]));
3038: n++;
3039: if (!(mm.size() == 1))
3040: error(test, n);
3041: n++;
3042: iter = mm.listStatements();
3043: n++;
3044: while (iter.hasNext()) {
3045: stmt = iter.nextStatement();
3046: if (!stmt.getLanguage().equals(lang[0]))
3047: error(test, n);
3048: }
3049: iter.close();
3050:
3051: } catch (Exception e) {
3052: logger.error("test " + test + "[" + n + "]", e);
3053: errors = true;
3054: }
3055: // System.out.println("End of " + test);
3056: }
3057:
3058: /** test model set operations
3059: * @param m the model implementation under test
3060: */
3061: public void test11(Model m1, Model m2) {
3062: String test = "Test11";
3063: int n = 0;
3064: Statement stmt;
3065:
3066: Model um = null;
3067: Model im = null;
3068: Model dm = null;
3069:
3070: if (!(m1.supportsSetOperations() // jjc
3071: && m2.supportsSetOperations())) // jjc
3072: return; // jjc
3073:
3074: try {
3075: StmtIterator iter;
3076: // System.out.println("Beginning " + test);
3077:
3078: try {
3079: n = 100;
3080: m2.addLiteral(m2.createResource(new ResTestObjF()),
3081: RDF.value, 1);
3082: if (m1.containsAll(m2))
3083: error(test, n);
3084: n++;
3085: um = m1.union(m2);
3086: n++;
3087: iter = um.listStatements();
3088: while (iter.hasNext()) {
3089: stmt = iter.nextStatement();
3090: if (!(m1.contains(stmt) || m2.contains(stmt))) {
3091: System.out.println(stmt.toString());
3092: error(test, n);
3093: }
3094: }
3095: n++;
3096: iter.close();
3097: n++;
3098: iter = m1.listStatements();
3099: while (iter.hasNext()) {
3100: stmt = iter.nextStatement();
3101: if (!um.contains(stmt))
3102: error(test, n);
3103: }
3104: n++;
3105: iter.close();
3106: n++;
3107: iter = m2.listStatements();
3108: while (iter.hasNext()) {
3109: stmt = iter.nextStatement();
3110: if (!um.contains(stmt))
3111: error(test, n);
3112: }
3113: n++;
3114: iter.close();
3115:
3116: n++;
3117: if (!um.containsAll(m1))
3118: error(test, n);
3119: n++;
3120: if (!um.containsAll(m2))
3121: error(test, n);
3122: n++;
3123: iter = m1.listStatements();
3124: n++;
3125: if (!um.containsAll(iter))
3126: error(test, n);
3127: iter.close();
3128: } catch (Exception e) {
3129: error(test, n, e);
3130: }
3131:
3132: try {
3133: n = 200;
3134: im = um.intersection(m1);
3135: n++;
3136: iter = im.listStatements();
3137: while (iter.hasNext()) {
3138: stmt = iter.nextStatement();
3139: if (!(um.contains(stmt) && m1.contains(stmt)))
3140: error(test, n);
3141: }
3142: n++;
3143: iter.close();
3144: n++;
3145: iter = um.listStatements();
3146: while (iter.hasNext()) {
3147: stmt = iter.nextStatement();
3148: if (m1.contains(stmt)) {
3149: if (!im.contains(stmt))
3150: error(test, n);
3151: }
3152: }
3153: n++;
3154: iter.close();
3155: n++;
3156: iter = m1.listStatements();
3157: while (iter.hasNext()) {
3158: stmt = iter.nextStatement();
3159: if (m1.contains(stmt)) {
3160: if (!im.contains(stmt))
3161: error(test, n);
3162: }
3163: }
3164: n++;
3165: iter.close();
3166: } catch (Exception e) {
3167: error(test, n, e);
3168: }
3169:
3170: try {
3171: n = 300;
3172: dm = um.difference(m2);
3173: n++;
3174: iter = dm.listStatements();
3175: while (iter.hasNext()) {
3176: stmt = iter.nextStatement();
3177: if (!(um.contains(stmt) && !(m2.contains(stmt))))
3178: error(test, n);
3179: }
3180: n++;
3181: iter.close();
3182: n++;
3183: iter = um.listStatements();
3184: while (iter.hasNext()) {
3185: stmt = iter.nextStatement();
3186: if (m2.contains(stmt)) {
3187: if (dm.contains(stmt))
3188: error(test, n);
3189: } else {
3190: if (!dm.contains(stmt))
3191: error(test, 1000 + n);
3192: }
3193: }
3194: n++;
3195: iter.close();
3196: n++;
3197: iter = m2.listStatements();
3198: while (iter.hasNext()) {
3199: stmt = iter.nextStatement();
3200: if (dm.contains(stmt))
3201: error(test, n);
3202: }
3203: n++;
3204: iter.close();
3205: n++;
3206: if (dm.containsAny(m2))
3207: error(test, n);
3208: n++;
3209: iter = m2.listStatements();
3210: n++;
3211: if (dm.containsAny(iter))
3212: error(test, n);
3213: n++;
3214: iter.close();
3215: } catch (Exception e) {
3216: error(test, n, e);
3217: }
3218: } catch (Exception e) {
3219: logger.error("test " + test + "[" + n + "]", e);
3220: errors = true;
3221: }
3222: // System.out.println("End of " + test);
3223: }
3224:
3225: /** test Resource methods
3226: * @param m the model implementation under test
3227: */
3228: public void test12(Model m) {
3229: String test = "Test12";
3230: int n = 0;
3231:
3232: try {
3233: StmtIterator iter;
3234: // System.out.println("Beginning " + test);
3235: Resource r = m.createResource();
3236: boolean tvBoolean = true;
3237: byte tvByte = 1;
3238: short tvShort = 2;
3239: int tvInt = -1;
3240: long tvLong = -2;
3241: char tvChar = '!';
3242: float tvFloat = (float) 123.456;
3243: double tvDouble = -123.456;
3244: String tvString = "test 12 string";
3245: LitTestObj tvObject = new LitTestObj(12345);
3246: Literal tvLiteral = m.createLiteral("test 12 string 2");
3247: Resource tvResource = m.createResource();
3248: String lang = "en";
3249: Statement stmt;
3250:
3251: n = 100;
3252: n++;
3253: if (!r.addLiteral(RDF.value, tvByte).hasLiteral(RDF.value,
3254: tvByte))
3255: error(test, n);
3256: n++;
3257: if (!r.addLiteral(RDF.value, tvShort).hasLiteral(RDF.value,
3258: tvShort))
3259: error(test, n);
3260: n++;
3261: if (!r.addLiteral(RDF.value, tvInt).hasLiteral(RDF.value,
3262: tvInt))
3263: error(test, n);
3264: n++;
3265: if (!r.addLiteral(RDF.value, tvLong).hasLiteral(RDF.value,
3266: tvLong))
3267: error(test, n);
3268: n++;
3269: if (!r.addLiteral(RDF.value, tvChar).hasLiteral(RDF.value,
3270: tvChar))
3271: error(test, n);
3272: n++;
3273: if (!r.addLiteral(RDF.value, tvFloat).hasLiteral(RDF.value,
3274: tvFloat))
3275: error(test, n);
3276: n++;
3277: if (!r.addLiteral(RDF.value, tvDouble).hasLiteral(
3278: RDF.value, tvDouble))
3279: error(test, n);
3280: n++;
3281: if (!r.addProperty(RDF.value, tvString).hasProperty(
3282: RDF.value, tvString))
3283: error(test, n);
3284: n++;
3285: if (!r.addProperty(RDF.value, tvString, lang).hasProperty(
3286: RDF.value, tvString, lang))
3287: error(test, n);
3288: n++;
3289: if (!r.addLiteral(RDF.value, tvObject).hasLiteral(
3290: RDF.value, tvObject))
3291: error(test, n);
3292: n++;
3293: if (!r.addProperty(RDF.value, tvLiteral).hasProperty(
3294: RDF.value, tvLiteral))
3295: error(test, n);
3296: n++;
3297: if (!r.addProperty(RDF.value, tvResource).hasProperty(
3298: RDF.value, tvResource))
3299: error(test, n);
3300: n++;
3301: if (!r.getRequiredProperty(RDF.value).getSubject()
3302: .equals(r))
3303: error(test, n);
3304: n++;
3305: try {
3306: r.getRequiredProperty(RDF.type);
3307: error(test, n);
3308: } catch (PropertyNotFoundException e) { // as expected
3309: }
3310: n++;
3311: iter = r.listProperties(RDF.value);
3312: int count = 0;
3313: while (iter.hasNext()) {
3314: stmt = iter.nextStatement();
3315: if (!stmt.getSubject().equals(r))
3316: error(test, n);
3317: count++;
3318: }
3319: n++;
3320: if (count != 12)
3321: error(test, n);
3322: n++;
3323: iter = r.listProperties(RDF.type);
3324: count = 0;
3325: while (iter.hasNext()) {
3326: stmt = iter.nextStatement();
3327: if (!stmt.getSubject().equals(r))
3328: error(test, n);
3329: count++;
3330: }
3331: n++;
3332: if (count != 0)
3333: error(test, n);
3334: n++;
3335: iter = r.listProperties();
3336: count = 0;
3337: while (iter.hasNext()) {
3338: stmt = iter.nextStatement();
3339: if (!stmt.getSubject().equals(r))
3340: error(test, n);
3341: count++;
3342: }
3343: n++;
3344: if (count != 12)
3345: error(test, n);
3346:
3347: n++;
3348: r.removeProperties();
3349: n++;
3350: Model mm = m.query(new SimpleSelector(r, null,
3351: (RDFNode) null));
3352: if (!(mm.size() == 0))
3353: error(test, n);
3354:
3355: } catch (Exception e) {
3356: logger.error("test " + test + "[" + n + "]", e);
3357: errors = true;
3358: }
3359: // System.out.println("End of " + test);
3360: }
3361:
3362: /** Test Statement methods
3363: * @param m the model implementation under test
3364: */
3365: public void test13(Model m) {
3366: String test = "Test13";
3367: int n = 0;
3368:
3369: try {
3370: StmtIterator iter;
3371: // System.out.println("Beginning " + test);
3372: Resource r = m.createResource();
3373: boolean tvBoolean = true;
3374: byte tvByte = 1;
3375: short tvShort = 2;
3376: int tvInt = -1;
3377: long tvLong = -2;
3378: char tvChar = '!';
3379: float tvFloat = (float) 123.456;
3380: double tvDouble = -123.456;
3381: String tvString = "test 12 string";
3382: LitTestObj tvObject = new LitTestObj(12345);
3383: Literal tvLiteral = m.createLiteral("test 12 string 2");
3384: Resource tvResObj = m.createResource(new ResTestObjF());
3385: Object tvLitObj = new LitTestObj(1234);
3386: Bag tvBag = m.createBag();
3387: Alt tvAlt = m.createAlt();
3388: Seq tvSeq = m.createSeq();
3389: Resource tvResource = m.createResource();
3390: String lang = "fr";
3391: Statement stmt;
3392:
3393: n = 100;
3394: n++;
3395: if (!m.createStatement(r, RDF.value, r).getResource()
3396: .equals(r))
3397: error(test, n);
3398: n++;
3399: try {
3400: m.createLiteralStatement(r, RDF.value, false)
3401: .getResource();
3402: error(test, n);
3403: } catch (ResourceRequiredException e) {
3404: // as required
3405: }
3406: n++;
3407: if (!m.createLiteralStatement(r, RDF.value, true)
3408: .getLiteral().getBoolean())
3409: error(test, n);
3410: n++;
3411: try {
3412: m.createStatement(r, RDF.value, r).getLiteral();
3413: error(test, n);
3414: } catch (LiteralRequiredException e) {
3415: // as required
3416: }
3417: n = 200;
3418: n++;
3419: if (!m.createLiteralStatement(r, RDF.value, true)
3420: .getBoolean())
3421: error(test, n);
3422: n++;
3423: if (!(m.createLiteralStatement(r, RDF.value, tvByte)
3424: .getByte() == tvByte))
3425: error(test, n);
3426: n++;
3427: if (!(m.createLiteralStatement(r, RDF.value, tvShort)
3428: .getShort() == tvShort))
3429: error(test, n);
3430: n++;
3431: if (!(m.createLiteralStatement(r, RDF.value, tvInt)
3432: .getInt() == tvInt))
3433: error(test, n);
3434: n++;
3435: if (!(m.createLiteralStatement(r, RDF.value, tvLong)
3436: .getLong() == tvLong))
3437: error(test, n);
3438: n++;
3439: if (!(m.createLiteralStatement(r, RDF.value, tvChar)
3440: .getChar() == tvChar))
3441: error(test, n);
3442: n++;
3443: if (!(m.createStatement(r, RDF.value,
3444: m.createTypedLiteral(tvFloat)).getFloat() == tvFloat))
3445: error(test, n);
3446: n++;
3447: if (!(m.createStatement(r, RDF.value,
3448: m.createTypedLiteral(tvDouble)).getDouble() == tvDouble))
3449: error(test, n);
3450: n++;
3451: if (!(m.createStatement(r, RDF.value, tvString).getString()
3452: .equals(tvString)))
3453: error(test, n);
3454: n++;
3455: if (!(m.createStatement(r, RDF.value, tvString, lang)
3456: .getString().equals(tvString)))
3457: error(test, n);
3458: n++;
3459: if (!(m.createStatement(r, RDF.value, tvString, lang)
3460: .getLanguage().equals(lang)))
3461: error(test, n);
3462: n++;
3463: if (!(m.createStatement(r, RDF.value, tvResObj)
3464: .getResource(new ResTestObjF()).equals(tvResObj)))
3465: error(test, n);
3466: n++;
3467: if (!(m.createLiteralStatement(r, RDF.value, tvLitObj)
3468: .getObject(new LitTestObjF()).equals(tvLitObj)))
3469: error(test, n);
3470: n++;
3471: if (!(m.createStatement(r, RDF.value, tvBag).getBag()
3472: .equals(tvBag)))
3473: error(test, n);
3474: n++;
3475: if (!(m.createStatement(r, RDF.value, tvAlt).getAlt()
3476: .equals(tvAlt)))
3477: error(test, n);
3478: n++;
3479: if (!(m.createStatement(r, RDF.value, tvSeq).getSeq()
3480: .equals(tvSeq)))
3481: error(test, n);
3482: n = 300;
3483: n++;
3484: stmt = m.createLiteralStatement(m.createResource(),
3485: RDF.value, tvBoolean);
3486: n++;
3487: m.add(stmt);
3488: n++;
3489: stmt = stmt.changeLiteralObject(!tvBoolean);
3490: n++;
3491: if (!(stmt.getBoolean() == !tvBoolean))
3492: error(test, n);
3493: n++;
3494: if (m.containsLiteral(stmt.getSubject(), RDF.value,
3495: tvBoolean))
3496: error(test, n);
3497: n++;
3498: if (!m.containsLiteral(stmt.getSubject(), RDF.value,
3499: !tvBoolean))
3500: error(test, n);
3501:
3502: n = 310;
3503: n++;
3504: stmt = m.createLiteralStatement(m.createResource(),
3505: RDF.value, tvBoolean);
3506: n++;
3507: m.add(stmt);
3508: n++;
3509: stmt = stmt.changeLiteralObject(tvByte);
3510: n++;
3511: if (!(stmt.getByte() == tvByte))
3512: error(test, n);
3513: n++;
3514: if (m.containsLiteral(stmt.getSubject(), RDF.value,
3515: tvBoolean))
3516: error(test, n);
3517: n++;
3518: if (!m
3519: .containsLiteral(stmt.getSubject(), RDF.value,
3520: tvByte))
3521: error(test, n);
3522:
3523: n = 320;
3524: n++;
3525: stmt = m.createLiteralStatement(m.createResource(),
3526: RDF.value, tvBoolean);
3527: n++;
3528: m.add(stmt);
3529: n++;
3530: stmt = stmt.changeLiteralObject(tvShort);
3531: n++;
3532: if (!(stmt.getShort() == tvShort))
3533: error(test, n);
3534: n++;
3535: if (m.containsLiteral(stmt.getSubject(), RDF.value,
3536: tvBoolean))
3537: error(test, n);
3538: n++;
3539: if (!m.containsLiteral(stmt.getSubject(), RDF.value,
3540: tvShort))
3541: error(test, n);
3542:
3543: n = 330;
3544: n++;
3545: stmt = m.createLiteralStatement(m.createResource(),
3546: RDF.value, tvBoolean);
3547: n++;
3548: m.add(stmt);
3549: n++;
3550: stmt = stmt.changeLiteralObject(tvInt);
3551: n++;
3552: if (!(stmt.getInt() == tvInt))
3553: error(test, n);
3554: n++;
3555: if (m.containsLiteral(stmt.getSubject(), RDF.value,
3556: tvBoolean))
3557: error(test, n);
3558: n++;
3559: if (!m.containsLiteral(stmt.getSubject(), RDF.value, tvInt))
3560: error(test, n);
3561:
3562: n = 340;
3563: n++;
3564: stmt = m.createLiteralStatement(m.createResource(),
3565: RDF.value, tvBoolean);
3566: n++;
3567: m.add(stmt);
3568: n++;
3569: stmt = stmt.changeLiteralObject(tvLong);
3570: n++;
3571: if (!(stmt.getLong() == tvLong))
3572: error(test, n);
3573: n++;
3574: if (m.containsLiteral(stmt.getSubject(), RDF.value,
3575: tvBoolean))
3576: error(test, n);
3577: n++;
3578: if (!m
3579: .containsLiteral(stmt.getSubject(), RDF.value,
3580: tvLong))
3581: error(test, n);
3582:
3583: n = 350;
3584: n++;
3585: stmt = m.createLiteralStatement(m.createResource(),
3586: RDF.value, tvBoolean);
3587: n++;
3588: m.add(stmt);
3589: n++;
3590: stmt = stmt.changeLiteralObject(tvChar);
3591: n++;
3592: if (!(stmt.getChar() == tvChar))
3593: error(test, n);
3594: n++;
3595: if (m.containsLiteral(stmt.getSubject(), RDF.value,
3596: tvBoolean))
3597: error(test, n);
3598: n++;
3599: if (!m
3600: .containsLiteral(stmt.getSubject(), RDF.value,
3601: tvChar))
3602: error(test, n);
3603:
3604: n = 360;
3605: n++;
3606: stmt = m.createLiteralStatement(m.createResource(),
3607: RDF.value, tvBoolean);
3608: n++;
3609: m.add(stmt);
3610: n++;
3611: stmt = stmt.changeLiteralObject(tvFloat);
3612: n++;
3613: if (!((stmt.getFloat() - tvFloat) < 0.00005))
3614: error(test, n);
3615: n++;
3616: if (m.containsLiteral(stmt.getSubject(), RDF.value,
3617: tvBoolean))
3618: error(test, n);
3619: n++;
3620: if (!m.containsLiteral(stmt.getSubject(), RDF.value,
3621: tvFloat))
3622: error(test, n);
3623:
3624: n = 370;
3625: n++;
3626: stmt = m.createLiteralStatement(m.createResource(),
3627: RDF.value, tvBoolean);
3628: n++;
3629: m.add(stmt);
3630: n++;
3631: stmt = stmt.changeLiteralObject(tvDouble);
3632: n++;
3633: if (!((stmt.getDouble() - tvDouble) < 0.0005))
3634: error(test, n);
3635: n++;
3636: if (m.containsLiteral(stmt.getSubject(), RDF.value,
3637: tvBoolean))
3638: error(test, n);
3639: n++;
3640: if (!m.containsLiteral(stmt.getSubject(), RDF.value,
3641: tvDouble))
3642: error(test, n);
3643:
3644: n = 380;
3645: n++;
3646: stmt = m.createLiteralStatement(m.createResource(),
3647: RDF.value, tvBoolean);
3648: n++;
3649: stmt = m.createLiteralStatement(m.createResource(),
3650: RDF.value, tvBoolean);
3651: n++;
3652: m.add(stmt);
3653: n++;
3654: stmt = stmt.changeObject(tvString);
3655: n++;
3656: if (!(stmt.getString().equals(tvString)))
3657: error(test, n);
3658: n++;
3659: if (m.containsLiteral(stmt.getSubject(), RDF.value,
3660: tvBoolean))
3661: error(test, n);
3662: n++;
3663: if (!m.contains(stmt.getSubject(), RDF.value, tvString))
3664: error(test, n);
3665: n++;
3666: stmt = stmt.changeObject(tvString, lang);
3667: n++;
3668: if (!(stmt.getString().equals(tvString)))
3669: error(test, n);
3670: n++;
3671: if (m.contains(stmt.getSubject(), RDF.value, tvString))
3672: error(test, n);
3673: n++;
3674: if (!m.contains(stmt.getSubject(), RDF.value, tvString,
3675: lang))
3676: error(test, n);
3677:
3678: n = 390;
3679: n++;
3680: stmt = m.createLiteralStatement(m.createResource(),
3681: RDF.value, tvBoolean);
3682: n++;
3683: m.add(stmt);
3684: n++;
3685: stmt = stmt.changeObject(tvResObj);
3686: n++;
3687: if (!(stmt.getResource().equals(tvResObj)))
3688: error(test, n);
3689: n++;
3690: if (m.containsLiteral(stmt.getSubject(), RDF.value,
3691: tvBoolean))
3692: error(test, n);
3693: n++;
3694: if (!m.contains(stmt.getSubject(), RDF.value, tvResObj))
3695: error(test, n);
3696:
3697: n = 400;
3698: n++;
3699: stmt = m.createLiteralStatement(m.createResource(),
3700: RDF.value, tvBoolean);
3701: n++;
3702: m.add(stmt);
3703: n++;
3704: stmt = stmt.changeObject(m.createTypedLiteral(tvLitObj));
3705: n++;
3706: if (!(stmt.getObject(new LitTestObjF()).equals(tvLitObj)))
3707: error(test, n);
3708: n++;
3709: if (m.containsLiteral(stmt.getSubject(), RDF.value,
3710: tvBoolean))
3711: error(test, n);
3712: n++;
3713: if (!m.containsLiteral(stmt.getSubject(), RDF.value,
3714: tvLitObj))
3715: error(test, n);
3716:
3717: n = 500;
3718: n++;
3719: stmt = m.createLiteralStatement(m.createResource(),
3720: RDF.value, tvBoolean);
3721: n++;
3722: m.add(stmt);
3723: n++;
3724: m.remove(stmt);
3725: n++;
3726: if (m.containsLiteral(stmt.getSubject(), RDF.value,
3727: tvBoolean))
3728: error(test, n);
3729: } catch (Exception e) {
3730: logger.error("test " + test + "[" + n + "]", e);
3731: errors = true;
3732: }
3733: // System.out.println("End of " + test);
3734: }
3735:
3736: /** test bag
3737: * @param m the model implementation under test
3738: */
3739: public void test14(Model m) {
3740: String test = "Test14";
3741: int n = 0;
3742:
3743: try {
3744: NodeIterator nIter;
3745: StmtIterator sIter;
3746: // System.out.println("Beginning " + test);
3747: boolean tvBoolean = true;
3748: byte tvByte = 1;
3749: short tvShort = 2;
3750: int tvInt = -1;
3751: long tvLong = -2;
3752: char tvChar = '!';
3753: float tvFloat = (float) 123.456;
3754: double tvDouble = -123.456;
3755: String tvString = "test 12 string";
3756: LitTestObj tvObject = new LitTestObj(12345);
3757: Literal tvLiteral = m.createLiteral("test 12 string 2");
3758: Resource tvResObj = m.createResource(new ResTestObjF());
3759: Object tvLitObj = new LitTestObj(1234);
3760: Bag tvBag = m.createBag();
3761: Alt tvAlt = m.createAlt();
3762: Seq tvSeq = m.createSeq();
3763: int num = 10;
3764: Statement stmt;
3765:
3766: n = 100;
3767: n++;
3768: Bag bag = m.createBag();
3769: n++;
3770: if (!m.contains(bag, RDF.type, RDF.Bag))
3771: error(test, n);
3772: n++;
3773: if (!(bag.size() == 0))
3774: error(test, n);
3775:
3776: n = 200;
3777: n++;
3778: bag.add(tvBoolean);
3779: n++;
3780: if (!bag.contains(tvBoolean))
3781: error(test, n);
3782: n++;
3783: bag.add(tvByte);
3784: n++;
3785: if (!bag.contains(tvByte))
3786: error(test, n);
3787: n++;
3788: bag.add(tvShort);
3789: n++;
3790: if (!bag.contains(tvShort))
3791: error(test, n);
3792: n++;
3793: bag.add(tvInt);
3794: n++;
3795: if (!bag.contains(tvInt))
3796: error(test, n);
3797: n++;
3798: bag.add(tvLong);
3799: n++;
3800: if (!bag.contains(tvLong))
3801: error(test, n);
3802: n++;
3803: bag.add(tvChar);
3804: n++;
3805: if (!bag.contains(tvChar))
3806: error(test, n);
3807: n++;
3808: bag.add(tvFloat);
3809: n++;
3810: if (!bag.contains(tvFloat))
3811: error(test, n);
3812: n++;
3813: bag.add(tvDouble);
3814: n++;
3815: if (!bag.contains(tvDouble))
3816: error(test, n);
3817: n++;
3818: bag.add(tvString);
3819: n++;
3820: if (!bag.contains(tvString))
3821: error(test, n);
3822: n++;
3823: bag.add(tvLiteral);
3824: n++;
3825: if (!bag.contains(tvLiteral))
3826: error(test, n);
3827: n++;
3828: bag.add(tvResObj);
3829: n++;
3830: if (!bag.contains(tvResObj))
3831: error(test, n);
3832: n++;
3833: bag.add(tvLitObj);
3834: n++;
3835: if (!bag.contains(tvLitObj))
3836: error(test, n);
3837: n++;
3838: if (!(bag.size() == 12))
3839: error(test, n);
3840:
3841: {
3842: n = 300;
3843: n++;
3844: bag = m.createBag();
3845: for (int i = 0; i < num; i++) {
3846: bag.add(i);
3847: }
3848: n++;
3849: if (!(bag.size() == num))
3850: error(test, n);
3851: n++;
3852: nIter = bag.iterator();
3853: for (int i = 0; i < num; i++) {
3854: if (!(((Literal) nIter.nextNode()).getInt() == i))
3855: error(test, 320 + i);
3856: }
3857: nIter.close();
3858: }
3859:
3860: {
3861: boolean[] found = new boolean[num];
3862: boolean[] pattern = { true, true, true, false, false,
3863: false, false, false, true, true };
3864:
3865: n = 400;
3866: n++;
3867: nIter = bag.iterator();
3868: for (int i = 0; i < num; i++) {
3869: n++;
3870: nIter.nextNode();
3871: n++;
3872: if (!pattern[i])
3873: nIter.remove();
3874: found[i] = false;
3875: }
3876: n++;
3877: nIter.close();
3878: n = 450;
3879: n++;
3880: nIter = bag.iterator();
3881: while (nIter.hasNext()) {
3882: int v = ((Literal) nIter.nextNode()).getInt();
3883: n++;
3884: if (found[v])
3885: error(test, n);
3886: found[v] = true;
3887: }
3888: n++;
3889: nIter.close();
3890: n = 480;
3891: for (int i = 0; i < num; i++) {
3892: n++;
3893: if (!(found[i] == pattern[i]))
3894: error(test, n);
3895: }
3896: }
3897:
3898: {
3899: boolean[] found = new boolean[num];
3900: boolean[] pattern = { false, true, true, false, false,
3901: false, false, false, true, false };
3902:
3903: n = 500;
3904: n++;
3905: bag = m.createBag();
3906: for (int i = 0; i < num; i++) {
3907: bag.add(i);
3908: }
3909: n++;
3910: nIter = bag.iterator();
3911: for (int i = 0; i < num; i++) {
3912: n++;
3913: nIter.nextNode();
3914: n++;
3915: if (!pattern[i])
3916: nIter.remove();
3917: found[i] = false;
3918: }
3919: n++;
3920: nIter.close();
3921: n = 550;
3922: n++;
3923: nIter = bag.iterator();
3924: while (nIter.hasNext()) {
3925: int v = ((Literal) nIter.nextNode()).getInt();
3926: n++;
3927: if (found[v])
3928: error(test, n);
3929: found[v] = true;
3930: }
3931: n++;
3932: nIter.close();
3933: n = 580;
3934: for (int i = 0; i < num; i++) {
3935: n++;
3936: if (!(found[i] == pattern[i]))
3937: error(test, n);
3938: }
3939: }
3940:
3941: {
3942: boolean[] found = new boolean[num];
3943: boolean[] pattern = { false, false, false, false,
3944: false, false, false, false, false, false };
3945:
3946: n = 600;
3947: n++;
3948: bag = m.createBag();
3949: for (int i = 0; i < num; i++) {
3950: bag.add(i);
3951: }
3952: n++;
3953: nIter = bag.iterator();
3954: for (int i = 0; i < num; i++) {
3955: n++;
3956: nIter.nextNode();
3957: n++;
3958: if (!pattern[i])
3959: nIter.remove();
3960: found[i] = false;
3961: }
3962: n++;
3963: nIter.close();
3964: n = 650;
3965: n++;
3966: nIter = bag.iterator();
3967: while (nIter.hasNext()) {
3968: int v = ((Literal) nIter.nextNode()).getInt();
3969: n++;
3970: if (found[v])
3971: error(test, n);
3972: found[v] = true;
3973: }
3974: n++;
3975: nIter.close();
3976: n = 680;
3977: for (int i = 0; i < num; i++) {
3978: n++;
3979: if (!(found[i] == pattern[i]))
3980: error(test, n);
3981: }
3982: }
3983:
3984: } catch (Exception e) {
3985: logger.error("test " + test + "[" + n + "]", e);
3986: errors = true;
3987: }
3988: // System.out.println("End of " + test);
3989: }
3990:
3991: /** test Alt
3992: * @param m the model implementation under test
3993: */
3994: public void test15(Model m) {
3995: String test = "Test15";
3996: int n = 0;
3997:
3998: try {
3999: NodeIterator nIter;
4000: StmtIterator sIter;
4001: // System.out.println("Beginning " + test);
4002: boolean tvBoolean = true;
4003: byte tvByte = 1;
4004: short tvShort = 2;
4005: int tvInt = -1;
4006: long tvLong = -2;
4007: char tvChar = '!';
4008: float tvFloat = (float) 123.456;
4009: double tvDouble = -123.456;
4010: String tvString = "test 12 string";
4011: LitTestObj tvObject = new LitTestObj(12345);
4012: Literal tvLiteral = m.createLiteral("test 12 string 2");
4013: Resource tvResource = m.createResource();
4014: Resource tvResObj = m.createResource(new ResTestObjF());
4015: Object tvLitObj = new LitTestObj(1234);
4016: Bag tvBag = m.createBag();
4017: Alt tvAlt = m.createAlt();
4018: Seq tvSeq = m.createSeq();
4019: int num = 10;
4020: Statement stmt;
4021:
4022: n = 100;
4023: n++;
4024: Alt alt = m.createAlt();
4025: n++;
4026: if (!m.contains(alt, RDF.type, RDF.Alt))
4027: error(test, n);
4028: n++;
4029: if (!(alt.size() == 0))
4030: error(test, n);
4031:
4032: n = 200;
4033: n++;
4034: alt.add(tvBoolean);
4035: n++;
4036: if (!alt.contains(tvBoolean))
4037: error(test, n);
4038: n++;
4039: alt.add(tvByte);
4040: n++;
4041: if (!alt.contains(tvByte))
4042: error(test, n);
4043: n++;
4044: alt.add(tvShort);
4045: n++;
4046: if (!alt.contains(tvShort))
4047: error(test, n);
4048: n++;
4049: alt.add(tvInt);
4050: n++;
4051: if (!alt.contains(tvInt))
4052: error(test, n);
4053: n++;
4054: alt.add(tvLong);
4055: n++;
4056: if (!alt.contains(tvLong))
4057: error(test, n);
4058: n++;
4059: alt.add(tvChar);
4060: n++;
4061: if (!alt.contains(tvChar))
4062: error(test, n);
4063: n++;
4064: alt.add(tvFloat);
4065: n++;
4066: if (!alt.contains(tvFloat))
4067: error(test, n);
4068: n++;
4069: alt.add(tvDouble);
4070: n++;
4071: if (!alt.contains(tvDouble))
4072: error(test, n);
4073: n++;
4074: alt.add(tvString);
4075: n++;
4076: if (!alt.contains(tvString))
4077: error(test, n);
4078: n++;
4079: alt.add(tvLiteral);
4080: n++;
4081: if (!alt.contains(tvLiteral))
4082: error(test, n);
4083: n++;
4084: alt.add(tvResObj);
4085: n++;
4086: if (!alt.contains(tvResObj))
4087: error(test, n);
4088: n++;
4089: alt.add(tvLitObj);
4090: n++;
4091: if (!alt.contains(tvLitObj))
4092: error(test, n);
4093: n++;
4094: if (!(alt.size() == 12))
4095: error(test, n);
4096:
4097: {
4098: n = 300;
4099: n++;
4100: alt = m.createAlt();
4101: for (int i = 0; i < num; i++) {
4102: alt.add(i);
4103: }
4104: n++;
4105: if (!(alt.size() == num))
4106: error(test, n);
4107: n++;
4108: nIter = alt.iterator();
4109: for (int i = 0; i < num; i++) {
4110: if (!(((Literal) nIter.nextNode()).getInt() == i))
4111: error(test, 320 + i);
4112: }
4113: nIter.close();
4114: }
4115:
4116: {
4117: boolean[] found = new boolean[num];
4118: boolean[] pattern = { true, true, true, false, false,
4119: false, false, false, true, true };
4120:
4121: n = 400;
4122: n++;
4123: nIter = alt.iterator();
4124: for (int i = 0; i < num; i++) {
4125: n++;
4126: nIter.nextNode();
4127: n++;
4128: if (!pattern[i])
4129: nIter.remove();
4130: found[i] = false;
4131: }
4132: n++;
4133: nIter.close();
4134: n = 450;
4135: n++;
4136: nIter = alt.iterator();
4137: while (nIter.hasNext()) {
4138: int v = ((Literal) nIter.nextNode()).getInt();
4139: n++;
4140: if (found[v])
4141: error(test, n);
4142: found[v] = true;
4143: }
4144: n++;
4145: nIter.close();
4146: n = 480;
4147: for (int i = 0; i < num; i++) {
4148: n++;
4149: if (!(found[i] == pattern[i]))
4150: error(test, n);
4151: }
4152: }
4153:
4154: {
4155: boolean[] found = new boolean[num];
4156: boolean[] pattern = { false, true, true, false, false,
4157: false, false, false, true, false };
4158:
4159: n = 500;
4160: n++;
4161: alt = m.createAlt();
4162: for (int i = 0; i < num; i++) {
4163: alt.add(i);
4164: }
4165: n++;
4166: nIter = alt.iterator();
4167: for (int i = 0; i < num; i++) {
4168: n++;
4169: nIter.nextNode();
4170: n++;
4171: if (!pattern[i])
4172: nIter.remove();
4173: found[i] = false;
4174: }
4175: n++;
4176: nIter.close();
4177: n = 550;
4178: n++;
4179: nIter = alt.iterator();
4180: while (nIter.hasNext()) {
4181: int v = ((Literal) nIter.nextNode()).getInt();
4182: n++;
4183: if (found[v])
4184: error(test, n);
4185: found[v] = true;
4186: }
4187: n++;
4188: nIter.close();
4189: n = 580;
4190: for (int i = 0; i < num; i++) {
4191: n++;
4192: if (!(found[i] == pattern[i]))
4193: error(test, n);
4194: }
4195: }
4196:
4197: {
4198: boolean[] found = new boolean[num];
4199: boolean[] pattern = { false, false, false, false,
4200: false, false, false, false, false, false };
4201:
4202: n = 600;
4203: n++;
4204: alt = m.createAlt();
4205: for (int i = 0; i < num; i++) {
4206: alt.add(i);
4207: }
4208: n++;
4209: nIter = alt.iterator();
4210: for (int i = 0; i < num; i++) {
4211: n++;
4212: nIter.nextNode();
4213: n++;
4214: if (!pattern[i])
4215: nIter.remove();
4216: found[i] = false;
4217: }
4218: n++;
4219: nIter.close();
4220: n = 650;
4221: n++;
4222: nIter = alt.iterator();
4223: while (nIter.hasNext()) {
4224: int v = ((Literal) nIter.nextNode()).getInt();
4225: n++;
4226: if (found[v])
4227: error(test, n);
4228: found[v] = true;
4229: }
4230: n++;
4231: nIter.close();
4232: n = 680;
4233: for (int i = 0; i < num; i++) {
4234: n++;
4235: if (!(found[i] == pattern[i]))
4236: error(test, n);
4237: }
4238: }
4239:
4240: {
4241: n = 700;
4242: n++;
4243: alt = m.createAlt();
4244: n++;
4245: if (!(alt.setDefault(tvLiteral).getDefault()
4246: .equals(tvLiteral)))
4247: error(test, n);
4248: n++;
4249: if (!(alt.setDefault(tvLiteral).getDefaultLiteral()
4250: .equals(tvLiteral)))
4251: error(test, n);
4252: n++;
4253: if (!alt.setDefault(tvResource).getDefaultResource()
4254: .equals(tvResource))
4255: error(test, n);
4256: n++;
4257: if (!(alt.setDefault(tvByte).getDefaultByte() == tvByte))
4258: error(test, n);
4259: n++;
4260: if (!(alt.setDefault(tvShort).getDefaultShort() == tvShort))
4261: error(test, n);
4262: n++;
4263: if (!(alt.setDefault(tvInt).getDefaultInt() == tvInt))
4264: error(test, n);
4265: n++;
4266: if (!(alt.setDefault(tvLong).getDefaultLong() == tvLong))
4267: error(test, n);
4268: n++;
4269: if (!(alt.setDefault(tvChar).getDefaultChar() == tvChar))
4270: error(test, n);
4271: n++;
4272: if (!(alt.setDefault(tvFloat).getDefaultFloat() == tvFloat))
4273: error(test, n);
4274: n++;
4275: if (!(alt.setDefault(tvDouble).getDefaultDouble() == tvDouble))
4276: error(test, n);
4277: n++;
4278: if (!alt.setDefault(tvString).getDefaultString()
4279: .equals(tvString))
4280: error(test, n);
4281: n++;
4282: if (!alt.setDefault(tvResObj).getDefaultResource(
4283: new ResTestObjF()).equals(tvResObj))
4284: error(test, n);
4285: n++;
4286: if (!alt.setDefault(tvLitObj).getDefaultObject(
4287: new LitTestObjF()).equals(tvLitObj))
4288: error(test, n);
4289: n++;
4290: if (!alt.setDefault(tvAlt).getDefaultAlt()
4291: .equals(tvAlt))
4292: error(test, n);
4293: n++;
4294: if (!alt.setDefault(tvBag).getDefaultBag()
4295: .equals(tvBag))
4296: error(test, n);
4297: n++;
4298: if (!alt.setDefault(tvSeq).getDefaultSeq()
4299: .equals(tvSeq))
4300: error(test, n);
4301: }
4302:
4303: } catch (Exception e) {
4304: logger.error("test " + test + "[" + n + "]", e);
4305: errors = true;
4306: }
4307: // System.out.println("End of " + test);
4308: }
4309:
4310: /** test Seq
4311: * @param m the model implementation under test
4312: */
4313: public void test16(Model m) {
4314: String test = "Test16";
4315: int n = 0;
4316:
4317: try {
4318: NodeIterator nIter;
4319: StmtIterator sIter;
4320: // System.out.println("Beginning " + test);
4321: boolean tvBoolean = true;
4322: byte tvByte = 1;
4323: short tvShort = 2;
4324: int tvInt = -1;
4325: long tvLong = -2;
4326: char tvChar = '!';
4327: float tvFloat = (float) 123.456;
4328: double tvDouble = -123.456;
4329: String tvString = "test 12 string";
4330: LitTestObj tvObject = new LitTestObj(12345);
4331: Literal tvLiteral = m.createLiteral("test 12 string 2");
4332: Resource tvResource = m.createResource();
4333: Resource tvResObj = m.createResource(new ResTestObjF());
4334: Object tvLitObj = new LitTestObj(1234);
4335: Bag tvBag = m.createBag();
4336: Alt tvAlt = m.createAlt();
4337: Seq tvSeq = m.createSeq();
4338: int num = 10;
4339: Statement stmt;
4340:
4341: n = 100;
4342: n++;
4343: Seq seq = m.createSeq();
4344: n++;
4345: if (!m.contains(seq, RDF.type, RDF.Seq))
4346: error(test, n);
4347: n++;
4348: if (!(seq.size() == 0))
4349: error(test, n);
4350:
4351: n = 200;
4352: n++;
4353: seq.add(tvBoolean);
4354: n++;
4355: if (!seq.contains(tvBoolean))
4356: error(test, n);
4357: n++;
4358: seq.add(tvByte);
4359: n++;
4360: if (!seq.contains(tvByte))
4361: error(test, n);
4362: n++;
4363: seq.add(tvShort);
4364: n++;
4365: if (!seq.contains(tvShort))
4366: error(test, n);
4367: n++;
4368: seq.add(tvInt);
4369: n++;
4370: if (!seq.contains(tvInt))
4371: error(test, n);
4372: n++;
4373: seq.add(tvLong);
4374: n++;
4375: if (!seq.contains(tvLong))
4376: error(test, n);
4377: n++;
4378: seq.add(tvChar);
4379: n++;
4380: if (!seq.contains(tvChar))
4381: error(test, n);
4382: n++;
4383: seq.add(tvFloat);
4384: n++;
4385: if (!seq.contains(tvFloat))
4386: error(test, n);
4387: n++;
4388: seq.add(tvDouble);
4389: n++;
4390: if (!seq.contains(tvDouble))
4391: error(test, n);
4392: n++;
4393: seq.add(tvString);
4394: n++;
4395: if (!seq.contains(tvString))
4396: error(test, n);
4397: n++;
4398: seq.add(tvLiteral);
4399: n++;
4400: if (!seq.contains(tvLiteral))
4401: error(test, n);
4402: n++;
4403: seq.add(tvResObj);
4404: n++;
4405: if (!seq.contains(tvResObj))
4406: error(test, n);
4407: n++;
4408: seq.add(tvLitObj);
4409: n++;
4410: if (!seq.contains(tvLitObj))
4411: error(test, n);
4412: n++;
4413: if (!(seq.size() == 12))
4414: error(test, n);
4415:
4416: {
4417: n = 300;
4418: n++;
4419: seq = m.createSeq();
4420: for (int i = 0; i < num; i++) {
4421: seq.add(i);
4422: }
4423: n++;
4424: if (!(seq.size() == num))
4425: error(test, n);
4426: n++;
4427: nIter = seq.iterator();
4428: for (int i = 0; i < num; i++) {
4429: if (!(((Literal) nIter.nextNode()).getInt() == i))
4430: error(test, 320 + i);
4431: }
4432: nIter.close();
4433: }
4434:
4435: {
4436: boolean[] found = new boolean[num];
4437: boolean[] pattern = { true, true, true, false, false,
4438: false, false, false, true, true };
4439:
4440: n = 400;
4441: n++;
4442: nIter = seq.iterator();
4443: for (int i = 0; i < num; i++) {
4444: n++;
4445: nIter.nextNode();
4446: n++;
4447: if (!pattern[i])
4448: nIter.remove();
4449: found[i] = false;
4450: }
4451: n++;
4452: nIter.close();
4453: n = 450;
4454: n++;
4455: nIter = seq.iterator();
4456: while (nIter.hasNext()) {
4457: int v = ((Literal) nIter.nextNode()).getInt();
4458: n++;
4459: if (found[v])
4460: error(test, n);
4461: found[v] = true;
4462: }
4463: n++;
4464: nIter.close();
4465: n = 480;
4466: for (int i = 0; i < num; i++) {
4467: n++;
4468: if (!(found[i] == pattern[i]))
4469: error(test, n);
4470: }
4471: }
4472:
4473: {
4474: boolean[] found = new boolean[num];
4475: boolean[] pattern = { false, true, true, false, false,
4476: false, false, false, true, false };
4477:
4478: n = 500;
4479: n++;
4480: seq = m.createSeq();
4481: for (int i = 0; i < num; i++) {
4482: seq.add(i);
4483: }
4484: n++;
4485: nIter = seq.iterator();
4486: for (int i = 0; i < num; i++) {
4487: n++;
4488: nIter.nextNode();
4489: n++;
4490: if (!pattern[i])
4491: nIter.remove();
4492: found[i] = false;
4493: }
4494: n++;
4495: nIter.close();
4496: n = 550;
4497: n++;
4498: nIter = seq.iterator();
4499: while (nIter.hasNext()) {
4500: int v = ((Literal) nIter.nextNode()).getInt();
4501: n++;
4502: if (found[v])
4503: error(test, n);
4504: found[v] = true;
4505: }
4506: n++;
4507: nIter.close();
4508: n = 580;
4509: for (int i = 0; i < num; i++) {
4510: n++;
4511: if (!(found[i] == pattern[i]))
4512: error(test, n);
4513: }
4514: }
4515:
4516: {
4517: boolean[] found = new boolean[num];
4518: boolean[] pattern = { false, false, false, false,
4519: false, false, false, false, false, false };
4520:
4521: n = 600;
4522: n++;
4523: seq = m.createSeq();
4524: for (int i = 0; i < num; i++) {
4525: seq.add(i);
4526: }
4527: n++;
4528: nIter = seq.iterator();
4529: for (int i = 0; i < num; i++) {
4530: n++;
4531: nIter.nextNode();
4532: n++;
4533: if (!pattern[i])
4534: nIter.remove();
4535: found[i] = false;
4536: }
4537: n++;
4538: nIter.close();
4539: n = 650;
4540: n++;
4541: nIter = seq.iterator();
4542: while (nIter.hasNext()) {
4543: int v = ((Literal) nIter.nextNode()).getInt();
4544: n++;
4545: if (found[v])
4546: error(test, n);
4547: found[v] = true;
4548: }
4549: n++;
4550: nIter.close();
4551: n = 680;
4552: for (int i = 0; i < num; i++) {
4553: n++;
4554: if (!(found[i] == pattern[i]))
4555: error(test, n);
4556: }
4557: }
4558:
4559: {
4560: n = 700;
4561: seq = m.createSeq();
4562: n++;
4563: seq.add(tvBoolean);
4564: n++;
4565: if (!(seq.getBoolean(1) == tvBoolean))
4566: error(test, n);
4567: n++;
4568: seq.add(tvByte);
4569: n++;
4570: if (!(seq.getByte(2) == tvByte))
4571: error(test, n);
4572: n++;
4573: seq.add(tvShort);
4574: n++;
4575: if (!(seq.getShort(3) == tvShort))
4576: error(test, n);
4577: n++;
4578: seq.add(tvInt);
4579: n++;
4580: if (!(seq.getInt(4) == tvInt))
4581: error(test, n);
4582: n++;
4583: seq.add(tvLong);
4584: n++;
4585: if (!(seq.getLong(5) == tvLong))
4586: error(test, n);
4587: n++;
4588: seq.add(tvChar);
4589: n++;
4590: if (!(seq.getChar(6) == tvChar))
4591: error(test, n);
4592: n++;
4593: seq.add(tvFloat);
4594: n++;
4595: if (!(seq.getFloat(7) == tvFloat))
4596: error(test, n);
4597: n++;
4598: seq.add(tvDouble);
4599: n++;
4600: if (!(seq.getDouble(8) == tvDouble))
4601: error(test, n);
4602: n++;
4603: seq.add(tvString);
4604: n++;
4605: if (!(seq.getString(9).equals(tvString)))
4606: error(test, n);
4607: n++;
4608: seq.add(tvLitObj);
4609: n++;
4610: if (!(seq.getObject(10, new LitTestObjF())
4611: .equals(tvLitObj)))
4612: error(test, n);
4613: n++;
4614: seq.add(tvResource);
4615: n++;
4616: if (!(seq.getResource(11).equals(tvResource)))
4617: error(test, n);
4618: n++;
4619: seq.add(tvLiteral);
4620: n++;
4621: if (!(seq.getLiteral(12).equals(tvLiteral)))
4622: error(test, n);
4623: n++;
4624: seq.add(tvResObj);
4625: n++;
4626: if (!(seq.getResource(13, new ResTestObjF())
4627: .equals(tvResObj)))
4628: error(test, n);
4629: n++;
4630: seq.add(tvBag);
4631: n++;
4632: if (!(seq.getBag(14).equals(tvBag)))
4633: error(test, n);
4634: n++;
4635: seq.add(tvAlt);
4636: n++;
4637: if (!(seq.getAlt(15).equals(tvAlt)))
4638: error(test, n);
4639: n++;
4640: seq.add(tvSeq);
4641: n++;
4642: if (!(seq.getSeq(16).equals(tvSeq)))
4643: error(test, n);
4644: n++;
4645: try {
4646: seq.getInt(17);
4647: error(test, n);
4648: } catch (SeqIndexBoundsException e) {
4649: // as required
4650: }
4651: n++;
4652: try {
4653: seq.getInt(0);
4654: error(test, n);
4655: } catch (SeqIndexBoundsException e) {
4656: // as required
4657: }
4658: }
4659:
4660: {
4661: n = 800;
4662: seq = m.createSeq();
4663: for (int i = 0; i < num; i++) {
4664: seq.add(i);
4665: }
4666:
4667: try {
4668: n++;
4669: seq.add(0, false);
4670: error(test, n);
4671: } catch (SeqIndexBoundsException e) {
4672: // as required
4673: }
4674: seq.add(num + 1, false);
4675: if (seq.size() != num + 1)
4676: error(test, n);
4677: seq.remove(num + 1);
4678: try {
4679: n++;
4680: seq.add(num + 2, false);
4681: error(test, n);
4682: } catch (SeqIndexBoundsException e) {
4683: // as required
4684: }
4685:
4686: n = 820;
4687: int size = seq.size();
4688: for (int i = 1; i <= num - 1; i++) {
4689: n++;
4690: seq.add(i, 1000 + i);
4691: n++;
4692: if (!(seq.getInt(i) == 1000 + i))
4693: error(test, n);
4694: n++;
4695: if (!(seq.getInt(i + 1) == 0))
4696: error(test, n);
4697: n++;
4698: if (!(seq.size() == (size + i)))
4699: error(test, n);
4700: n++;
4701: if (!(seq.getInt(size) == (num - i - 1)))
4702: error(test, n);
4703: }
4704: n = 900;
4705: seq = m.createSeq();
4706: seq.add(m.createResource());
4707: seq.add(1, tvBoolean);
4708: n++;
4709: if (!(seq.getBoolean(1) == tvBoolean))
4710: error(test, n);
4711: seq.add(1, tvByte);
4712: n++;
4713: if (!(seq.getByte(1) == tvByte))
4714: error(test, n);
4715: seq.add(1, tvShort);
4716: n++;
4717: if (!(seq.getShort(1) == tvShort))
4718: error(test, n);
4719: seq.add(1, tvInt);
4720: n++;
4721: if (!(seq.getInt(1) == tvInt))
4722: error(test, n);
4723: seq.add(1, tvLong);
4724: n++;
4725: if (!(seq.getLong(1) == tvLong))
4726: error(test, n);
4727: seq.add(1, tvChar);
4728: n++;
4729: if (!(seq.getChar(1) == tvChar))
4730: error(test, n);
4731: seq.add(1, tvFloat);
4732: n++;
4733: if (!(seq.getFloat(1) == tvFloat))
4734: error(test, n);
4735: seq.add(1, tvDouble);
4736: n++;
4737: if (!(seq.getDouble(1) == tvDouble))
4738: error(test, n);
4739: seq.add(1, tvString);
4740: n++;
4741: if (!(seq.getString(1).equals(tvString)))
4742: error(test, n);
4743: seq.add(1, tvResource);
4744: n++;
4745: if (!(seq.getResource(1).equals(tvResource)))
4746: error(test, n);
4747: seq.add(1, tvLiteral);
4748: n++;
4749: if (!(seq.getLiteral(1).equals(tvLiteral)))
4750: error(test, n);
4751: seq.add(1, tvLitObj);
4752: n++;
4753: if (!(seq.getObject(1, new LitTestObjF())
4754: .equals(tvLitObj)))
4755: error(test, n);
4756:
4757: n = 1000;
4758: n++;
4759: if (!(seq.indexOf(tvLitObj) == 1))
4760: error(test, n);
4761: n++;
4762: if (!(seq.indexOf(tvLiteral) == 2))
4763: error(test, n);
4764: n++;
4765: if (!(seq.indexOf(tvResource) == 3))
4766: error(test, n);
4767: n++;
4768: if (!(seq.indexOf(tvString) == 4))
4769: error(test, n);
4770: n++;
4771: if (!(seq.indexOf(tvDouble) == 5))
4772: error(test, n);
4773: n++;
4774: if (!(seq.indexOf(tvFloat) == 6))
4775: error(test, n);
4776: n++;
4777: if (!(seq.indexOf(tvChar) == 7))
4778: error(test, n);
4779: n++;
4780: if (!(seq.indexOf(tvLong) == 8))
4781: error(test, n);
4782: n++;
4783: if (!(seq.indexOf(tvInt) == 9))
4784: error(test, n);
4785: n++;
4786: if (!(seq.indexOf(tvShort) == 10))
4787: error(test, n);
4788: n++;
4789: if (!(seq.indexOf(tvByte) == 11))
4790: error(test, n);
4791: n++;
4792: if (!(seq.indexOf(tvBoolean) == 12))
4793: error(test, n);
4794: n++;
4795: if (!(seq.indexOf(1234543) == 0))
4796: error(test, n);
4797:
4798: n = 1100;
4799: seq = m.createSeq();
4800: for (int i = 0; i < num; i++) {
4801: seq.add(i);
4802: }
4803: n = 1110;
4804: seq.set(5, tvBoolean);
4805: n++;
4806: if (!(seq.getBoolean(5) == tvBoolean))
4807: error(test, n);
4808: n++;
4809: if (!(seq.getInt(4) == 3))
4810: error(test, n);
4811: n++;
4812: if (!(seq.getInt(6) == 5))
4813: error(test, n);
4814: n++;
4815: if (!(seq.size() == num))
4816: error(test, n);
4817: n = 1120;
4818: seq.set(5, tvByte);
4819: n++;
4820: if (!(seq.getByte(5) == tvByte))
4821: error(test, n);
4822: n++;
4823: if (!(seq.getInt(4) == 3))
4824: error(test, n);
4825: n++;
4826: if (!(seq.getInt(6) == 5))
4827: error(test, n);
4828: n++;
4829: if (!(seq.size() == num))
4830: error(test, n);
4831: n = 1130;
4832: seq.set(5, tvShort);
4833: n++;
4834: if (!(seq.getShort(5) == tvShort))
4835: error(test, n);
4836: n++;
4837: if (!(seq.getInt(4) == 3))
4838: error(test, n);
4839: n++;
4840: if (!(seq.getInt(6) == 5))
4841: error(test, n);
4842: n++;
4843: if (!(seq.size() == num))
4844: error(test, n);
4845: n = 1140;
4846: seq.set(5, tvInt);
4847: n++;
4848: if (!(seq.getInt(5) == tvInt))
4849: error(test, n);
4850: n++;
4851: if (!(seq.getInt(4) == 3))
4852: error(test, n);
4853: n++;
4854: if (!(seq.getInt(6) == 5))
4855: error(test, n);
4856: n++;
4857: if (!(seq.size() == num))
4858: error(test, n);
4859: n = 1150;
4860: seq.set(5, tvLong);
4861: n++;
4862: if (!(seq.getLong(5) == tvLong))
4863: error(test, n);
4864: n++;
4865: if (!(seq.getInt(4) == 3))
4866: error(test, n);
4867: n++;
4868: if (!(seq.getInt(6) == 5))
4869: error(test, n);
4870: n++;
4871: if (!(seq.size() == num))
4872: error(test, n);
4873: n = 1160;
4874: seq.set(5, tvChar);
4875: n++;
4876: if (!(seq.getChar(5) == tvChar))
4877: error(test, n);
4878: n++;
4879: if (!(seq.getInt(4) == 3))
4880: error(test, n);
4881: n++;
4882: if (!(seq.getInt(6) == 5))
4883: error(test, n);
4884: n++;
4885: if (!(seq.size() == num))
4886: error(test, n);
4887: n = 1170;
4888: seq.set(5, tvFloat);
4889: n++;
4890: if (!(seq.getFloat(5) == tvFloat))
4891: error(test, n);
4892: n++;
4893: if (!(seq.getInt(4) == 3))
4894: error(test, n);
4895: n++;
4896: if (!(seq.getInt(6) == 5))
4897: error(test, n);
4898: n++;
4899: if (!(seq.size() == num))
4900: error(test, n);
4901: n = 1180;
4902: seq.set(5, tvDouble);
4903: n++;
4904: if (!(seq.getDouble(5) == tvDouble))
4905: error(test, n);
4906: n++;
4907: if (!(seq.getInt(4) == 3))
4908: error(test, n);
4909: n++;
4910: if (!(seq.getInt(6) == 5))
4911: error(test, n);
4912: n++;
4913: if (!(seq.size() == num))
4914: error(test, n);
4915: n = 1190;
4916: seq.set(5, tvLiteral);
4917: n++;
4918: if (!(seq.getLiteral(5).equals(tvLiteral)))
4919: error(test, n);
4920: n++;
4921: if (!(seq.getInt(4) == 3))
4922: error(test, n);
4923: n++;
4924: if (!(seq.getInt(6) == 5))
4925: error(test, n);
4926: n++;
4927: if (!(seq.size() == num))
4928: error(test, n);
4929: n = 1200;
4930: seq.set(5, tvResource);
4931: n++;
4932: if (!(seq.getResource(5).equals(tvResource)))
4933: error(test, n);
4934: n++;
4935: if (!(seq.getInt(4) == 3))
4936: error(test, n);
4937: n++;
4938: if (!(seq.getInt(6) == 5))
4939: error(test, n);
4940: n++;
4941: if (!(seq.size() == num))
4942: error(test, n);
4943: n = 1210;
4944: seq.set(5, tvLitObj);
4945: n++;
4946: if (!(seq.getObject(5, new LitTestObjF()))
4947: .equals(tvLitObj))
4948: error(test, n);
4949: n++;
4950: if (!(seq.getInt(4) == 3))
4951: error(test, n);
4952: n++;
4953: if (!(seq.getInt(6) == 5))
4954: error(test, n);
4955: n++;
4956: if (!(seq.size() == num))
4957: error(test, n);
4958: n = 1220;
4959: seq.set(5, tvResObj);
4960: n++;
4961: if (!(seq.getResource(5, new ResTestObjF())
4962: .equals(tvResObj)))
4963: error(test, n);
4964: n++;
4965: if (!(seq.getInt(4) == 3))
4966: error(test, n);
4967: n++;
4968: if (!(seq.getInt(6) == 5))
4969: error(test, n);
4970: n++;
4971: if (!(seq.size() == num))
4972: error(test, n);
4973: }
4974:
4975: } catch (Exception e) {
4976: logger.error("test " + test + "[" + n + "]", e);
4977: errors = true;
4978: }
4979: // System.out.println("End of " + test);
4980: }
4981:
4982: /** test enhanced resources
4983: * @param m the model implementation under test
4984: */
4985: public void test17(Model m) {
4986: String test = "Test17";
4987: int n = 0;
4988:
4989: try {
4990: // System.out.println("Beginning " + test);
4991: Resource r = new ResourceImpl((ModelCom) m);
4992: n = 1000;
4993: testResource(m, r, test, n, 0);
4994:
4995: n = 2000;
4996: testResource(m, m.createBag(), test, n, 1);
4997: n = 3000;
4998: testContainer(m, m.createBag(), m.createBag(), test, n);
4999: n = 4000;
5000: testBag(m, m.createBag(), m.createBag(), m.createBag(),
5001: test, n);
5002:
5003: n = 5000;
5004: testResource(m, m.createAlt(), test, n, 1);
5005: n = 6000;
5006: testContainer(m, m.createAlt(), m.createAlt(), test, n);
5007: n = 7000;
5008: testAlt(m, m.createAlt(), m.createAlt(), m.createAlt(), m
5009: .createAlt(), test, n);
5010:
5011: n = 8000;
5012: testResource(m, m.createSeq(), test, n, 1);
5013: n = 9000;
5014: testContainer(m, m.createSeq(), m.createSeq(), test, n);
5015: n = 10000;
5016: testSeq(m, m.createSeq(), m.createSeq(), m.createSeq(), m
5017: .createSeq(), m.createSeq(), m.createSeq(), m
5018: .createSeq(), test, n);
5019: } catch (Exception e) {
5020: logger.error("test " + test + "[" + n + "]", e);
5021: errors = true;
5022: }
5023: // System.out.println("End of " + test);
5024: }
5025:
5026: /** test load from xml file
5027: * @param m the model implementation under test
5028: */
5029: public void test18(Model m) {
5030: String test = "Test18";
5031: if (test.equals(test))
5032: return;
5033: String testURI = "http://aldabaran.hpl.hp.com/rdftest/test18/";
5034: String subject1 = testURI + "1";
5035: String object1 = "<foo bar=\"bar\"><bar>abc<foobar/>def<>'"&</bar></foo>";
5036: String RDFSchemaURI = "http://lists.w3.org/Archives/Public/www-archive/"
5037: + "2001Sep/att-0064/00-rdfschema.rdf";
5038: int n = 0;
5039:
5040: try {
5041: System.out.println("Beginning " + test);
5042: m.read(ResourceReader
5043: .getInputStream("modules/rdf/rdfschema.html"),
5044: RDFSchemaURI);
5045: n++;
5046: if (m.size() != 124)
5047: error(test, n);
5048: // n++; m.write(new PrintWriter(System.out));
5049:
5050: StmtIterator iter = m.listStatements();
5051: while (iter.hasNext()) {
5052: iter.nextStatement();
5053: iter.remove();
5054: }
5055:
5056: m.read(ResourceReader
5057: .getInputStream("modules/rdf/embeddedxml.xml"), "");
5058: n++;
5059: /* I'd like to test for the exactly correct value here, but can't since the
5060: * exactly correct value is not defined.
5061: if (! m.contains(m.createResource(subject1),
5062: RDF.value, object1)) error(test, n++);
5063: * So instead lets do some rough checks its right */
5064: String xml = m.getResource(subject1).getRequiredProperty(
5065: RDF.value).getString();
5066: n++;
5067: if (xml.indexOf("<") == -1)
5068: error(test, n);
5069: n++;
5070: if (xml.indexOf(">") == -1)
5071: error(test, n);
5072: n++;
5073: if (xml.indexOf("&") == -1)
5074: error(test, n);
5075: n++;
5076: if ((xml.indexOf("'bar'") == -1)
5077: && (xml.indexOf("\"bar\"") == -1))
5078: error(test, n);
5079:
5080: m.createResource().addProperty(RDF.value, "can't loose");
5081: // m.write(new PrintWriter(System.out));
5082:
5083: iter = m.listStatements();
5084: while (iter.hasNext()) {
5085: iter.nextStatement();
5086: iter.remove();
5087: }
5088: n++;
5089: m.read(ResourceReader
5090: .getInputStream("modules/rdf/testcollection.rdf"),
5091: "");
5092: if (m.size() != 24)
5093: error(test, (int) m.size());
5094:
5095: iter = m.listStatements();
5096: while (iter.hasNext()) {
5097: iter.nextStatement();
5098: iter.remove();
5099: }
5100:
5101: try {
5102: m.read(System.getProperty(
5103: "com.hp.hpl.jena.regression.testURL",
5104: RDFSchemaURI));
5105: // n++; m.write(new PrintWriter(System.out));
5106: n++;
5107: if ((m.size() != 124) && (m.size() != 125)) {
5108: System.out.println("size = " + m.size());
5109: error(test, n);
5110: }
5111: if (!m.contains(RDF.Property, RDF.type, RDFS.Class))
5112: error(test, n);
5113: } catch (JenaException rdfx) {
5114: Throwable th = rdfx.getCause();
5115: if (th instanceof NoRouteToHostException
5116: || th instanceof UnknownHostException
5117: || th instanceof IOException
5118: || th instanceof ConnectException) {
5119: logger
5120: .warn("Cannot access public internet- part of test not executed");
5121: } else {
5122: throw rdfx;
5123: }
5124: }
5125:
5126: } catch (Exception e) {
5127: logger.error("test " + test + "[" + n + "]", e);
5128: errors = true;
5129: }
5130: // System.out.println("End of " + test);
5131: }
5132:
5133: /** test moving things between models
5134: * @param m the model implementation under test
5135: */
5136: public void test19(Model m1, Model m2) {
5137: String test = "Test19";
5138: int n = 0;
5139:
5140: try {
5141: Statement stmt;
5142: StmtIterator sIter;
5143: // System.out.println("Beginning " + test);
5144:
5145: try {
5146: n = 100;
5147: Resource r11 = m1.createResource();
5148: Resource r12 = m2.createResource(new ResTestObjF());
5149: long size1 = m1.size();
5150: long size2 = m2.size();
5151:
5152: r11.addLiteral(RDF.value, 1);
5153: n++;
5154: if (!(m1.size() == ++size1))
5155: error(test, n);
5156: n++;
5157: if (!(m2.size() == size2))
5158: error(test, n);
5159:
5160: stmt = m2.createStatement(r11, RDF.value, r12);
5161: n++;
5162: if (!(stmt.getSubject().getModel() == m2))
5163: error(test, n);
5164: n++;
5165: if (!(stmt.getResource().getModel() == m2))
5166: error(test, n);
5167:
5168: m1.add(stmt);
5169: n++;
5170: if (!(m1.size() == ++size1))
5171: error(test, n);
5172: n++;
5173: if (!(m2.size() == size2))
5174: error(test, n);
5175:
5176: sIter = m1.listStatements(new SimpleSelector(r11,
5177: RDF.value, r12));
5178: n++;
5179: if (!sIter.hasNext())
5180: error(test, n);
5181: n++;
5182: stmt = sIter.nextStatement();
5183: n++;
5184: if (!(stmt.getSubject().getModel() == m1))
5185: error(test, n);
5186: n++;
5187: if (!(stmt.getResource().getModel() == m1))
5188: error(test, n);
5189: sIter.close();
5190:
5191: } catch (Exception e) {
5192: error(test, n, e);
5193: }
5194: } catch (Exception e) {
5195: logger.error("test " + test + "[" + n + "]", e);
5196: errors = true;
5197: }
5198: // System.out.println("End of " + test);
5199: }
5200:
5201: /** Empty the passed in model
5202: * @param m the model implementation under test
5203: */
5204: public void test20(Model m) {
5205: String test = "Test20";
5206: int n = 0;
5207:
5208: try {
5209: // System.out.println("Beginning " + test);
5210: Statement s1 = null;
5211: Statement s2 = null;
5212:
5213: try {
5214: n = 100;
5215: n++;
5216: s1 = m.createStatement(m.createResource(), RDF.type,
5217: RDFS.Class);
5218: n++;
5219: if (s1.isReified())
5220: error(test, n);
5221: n++;
5222: m.add(s1);
5223: n++;
5224: if (s1.isReified())
5225: error(test, n);
5226: n++;
5227: s2 = m.createStatement(m.createResource(), RDF.type,
5228: RDFS.Class);
5229: n++;
5230: if (s2.isReified())
5231: error(test, n);
5232: n++;
5233: m.add(s2);
5234: n++;
5235: if (s2.isReified())
5236: error(test, n);
5237: /*
5238: n++; m.add(s1, RDF.value, new LiteralImpl("foo"));
5239: n++; if (!s1.isReified()) error(test,n);
5240:
5241: n++; m.add(s1, RDF.value, s2);
5242: n++; if (!s2.isReified()) error(test,n);
5243: */
5244: } catch (Exception e) {
5245: error(test, n, e);
5246: }
5247: } catch (Exception e) {
5248: logger.error("test " + test + "[" + n + "]", e);
5249: errors = true;
5250: }
5251: // System.out.println("End of " + test);
5252: }
5253:
5254: /** Testing for miscellaneous bugs
5255: * @param m the model implementation under test
5256: */
5257: public void test97(Model m) {
5258: String test = "Test97";
5259: int n = 0;
5260:
5261: try {
5262:
5263: // System.out.println("Beginning " + test);
5264:
5265: /*
5266: the _null_ argument to LiteralImpl was preserved only for backward
5267: compatability. It was be logged and has now become an exception.
5268: (Brian and Chris had a discussion about this and agreed).
5269: */
5270: // Node.nullLiteralsGenerateWarnings();
5271: try {
5272: n = 100;
5273: m.query(new SimpleSelector(null, null, new LiteralImpl(
5274: Node.createLiteral(null, "", false),
5275: (ModelCom) m)));
5276: error(test, n);
5277: } catch (NullPointerException e) {
5278: }
5279: try {
5280: n = 101;
5281: m.query(new SimpleSelector(null, null, new LiteralImpl(
5282: Node.createLiteral(null, "en", false),
5283: (ModelCom) m)));
5284: error(test, n);
5285: } catch (NullPointerException e) {
5286: }
5287: // end of nullLiteralsGenerateWarnings code
5288:
5289: n = 102;
5290: StmtIterator iter = m.listStatements(new SimpleSelector(
5291: null, null, (String) null));
5292: while (iter.hasNext()) {
5293: RDFNode o = iter.nextStatement().getObject();
5294: }
5295:
5296: n = 103;
5297: iter = m.listStatements(new SimpleSelector(null, null,
5298: (Object) null));
5299: while (iter.hasNext()) {
5300: RDFNode o = iter.nextStatement().getObject();
5301: }
5302:
5303: } catch (Exception e) {
5304: error(test, n, e);
5305: }
5306: // System.out.println("End of " + test);
5307: }
5308:
5309: /** Empty the passed in model
5310: * @param m the model implementation under test
5311: */
5312: public void test99(Model m) {
5313: String test = "Test5";
5314: int n = 0;
5315:
5316: try {
5317: StmtIterator iter;
5318: // System.out.println("Beginning " + test);
5319:
5320: try {
5321: n = 100;
5322: n++;
5323: iter = m.listStatements();
5324: while (iter.hasNext()) {
5325: iter.nextStatement();
5326: n++;
5327: iter.remove();
5328: }
5329: n++;
5330: iter.close();
5331: n++;
5332: if (!(m.size() == 0))
5333: error(test, 999);
5334: } catch (Exception e) {
5335: error(test, n, e);
5336: }
5337: } catch (Exception e) {
5338: logger.error("test " + test + "[" + n + "]", e);
5339: errors = true;
5340: }
5341: // System.out.println("End of " + test);
5342: }
5343:
5344: public void testResource(Model m, Resource r, String test, int n,
5345: int numProps) {
5346: try {
5347: StmtIterator iter;
5348: boolean tvBoolean = true;
5349: byte tvByte = 1;
5350: short tvShort = 2;
5351: int tvInt = -1;
5352: long tvLong = -2;
5353: char tvChar = '!';
5354: float tvFloat = (float) 123.456;
5355: double tvDouble = -123.456;
5356: String tvString = "test 12 string";
5357: LitTestObj tvObject = new LitTestObj(12345);
5358: Literal tvLiteral = m.createLiteral("test 12 string 2");
5359: Resource tvResource = m.createResource();
5360: String lang = "fr";
5361: Statement stmt;
5362:
5363: n++;
5364: if (!r.addLiteral(RDF.value, tvByte).hasLiteral(RDF.value,
5365: tvByte))
5366: error(test, n);
5367: n++;
5368: if (!r.addLiteral(RDF.value, tvShort).hasLiteral(RDF.value,
5369: tvShort))
5370: error(test, n);
5371: n++;
5372: if (!r.addLiteral(RDF.value, tvInt).hasLiteral(RDF.value,
5373: tvInt))
5374: error(test, n);
5375: n++;
5376: if (!r.addLiteral(RDF.value, tvLong).hasLiteral(RDF.value,
5377: tvLong))
5378: error(test, n);
5379: n++;
5380: if (!r.addLiteral(RDF.value, tvChar).hasLiteral(RDF.value,
5381: tvChar))
5382: error(test, n);
5383: n++;
5384: if (!r.addLiteral(RDF.value, tvFloat).hasLiteral(RDF.value,
5385: tvFloat))
5386: error(test, n);
5387: n++;
5388: if (!r.addLiteral(RDF.value, tvDouble).hasLiteral(
5389: RDF.value, tvDouble))
5390: error(test, n);
5391: n++;
5392: if (!r.addProperty(RDF.value, tvString).hasProperty(
5393: RDF.value, tvString))
5394: error(test, n);
5395: n++;
5396: if (!r.addProperty(RDF.value, tvString, lang).hasProperty(
5397: RDF.value, tvString, lang))
5398: error(test, n);
5399: n++;
5400: if (!r.addLiteral(RDF.value, tvObject).hasLiteral(
5401: RDF.value, tvObject))
5402: error(test, n);
5403: n++;
5404: if (!r.addProperty(RDF.value, tvLiteral).hasProperty(
5405: RDF.value, tvLiteral))
5406: error(test, n);
5407: n++;
5408: if (!r.addProperty(RDF.value, tvResource).hasProperty(
5409: RDF.value, tvResource))
5410: error(test, n);
5411: n++;
5412: if (!r.getRequiredProperty(RDF.value).getSubject()
5413: .equals(r))
5414: error(test, n);
5415: n++;
5416: Property p = m.createProperty("foo/", "bar");
5417: try {
5418: r.getRequiredProperty(p);
5419: error(test, n);
5420: } catch (PropertyNotFoundException e) {
5421: // as required
5422: }
5423: n++;
5424: iter = r.listProperties(RDF.value);
5425: int count = 0;
5426: while (iter.hasNext()) {
5427: stmt = iter.nextStatement();
5428: if (!stmt.getSubject().equals(r))
5429: error(test, n);
5430: count++;
5431: }
5432: n++;
5433: if (count != 12)
5434: error(test, n);
5435: n++;
5436: iter = r.listProperties(p);
5437: count = 0;
5438: while (iter.hasNext()) {
5439: stmt = iter.nextStatement();
5440: if (!stmt.getSubject().equals(r))
5441: error(test, n);
5442: count++;
5443: }
5444: n++;
5445: if (count != 0)
5446: error(test, n);
5447: n++;
5448: iter = r.listProperties();
5449: count = 0;
5450: while (iter.hasNext()) {
5451: stmt = iter.nextStatement();
5452: if (!stmt.getSubject().equals(r))
5453: error(test, n);
5454: count++;
5455: }
5456: n++;
5457: if (count != (12 + numProps))
5458: error(test, n);
5459:
5460: n++;
5461: r.removeProperties();
5462: n++;
5463: Model mm = m.query(new SimpleSelector(r, null,
5464: (RDFNode) null));
5465: if (!(mm.size() == 0))
5466: error(test, n);
5467:
5468: } catch (Exception e) {
5469: logger.error("test " + test + "[" + n + "]", e);
5470: errors = true;
5471: }
5472: }
5473:
5474: public void testContainer(Model m, Container cont1,
5475: Container cont2, String test, int n) {
5476:
5477: try {
5478: NodeIterator nIter;
5479: StmtIterator sIter;
5480: boolean tvBoolean = true;
5481: byte tvByte = 1;
5482: short tvShort = 2;
5483: int tvInt = -1;
5484: long tvLong = -2;
5485: char tvChar = '!';
5486: float tvFloat = (float) 123.456;
5487: double tvDouble = -123.456;
5488: String tvString = "test 12 string";
5489: LitTestObj tvObject = new LitTestObj(12345);
5490: Literal tvLiteral = m.createLiteral("test 12 string 2");
5491: Resource tvResObj = m.createResource(new ResTestObjF());
5492: Object tvLitObj = new LitTestObj(1234);
5493: Bag tvBag = m.createBag();
5494: Alt tvAlt = m.createAlt();
5495: Seq tvSeq = m.createSeq();
5496: String lang = "en";
5497: int num = 10;
5498: Statement stmt;
5499:
5500: n = (n / 100 + 1) * 100;
5501: n++;
5502: if (!(cont1.size() == 0))
5503: error(test, n);
5504:
5505: n = (n / 100 + 1) * 100;
5506: n++;
5507: cont1.add(tvBoolean);
5508: n++;
5509: if (!cont1.contains(tvBoolean))
5510: error(test, n);
5511: n++;
5512: cont1.add(tvByte);
5513: n++;
5514: if (!cont1.contains(tvByte))
5515: error(test, n);
5516: n++;
5517: cont1.add(tvShort);
5518: n++;
5519: if (!cont1.contains(tvShort))
5520: error(test, n);
5521: n++;
5522: cont1.add(tvInt);
5523: n++;
5524: if (!cont1.contains(tvInt))
5525: error(test, n);
5526: n++;
5527: cont1.add(tvLong);
5528: n++;
5529: if (!cont1.contains(tvLong))
5530: error(test, n);
5531: n++;
5532: cont1.add(tvChar);
5533: n++;
5534: if (!cont1.contains(tvChar))
5535: error(test, n);
5536: n++;
5537: cont1.add(tvFloat);
5538: n++;
5539: if (!cont1.contains(tvFloat))
5540: error(test, n);
5541: n++;
5542: cont1.add(tvDouble);
5543: n++;
5544: if (!cont1.contains(tvDouble))
5545: error(test, n);
5546: n++;
5547: cont1.add(tvString);
5548: n++;
5549: if (!cont1.contains(tvString))
5550: error(test, n);
5551: n++;
5552: if (cont1.contains(tvString, lang))
5553: error(test, n);
5554: n++;
5555: cont1.add(tvString, lang);
5556: n++;
5557: if (!cont1.contains(tvString, lang))
5558: error(test, n);
5559: n++;
5560: cont1.add(tvLiteral);
5561: n++;
5562: if (!cont1.contains(tvLiteral))
5563: error(test, n);
5564: n++;
5565: cont1.add(tvResObj);
5566: n++;
5567: if (!cont1.contains(tvResObj))
5568: error(test, n);
5569: n++;
5570: cont1.add(tvLitObj);
5571: n++;
5572: if (!cont1.contains(tvLitObj))
5573: error(test, n);
5574: n++;
5575: if (!(cont1.size() == 13))
5576: error(test, n);
5577:
5578: {
5579: n = (n / 100 + 1) * 100;
5580: ;
5581: for (int i = 0; i < num; i++) {
5582: cont2.add(i);
5583: }
5584: n++;
5585: if (!(cont2.size() == num))
5586: error(test, n);
5587: n++;
5588: nIter = cont2.iterator();
5589: for (int i = 0; i < num; i++) {
5590: if (!(((Literal) nIter.nextNode()).getInt() == i))
5591: error(test, 320 + i);
5592: }
5593: nIter.close();
5594: }
5595:
5596: {
5597: boolean[] found = new boolean[num];
5598: boolean[] pattern = { true, true, true, false, false,
5599: false, false, false, true, true };
5600:
5601: n = (n / 100 + 1) * 100;
5602: ;
5603: n++;
5604: nIter = cont2.iterator();
5605: for (int i = 0; i < num; i++) {
5606: n++;
5607: nIter.nextNode();
5608: n++;
5609: if (!pattern[i])
5610: nIter.remove();
5611: found[i] = false;
5612: }
5613: n++;
5614: nIter.close();
5615: n = (n / 100 + 1) * 100;
5616: ;
5617: n++;
5618: nIter = cont2.iterator();
5619: while (nIter.hasNext()) {
5620: int v = ((Literal) nIter.nextNode()).getInt();
5621: n++;
5622: if (found[v])
5623: error(test, n);
5624: found[v] = true;
5625: }
5626: n++;
5627: nIter.close();
5628: n = (n / 100 + 1) * 100;
5629: for (int i = 0; i < num; i++) {
5630: n++;
5631: if (!(found[i] == pattern[i]))
5632: error(test, n);
5633: }
5634: }
5635: } catch (Exception e) {
5636: logger.error("test " + test + "[" + n + "]", e);
5637: errors = true;
5638: }
5639: }
5640:
5641: public void testBag(Model m, Bag bag1, Bag bag2, Bag bag3,
5642: String test, int n) {
5643: int num = 10;
5644: NodeIterator nIter;
5645:
5646: try {
5647: {
5648: boolean[] found = new boolean[num];
5649: boolean[] pattern = { true, true, true, false, false,
5650: false, false, false, true, true };
5651:
5652: for (int i = 0; i < num; i++) {
5653: bag1.add(i);
5654: }
5655: n++;
5656: nIter = bag1.iterator();
5657: for (int i = 0; i < num; i++) {
5658: n++;
5659: nIter.nextNode();
5660: n++;
5661: if (!pattern[i])
5662: nIter.remove();
5663: found[i] = false;
5664: }
5665: nIter.close();
5666: n = (n / 100 + 1) * 100;
5667: n++;
5668: nIter = bag1.iterator();
5669: while (nIter.hasNext()) {
5670: int v = ((Literal) nIter.nextNode()).getInt();
5671: n++;
5672: if (found[v])
5673: error(test, n);
5674: found[v] = true;
5675: }
5676: n++;
5677: nIter.close();
5678: n = (n / 100 + 1) * 100;
5679: for (int i = 0; i < num; i++) {
5680: n++;
5681: if (!(found[i] == pattern[i]))
5682: error(test, n);
5683: }
5684: }
5685:
5686: {
5687: boolean[] found = new boolean[num];
5688: boolean[] pattern = { false, true, true, false, false,
5689: false, false, false, true, false };
5690:
5691: n = (n / 100 + 1) * 100;
5692: for (int i = 0; i < num; i++) {
5693: bag2.add(i);
5694: }
5695: n++;
5696: nIter = bag2.iterator();
5697: for (int i = 0; i < num; i++) {
5698: n++;
5699: nIter.nextNode();
5700: n++;
5701: if (!pattern[i])
5702: nIter.remove();
5703: found[i] = false;
5704: }
5705: n++;
5706: nIter.close();
5707: n = (n / 100 + 1) * 100;
5708: n++;
5709: nIter = bag2.iterator();
5710: while (nIter.hasNext()) {
5711: int v = ((Literal) nIter.nextNode()).getInt();
5712: n++;
5713: if (found[v])
5714: error(test, n);
5715: found[v] = true;
5716: }
5717: n++;
5718: nIter.close();
5719: n = (n / 100 + 1) * 100;
5720: for (int i = 0; i < num; i++) {
5721: n++;
5722: if (!(found[i] == pattern[i]))
5723: error(test, n);
5724: }
5725: }
5726:
5727: {
5728: boolean[] found = new boolean[num];
5729: boolean[] pattern = { false, false, false, false,
5730: false, false, false, false, false, false };
5731:
5732: n = (n / 100 + 1) * 100;
5733: for (int i = 0; i < num; i++) {
5734: bag3.add(i);
5735: }
5736: n++;
5737: nIter = bag3.iterator();
5738: for (int i = 0; i < num; i++) {
5739: n++;
5740: nIter.nextNode();
5741: n++;
5742: if (!pattern[i])
5743: nIter.remove();
5744: found[i] = false;
5745: }
5746: n++;
5747: nIter.close();
5748: n = (n / 100 + 1) * 100;
5749: ;
5750: n++;
5751: nIter = bag3.iterator();
5752: while (nIter.hasNext()) {
5753: int v = ((Literal) nIter.nextNode()).getInt();
5754: n++;
5755: if (found[v])
5756: error(test, n);
5757: found[v] = true;
5758: }
5759: n++;
5760: nIter.close();
5761: n = (n / 100 + 1) * 100;
5762: for (int i = 0; i < num; i++) {
5763: n++;
5764: if (!(found[i] == pattern[i]))
5765: error(test, n);
5766: }
5767: }
5768:
5769: } catch (Exception e) {
5770: logger.error("test " + test + "[" + n + "]", e);
5771: errors = true;
5772: }
5773: }
5774:
5775: public void testAlt(Model m, Alt alt1, Alt alt2, Alt alt3,
5776: Alt alt4, String test, int n) {
5777:
5778: try {
5779: NodeIterator nIter;
5780: StmtIterator sIter;
5781: boolean tvBoolean = true;
5782: byte tvByte = 1;
5783: short tvShort = 2;
5784: int tvInt = -1;
5785: long tvLong = -2;
5786: char tvChar = '!';
5787: float tvFloat = (float) 123.456;
5788: double tvDouble = -123.456;
5789: String tvString = "test 12 string";
5790: LitTestObj tvObject = new LitTestObj(12345);
5791: Literal tvLiteral = m.createLiteral("test 12 string 2");
5792: Resource tvResource = m.createResource();
5793: Resource tvResObj = m.createResource(new ResTestObjF());
5794: Object tvLitObj = new LitTestObj(1234);
5795: Bag tvBag = m.createBag();
5796: Alt tvAlt = m.createAlt();
5797: Seq tvSeq = m.createSeq();
5798: String lang = "fr";
5799: int num = 10;
5800: Statement stmt;
5801:
5802: {
5803: boolean[] found = new boolean[num];
5804: boolean[] pattern = { true, true, true, false, false,
5805: false, false, false, true, true };
5806:
5807: n = (n / 100 + 1) * 100;
5808: for (int i = 0; i < num; i++) {
5809: alt1.add(i);
5810: }
5811: n++;
5812: nIter = alt1.iterator();
5813: for (int i = 0; i < num; i++) {
5814: n++;
5815: nIter.nextNode();
5816: n++;
5817: if (!pattern[i])
5818: nIter.remove();
5819: found[i] = false;
5820: }
5821: n++;
5822: nIter.close();
5823: n = (n / 100 + 1) * 100;
5824: n++;
5825: nIter = alt1.iterator();
5826: while (nIter.hasNext()) {
5827: int v = ((Literal) nIter.nextNode()).getInt();
5828: n++;
5829: if (found[v])
5830: error(test, n);
5831: found[v] = true;
5832: }
5833: n++;
5834: nIter.close();
5835: n = (n / 100 + 1) * 100;
5836: for (int i = 0; i < num; i++) {
5837: n++;
5838: if (!(found[i] == pattern[i]))
5839: error(test, n);
5840: }
5841: }
5842:
5843: {
5844: boolean[] found = new boolean[num];
5845: boolean[] pattern = { false, true, true, false, false,
5846: false, false, false, true, false };
5847:
5848: n = (n / 100 + 1) * 100;
5849: for (int i = 0; i < num; i++) {
5850: alt2.add(i);
5851: }
5852: n++;
5853: nIter = alt2.iterator();
5854: for (int i = 0; i < num; i++) {
5855: n++;
5856: nIter.nextNode();
5857: n++;
5858: if (!pattern[i])
5859: nIter.remove();
5860: found[i] = false;
5861: }
5862: n++;
5863: nIter.close();
5864: n = 550;
5865: n++;
5866: nIter = alt2.iterator();
5867: while (nIter.hasNext()) {
5868: int v = ((Literal) nIter.nextNode()).getInt();
5869: n++;
5870: if (found[v])
5871: error(test, n);
5872: found[v] = true;
5873: }
5874: n++;
5875: nIter.close();
5876: n = 580;
5877: for (int i = 0; i < num; i++) {
5878: n++;
5879: if (!(found[i] == pattern[i]))
5880: error(test, n);
5881: }
5882: }
5883:
5884: {
5885: boolean[] found = new boolean[num];
5886: boolean[] pattern = { false, false, false, false,
5887: false, false, false, false, false, false };
5888:
5889: n = (n / 100 + 1) * 100;
5890: for (int i = 0; i < num; i++) {
5891: alt3.add(i);
5892: }
5893: n++;
5894: nIter = alt3.iterator();
5895: for (int i = 0; i < num; i++) {
5896: n++;
5897: nIter.nextNode();
5898: n++;
5899: if (!pattern[i])
5900: nIter.remove();
5901: found[i] = false;
5902: }
5903: n++;
5904: nIter.close();
5905: n = (n / 100 + 1) * 100;
5906: n++;
5907: nIter = alt3.iterator();
5908: while (nIter.hasNext()) {
5909: int v = ((Literal) nIter.nextNode()).getInt();
5910: n++;
5911: if (found[v])
5912: error(test, n);
5913: found[v] = true;
5914: }
5915: n++;
5916: nIter.close();
5917: n = (n / 100 + 1) * 100;
5918: for (int i = 0; i < num; i++) {
5919: n++;
5920: if (!(found[i] == pattern[i]))
5921: error(test, n);
5922: }
5923: }
5924:
5925: {
5926: n = (n / 100 + 1) * 100;
5927: n++;
5928: if (!(alt4.setDefault(tvLiteral).getDefault()
5929: .equals(tvLiteral)))
5930: error(test, n);
5931: n++;
5932: if (!(alt4.setDefault(tvLiteral).getDefaultLiteral()
5933: .equals(tvLiteral)))
5934: error(test, n);
5935: n++;
5936: if (!alt4.setDefault(tvResource).getDefaultResource()
5937: .equals(tvResource))
5938: error(test, n);
5939: n++;
5940: if (!(alt4.setDefault(tvByte).getDefaultByte() == tvByte))
5941: error(test, n);
5942: n++;
5943: if (!(alt4.setDefault(tvShort).getDefaultShort() == tvShort))
5944: error(test, n);
5945: n++;
5946: if (!(alt4.setDefault(tvInt).getDefaultInt() == tvInt))
5947: error(test, n);
5948: n++;
5949: if (!(alt4.setDefault(tvLong).getDefaultLong() == tvLong))
5950: error(test, n);
5951: n++;
5952: if (!(alt4.setDefault(tvChar).getDefaultChar() == tvChar))
5953: error(test, n);
5954: n++;
5955: if (!(alt4.setDefault(tvFloat).getDefaultFloat() == tvFloat))
5956: error(test, n);
5957: n++;
5958: if (!(alt4.setDefault(tvDouble).getDefaultDouble() == tvDouble))
5959: error(test, n);
5960: n++;
5961: if (!alt4.setDefault(tvString).getDefaultString()
5962: .equals(tvString))
5963: error(test, n);
5964: n++;
5965: if (!alt4.getDefaultLanguage().equals(""))
5966: error(test, n);
5967: n++;
5968: if (!alt4.setDefault(tvString, lang).getDefaultString()
5969: .equals(tvString))
5970: error(test, n);
5971: n++;
5972: if (!alt4.getDefaultLanguage().equals(lang))
5973: error(test, n);
5974: n++;
5975: if (!alt4.setDefault(tvResObj).getDefaultResource(
5976: new ResTestObjF()).equals(tvResObj))
5977: error(test, n);
5978: n++;
5979: if (!alt4.setDefault(tvLitObj).getDefaultObject(
5980: new LitTestObjF()).equals(tvLitObj))
5981: error(test, n);
5982: n++;
5983: if (!alt4.setDefault(tvAlt).getDefaultAlt().equals(
5984: tvAlt))
5985: error(test, n);
5986: n++;
5987: if (!alt4.setDefault(tvBag).getDefaultBag().equals(
5988: tvBag))
5989: error(test, n);
5990: n++;
5991: if (!alt4.setDefault(tvSeq).getDefaultSeq().equals(
5992: tvSeq))
5993: error(test, n);
5994: }
5995:
5996: } catch (Exception e) {
5997: logger.error("test " + test + "[" + n + "]", e);
5998: errors = true;
5999: }
6000: }
6001:
6002: public void testSeq(Model m, Seq seq1, Seq seq2, Seq seq3,
6003: Seq seq4, Seq seq5, Seq seq6, Seq seq7, String test, int n) {
6004:
6005: try {
6006: NodeIterator nIter;
6007: StmtIterator sIter;
6008: boolean tvBoolean = true;
6009: byte tvByte = 1;
6010: short tvShort = 2;
6011: int tvInt = -1;
6012: long tvLong = -2;
6013: char tvChar = '!';
6014: float tvFloat = (float) 123.456;
6015: double tvDouble = -123.456;
6016: String tvString = "test 12 string";
6017: LitTestObj tvObject = new LitTestObj(12345);
6018: Literal tvLiteral = m.createLiteral("test 12 string 2");
6019: Resource tvResource = m.createResource();
6020: Resource tvResObj = m.createResource(new ResTestObjF());
6021: Object tvLitObj = new LitTestObj(1234);
6022: Bag tvBag = m.createBag();
6023: Alt tvAlt = m.createAlt();
6024: Seq tvSeq = m.createSeq();
6025: String lang = "fr";
6026: int num = 10;
6027: Statement stmt;
6028:
6029: {
6030:
6031: for (int i = 0; i < num; i++) {
6032: seq1.add(i);
6033: }
6034: n++;
6035: if (!(seq1.size() == num))
6036: error(test, n);
6037: n++;
6038: nIter = seq1.iterator();
6039: for (int i = 0; i < num; i++) {
6040: if (!(((Literal) nIter.nextNode()).getInt() == i))
6041: error(test, 320 + i);
6042: }
6043: nIter.close();
6044: }
6045:
6046: {
6047: boolean[] found = new boolean[num];
6048: boolean[] pattern = { true, true, true, false, false,
6049: false, false, false, true, true };
6050:
6051: n = (n / 100) * 100 + 100;
6052: n++;
6053: nIter = seq1.iterator();
6054: for (int i = 0; i < num; i++) {
6055: n++;
6056: nIter.nextNode();
6057: n++;
6058: if (!pattern[i])
6059: nIter.remove();
6060: found[i] = false;
6061: }
6062: n++;
6063: nIter.close();
6064: n = (n / 100) * 100 + 100;
6065: n++;
6066: nIter = seq1.iterator();
6067: while (nIter.hasNext()) {
6068: int v = ((Literal) nIter.nextNode()).getInt();
6069: n++;
6070: if (found[v])
6071: error(test, n);
6072: found[v] = true;
6073: }
6074: n++;
6075: nIter.close();
6076: n = (n / 100) * 100 + 100;
6077: for (int i = 0; i < num; i++) {
6078: n++;
6079: if (!(found[i] == pattern[i]))
6080: error(test, n);
6081: }
6082: }
6083:
6084: {
6085: boolean[] found = new boolean[num];
6086: boolean[] pattern = { false, true, true, false, false,
6087: false, false, false, true, false };
6088:
6089: n = (n / 100) * 100 + 100;
6090: for (int i = 0; i < num; i++) {
6091: seq2.add(i);
6092: }
6093: n++;
6094: nIter = seq2.iterator();
6095: for (int i = 0; i < num; i++) {
6096: n++;
6097: nIter.nextNode();
6098: n++;
6099: if (!pattern[i])
6100: nIter.remove();
6101: found[i] = false;
6102: }
6103: n++;
6104: nIter.close();
6105: n = (n / 100) * 100 + 100;
6106: n++;
6107: nIter = seq2.iterator();
6108: while (nIter.hasNext()) {
6109: int v = ((Literal) nIter.nextNode()).getInt();
6110: n++;
6111: if (found[v])
6112: error(test, n);
6113: found[v] = true;
6114: }
6115: n++;
6116: nIter.close();
6117: n = (n / 100) * 100 + 100;
6118: for (int i = 0; i < num; i++) {
6119: n++;
6120: if (!(found[i] == pattern[i]))
6121: error(test, n);
6122: }
6123: }
6124:
6125: {
6126: boolean[] found = new boolean[num];
6127: boolean[] pattern = { false, false, false, false,
6128: false, false, false, false, false, false };
6129:
6130: n = (n / 100) * 100 + 100;
6131: for (int i = 0; i < num; i++) {
6132: seq3.add(i);
6133: }
6134: n++;
6135: nIter = seq3.iterator();
6136: for (int i = 0; i < num; i++) {
6137: n++;
6138: nIter.nextNode();
6139: n++;
6140: if (!pattern[i])
6141: nIter.remove();
6142: found[i] = false;
6143: }
6144: n++;
6145: nIter.close();
6146: n = (n / 100) * 100 + 100;
6147: n++;
6148: nIter = seq3.iterator();
6149: while (nIter.hasNext()) {
6150: int v = ((Literal) nIter.nextNode()).getInt();
6151: n++;
6152: if (found[v])
6153: error(test, n);
6154: found[v] = true;
6155: }
6156: n++;
6157: nIter.close();
6158: n = (n / 100) * 100 + 100;
6159: for (int i = 0; i < num; i++) {
6160: n++;
6161: if (!(found[i] == pattern[i]))
6162: error(test, n);
6163: }
6164: }
6165:
6166: {
6167: n = (n / 100) * 100 + 100;
6168: n++;
6169: seq4.add(tvBoolean);
6170: n++;
6171: if (!(seq4.getBoolean(1) == tvBoolean))
6172: error(test, n);
6173: n++;
6174: seq4.add(tvByte);
6175: n++;
6176: if (!(seq4.getByte(2) == tvByte))
6177: error(test, n);
6178: n++;
6179: seq4.add(tvShort);
6180: n++;
6181: if (!(seq4.getShort(3) == tvShort))
6182: error(test, n);
6183: n++;
6184: seq4.add(tvInt);
6185: n++;
6186: if (!(seq4.getInt(4) == tvInt))
6187: error(test, n);
6188: n++;
6189: seq4.add(tvLong);
6190: n++;
6191: if (!(seq4.getLong(5) == tvLong))
6192: error(test, n);
6193: n++;
6194: seq4.add(tvChar);
6195: n++;
6196: if (!(seq4.getChar(6) == tvChar))
6197: error(test, n);
6198: n++;
6199: seq4.add(tvFloat);
6200: n++;
6201: if (!(seq4.getFloat(7) == tvFloat))
6202: error(test, n);
6203: n++;
6204: seq4.add(tvDouble);
6205: n++;
6206: if (!(seq4.getDouble(8) == tvDouble))
6207: error(test, n);
6208: n++;
6209: seq4.add(tvString);
6210: n++;
6211: if (!(seq4.getString(9).equals(tvString)))
6212: error(test, n);
6213: n++;
6214: if (!(seq4.getLanguage(9).equals("")))
6215: error(test, n);
6216: n++;
6217: seq4.add(tvString, lang);
6218: n++;
6219: if (!(seq4.getString(10).equals(tvString)))
6220: error(test, n);
6221: n++;
6222: if (!(seq4.getLanguage(10).equals(lang)))
6223: error(test, n);
6224: n++;
6225: seq4.add(tvLitObj);
6226: n++;
6227: if (!(seq4.getObject(11, new LitTestObjF())
6228: .equals(tvLitObj)))
6229: error(test, n);
6230: n++;
6231: seq4.add(tvResource);
6232: n++;
6233: if (!(seq4.getResource(12).equals(tvResource)))
6234: error(test, n);
6235: n++;
6236: seq4.add(tvLiteral);
6237: n++;
6238: if (!(seq4.getLiteral(13).equals(tvLiteral)))
6239: error(test, n);
6240: n++;
6241: seq4.add(tvResObj);
6242: n++;
6243: if (!(seq4.getResource(14, new ResTestObjF())
6244: .equals(tvResObj)))
6245: error(test, n);
6246: n++;
6247: seq4.add(tvBag);
6248: n++;
6249: if (!(seq4.getBag(15).equals(tvBag)))
6250: error(test, n);
6251: n++;
6252: seq4.add(tvAlt);
6253: n++;
6254: if (!(seq4.getAlt(16).equals(tvAlt)))
6255: error(test, n);
6256: n++;
6257: seq4.add(tvSeq);
6258: n++;
6259: if (!(seq4.getSeq(17).equals(tvSeq)))
6260: error(test, n);
6261: n++;
6262: try {
6263: seq4.getInt(18);
6264: error(test, n);
6265: } catch (SeqIndexBoundsException e) {
6266: // as required
6267: }
6268: n++;
6269: try {
6270: seq4.getInt(0);
6271: error(test, n);
6272: } catch (SeqIndexBoundsException e) {
6273: // as required
6274: }
6275: }
6276:
6277: {
6278: n = (n / 100) * 100 + 100;
6279: for (int i = 0; i < num; i++) {
6280: seq5.add(i);
6281: }
6282:
6283: try {
6284: n++;
6285: seq5.add(0, false);
6286: error(test, n);
6287: } catch (SeqIndexBoundsException e) {
6288: // as required
6289: }
6290: seq5.add(num + 1, false);
6291: if (seq5.size() != num + 1)
6292: error(test, n);
6293: seq5.remove(num + 1);
6294: try {
6295: n++;
6296: seq5.add(num + 2, false);
6297: error(test, n);
6298: } catch (SeqIndexBoundsException e) {
6299: // as required
6300: }
6301:
6302: n = (n / 100) * 100 + 100;
6303: int size = seq5.size();
6304: for (int i = 1; i <= num - 1; i++) {
6305: n++;
6306: seq5.add(i, 1000 + i);
6307: n++;
6308: if (!(seq5.getInt(i) == 1000 + i))
6309: error(test, n);
6310: n++;
6311: if (!(seq5.getInt(i + 1) == 0))
6312: error(test, n);
6313: n++;
6314: if (!(seq5.size() == (size + i)))
6315: error(test, n);
6316: n++;
6317: if (!(seq5.getInt(size) == (num - i - 1)))
6318: error(test, n);
6319: }
6320: n = (n / 100) * 100 + 100;
6321: seq6.add(m.createResource());
6322: seq6.add(1, tvBoolean);
6323: n++;
6324: if (!(seq6.getBoolean(1) == tvBoolean))
6325: error(test, n);
6326: seq6.add(1, tvByte);
6327: n++;
6328: if (!(seq6.getByte(1) == tvByte))
6329: error(test, n);
6330: seq6.add(1, tvShort);
6331: n++;
6332: if (!(seq6.getShort(1) == tvShort))
6333: error(test, n);
6334: seq6.add(1, tvInt);
6335: n++;
6336: if (!(seq6.getInt(1) == tvInt))
6337: error(test, n);
6338: seq6.add(1, tvLong);
6339: n++;
6340: if (!(seq6.getLong(1) == tvLong))
6341: error(test, n);
6342: seq6.add(1, tvChar);
6343: n++;
6344: if (!(seq6.getChar(1) == tvChar))
6345: error(test, n);
6346: seq6.add(1, tvFloat);
6347: n++;
6348: if (!(seq6.getFloat(1) == tvFloat))
6349: error(test, n);
6350: seq6.add(1, tvDouble);
6351: n++;
6352: if (!(seq6.getDouble(1) == tvDouble))
6353: error(test, n);
6354: seq6.add(1, tvString);
6355: n++;
6356: if (!(seq6.getString(1).equals(tvString)))
6357: error(test, n);
6358: seq6.add(1, tvString, lang);
6359: n++;
6360: if (!(seq6.getString(1).equals(tvString)))
6361: error(test, n);
6362: seq6.add(1, tvResource);
6363: n++;
6364: if (!(seq6.getResource(1).equals(tvResource)))
6365: error(test, n);
6366: seq6.add(1, tvLiteral);
6367: n++;
6368: if (!(seq6.getLiteral(1).equals(tvLiteral)))
6369: error(test, n);
6370: seq6.add(1, tvLitObj);
6371: n++;
6372: if (!(seq6.getObject(1, new LitTestObjF())
6373: .equals(tvLitObj)))
6374: error(test, n);
6375:
6376: n = (n / 100) * 100 + 100;
6377: n++;
6378: if (!(seq6.indexOf(tvLitObj) == 1))
6379: error(test, n);
6380: n++;
6381: if (!(seq6.indexOf(tvLiteral) == 2))
6382: error(test, n);
6383: n++;
6384: if (!(seq6.indexOf(tvResource) == 3))
6385: error(test, n);
6386: n++;
6387: if (!(seq6.indexOf(tvString, lang) == 4))
6388: error(test, n);
6389: n++;
6390: if (!(seq6.indexOf(tvString) == 5))
6391: error(test, n);
6392: n++;
6393: if (!(seq6.indexOf(tvDouble) == 6))
6394: error(test, n);
6395: n++;
6396: if (!(seq6.indexOf(tvFloat) == 7))
6397: error(test, n);
6398: n++;
6399: if (!(seq6.indexOf(tvChar) == 8))
6400: error(test, n);
6401: n++;
6402: if (!(seq6.indexOf(tvLong) == 9))
6403: error(test, n);
6404: n++;
6405: if (!(seq6.indexOf(tvInt) == 10))
6406: error(test, n);
6407: n++;
6408: if (!(seq6.indexOf(tvShort) == 11))
6409: error(test, n);
6410: n++;
6411: if (!(seq6.indexOf(tvByte) == 12))
6412: error(test, n);
6413: n++;
6414: if (!(seq6.indexOf(tvBoolean) == 13))
6415: error(test, n);
6416: n++;
6417: if (!(seq6.indexOf(1234543) == 0))
6418: error(test, n);
6419:
6420: n = (n / 100) * 100 + 100;
6421: for (int i = 0; i < num; i++) {
6422: seq7.add(i);
6423: }
6424: n = (n / 100) * 100 + 100;
6425: seq7.set(5, tvBoolean);
6426: n++;
6427: if (!(seq7.getBoolean(5) == tvBoolean))
6428: error(test, n);
6429: n++;
6430: if (!(seq7.getInt(4) == 3))
6431: error(test, n);
6432: n++;
6433: if (!(seq7.getInt(6) == 5))
6434: error(test, n);
6435: n++;
6436: if (!(seq7.size() == num))
6437: error(test, n);
6438: n = (n / 100) * 100 + 100;
6439: seq7.set(5, tvByte);
6440: n++;
6441: if (!(seq7.getByte(5) == tvByte))
6442: error(test, n);
6443: n++;
6444: if (!(seq7.getInt(4) == 3))
6445: error(test, n);
6446: n++;
6447: if (!(seq7.getInt(6) == 5))
6448: error(test, n);
6449: n++;
6450: if (!(seq7.size() == num))
6451: error(test, n);
6452: n = (n / 100) * 100 + 100;
6453: seq7.set(5, tvShort);
6454: n++;
6455: if (!(seq7.getShort(5) == tvShort))
6456: error(test, n);
6457: n++;
6458: if (!(seq7.getInt(4) == 3))
6459: error(test, n);
6460: n++;
6461: if (!(seq7.getInt(6) == 5))
6462: error(test, n);
6463: n++;
6464: if (!(seq7.size() == num))
6465: error(test, n);
6466: n = (n / 100) * 100 + 100;
6467: seq7.set(5, tvInt);
6468: n++;
6469: if (!(seq7.getInt(5) == tvInt))
6470: error(test, n);
6471: n++;
6472: if (!(seq7.getInt(4) == 3))
6473: error(test, n);
6474: n++;
6475: if (!(seq7.getInt(6) == 5))
6476: error(test, n);
6477: n++;
6478: if (!(seq7.size() == num))
6479: error(test, n);
6480: n = (n / 100) * 100 + 100;
6481: seq7.set(5, tvLong);
6482: n++;
6483: if (!(seq7.getLong(5) == tvLong))
6484: error(test, n);
6485: n++;
6486: if (!(seq7.getInt(4) == 3))
6487: error(test, n);
6488: n++;
6489: if (!(seq7.getInt(6) == 5))
6490: error(test, n);
6491: n++;
6492: if (!(seq7.size() == num))
6493: error(test, n);
6494: n = (n / 100) * 100 + 100;
6495: seq7.set(5, tvChar);
6496: n++;
6497: if (!(seq7.getChar(5) == tvChar))
6498: error(test, n);
6499: n++;
6500: if (!(seq7.getInt(4) == 3))
6501: error(test, n);
6502: n++;
6503: if (!(seq7.getInt(6) == 5))
6504: error(test, n);
6505: n++;
6506: if (!(seq7.size() == num))
6507: error(test, n);
6508: n = (n / 100) * 100 + 100;
6509: seq7.set(5, tvFloat);
6510: n++;
6511: if (!(seq7.getFloat(5) == tvFloat))
6512: error(test, n);
6513: n++;
6514: if (!(seq7.getInt(4) == 3))
6515: error(test, n);
6516: n++;
6517: if (!(seq7.getInt(6) == 5))
6518: error(test, n);
6519: n++;
6520: if (!(seq7.size() == num))
6521: error(test, n);
6522: n = (n / 100) * 100 + 100;
6523: seq7.set(5, tvDouble);
6524: n++;
6525: if (!(seq7.getDouble(5) == tvDouble))
6526: error(test, n);
6527: n++;
6528: if (!(seq7.getInt(4) == 3))
6529: error(test, n);
6530: n++;
6531: if (!(seq7.getInt(6) == 5))
6532: error(test, n);
6533: n++;
6534: if (!(seq7.size() == num))
6535: error(test, n);
6536: n = (n / 100) * 100 + 100;
6537: seq7.set(5, tvString);
6538: n++;
6539: if (!(seq7.getString(5).equals(tvString)))
6540: error(test, n);
6541: n++;
6542: if (!(seq7.getLanguage(5).equals("")))
6543: error(test, n);
6544: n++;
6545: if (!(seq7.getInt(4) == 3))
6546: error(test, n);
6547: n++;
6548: if (!(seq7.getInt(6) == 5))
6549: error(test, n);
6550: n++;
6551: if (!(seq7.size() == num))
6552: error(test, n);
6553: seq7.set(5, tvString, lang);
6554: n++;
6555: if (!(seq7.getString(5).equals(tvString)))
6556: error(test, n);
6557: n++;
6558: if (!(seq7.getLanguage(5).equals(lang)))
6559: error(test, n);
6560: n++;
6561: if (!(seq7.getInt(4) == 3))
6562: error(test, n);
6563: n++;
6564: if (!(seq7.getInt(6) == 5))
6565: error(test, n);
6566: n++;
6567: if (!(seq7.size() == num))
6568: error(test, n);
6569: n = (n / 100) * 100 + 100;
6570: seq7.set(5, tvLiteral);
6571: n++;
6572: if (!(seq7.getLiteral(5).equals(tvLiteral)))
6573: error(test, n);
6574: n++;
6575: if (!(seq7.getInt(4) == 3))
6576: error(test, n);
6577: n++;
6578: if (!(seq7.getInt(6) == 5))
6579: error(test, n);
6580: n++;
6581: if (!(seq7.size() == num))
6582: error(test, n);
6583: n = (n / 100) * 100 + 100;
6584: seq7.set(5, tvResource);
6585: n++;
6586: if (!(seq7.getResource(5).equals(tvResource)))
6587: error(test, n);
6588: n++;
6589: if (!(seq7.getInt(4) == 3))
6590: error(test, n);
6591: n++;
6592: if (!(seq7.getInt(6) == 5))
6593: error(test, n);
6594: n++;
6595: if (!(seq7.size() == num))
6596: error(test, n);
6597: n = (n / 100) * 100 + 100;
6598: seq7.set(5, tvLitObj);
6599: n++;
6600: if (!(seq7.getObject(5, new LitTestObjF()))
6601: .equals(tvLitObj))
6602: error(test, n);
6603: n++;
6604: if (!(seq7.getInt(4) == 3))
6605: error(test, n);
6606: n++;
6607: if (!(seq7.getInt(6) == 5))
6608: error(test, n);
6609: n++;
6610: if (!(seq7.size() == num))
6611: error(test, n);
6612: n = (n / 100) * 100 + 100;
6613: seq7.set(5, tvResObj);
6614: n++;
6615: if (!(seq7.getResource(5, new ResTestObjF())
6616: .equals(tvResObj)))
6617: error(test, n);
6618: n++;
6619: if (!(seq7.getInt(4) == 3))
6620: error(test, n);
6621: n++;
6622: if (!(seq7.getInt(6) == 5))
6623: error(test, n);
6624: n++;
6625: if (!(seq7.size() == num))
6626: error(test, n);
6627:
6628: }
6629:
6630: } catch (Exception e) {
6631: logger.error("test " + test + "[" + n + "]", e);
6632: errors = true;
6633: }
6634: }
6635:
6636: public void error(String testName, int testNum) {
6637: System.out.println("Test Failed: " + testName + " " + testNum
6638: + " ");
6639: errors = true;
6640: throw new RuntimeException("BOOM BOOM BOOM");
6641: }
6642:
6643: public void error(String testName, int testNum, long v) {
6644: System.out.println("Test Failed: " + testName + " " + testNum
6645: + " " + Long.toString(v));
6646: errors = true;
6647: throw new RuntimeException("BOOM BOOM BOOM");
6648: }
6649:
6650: public void error(String testName, int testNum, Exception e) {
6651: System.out.println("Test Failed: " + testName + " " + testNum
6652: + " " + e.toString());
6653: errors = true;
6654: throw new RuntimeException("BOOM BOOM BOOM");
6655: }
6656:
6657: public boolean getErrors() {
6658: return errors;
6659: }
6660:
6661: public boolean setErrors(boolean b) {
6662: boolean temp = errors;
6663: errors = b;
6664: return temp;
6665: }
6666:
6667: public static class LitTestObj {
6668: protected long content;
6669:
6670: public LitTestObj(long l) {
6671: content = l;
6672: }
6673:
6674: public LitTestObj(String s) {
6675: content = Long.parseLong(s.substring(1, s.length() - 1));
6676: }
6677:
6678: public String toString() {
6679: return "[" + Long.toString(content) + "]";
6680: }
6681:
6682: public int hashCode() {
6683: return (int) (content ^ (content >> 32));
6684: }
6685:
6686: public boolean equals(Object o) {
6687: if (o instanceof LitTestObj) {
6688: return content == ((LitTestObj) o).content;
6689: } else {
6690: return false;
6691: }
6692: }
6693: }
6694:
6695: public static class LitTestObjF implements ObjectF {
6696: public Object createObject(String s) {
6697: return new LitTestObj(s);
6698: }
6699: }
6700:
6701: public static class ResTestObjF implements ResourceF {
6702: public Resource createResource(Resource r) {
6703: return new ResourceImpl(r, (ModelCom) r.getModel());
6704: }
6705: }
6706: }
6707: /*
6708: * (c) Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
6709: * All rights reserved.
6710: *
6711: * Redistribution and use in source and binary forms, with or without
6712: * modification, are permitted provided that the following conditions
6713: * are met:
6714: * 1. Redistributions of source code must retain the above copyright
6715: * notice, this list of conditions and the following disclaimer.
6716: * 2. Redistributions in binary form must reproduce the above copyright
6717: * notice, this list of conditions and the following disclaimer in the
6718: * documentation and/or other materials provided with the distribution.
6719: * 3. The name of the author may not be used to endorse or promote products
6720: * derived from this software without specific prior written permission.
6721:
6722: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
6723: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
6724: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
6725: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
6726: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
6727: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
6728: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
6729: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
6730: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
6731: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6732: *
6733: * $Id: Regression.java,v 1.42 2008/02/13 07:54:03 chris-dollin Exp $
6734: */
|