001: /**
002: * Speedo: an implementation of JDO compliant personality on top of JORM generic
003: * I/O sub-system.
004: * Copyright (C) 2001-2004 France Telecom R&D
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: *
021: *
022: * Contact: speedo@objectweb.org
023: *
024: * Authors: S.Chassande-Barrioz.
025: *
026: */package org.objectweb.speedo.runtime.query.parser;
027:
028: import junit.framework.TestCase;
029:
030: import java.io.CharArrayReader;
031:
032: import org.objectweb.util.monolog.api.Logger;
033: import org.objectweb.util.monolog.api.BasicLevel;
034: import org.objectweb.util.monolog.Monolog;
035: import org.objectweb.speedo.query.jdo.parser.SpeedoQL;
036:
037: /**
038: * Speedo QL Test
039: * Test a list of valid filters.
040: */
041: public class SpeedoQLTest extends TestCase {
042: final static String filters[] = {
043: "toto.titi",
044: "toto.titi()",
045: "this.toto",
046: "this.titi()",
047: "(+78)",
048: "(-89458.457)",
049: "(~788)",
050: "((~abc)|| tyty)",
051: "(!rere && toto+7)",
052: "((boolean)john)",
053: "(a < b > c <= d >= e | f || g & h && i == j != k + l - m / n * o ^ p.jotp())",
054: "((byte)b && (short)s || (int)i <= (long)l == (char)c * (float)f / (double)d == (true) && (false | null))",
055: "null",
056: "((char)(byte)(short)b || (char)(java.lang.String)s)",
057: "my.toto((q<b) + 9)", "(house.b())", "((((g)a < b.g())))",
058: "(+4 < t)", "((-4+9*8) == toto.titi.titi.ktkt(one))",
059: "((a < b.house()) || (c.name > ((d*4)/100)))",
060: "toto(tutu).titi(tata)", "toto(titi)",
061: "((1 < 5 > 3) || (4 && 5 <= (934 == 4)))",
062: "(((1 < 5) > 3) || ((4 && 5) <= (934 == 4)))",
063: "(true == a)", "true == a", "(a+b).method()",
064: "(salary > 3000)", "(salary > sal)", "(dept.name == dep)",
065: "(emps.contains(emp) & emp.salary > sal)",
066: "(depts.contains(name))",
067: "((getEmpId () >= 1) && (getEmpId () <= 10))",
068: "a == \"Paul\"", "a >= 1 && b <= 10", "x == param",
069: "x == 4", "x == param1 && y == param2",
070: "reviewers.contains(person) && person == Employee",
071: "reviewers.contains(person) && person == person"
072: //"toto(titi, tatat)",
073: };
074:
075: private final static String LOGGER_NAME = "org.objectweb.speedo.rt.query.parser.speedoql";
076:
077: private static Logger logger = null;
078:
079: static {
080: logger = Monolog.initialize().getLogger(LOGGER_NAME);
081: }
082:
083: public SpeedoQLTest(String name) {
084: super (name);
085: }
086:
087: public void testAll() {
088: logger.log(BasicLevel.DEBUG, "SpeedoQL Test - javacc grammar");
089: for (int i = 0; i < filters.length; i++) {
090: String filter = filters[i];
091: logger.log(BasicLevel.DEBUG, "Testing: " + filter);
092: try {
093: filter = '(' + filter + ')';
094: new SpeedoQL(new CharArrayReader(filter.toCharArray()))
095: .SpeedoQL();
096: } catch (Throwable e) {
097: logger
098: .log(BasicLevel.ERROR, "Parsing of: " + filter,
099: e);
100: fail("Parsing of: " + filter);
101: }
102:
103: }
104: }
105: }
|