/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4886011
* @summary Test that QueryExp.toString() is reversible
* @author Eamonn McManus
* @run clean QueryExpStringTest
* @run build QueryExpStringTest
* @run main QueryExpStringTest
*/
import javax.management.*;
public class QueryExpStringTest {
private static final ValueExp
private static final QueryExp
// Commented-out tests below require change to implementation
attr, "attr",
// qattr, "className.attr",
// Preceding form now appears as className#attr, an incompatible change
// which we don't mind much because nobody uses the two-arg Query.attr.
classattr, "Class",
simpleString, "'simpleString'",
complexString, "'a''b\\\''\"'",
intValue, "12345678",
integerValue, "12345678",
longValue, "12345678",
floatValue, "2.5",
doubleValue, "2.5",
booleanValue, "true",
plusValue, "12345678 + 12345678",
timesValue, "2.5 * 2.5",
minusValue, "2.5 - 2.5",
divValue, "2.5 / 2.5",
gt, "(12345678) > (2.5)",
geq, "(12345678) >= (2.5)",
leq, "(12345678) <= (2.5)",
lt, "(12345678) < (2.5)",
eq, "(12345678) = (2.5)",
between, "(12345678) between (2.5) and (2.5)",
match, "attr like 'simpleString'",
initial, "attr like 'simpleString*'",
initialStar, "attr like '\\**'",
initialPercent, "attr like '%*'",
any, "attr like '*simpleString*'",
anyStar, "attr like '*\\**'",
anyPercent, "attr like '*%*'",
ffinal, "attr like '*simpleString'",
finalMagic, "attr like '*\\?\\*\\[\\\\'",
in, "12345678 in (12345678, 2.5)",
and, "((12345678) > (2.5)) and ((12345678) < (2.5))",
or, "((12345678) > (2.5)) or ((12345678) < (2.5))",
not, "not ((12345678) > (2.5))",
aPlusB_PlusC, "(A + B + C) > (0)",
// aPlus_BPlusC, "(A + (B + C)) > (0)",
};
boolean ok = true;
else {
testString + "}");
ok = false;
}
try {
else
else {
expected + "}; got: {" +
parsedString + "}");
ok = false;
}
} catch (Exception e) {
"}: " + e);
ok = false;
}
}
if (ok)
else {
}
}
return parseQueryAfterParen(ss);
throw new Exception("Expected ) after not (...");
}
if (!(exp instanceof AttributeValueExp &&
pat instanceof StringValueExp)) {
throw new Exception("Expected types `attr like string': " +
}
}
do {
throw new Exception("Expected ) after in (...");
}
}
throw new Exception("Expected in or like after expression");
}
throws Exception {
/* This is very ugly. We might have "(q1) and (q2)" here, or
we might have "(e1) < (e2)". Since the syntax for a query
(q1) is not the same as for an expression (e1), but can
begin with one, we try to parse the query, and if we get an
exception we then try to parse an expression. It's a hacky
kind of look-ahead. */
try {
else
throw new Exception("Expected `)' after subquery");
return result;
} catch (Exception e) {
throw new Exception("Expected `)' after subexpression");
throw new Exception("Expected ` and (' after between");
throw new Exception("Expected `)' after subexpression");
}
}
while (true) {
/* Look ahead to see if we have an arithmetic operator. */
return lhs;
return lhs;
}
throw new Exception("Expected arithmetic operator after space");
throw new Exception("Expected space after arithmetic operator");
}
}
}
if (s.length() == 0)
throw new Exception("Empty string found, expression expected");
if (first == ' ')
throw new Exception("Space found, expression expected");
return parseNumberExp(ss);
if (first == '\'')
return parseString(ss);
if (lastDot < 0)
else
}
return s;
}
int stop;
else // string has only one, stop at it
return word;
}
throws Exception {
if (s.startsWith(word)) {
return true;
}
}
return false;
}
boolean isFloat = false;
int i;
for (i = 0; i < len; i++) {
char c = s.charAt(i);
continue;
if (c == '.' || c == 'e' || c == 'E') {
isFloat = true;
continue;
}
break;
}
s = s.substring(0, i);
if (isFloat)
else
}
throw new Exception("Expected ' at start of string");
int i;
for (i = 0; i < len; i++) {
char c = s.charAt(i);
if (c == '\'') {
++i;
}
}
}
throw new Exception("No closing ' at end of string");
}
return true;
} else
return false;
}
}