Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export BC_JDK17=/path/to/java17

## Building

To run the tests of the project as part of the build test data is needed.
Our test data can be found at the https://github.com/bcgit/bc-test-data.git repository.
Best approach to provide the data for the tests is to check out the repository and define the `BC_TEST_DATA_DIR` env variable pointing to that folder.
If the env variable is not present the test data will be assumed in a `bc-test-data` folder in your user root dir.

The project now uses ```gradlew``` which can be invoked for example:

```
Expand Down
47 changes: 29 additions & 18 deletions core/src/test/java/org/bouncycastle/test/TestResourceFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,42 @@ public class TestResourceFinder
{
private static final String dataDirName = "bc-test-data";

private static final String CUSTOM_TEST_DATA_DIR_ENV_NAME = "BC_TEST_DATA_DIR";

/**
* We search starting at the working directory looking for the bc-test-data directory.
*
* @throws FileNotFoundException
*/
public static InputStream findTestResource(String homeDir, String fileName)
throws FileNotFoundException
throws FileNotFoundException
{
String wrkDirName = System.getProperty("user.dir");
String separator = System.getProperty("file.separator");
File wrkDir = new File(wrkDirName);
File dataDir = new File(wrkDir, dataDirName);
while (!dataDir.exists() && wrkDirName.length() > 1)
{
wrkDirName = wrkDirName.substring(0, wrkDirName.lastIndexOf(separator));
wrkDir = new File(wrkDirName);
dataDir = new File(wrkDir, dataDirName);
}

if (!dataDir.exists())
{
String ln = System.getProperty("line.separator");
throw new FileNotFoundException("Test data directory " + dataDirName + " not found." + ln + "Test data available from: https://github.com/bcgit/bc-test-data.git");
final String separator = System.getProperty("file.separator");
final String customDataDirName = System.getenv(CUSTOM_TEST_DATA_DIR_ENV_NAME);
if (customDataDirName != null) {
File dataDir = new File(customDataDirName);
if (!dataDir.exists())
{
String ln = System.getProperty("line.separator");
throw new FileNotFoundException("Test data directory " + customDataDirName + " not found." + ln + "Test data available from: https://github.com/bcgit/bc-test-data.git");
}
return new FileInputStream(new File(dataDir, homeDir + separator + fileName));
} else {
String wrkDirName = System.getProperty("user.dir");
File wrkDir = new File(wrkDirName);
File dataDir = new File(wrkDir, dataDirName);
while (!dataDir.exists() && wrkDirName.length() > 1)
{
wrkDirName = wrkDirName.substring(0, wrkDirName.lastIndexOf(separator));
wrkDir = new File(wrkDirName);
dataDir = new File(wrkDir, dataDirName);
}
if (!dataDir.exists())
{
String ln = System.getProperty("line.separator");
throw new FileNotFoundException("Test data directory " + dataDir + " not found." + ln + "Test data available from: https://github.com/bcgit/bc-test-data.git");
}
return new FileInputStream(new File(dataDir, homeDir + separator + fileName));
}

return new FileInputStream(new File(dataDir, homeDir + separator + fileName));
}
}
47 changes: 29 additions & 18 deletions kmip/src/test/java/org/bouncycastle/test/TestResourceFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,42 @@ public class TestResourceFinder
{
private static final String dataDirName = "bc-test-data";

private static final String CUSTOM_TEST_DATA_DIR_ENV_NAME = "BC_TEST_DATA_DIR";

/**
* We search starting at the working directory looking for the bc-test-data directory.
*
* @throws FileNotFoundException
*/
public static InputStream findTestResource(String homeDir, String fileName)
throws FileNotFoundException
throws FileNotFoundException
{
String wrkDirName = System.getProperty("user.dir");
String separator = System.getProperty("file.separator");
File wrkDir = new File(wrkDirName);
File dataDir = new File(wrkDir, dataDirName);
while (!dataDir.exists() && wrkDirName.length() > 1)
{
wrkDirName = wrkDirName.substring(0, wrkDirName.lastIndexOf(separator));
wrkDir = new File(wrkDirName);
dataDir = new File(wrkDir, dataDirName);
}

if (!dataDir.exists())
{
String ln = System.getProperty("line.separator");
throw new FileNotFoundException("Test data directory " + dataDirName + " not found." + ln + "Test data available from: https://github.com/bcgit/bc-test-data.git");
final String separator = System.getProperty("file.separator");
final String customDataDirName = System.getenv(CUSTOM_TEST_DATA_DIR_ENV_NAME);
if (customDataDirName != null) {
File dataDir = new File(customDataDirName);
if (!dataDir.exists())
{
String ln = System.getProperty("line.separator");
throw new FileNotFoundException("Test data directory " + customDataDirName + " not found." + ln + "Test data available from: https://github.com/bcgit/bc-test-data.git");
}
return new FileInputStream(new File(dataDir, homeDir + separator + fileName));
} else {
String wrkDirName = System.getProperty("user.dir");
File wrkDir = new File(wrkDirName);
File dataDir = new File(wrkDir, dataDirName);
while (!dataDir.exists() && wrkDirName.length() > 1)
{
wrkDirName = wrkDirName.substring(0, wrkDirName.lastIndexOf(separator));
wrkDir = new File(wrkDirName);
dataDir = new File(wrkDir, dataDirName);
}
if (!dataDir.exists())
{
String ln = System.getProperty("line.separator");
throw new FileNotFoundException("Test data directory " + dataDir + " not found." + ln + "Test data available from: https://github.com/bcgit/bc-test-data.git");
}
return new FileInputStream(new File(dataDir, homeDir + separator + fileName));
}

return new FileInputStream(new File(dataDir, homeDir + separator + fileName));
}
}
47 changes: 29 additions & 18 deletions mls/src/test/java/org/bouncycastle/test/TestResourceFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,42 @@ public class TestResourceFinder
{
private static final String dataDirName = "bc-test-data";

private static final String CUSTOM_TEST_DATA_DIR_ENV_NAME = "BC_TEST_DATA_DIR";

/**
* We search starting at the working directory looking for the bc-test-data directory.
*
* @throws FileNotFoundException
*/
public static InputStream findTestResource(String homeDir, String fileName)
throws FileNotFoundException
throws FileNotFoundException
{
String wrkDirName = System.getProperty("user.dir");
String separator = System.getProperty("file.separator");
File wrkDir = new File(wrkDirName);
File dataDir = new File(wrkDir, dataDirName);
while (!dataDir.exists() && wrkDirName.length() > 1)
{
wrkDirName = wrkDirName.substring(0, wrkDirName.lastIndexOf(separator));
wrkDir = new File(wrkDirName);
dataDir = new File(wrkDir, dataDirName);
}

if (!dataDir.exists())
{
String ln = System.getProperty("line.separator");
throw new FileNotFoundException("Test data directory " + dataDirName + " not found." + ln + "Test data available from: https://github.com/bcgit/bc-test-data.git");
final String separator = System.getProperty("file.separator");
final String customDataDirName = System.getenv(CUSTOM_TEST_DATA_DIR_ENV_NAME);
if (customDataDirName != null) {
File dataDir = new File(customDataDirName);
if (!dataDir.exists())
{
String ln = System.getProperty("line.separator");
throw new FileNotFoundException("Test data directory " + customDataDirName + " not found." + ln + "Test data available from: https://github.com/bcgit/bc-test-data.git");
}
return new FileInputStream(new File(dataDir, homeDir + separator + fileName));
} else {
String wrkDirName = System.getProperty("user.dir");
File wrkDir = new File(wrkDirName);
File dataDir = new File(wrkDir, dataDirName);
while (!dataDir.exists() && wrkDirName.length() > 1)
{
wrkDirName = wrkDirName.substring(0, wrkDirName.lastIndexOf(separator));
wrkDir = new File(wrkDirName);
dataDir = new File(wrkDir, dataDirName);
}
if (!dataDir.exists())
{
String ln = System.getProperty("line.separator");
throw new FileNotFoundException("Test data directory " + dataDir + " not found." + ln + "Test data available from: https://github.com/bcgit/bc-test-data.git");
}
return new FileInputStream(new File(dataDir, homeDir + separator + fileName));
}

return new FileInputStream(new File(dataDir, homeDir + separator + fileName));
}
}
47 changes: 29 additions & 18 deletions pkix/src/test/java/org/bouncycastle/test/TestResourceFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,42 @@ public class TestResourceFinder
{
private static final String dataDirName = "bc-test-data";

private static final String CUSTOM_TEST_DATA_DIR_ENV_NAME = "BC_TEST_DATA_DIR";

/**
* We search starting at the working directory looking for the bc-test-data directory.
*
* @throws FileNotFoundException
*/
public static InputStream findTestResource(String homeDir, String fileName)
throws FileNotFoundException
throws FileNotFoundException
{
String wrkDirName = System.getProperty("user.dir");
String separator = System.getProperty("file.separator");
File wrkDir = new File(wrkDirName);
File dataDir = new File(wrkDir, dataDirName);
while (!dataDir.exists() && wrkDirName.length() > 1)
{
wrkDirName = wrkDirName.substring(0, wrkDirName.lastIndexOf(separator));
wrkDir = new File(wrkDirName);
dataDir = new File(wrkDir, dataDirName);
}

if (!dataDir.exists())
{
String ln = System.getProperty("line.separator");
throw new FileNotFoundException("Test data directory " + dataDirName + " not found." + ln + "Test data available from: https://github.com/bcgit/bc-test-data.git");
final String separator = System.getProperty("file.separator");
final String customDataDirName = System.getenv(CUSTOM_TEST_DATA_DIR_ENV_NAME);
if (customDataDirName != null) {
File dataDir = new File(customDataDirName);
if (!dataDir.exists())
{
String ln = System.getProperty("line.separator");
throw new FileNotFoundException("Test data directory " + customDataDirName + " not found." + ln + "Test data available from: https://github.com/bcgit/bc-test-data.git");
}
return new FileInputStream(new File(dataDir, homeDir + separator + fileName));
} else {
String wrkDirName = System.getProperty("user.dir");
File wrkDir = new File(wrkDirName);
File dataDir = new File(wrkDir, dataDirName);
while (!dataDir.exists() && wrkDirName.length() > 1)
{
wrkDirName = wrkDirName.substring(0, wrkDirName.lastIndexOf(separator));
wrkDir = new File(wrkDirName);
dataDir = new File(wrkDir, dataDirName);
}
if (!dataDir.exists())
{
String ln = System.getProperty("line.separator");
throw new FileNotFoundException("Test data directory " + dataDir + " not found." + ln + "Test data available from: https://github.com/bcgit/bc-test-data.git");
}
return new FileInputStream(new File(dataDir, homeDir + separator + fileName));
}

return new FileInputStream(new File(dataDir, homeDir + separator + fileName));
}
}
47 changes: 29 additions & 18 deletions prov/src/test/java/org/bouncycastle/test/TestResourceFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,42 @@ public class TestResourceFinder
{
private static final String dataDirName = "bc-test-data";

private static final String CUSTOM_TEST_DATA_DIR_ENV_NAME = "BC_TEST_DATA_DIR";

/**
* We search starting at the working directory looking for the bc-test-data directory.
*
* @throws FileNotFoundException
*/
public static InputStream findTestResource(String homeDir, String fileName)
throws FileNotFoundException
throws FileNotFoundException
{
String wrkDirName = System.getProperty("user.dir");
String separator = System.getProperty("file.separator");
File wrkDir = new File(wrkDirName);
File dataDir = new File(wrkDir, dataDirName);
while (!dataDir.exists() && wrkDirName.length() > 1)
{
wrkDirName = wrkDirName.substring(0, wrkDirName.lastIndexOf(separator));
wrkDir = new File(wrkDirName);
dataDir = new File(wrkDir, dataDirName);
}

if (!dataDir.exists())
{
String ln = System.getProperty("line.separator");
throw new FileNotFoundException("Test data directory " + dataDirName + " not found." + ln + "Test data available from: https://github.com/bcgit/bc-test-data.git");
final String separator = System.getProperty("file.separator");
final String customDataDirName = System.getenv(CUSTOM_TEST_DATA_DIR_ENV_NAME);
if (customDataDirName != null) {
File dataDir = new File(customDataDirName);
if (!dataDir.exists())
{
String ln = System.getProperty("line.separator");
throw new FileNotFoundException("Test data directory " + customDataDirName + " not found." + ln + "Test data available from: https://github.com/bcgit/bc-test-data.git");
}
return new FileInputStream(new File(dataDir, homeDir + separator + fileName));
} else {
String wrkDirName = System.getProperty("user.dir");
File wrkDir = new File(wrkDirName);
File dataDir = new File(wrkDir, dataDirName);
while (!dataDir.exists() && wrkDirName.length() > 1)
{
wrkDirName = wrkDirName.substring(0, wrkDirName.lastIndexOf(separator));
wrkDir = new File(wrkDirName);
dataDir = new File(wrkDir, dataDirName);
}
if (!dataDir.exists())
{
String ln = System.getProperty("line.separator");
throw new FileNotFoundException("Test data directory " + dataDir + " not found." + ln + "Test data available from: https://github.com/bcgit/bc-test-data.git");
}
return new FileInputStream(new File(dataDir, homeDir + separator + fileName));
}

return new FileInputStream(new File(dataDir, homeDir + separator + fileName));
}
}
47 changes: 29 additions & 18 deletions tls/src/test/java/org/bouncycastle/test/TestResourceFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,42 @@ public class TestResourceFinder
{
private static final String dataDirName = "bc-test-data";

private static final String CUSTOM_TEST_DATA_DIR_ENV_NAME = "BC_TEST_DATA_DIR";

/**
* We search starting at the working directory looking for the bc-test-data directory.
*
* @throws FileNotFoundException
*/
public static InputStream findTestResource(String homeDir, String fileName)
throws FileNotFoundException
throws FileNotFoundException
{
String wrkDirName = System.getProperty("user.dir");
String separator = System.getProperty("file.separator");
File wrkDir = new File(wrkDirName);
File dataDir = new File(wrkDir, dataDirName);
while (!dataDir.exists() && wrkDirName.length() > 1)
{
wrkDirName = wrkDirName.substring(0, wrkDirName.lastIndexOf(separator));
wrkDir = new File(wrkDirName);
dataDir = new File(wrkDir, dataDirName);
}

if (!dataDir.exists())
{
String ln = System.getProperty("line.separator");
throw new FileNotFoundException("Test data directory " + dataDirName + " not found." + ln + "Test data available from: https://github.com/bcgit/bc-test-data.git");
final String separator = System.getProperty("file.separator");
final String customDataDirName = System.getenv(CUSTOM_TEST_DATA_DIR_ENV_NAME);
if (customDataDirName != null) {
File dataDir = new File(customDataDirName);
if (!dataDir.exists())
{
String ln = System.getProperty("line.separator");
throw new FileNotFoundException("Test data directory " + customDataDirName + " not found." + ln + "Test data available from: https://github.com/bcgit/bc-test-data.git");
}
return new FileInputStream(new File(dataDir, homeDir + separator + fileName));
} else {
String wrkDirName = System.getProperty("user.dir");
File wrkDir = new File(wrkDirName);
File dataDir = new File(wrkDir, dataDirName);
while (!dataDir.exists() && wrkDirName.length() > 1)
{
wrkDirName = wrkDirName.substring(0, wrkDirName.lastIndexOf(separator));
wrkDir = new File(wrkDirName);
dataDir = new File(wrkDir, dataDirName);
}
if (!dataDir.exists())
{
String ln = System.getProperty("line.separator");
throw new FileNotFoundException("Test data directory " + dataDir + " not found." + ln + "Test data available from: https://github.com/bcgit/bc-test-data.git");
}
return new FileInputStream(new File(dataDir, homeDir + separator + fileName));
}

return new FileInputStream(new File(dataDir, homeDir + separator + fileName));
}
}