Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for exceptions on wrong parameter types in Query, and column out of bounds #104

Merged
merged 3 commits into from
Sep 9, 2013
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 154 additions & 0 deletions tightdb-java-test/src/test/java/com/tightdb/JNIQueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static org.testng.AssertJUnit.*;
import org.testng.annotations.Test;

import java.util.Date;

public class JNIQueryTest {

Table table;
Expand Down Expand Up @@ -45,4 +47,156 @@ public void shouldQuery() {

// TODO: Add tests with all parameters
}

@Test
public void queryWithWrongDataType() {

Table table = new Table();

table.addColumn(ColumnType.ColumnTypeBinary, "binary"); // 0
table.addColumn(ColumnType.ColumnTypeBool, "boolean"); // 1
table.addColumn(ColumnType.ColumnTypeDate, "date"); // 2
table.addColumn(ColumnType.ColumnTypeDouble, "double"); // 3
table.addColumn(ColumnType.ColumnTypeFloat, "float"); // 4
table.addColumn(ColumnType.ColumnTypeInt, "long"); // 5
table.addColumn(ColumnType.ColumnTypeMixed, "mixed"); // 6
table.addColumn(ColumnType.ColumnTypeString, "string"); // 7
table.addColumn(ColumnType.ColumnTypeTable, "table"); // 8
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In TestHelper there is a static method getTableWithAllColumnTypes, that returns excactly this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but TestHelper is not in develop, it is in Breaking-updates

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point :)


// Query the table
TableQuery query = table.where();

// Compare strings in non string columns
for(int i = 0; i <= 8; i++) {
if(i != 7) {
try { query.equal(i, "string"); assert(false); } catch(IllegalArgumentException e) {}
try { query.notEqual(i, "string"); assert(false); } catch(IllegalArgumentException e) {}
try { query.beginsWith(i, "string"); assert(false); } catch(IllegalArgumentException e) {}
try { query.endsWith(i, "string"); assert(false); } catch(IllegalArgumentException e) {}
try { query.contains(i, "string"); assert(false); } catch(IllegalArgumentException e) {}
}
}

// Compare integer in non integer columns
for(int i = 0; i <= 8; i++) {
if(i != 5) {
try { query.equal(i, 123); assert(false); } catch(IllegalArgumentException e) {}
try { query.notEqual(i, 123); assert(false); } catch(IllegalArgumentException e) {}
try { query.lessThan(i, 123); assert(false); } catch(IllegalArgumentException e) {}
try { query.lessThanOrEqual(i, 123); assert(false); } catch(IllegalArgumentException e) {}
try { query.greaterThan(i, 123); assert(false); } catch(IllegalArgumentException e) {}
try { query.greaterThanOrEqual(i, 123); assert(false); } catch(IllegalArgumentException e) {}
try { query.between(i, 123, 321); assert(false); } catch(IllegalArgumentException e) {}
}
}

// Compare float in non float columns
for(int i = 0; i <= 8; i++) {
if(i != 4) {
try { query.equal(i, 123F); assert(false); } catch(IllegalArgumentException e) {}
try { query.notEqual(i, 123F); assert(false); } catch(IllegalArgumentException e) {}
try { query.lessThan(i, 123F); assert(false); } catch(IllegalArgumentException e) {}
try { query.lessThanOrEqual(i, 123F); assert(false); } catch(IllegalArgumentException e) {}
try { query.greaterThan(i, 123F); assert(false); } catch(IllegalArgumentException e) {}
try { query.greaterThanOrEqual(i, 123F); assert(false); } catch(IllegalArgumentException e) {}
try { query.between(i, 123F, 321F); assert(false); } catch(IllegalArgumentException e) {}
}
}

// Compare double in non double columns
for(int i = 0; i <= 8; i++) {
if(i != 3) {
try { query.equal(i, 123D); assert(false); } catch(IllegalArgumentException e) {}
try { query.notEqual(i, 123D); assert(false); } catch(IllegalArgumentException e) {}
try { query.lessThan(i, 123D); assert(false); } catch(IllegalArgumentException e) {}
try { query.lessThanOrEqual(i, 123D); assert(false); } catch(IllegalArgumentException e) {}
try { query.greaterThan(i, 123D); assert(false); } catch(IllegalArgumentException e) {}
try { query.greaterThanOrEqual(i, 123D); assert(false); } catch(IllegalArgumentException e) {}
try { query.between(i, 123D, 321D); assert(false); } catch(IllegalArgumentException e) {}
}
}

// Compare boolean in non boolean columns
for(int i = 0; i <= 8; i++) {
if(i != 1) {
try { query.equal(i, true); assert(false); } catch(IllegalArgumentException e) {}
}
}

// Compare date
/*
for(int i = 0; i <= 8; i++) {
if(i != 2) {
try { query.equal(i, new Date()); assert(false); } catch(IllegalArgumentException e) {}
try { query.lessThan(i, new Date()); assert(false); } catch(IllegalArgumentException e) {}
try { query.lessThanOrEqual(i, new Date()); assert(false); } catch(IllegalArgumentException e) {}
try { query.greaterThan(i, new Date()); assert(false); } catch(IllegalArgumentException e) {}
try { query.greaterThanOrEqual(i, new Date()); assert(false); } catch(IllegalArgumentException e) {}
try { query.between(i, new Date(), new Date()); assert(false); } catch(IllegalArgumentException e) {}
}
}
*/
}

@Test
public void columnIndexOutOfBounds() {
Table table = new Table();

table.addColumn(ColumnType.ColumnTypeBinary, "binary"); // 0
table.addColumn(ColumnType.ColumnTypeBool, "boolean"); // 1
table.addColumn(ColumnType.ColumnTypeDate, "date"); // 2
table.addColumn(ColumnType.ColumnTypeDouble, "double"); // 3
table.addColumn(ColumnType.ColumnTypeFloat, "float"); // 4
table.addColumn(ColumnType.ColumnTypeInt, "long"); // 5
table.addColumn(ColumnType.ColumnTypeMixed, "mixed"); // 6
table.addColumn(ColumnType.ColumnTypeString, "string"); // 7
table.addColumn(ColumnType.ColumnTypeTable, "table"); // 8

// Query the table
TableQuery query = table.where();

// Compare strings in non string columns
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments are wrong all the way down (copy/paste :-)?)

try { query.equal(9, "string"); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}
try { query.notEqual(9, "string"); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}
try { query.beginsWith(9, "string"); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}
try { query.endsWith(9, "string"); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}
try { query.contains(9, "string"); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}


// Compare integer in non integer columns
try { query.equal(9, 123); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}
try { query.notEqual(9, 123); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}
try { query.lessThan(9, 123); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}
try { query.lessThanOrEqual(9, 123); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}
try { query.greaterThan(9, 123); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}
try { query.greaterThanOrEqual(9, 123); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}
try { query.between(9, 123, 321); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}


// Compare float in non float columns
try { query.equal(9, 123F); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}
try { query.notEqual(9, 123F); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}
try { query.lessThan(9, 123F); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}
try { query.lessThanOrEqual(9, 123F); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}
try { query.greaterThan(9, 123F); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}
try { query.greaterThanOrEqual(9, 123F); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}
try { query.between(9, 123F, 321F); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}


// Compare double in non double columns

try { query.equal(9, 123D); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}
try { query.notEqual(9, 123D); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}
try { query.lessThan(9, 123D); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}
try { query.lessThanOrEqual(9, 123D); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}
try { query.greaterThan(9, 123D); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}
try { query.greaterThanOrEqual(9, 123D); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}
try { query.between(9, 123D, 321D); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}


// Compare boolean in non boolean columns
try { query.equal(9, true); assert(false); } catch(ArrayIndexOutOfBoundsException e) {}

}

}