Search in sources :

Example 1 with TestDataFile

use of com.intellij.testFramework.TestDataFile in project intellij-community by JetBrains.

the class PyResolveTestCase method configureByFile.

protected PsiReference configureByFile(@TestDataFile final String filePath) {
    VirtualFile testDataRoot = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(getTestDataPath()));
    final VirtualFile file = testDataRoot.findFileByRelativePath(filePath);
    assertNotNull(file);
    String fileText;
    try {
        fileText = StringUtil.convertLineSeparators(VfsUtil.loadText(file));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    int offset = fileText.indexOf(MARKER);
    assertTrue(offset >= 0);
    fileText = fileText.substring(0, offset) + fileText.substring(offset + MARKER.length());
    final String finalFileText = fileText;
    myFixture.configureByText(new File(filePath).getName(), finalFileText);
    final PsiReference reference = myFixture.getFile().findReferenceAt(offset);
    return reference;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) TestDataFile(com.intellij.testFramework.TestDataFile)

Example 2 with TestDataFile

use of com.intellij.testFramework.TestDataFile in project intellij-community by JetBrains.

the class CodeInsightTestUtil method doWordSelectionTestOnDirectory.

public static void doWordSelectionTestOnDirectory(@NotNull final CodeInsightTestFixture fixture, @TestDataFile @NotNull final String directoryName, @NotNull final String filesExtension) {
    final SelectWordHandler action = new SelectWordHandler(null);
    fixture.copyDirectoryToProject(directoryName, directoryName);
    fixture.configureByFile(directoryName + "/before." + filesExtension);
    int i = 1;
    while (true) {
        final String fileName = directoryName + "/after" + i + "." + filesExtension;
        if (new File(fixture.getTestDataPath() + "/" + fileName).exists()) {
            action.execute(fixture.getEditor(), DataManager.getInstance().getDataContext(fixture.getEditor().getComponent()));
            fixture.checkResultByFile(fileName);
            i++;
        } else {
            break;
        }
    }
    assertTrue("At least one 'after'-file required", i > 1);
}
Also used : SelectWordHandler(com.intellij.codeInsight.editorActions.SelectWordHandler) TestDataFile(com.intellij.testFramework.TestDataFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File)

Example 3 with TestDataFile

use of com.intellij.testFramework.TestDataFile in project intellij-community by JetBrains.

the class EditorPaintingTest method checkResult.

private void checkResult(@TestDataFile String expectedResultFileName) throws IOException {
    myEditor.getSettings().setAdditionalLinesCount(0);
    myEditor.getSettings().setAdditionalColumnsCount(1);
    JComponent editorComponent = myEditor.getContentComponent();
    Dimension size = editorComponent.getPreferredSize();
    editorComponent.setSize(size);
    //noinspection UndesirableClassUsage
    BufferedImage image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);
    BitmapFont plainFont = BitmapFont.loadFromFile(getFontFile(false));
    BitmapFont boldFont = BitmapFont.loadFromFile(getFontFile(true));
    MyGraphics graphics = new MyGraphics(image.createGraphics(), plainFont, boldFont);
    try {
        editorComponent.paint(graphics);
    } finally {
        graphics.dispose();
    }
    File fileWithExpectedResult = getTestDataFile(expectedResultFileName);
    if (OVERWRITE_TESTDATA) {
        ImageIO.write(image, "png", fileWithExpectedResult);
        System.out.println("File " + fileWithExpectedResult.getPath() + " created.");
    }
    if (fileWithExpectedResult.exists()) {
        BufferedImage expectedResult = ImageIO.read(fileWithExpectedResult);
        if (expectedResult.getWidth() != image.getWidth()) {
            fail("Unexpected image width", fileWithExpectedResult, image);
        }
        if (expectedResult.getHeight() != image.getHeight()) {
            fail("Unexpected image height", fileWithExpectedResult, image);
        }
        for (int i = 0; i < expectedResult.getWidth(); i++) {
            for (int j = 0; j < expectedResult.getHeight(); j++) {
                if (expectedResult.getRGB(i, j) != image.getRGB(i, j)) {
                    fail("Unexpected image contents", fileWithExpectedResult, image);
                }
            }
        }
    } else {
        ImageIO.write(image, "png", fileWithExpectedResult);
        fail("Missing test data created: " + fileWithExpectedResult.getPath());
    }
}
Also used : TestDataFile(com.intellij.testFramework.TestDataFile) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Aggregations

TestDataFile (com.intellij.testFramework.TestDataFile)3 File (java.io.File)3 SelectWordHandler (com.intellij.codeInsight.editorActions.SelectWordHandler)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1