Index: tck/src/java/org/apache/jdo/tck/query/jdoql/operators/BitwiseBinaryOperators.java =================================================================== --- tck/src/java/org/apache/jdo/tck/query/jdoql/operators/BitwiseBinaryOperators.java (nonexistent) +++ tck/src/java/org/apache/jdo/tck/query/jdoql/operators/BitwiseBinaryOperators.java (working copy) @@ -0,0 +1,276 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.query.jdoql.operators; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.mylib.PrimitiveTypes; +import org.apache.jdo.tck.query.QueryTest; +import org.apache.jdo.tck.util.BatchTestRunner; + +import javax.jdo.JDOUserException; +import javax.jdo.PersistenceManager; +import javax.jdo.Query; +import javax.jdo.Transaction; +import java.util.List; + +/** + *Title: Bitwise Binary Query Operators + *
+ *Keywords: query + *
+ *Assertion ID: A14.6.2-xx. + *
+ *Assertion Description: + A JDO implementation including javax.jdo.query.JDOQL.bitwiseOperations in the result of + PMF.supportedOptions() supports JDOQL queries that contain bitwise operations. + Then the integral binary bitwise operators (& and | and ^) are supported + for the following types: + + */ +public class BitwiseBinaryOperators extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.6.2-xx (BitwiseBinaryOperators) failed: "; + + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(BitwiseBinaryOperators.class); + } + + /** + * Testing bitwise AND + */ + public void testBitwiseAndPositive() { + if (isBitwiseOperationsSupported()) { + PersistenceManager pm = getPM(); + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + + // Expected result + List expected = pm.newQuery(PrimitiveTypes.class, "4 <= id && id <= 7").executeList(); + + runSimplePrimitiveTypesQuery("(byteNotNull & 4) != 0", pm, expected, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("(byteNull & 4) != 0", pm, expected, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("(shortNotNull & 4) != 0", pm, expected, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("(shortNull & 4) != 0", pm, expected, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("(intNotNull & 4) != 0", pm, expected, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("(intNull & 4) != 0", pm, expected, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("(longNotNull & 4) != 0", pm, expected, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("(longNull & 4) != 0", pm, expected, ASSERTION_FAILED); + + tx.commit(); + tx = null; + } finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } + } + + /** + * Testing bitwise OR + */ + public void testBitwiseOrPositive() { + if (isBitwiseOperationsSupported()) { + PersistenceManager pm = getPM(); + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + + // Expected result + List expected = pm.newQuery(PrimitiveTypes.class, "4 <= id && id <= 7").executeList(); + + runSimplePrimitiveTypesQuery("(byteNotNull | 3) == 7", pm, expected, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("(byteNull | 3) == 7", pm, expected, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("(shortNotNull | 3) == 7", pm, expected, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("(shortNull | 3) == 7", pm, expected, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("(intNotNull | 3) == 7", pm, expected, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("(intNull | 3) == 7", pm, expected, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("(longNotNull | 3) == 7", pm, expected, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("(longNull | 3) == 7", pm, expected, ASSERTION_FAILED); + + tx.commit(); + tx = null; + } finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } + } + + /** + * Testing bitwise XOR + */ + public void testBitwiseXOrPositive() { + if (isBitwiseOperationsSupported()) { + PersistenceManager pm = getPM(); + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + + // Expected result + List expected = pm.newQuery(PrimitiveTypes.class, "id == 1").executeList(); + + runSimplePrimitiveTypesQuery("(byteNotNull ^ 1) == 0", pm, expected, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("(byteNull ^ 1) == 0", pm, expected, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("(shortNotNull ^ 1) == 0", pm, expected, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("(shortNull ^ 1) == 0", pm, expected, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("(intNotNull ^ 1) == 0", pm, expected, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("(intNull ^ 1) == 0", pm, expected, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("(longNotNull ^ 1) == 0", pm, expected, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("(longNull ^ 1) == 0", pm, expected, ASSERTION_FAILED); + + tx.commit(); + tx = null; + } finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } + } + + /** + * Queries using bitwise AND that should result in a JDOException. + */ + public void testBitwiseAndNegative() { + PersistenceManager pm = getPM(); + Transaction tx = pm.currentTransaction(); + tx.begin(); + + try { + Query q = pm.newQuery(PrimitiveTypes.class, "stringNull & stringNull == stringNull"); + Object result = q.execute(); + fail(ASSERTION_FAILED, + "Query using & operator for non-supported types should throw JDOUserException."); + } + catch (JDOUserException ex) { + // expected exception + if (debug) { + logger.debug("expected exception: " + ex); + } + } + + if (!isBitwiseOperationsSupported()) { + try { + Query q = pm.newQuery(PrimitiveTypes.class, "(intNotNull & 4) > 0"); + Object result = q.execute(); + fail(ASSERTION_FAILED, + "Query using & operator for non-supported types should throw JDOUserException."); + } catch (JDOUserException ex) { + // expected exception + if (debug) { + logger.debug("expected exception: " + ex); + } + } + } + + tx.commit(); + } + + /** + * Queries using bitwise AND that should result in a JDOException. + */ + public void testBitwiseOrNegative() { + PersistenceManager pm = getPM(); + Transaction tx = pm.currentTransaction(); + tx.begin(); + + try { + Query q = pm.newQuery(PrimitiveTypes.class, "stringNull | stringNull == stringNull"); + Object result = q.execute(); + fail(ASSERTION_FAILED, + "Query using | operator for non-supported types should throw JDOUserException."); + } + catch (JDOUserException ex) { + // expected exception + if (debug) { + logger.debug("expected exception: " + ex); + } + } + + if (!isBitwiseOperationsSupported()) { + try { + Query q = pm.newQuery(PrimitiveTypes.class, "(intNotNull | 3) == 7"); + Object result = q.execute(); + fail(ASSERTION_FAILED, + "Query using & operator for non-supported types should throw JDOUserException."); + } catch (JDOUserException ex) { + // expected exception + if (debug) { + logger.debug("expected exception: " + ex); + } + } + } + + tx.commit(); + } + + /** + * Queries using bitwise AND that should result in a JDOException. + */ + public void testBitwiseXOrNegative() { + PersistenceManager pm = getPM(); + Transaction tx = pm.currentTransaction(); + tx.begin(); + + try { + Query q = pm.newQuery(PrimitiveTypes.class, "stringNull ^ stringNul == stringNull"); + Object result = q.execute(); + fail(ASSERTION_FAILED, + "Query using & operator for non-supported types should throw JDOUserException."); + } + catch (JDOUserException ex) { + // expected exception + if (debug) { + logger.debug("expected exception: " + ex); + } + } + + if (!isBitwiseOperationsSupported()) { + try { + Query q = pm.newQuery(PrimitiveTypes.class, "(intNotNull ^ 1) == 0"); + Object result = q.execute(); + fail(ASSERTION_FAILED, + "Query using & operator for non-supported types should throw JDOUserException."); + } catch (JDOUserException ex) { + // expected exception + if (debug) { + logger.debug("expected exception: " + ex); + } + } + } + + tx.commit(); + } + + /** + * @see JDO_Test#localSetUp() + */ + protected void localSetUp() { + addTearDownClass(PrimitiveTypes.class); + loadAndPersistPrimitiveTypes(getPM()); + } +} Index: tck/src/java/org/apache/jdo/tck/query/jdoql/operators/BooleanLogicalAND.java =================================================================== --- tck/src/java/org/apache/jdo/tck/query/jdoql/operators/BooleanLogicalAND.java (revision 1808942) +++ tck/src/java/org/apache/jdo/tck/query/jdoql/operators/BooleanLogicalAND.java (working copy) @@ -126,30 +126,6 @@ tx.commit(); } - /** */ - public void testNegative() { - PersistenceManager pm = getPM(); - if (debug) logger.debug("\nExecuting positive test BooleanLogicalAND() ..."); - - Transaction tx = pm.currentTransaction(); - tx.begin(); - - try { - Query q = pm.newQuery(PrimitiveTypes.class, - "stringNull & stringNull"); - Object result = q.execute(); - fail(ASSERTION_FAILED, - "Query using & operator for non-supported types should throw JDOUserException."); - } - catch (JDOUserException ex) { - // expected exception - if (debug) { - logger.debug("expected exception: " + ex); - } - } - tx.commit(); - } - /** * @see JDO_Test#localSetUp() */ Index: tck/src/java/org/apache/jdo/tck/JDO_Test.java =================================================================== --- tck/src/java/org/apache/jdo/tck/JDO_Test.java (revision 1808942) +++ tck/src/java/org/apache/jdo/tck/JDO_Test.java (working copy) @@ -894,8 +894,14 @@ /** Reports whether UnconstrainedVariables is supported. */ public boolean isUnconstrainedVariablesSupported() { return supportedOptions.contains( - "javax.jdo.option.UnconstrainedVariables"); + "javax.jdo.query.JDOQL.UnconstraintedQueryVariables"); } + + /** Reports whether BitwiseOperations is supported. */ + public boolean isBitwiseOperationsSupported() { + return supportedOptions.contains( + "javax.jdo.query.JDOQL.bitwiseOperations"); + } /** Reports whether SQL queries are supported. */ public boolean isSQLSupported() { Index: tck/src/conf/jdoql.conf =================================================================== --- tck/src/conf/jdoql.conf (revision 1808943) +++ tck/src/conf/jdoql.conf (working copy) @@ -76,6 +76,7 @@ org.apache.jdo.tck.query.jdoql.methods.SupportedStringMethods \ org.apache.jdo.tck.query.jdoql.operators.BinaryAddition \ org.apache.jdo.tck.query.jdoql.operators.BinarySubtraction \ +org.apache.jdo.tck.query.jdoql.operators.BitwiseBinaryOperators \ org.apache.jdo.tck.query.jdoql.operators.BitwiseComplement \ org.apache.jdo.tck.query.jdoql.operators.BooleanLogicalAND \ org.apache.jdo.tck.query.jdoql.operators.BooleanLogicalOR \