Esempio n. 1
0
  public void testIndices() throws StorageFileException, IOException {
    // INDICES OUT OF BOUNDS
    Header header = Header.createHeader();

    // indexFree
    try {
      header.setIndexEmpty(0x0100000000L);
      assertTrue(false);
    } catch (IndexOutOfBoundsException ex) {
    }

    try {
      header.setIndexEmpty(-1L);
      assertTrue(false);
    } catch (IndexOutOfBoundsException ex) {
    }

    // indexConversation
    try {
      header.setIndexConversations(0x0100000000L);
      assertTrue(false);
    } catch (IndexOutOfBoundsException ex) {
    }

    try {
      header.setIndexConversations(-1L);
      assertTrue(false);
    } catch (IndexOutOfBoundsException ex) {
    }

    // version
    try {
      header.setVersion(0x100);
      assertTrue(false);
    } catch (IndexOutOfBoundsException ex) {
    }
  }
Esempio n. 2
0
  public void testConstruction() throws StorageFileException, IOException {
    // create a header
    Header header = Header.createHeader();
    header.setVersion(12);
    header.setIndexEmpty(13L);
    header.setIndexConversations(15L);
    header.saveToFile();

    // force it to be re-read from file
    Header.forceClearCache();
    header = Header.getHeader();

    assertEquals(header.getVersion(), 12);
    assertEquals(header.getIndexEmpty(), 13L);
    assertEquals(header.getIndexConversations(), 15L);
  }
Esempio n. 3
0
  public void testCreateData() throws StorageFileException, IOException, WrongKeyException {
    long indexFree = 25L;
    long indexConversation = 13L;
    int version = 32;

    Header header = Header.createHeader();
    header.setIndexEmpty(indexFree);
    header.setIndexConversations(indexConversation);
    header.setVersion(version);
    header.saveToFile();

    byte[] dataAll = Storage.getDatabase().getEntry(0);

    // chunk length
    assertEquals(dataAll.length, Storage.CHUNK_SIZE);

    // plain header
    assertEquals(dataAll[0], (byte) 0x53); // S
    assertEquals(dataAll[1], (byte) 0x4D); // M
    assertEquals(dataAll[2], (byte) 0x53); // S
    assertEquals(dataAll[3], (byte) version); // Version

    // decrypt the encoded part
    ByteBuffer buf = ByteBuffer.allocate(Storage.CHUNK_SIZE - 4);
    buf.put(dataAll, 4, Storage.CHUNK_SIZE - 4);
    byte[] dataPlain = Encryption.decryptSymmetric(buf.array(), Encryption.retreiveEncryptionKey());

    // check the indices
    assertEquals(
        LowLevel.getUnsignedInt(
            dataPlain, Storage.CHUNK_SIZE - 4 - Encryption.ENCRYPTION_OVERHEAD - 8),
        indexFree);
    assertEquals(
        LowLevel.getUnsignedInt(
            dataPlain, Storage.CHUNK_SIZE - 4 - Encryption.ENCRYPTION_OVERHEAD - 4),
        indexConversation);
  }