Skip to content

Commit

Permalink
minor reorg of test classes - relates to github #1634
Browse files Browse the repository at this point in the history
  • Loading branch information
dghgit committed May 1, 2024
1 parent 7d3efae commit 8ce0891
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 37 deletions.
5 changes: 4 additions & 1 deletion ant/bc+-build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,10 @@
<copyStandardFiles toDir="${pg.target.dir}" />

<copy todir="${pg.target.src.dir}" filtering="true">
<fileset dir="${src.dir}" includes="org/bouncycastle/bcpg/**/*.java" />
<fileset dir="${src.dir}">
<include name="org/bouncycastle/bcpg/**/*.java" />
<exclude name="org/bouncycastle/**/test/**/*.java" />
</fileset>
</copy>

<copy todir="${pg.target.src.dir}">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.bouncycastle.bcpg.test;

import org.bouncycastle.bcpg.ContainedPacket;
import org.bouncycastle.bcpg.HexDumpUtil;
import org.bouncycastle.test.DumpUtil;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.test.SimpleTest;

Expand Down Expand Up @@ -36,8 +36,8 @@ public void isEncodingEqual(String message, byte[] first, byte[] second)
{
sb.append(message).append("\n");
}
sb.append("Expected: \n").append(HexDumpUtil.hexdump(first)).append("\n");
sb.append("Got: \n").append(HexDumpUtil.hexdump(second));
sb.append("Expected: \n").append(DumpUtil.hexdump(first)).append("\n");
sb.append("Got: \n").append(DumpUtil.hexdump(second));

isTrue(sb.toString(), first == second || Arrays.areEqual(first, second));
}
Expand Down Expand Up @@ -69,8 +69,8 @@ public void isEncodingEqual(String message, ContainedPacket first, ContainedPack
{
sb.append(message).append("\n");
}
sb.append("Expected: \n").append(HexDumpUtil.hexdump(first)).append("\n");
sb.append("Got: \n").append(HexDumpUtil.hexdump(second));
sb.append("Expected: \n").append(PacketDumpUtil.hexdump(first)).append("\n");
sb.append("Got: \n").append(PacketDumpUtil.hexdump(second));
isTrue(sb.toString(), first == second || Arrays.areEqual(first.getEncoded(), second.getEncoded()));
}

Expand Down
35 changes: 35 additions & 0 deletions pg/src/test/java/org/bouncycastle/bcpg/test/PacketDumpUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.bouncycastle.bcpg.test;

import java.io.IOException;

import org.bouncycastle.bcpg.ContainedPacket;
import org.bouncycastle.test.DumpUtil;

public class PacketDumpUtil
{
/**
* Return a formatted hex dump of the packet encoding of the given packet.
* @param packet packet
* @return formatted hex dump
* @throws IOException if an exception happens during packet encoding
*/
public static String hexdump(ContainedPacket packet)
throws IOException
{
return DumpUtil.hexdump(packet.getEncoded());
}

/**
* Return a formatted hex dump of the packet encoding of the given packet.
* If startIndent is non-zero, the hex dump is shifted right by the startIndent octets.
* @param startIndent shift the encodings octet stream by a number of bytes
* @param packet packet
* @return formatted hex dump
* @throws IOException if an exception happens during packet encoding
*/
public static String hexdump(int startIndent, ContainedPacket packet)
throws IOException
{
return DumpUtil.hexdump(startIndent, packet.getEncoded());
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package org.bouncycastle.bcpg;
package org.bouncycastle.test;

import org.bouncycastle.util.encoders.Hex;

import java.io.IOException;

public class HexDumpUtil
public class DumpUtil
{

/**
* Return a formatted hex dump of the given byte array.
* @param array byte array
Expand Down Expand Up @@ -65,30 +62,4 @@ public static String hexdump(int startIndent, byte[] array)
}
return out.toString();
}

/**
* Return a formatted hex dump of the packet encoding of the given packet.
* @param packet packet
* @return formatted hex dump
* @throws IOException if an exception happens during packet encoding
*/
public static String hexdump(ContainedPacket packet)
throws IOException
{
return hexdump(packet.getEncoded());
}

/**
* Return a formatted hex dump of the packet encoding of the given packet.
* If startIndent is non-zero, the hex dump is shifted right by the startIndent octets.
* @param startIndent shift the encodings octet stream by a number of bytes
* @param packet packet
* @return formatted hex dump
* @throws IOException if an exception happens during packet encoding
*/
public static String hexdump(int startIndent, ContainedPacket packet)
throws IOException
{
return hexdump(startIndent, packet.getEncoded());
}
}

0 comments on commit 8ce0891

Please sign in to comment.