HHH-15519 start testing bitor() and xor() functions

This commit is contained in:
Gavin King 2024-02-19 23:56:04 +01:00
parent af6edebb92
commit 399b1a0715
4 changed files with 71 additions and 97 deletions

View File

@ -0,0 +1,57 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.orm.test.hql.bitwise;
import org.hibernate.dialect.DerbyDialect;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
/**
* @author Brett Meyer
*/
@DomainModel(annotatedClasses = IntEntity.class)
@SessionFactory
public class BitwiseFunctionsTest {
@Test @SkipForDialect(dialectClass = DerbyDialect.class)
public void test(SessionFactoryScope scope) {
IntEntity five = new IntEntity();
five.setIntValue(5);
scope.inTransaction(session -> session.persist(five));
scope.inTransaction(
session -> {
assertEquals(session.createSelectionQuery(
"select bitand(intValue,0) from IntEntity", Integer.class )
.uniqueResult().intValue(), 0 );
assertEquals(session.createSelectionQuery(
"select bitand(intValue,2) from IntEntity", Integer.class )
.uniqueResult().intValue(), 0 );
assertEquals(session.createSelectionQuery(
"select bitand(intValue,3) from IntEntity", Integer.class )
.uniqueResult().intValue(), 1 );
assertEquals(session.createSelectionQuery(
"select bitor(intValue,0) from IntEntity", Integer.class )
.uniqueResult().intValue(), 5 );
assertEquals(session.createSelectionQuery(
"select bitor(intValue,2) from IntEntity", Integer.class )
.uniqueResult().intValue(), 7 );
assertEquals(session.createSelectionQuery(
"select bitor(intValue,3) from IntEntity", Integer.class )
.uniqueResult().intValue(), 7 );
assertEquals(session.createSelectionQuery(
"select bitxor(intValue,3) from IntEntity", Integer.class )
.uniqueResult().intValue(), 6 );
}
);
}
}

View File

@ -4,16 +4,22 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.orm.test.math;
package org.hibernate.orm.test.hql.bitwise;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
/**
* @author Brett Meyer
*/
public class MathEntity {
@Entity
public class IntEntity {
@Id @GeneratedValue
private Long id;
private int value;
private int intValue;
public Long getId() {
return id;
@ -23,12 +29,12 @@ public class MathEntity {
this.id = id;
}
public int getValue() {
return value;
public int getIntValue() {
return intValue;
}
public void setValue(int value) {
this.value = value;
public void setIntValue(int value) {
this.intValue = value;
}
}

View File

@ -1,62 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.orm.test.math;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.OracleDialect;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.hibernate.testing.orm.junit.RequiresDialects;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
/**
* @author Brett Meyer
*/
@RequiresDialects(value = {
@RequiresDialect(H2Dialect.class),
@RequiresDialect(OracleDialect.class)
})
@DomainModel(
xmlMappings = "org/hibernate/orm/test/math/Math.hbm.xml"
)
@SessionFactory
public class MathTest {
@Test
public void testBitAnd(SessionFactoryScope scope) {
MathEntity me = new MathEntity();
me.setValue( 5 );
Long id = (Long) scope.fromTransaction(
session ->
session.save( me )
);
scope.inTransaction(
session -> {
int value1 = ( (Integer) session.createQuery(
"select bitand(m.value,0) from MathEntity m where m.id=" + id )
.uniqueResult() ).intValue();
int value2 = ( (Integer) session.createQuery(
"select bitand(m.value,2) from MathEntity m where m.id=" + id )
.uniqueResult() ).intValue();
int value3 = ( (Integer) session.createQuery(
"select bitand(m.value,3) from MathEntity m where m.id=" + id )
.uniqueResult() ).intValue();
assertEquals( value1, 0 );
assertEquals( value2, 0 );
assertEquals( value3, 1 );
}
);
}
}

View File

@ -1,27 +0,0 @@
<?xml version="1.0"?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.orm.test.math">
<class name="MathEntity" table="MathEntity">
<id name="id">
<generator class="native"/>
</id>
<property name="value">
<column name="val" not-null="true" />
</property>
</class>
</hibernate-mapping>