Skip to content

Commit

Permalink
Added wrapper and tests for mixed type retrieval method (issue #53).
Browse files Browse the repository at this point in the history
  • Loading branch information
nmihajlovski committed Sep 7, 2012
1 parent 762a522 commit 49ab879
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/tightdb/lib/MixedCursorColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public Mixed get() {
return cursor.rowset.getMixed(columnIndex, cursor.getPosition());
}

public ColumnType getType() {
return cursor.rowset.getMixedType(columnIndex, cursor.getPosition());
}

@Override
public void set(Mixed value) {
cursor.rowset.setMixed(columnIndex, cursor.getPosition(), value);
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/com/tightdb/lib/CursorColumnsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.testng.annotations.Test;

import com.tightdb.ColumnType;
import com.tightdb.Mixed;
import com.tightdb.test.EmployeesFixture;
import com.tightdb.test.TestEmployeeQuery;
Expand Down Expand Up @@ -60,6 +61,7 @@ private void checkSetAndGetMixedValues(

employee.extra.set(true);
assertEquals(true, employee.extra.get().getBooleanValue());
assertEquals(ColumnType.ColumnTypeBool, employee.extra.getType());

byte[] arr = { 1, 3, 5 };
employee.extra.set(arr);
Expand All @@ -68,6 +70,7 @@ private void checkSetAndGetMixedValues(
.getBinaryType());
assertEquals(ByteBuffer.wrap(arr), employee.extra.get()
.getBinaryValue());
assertEquals(ColumnType.ColumnTypeBinary, employee.extra.getType());

ByteBuffer buf = ByteBuffer.allocateDirect(3);
byte[] arr2 = { 10, 20, 30 };
Expand All @@ -77,21 +80,26 @@ private void checkSetAndGetMixedValues(
.getBinaryType());
assertEquals(ByteBuffer.wrap(arr2), employee.extra.get()
.getBinaryValue());
assertEquals(ColumnType.ColumnTypeBinary, employee.extra.getType());

Date date = new Date(6547);
employee.extra.set(date);
assertEquals(date, employee.extra.get().getDateValue());
assertEquals(ColumnType.ColumnTypeDate, employee.extra.getType());

long num = 135L;
employee.extra.set(num);
assertEquals(num, employee.extra.get().getLongValue());
assertEquals(ColumnType.ColumnTypeInt, employee.extra.getType());

Mixed mixed = Mixed.mixedValue("mixed");
employee.extra.set(mixed);
assertEquals(mixed, employee.extra.get());
assertEquals(ColumnType.ColumnTypeString, employee.extra.getType());

employee.extra.set("abc");
assertEquals("abc", employee.extra.get().getStringValue());
assertEquals(ColumnType.ColumnTypeString, employee.extra.getType());
}

@Test(expectedExceptions = UnsupportedOperationException.class)
Expand Down

0 comments on commit 49ab879

Please sign in to comment.