mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-11-22 20:22:44 +00:00
GT-3035 - Restore Integration Tests - converted groovy tests to java
This commit is contained in:
parent
8369ef12a2
commit
822e5a0610
@ -593,7 +593,7 @@ public class GhidraScriptUtil {
|
||||
* @param name the name of the script
|
||||
* @return the name as a '.java' file path (with '/'s and not '.'s)
|
||||
*/
|
||||
private static String fixupName(String name) {
|
||||
static String fixupName(String name) {
|
||||
if (name.endsWith(".java")) {
|
||||
name = name.substring(0, name.length() - 5);
|
||||
}
|
||||
|
@ -0,0 +1,61 @@
|
||||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ghidra.app.script;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import generic.test.AbstractGenericTest;
|
||||
|
||||
public class GhidraScriptUtilTest extends AbstractGenericTest {
|
||||
|
||||
@Test
|
||||
public void fixupName_WithExtension() {
|
||||
String input = "Bob.java";
|
||||
assertEquals(GhidraScriptUtil.fixupName(input), "Bob.java");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fixupName_WithoutExtension() {
|
||||
String input = "Bob";
|
||||
assertEquals(GhidraScriptUtil.fixupName(input), "Bob.java");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fixupName_WithPackageDots() {
|
||||
String input = "a.b.c.Bob";
|
||||
assertEquals(GhidraScriptUtil.fixupName(input), "a/b/c/Bob.java");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fixupName_WithPackageSlashes() {
|
||||
String input = "a/b/c/Bob";
|
||||
assertEquals(GhidraScriptUtil.fixupName(input), "a/b/c/Bob.java");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fixupName_InnerClass() {
|
||||
String input = "Bob$InnerClass";
|
||||
assertEquals(GhidraScriptUtil.fixupName(input), "Bob.java");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fixupName_InnerClass_WithPackageDots() {
|
||||
String input = "a.b.c.Bob$InnerClass";
|
||||
assertEquals(GhidraScriptUtil.fixupName(input), "a/b/c/Bob.java");
|
||||
}
|
||||
}
|
@ -15,13 +15,16 @@
|
||||
*/
|
||||
package utilities.util;
|
||||
|
||||
import static generic.test.AbstractGenericTest.assertListEqualsArrayOrdered;
|
||||
import static generic.test.AbstractGTest.assertListEqualsArrayOrdered;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -159,4 +162,62 @@ public class FileUtilitiesTest {
|
||||
assertFalse(FileUtilities.isPathContainedWithin(new File("/a/b"), new File("/a/b/../c")));
|
||||
assertFalse(FileUtilities.isPathContainedWithin(new File("/a/b"), new File("/a/bc")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyFile_ResourceFile_To_ResourceFile() throws Exception {
|
||||
|
||||
File from = File.createTempFile("from.file", ".txt");
|
||||
FileUtilities.writeLinesToFile(from, Arrays.asList("From file contents"));
|
||||
from.deleteOnExit();
|
||||
|
||||
File to = File.createTempFile("to.file", ".txt");
|
||||
to.deleteOnExit();
|
||||
FileUtilities.writeLinesToFile(to, Arrays.asList("To file contents"));
|
||||
|
||||
FileUtilities.copyFile(new ResourceFile(from), new ResourceFile(to), null);
|
||||
|
||||
String text = FileUtils.readFileToString(to, Charset.defaultCharset());
|
||||
assertThat(text, equalTo("From file contents\n"));
|
||||
}
|
||||
|
||||
@Test(expected = IOException.class)
|
||||
public void copyFile_ExceptionFromInputStream() throws Exception {
|
||||
|
||||
ResourceFile from = new ResourceFile(new File("/fake.from.file")) {
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
throw new IOException("Test Exception");
|
||||
}
|
||||
};
|
||||
|
||||
File to = File.createTempFile("to.file", ".txt");
|
||||
to.deleteOnExit();
|
||||
|
||||
// should fail
|
||||
FileUtilities.copyFile(from, new ResourceFile(to), null);
|
||||
}
|
||||
|
||||
@Test(expected = IOException.class)
|
||||
public void copyFile_ExceptionFromOutputStream() throws Exception {
|
||||
|
||||
File from = File.createTempFile("from.file", ".txt");
|
||||
from.deleteOnExit();
|
||||
|
||||
ResourceFile to = new ResourceFile(new File("/to.from.file")) {
|
||||
|
||||
@Override
|
||||
public OutputStream getOutputStream() throws FileNotFoundException {
|
||||
throw new FileNotFoundException("Test Exception");
|
||||
}
|
||||
};
|
||||
|
||||
// should fail
|
||||
FileUtilities.copyFile(new ResourceFile(from), to, null);
|
||||
}
|
||||
|
||||
public void copyFile_WithMonitor() {
|
||||
// too slow due to the nature of how the progress is reported in chunks--we would
|
||||
// have to generate too much data, which would take seconds to test that progress
|
||||
// is correctly reported
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,88 @@
|
||||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package docking.widgets.formatter;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.text.ParseException;
|
||||
|
||||
import javax.swing.JFormattedTextField;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import docking.widgets.textfield.HexIntegerFormatter;
|
||||
import ghidra.feature.vt.gui.filters.IntegerFormatterFactory;
|
||||
|
||||
public class HexIntegerFormatterTest {
|
||||
|
||||
private HexIntegerFormatter formatter;
|
||||
private JFormattedTextField formattedField;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
formatter = new HexIntegerFormatter();
|
||||
IntegerFormatterFactory factory = new IntegerFormatterFactory(formatter, false);
|
||||
formattedField = new JFormattedTextField(factory);
|
||||
}
|
||||
|
||||
@Test(expected = ParseException.class)
|
||||
public void invalidInput() throws ParseException {
|
||||
formattedField.setText("bob");
|
||||
formattedField.commitEdit();
|
||||
assertThat(formattedField.getValue(), is(nullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void positiveInput() throws ParseException {
|
||||
long value = 1L;
|
||||
formattedField.setText(Long.toString(value));
|
||||
formattedField.commitEdit();
|
||||
assertThat(formattedField.getValue(), is(value));
|
||||
|
||||
String hexString = "ab";
|
||||
formattedField.setText(hexString);
|
||||
formattedField.commitEdit();
|
||||
String currentStringValue = Long.toHexString((Long) formattedField.getValue());
|
||||
assertThat(currentStringValue, is(hexString));
|
||||
}
|
||||
|
||||
@Test(expected = ParseException.class)
|
||||
public void negativeIntegerInput() throws ParseException {
|
||||
long value = -1L;
|
||||
formattedField.setText(Long.toString(value));
|
||||
formattedField.commitEdit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void negativeInput() throws ParseException {
|
||||
String hexString = "ab";
|
||||
formattedField.setText(hexString);
|
||||
formattedField.commitEdit();
|
||||
String currentStringValue = Long.toHexString((Long) formattedField.getValue());
|
||||
assertThat(currentStringValue, is(hexString));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyString() throws ParseException {
|
||||
long value = 1;
|
||||
formattedField.setValue(value);
|
||||
formattedField.commitEdit();
|
||||
assertThat(formattedField.getValue(), is(1L));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user