Exemplo n.º 1
0
  // No sorting order defined. There are Korean, Arabic and Chinese characters.
  public void testSortWithManyDifferentCharacters() {
    testRealm.beginTransaction();
    testRealm.clear(AllTypes.class);
    AllTypes at1 = testRealm.createObject(AllTypes.class);
    at1.setColumnString("단위");
    AllTypes at2 = testRealm.createObject(AllTypes.class);
    at2.setColumnString("테스트");
    AllTypes at3 = testRealm.createObject(AllTypes.class);
    at3.setColumnString("وحدة");
    AllTypes at4 = testRealm.createObject(AllTypes.class);
    at4.setColumnString("اختبار");
    AllTypes at5 = testRealm.createObject(AllTypes.class);
    at5.setColumnString("单位");
    AllTypes at6 = testRealm.createObject(AllTypes.class);
    at6.setColumnString("试验");
    AllTypes at7 = testRealm.createObject(AllTypes.class);
    at7.setColumnString("單位");
    AllTypes at8 = testRealm.createObject(AllTypes.class);
    at8.setColumnString("測試");
    testRealm.commitTransaction();

    RealmResults<AllTypes> result = testRealm.allObjects(AllTypes.class);
    RealmResults<AllTypes> sortedResult = result.where().findAll();
    sortedResult.sort(FIELD_STRING);

    assertEquals(8, sortedResult.size());

    @SuppressWarnings("UnnecessaryLocalVariable")
    RealmResults<AllTypes> reverseResult = result;
    reverseResult.sort(FIELD_STRING, RealmResults.SORT_ORDER_DESCENDING);
    assertEquals(8, reverseResult.size());
  }
Exemplo n.º 2
0
  public void testSortWithGreekCharacters() {
    testRealm.beginTransaction();
    testRealm.clear(AllTypes.class);
    AllTypes at1 = testRealm.createObject(AllTypes.class);
    at1.setColumnString("αύριο");
    AllTypes at2 = testRealm.createObject(AllTypes.class);
    at2.setColumnString("ημέρες");
    AllTypes at3 = testRealm.createObject(AllTypes.class);
    at3.setColumnString("δοκιμές");
    testRealm.commitTransaction();

    RealmResults<AllTypes> result = testRealm.allObjects(AllTypes.class);
    RealmResults<AllTypes> sortedResult = result.where().findAll();
    sortedResult.sort(FIELD_STRING);

    assertEquals(3, sortedResult.size());
    assertEquals("αύριο", sortedResult.first().getColumnString());
    assertEquals("αύριο", sortedResult.get(0).getColumnString());
    assertEquals("δοκιμές", sortedResult.get(1).getColumnString());
    assertEquals("ημέρες", sortedResult.get(2).getColumnString());

    RealmResults<AllTypes> reverseResult = result.where().findAll();
    reverseResult.sort(FIELD_STRING, RealmResults.SORT_ORDER_DESCENDING);
    assertEquals(3, reverseResult.size());
    assertEquals("αύριο", reverseResult.last().getColumnString());
    assertEquals("ημέρες", reverseResult.get(0).getColumnString());
    assertEquals("δοκιμές", reverseResult.get(1).getColumnString());
    assertEquals("αύριο", reverseResult.get(2).getColumnString());
  }
Exemplo n.º 3
0
  public void testSortWithRussianCharacters() {
    testRealm.beginTransaction();
    testRealm.clear(AllTypes.class);
    AllTypes at1 = testRealm.createObject(AllTypes.class);
    at1.setColumnString("Санкт-Петербург");
    AllTypes at2 = testRealm.createObject(AllTypes.class);
    at2.setColumnString("Москва");
    AllTypes at3 = testRealm.createObject(AllTypes.class);
    at3.setColumnString("Новороссийск");
    testRealm.commitTransaction();

    RealmResults<AllTypes> result = testRealm.allObjects(AllTypes.class);
    RealmResults<AllTypes> sortedResult = result.where().findAll();
    sortedResult.sort(FIELD_STRING);

    assertEquals(3, sortedResult.size());
    assertEquals("Москва", sortedResult.first().getColumnString());
    assertEquals("Москва", sortedResult.get(0).getColumnString());
    assertEquals("Новороссийск", sortedResult.get(1).getColumnString());
    assertEquals("Санкт-Петербург", sortedResult.get(2).getColumnString());

    RealmResults<AllTypes> reverseResult = result.where().findAll();
    reverseResult.sort(FIELD_STRING, RealmResults.SORT_ORDER_DESCENDING);
    assertEquals(3, reverseResult.size());
    assertEquals("Москва", reverseResult.last().getColumnString());
    assertEquals("Санкт-Петербург", reverseResult.get(0).getColumnString());
    assertEquals("Новороссийск", reverseResult.get(1).getColumnString());
    assertEquals("Москва", reverseResult.get(2).getColumnString());
  }
Exemplo n.º 4
0
  public void testSortWithDanishCharacters() {
    testRealm.beginTransaction();
    testRealm.clear(AllTypes.class);
    AllTypes at1 = testRealm.createObject(AllTypes.class);
    at1.setColumnString("Æble");
    AllTypes at2 = testRealm.createObject(AllTypes.class);
    at2.setColumnString("Øl");
    AllTypes at3 = testRealm.createObject(AllTypes.class);
    at3.setColumnString("Århus");
    testRealm.commitTransaction();

    RealmResults<AllTypes> result = testRealm.allObjects(AllTypes.class);
    RealmResults<AllTypes> sortedResult = result.where().findAll();
    sortedResult.sort(FIELD_STRING);

    assertEquals(3, sortedResult.size());
    assertEquals("Æble", sortedResult.first().getColumnString());
    assertEquals("Æble", sortedResult.get(0).getColumnString());
    assertEquals("Øl", sortedResult.get(1).getColumnString());
    assertEquals("Århus", sortedResult.get(2).getColumnString());

    RealmResults<AllTypes> reverseResult = result.where().findAll();
    reverseResult.sort(FIELD_STRING, Sort.DESCENDING);
    assertEquals(3, reverseResult.size());
    assertEquals("Æble", reverseResult.last().getColumnString());
    assertEquals("Århus", reverseResult.get(0).getColumnString());
    assertEquals("Øl", reverseResult.get(1).getColumnString());
    assertEquals("Æble", reverseResult.get(2).getColumnString());
  }
Exemplo n.º 5
0
  // Triggered an ARM bug
  public void testComparisons() {
    testRealm.beginTransaction();
    testRealm.clear(AllTypes.class);
    long id = -1;
    for (int i = 0; i < 10; i++) {
      AllTypes allTypes = testRealm.createObject(AllTypes.class);
      allTypes.setColumnLong(id--);
    }
    testRealm.commitTransaction();

    assertEquals(
        10, testRealm.where(AllTypes.class).between(AllTypes.FIELD_LONG, -10, -1).findAll().size());
    assertEquals(
        10, testRealm.where(AllTypes.class).greaterThan(AllTypes.FIELD_LONG, -11).findAll().size());
    assertEquals(
        10,
        testRealm
            .where(AllTypes.class)
            .greaterThanOrEqualTo(AllTypes.FIELD_LONG, -10)
            .findAll()
            .size());
    assertEquals(
        10, testRealm.where(AllTypes.class).lessThan(AllTypes.FIELD_LONG, 128).findAll().size());
    assertEquals(
        10, testRealm.where(AllTypes.class).lessThan(AllTypes.FIELD_LONG, 127).findAll().size());
    assertEquals(
        10,
        testRealm
            .where(AllTypes.class)
            .lessThanOrEqualTo(AllTypes.FIELD_LONG, -1)
            .findAll()
            .size());
    assertEquals(
        10, testRealm.where(AllTypes.class).lessThan(AllTypes.FIELD_LONG, 0).findAll().size());
  }
Exemplo n.º 6
0
 public void testWithEmptyRealmObjects() {
   testRealm.beginTransaction();
   testRealm.clear(AllTypes.class);
   testRealm.commitTransaction();
   try {
     testRealm.where(AllTypes.class).findAll().sort(FIELD_STRING);
   } catch (IllegalArgumentException e) {
     fail("Failed to sort an empty RealmResults");
   }
 }
Exemplo n.º 7
0
  public void testSortWithTwoLanguages() {
    testRealm.beginTransaction();
    testRealm.clear(AllTypes.class);
    AllTypes allTypes1 = testRealm.createObject(AllTypes.class);
    allTypes1.setColumnString("test");
    AllTypes allTypes2 = testRealm.createObject(AllTypes.class);
    allTypes2.setColumnString("αύριο");
    AllTypes allTypes3 = testRealm.createObject(AllTypes.class);
    allTypes3.setColumnString("work");
    testRealm.commitTransaction();

    try {
      RealmResults<AllTypes> result = testRealm.allObjects(AllTypes.class);
      result.sort(FIELD_STRING);
    } catch (IllegalArgumentException e) {
      fail("Failed to sort with two kinds of alphabets");
    }
  }
Exemplo n.º 8
0
  // first() and last() will throw an exception when no element exist
  public void testResultListFirstLastThrowIfEmpty() {
    testRealm.beginTransaction();
    testRealm.clear(AllTypes.class);
    testRealm.commitTransaction();

    RealmResults<AllTypes> allTypes = testRealm.allObjects(AllTypes.class);
    assertEquals(0, allTypes.size());
    try {
      allTypes.first();
      fail();
    } catch (ArrayIndexOutOfBoundsException ignored) {
    }

    try {
      allTypes.last();
      fail();
    } catch (ArrayIndexOutOfBoundsException ignored) {
    }
  }