Search in sources :

Example 6 with MediaClipField

use of com.ichi2.anki.multimediacard.fields.MediaClipField in project Anki-Android by ankidroid.

the class NoteServiceTest method importImageToDirectoryTest.

// Similar test like above, but with an ImageField instead of a MediaClipField
@Test
public void importImageToDirectoryTest() throws IOException {
    File fileImage = directory.newFile("testimage.png");
    // writes a line in the file so the file's length isn't 0
    try (FileWriter fileWriter = new FileWriter(fileImage)) {
        fileWriter.write("line1");
    }
    ImageField imgField = new ImageField();
    imgField.setImagePath(fileImage.getAbsolutePath());
    NoteService.importMediaToDirectory(mTestCol, imgField);
    File outFile = new File(mTestCol.getMedia().dir(), fileImage.getName());
    assertEquals("path should be equal to the new file made in NoteService.importMediaToDirectory", outFile.getAbsolutePath(), imgField.getImagePath());
}
Also used : ImageField(com.ichi2.anki.multimediacard.fields.ImageField) FileWriter(java.io.FileWriter) File(java.io.File) FileSystemUtilsKt.createTransientFile(com.ichi2.testutils.FileSystemUtilsKt.createTransientFile) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 7 with MediaClipField

use of com.ichi2.anki.multimediacard.fields.MediaClipField in project Anki-Android by ankidroid.

the class NoteServiceTest method tempAudioIsDeletedAfterImport.

/**
 * Sometimes media files cannot be imported directly to the media directory,
 * so they are copied to cache then imported and deleted.
 * This tests if cached media are properly deleted after import.
 */
@Test
public void tempAudioIsDeletedAfterImport() {
    File file = createTransientFile("foo");
    MediaClipField field = new MediaClipField();
    field.setAudioPath(file.getAbsolutePath());
    field.setHasTemporaryMedia(true);
    NoteService.importMediaToDirectory(mTestCol, field);
    assertFalse("Audio temporary file should have been deleted after importing", file.exists());
}
Also used : MediaClipField(com.ichi2.anki.multimediacard.fields.MediaClipField) File(java.io.File) FileSystemUtilsKt.createTransientFile(com.ichi2.testutils.FileSystemUtilsKt.createTransientFile) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 8 with MediaClipField

use of com.ichi2.anki.multimediacard.fields.MediaClipField in project Anki-Android by ankidroid.

the class NoteServiceTest method tempImageIsDeletedAfterImport.

// Similar test like above, but with an ImageField instead of a MediaClipField
@Test
public void tempImageIsDeletedAfterImport() {
    File file = createTransientFile("foo");
    ImageField field = new ImageField();
    field.setImagePath(file.getAbsolutePath());
    field.setHasTemporaryMedia(true);
    NoteService.importMediaToDirectory(mTestCol, field);
    assertFalse("Image temporary file should have been deleted after importing", file.exists());
}
Also used : ImageField(com.ichi2.anki.multimediacard.fields.ImageField) File(java.io.File) FileSystemUtilsKt.createTransientFile(com.ichi2.testutils.FileSystemUtilsKt.createTransientFile) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Aggregations

RobolectricTest (com.ichi2.anki.RobolectricTest)6 FileSystemUtilsKt.createTransientFile (com.ichi2.testutils.FileSystemUtilsKt.createTransientFile)6 File (java.io.File)6 Test (org.junit.Test)6 MediaClipField (com.ichi2.anki.multimediacard.fields.MediaClipField)5 ImageField (com.ichi2.anki.multimediacard.fields.ImageField)4 FileWriter (java.io.FileWriter)4 SuppressLint (android.annotation.SuppressLint)1 MenuInflater (android.view.MenuInflater)1 IMultimediaEditableNote (com.ichi2.anki.multimediacard.IMultimediaEditableNote)1 AudioRecordingField (com.ichi2.anki.multimediacard.fields.AudioRecordingField)1 PopupMenuWithIcons (com.ichi2.anki.widgets.PopupMenuWithIcons)1 Collection (com.ichi2.libanki.Collection)1