Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc-Andre Laperle2014-10-18 03:07:23 +0000
committerMarc-Andre Laperle2014-10-22 04:30:19 +0000
commitd2f7f27da14277d7e1b342ed267cfaecdc3a96d5 (patch)
tree38bb3fedc551941620c3a3805db42caf0772ee72
parent75704836bd061a8d66588792170d9528a0946b3c (diff)
downloadorg.eclipse.linuxtools-d2f7f27da14277d7e1b342ed267cfaecdc3a96d5.tar.gz
org.eclipse.linuxtools-d2f7f27da14277d7e1b342ed267cfaecdc3a96d5.tar.xz
org.eclipse.linuxtools-d2f7f27da14277d7e1b342ed267cfaecdc3a96d5.zip
pcap: Fix a test so that it works in any time zone
Change-Id: I79d1cff9cb6be30c73ec0d5c4ba05d682b919202 Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com> Reviewed-on: https://git.eclipse.org/r/35081 Tested-by: Hudson CI Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
-rw-r--r--lttng/org.eclipse.linuxtools.pcap.core.tests/src/org/eclipse/linuxtools/pcap/core/tests/protocol/pcap/PcapPacketTest.java36
1 files changed, 29 insertions, 7 deletions
diff --git a/lttng/org.eclipse.linuxtools.pcap.core.tests/src/org/eclipse/linuxtools/pcap/core/tests/protocol/pcap/PcapPacketTest.java b/lttng/org.eclipse.linuxtools.pcap.core.tests/src/org/eclipse/linuxtools/pcap/core/tests/protocol/pcap/PcapPacketTest.java
index bf066354c1..d635bfe39b 100644
--- a/lttng/org.eclipse.linuxtools.pcap.core.tests/src/org/eclipse/linuxtools/pcap/core/tests/protocol/pcap/PcapPacketTest.java
+++ b/lttng/org.eclipse.linuxtools.pcap.core.tests/src/org/eclipse/linuxtools/pcap/core/tests/protocol/pcap/PcapPacketTest.java
@@ -21,7 +21,11 @@ import static org.junit.Assume.assumeTrue;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.Map;
+import java.util.TimeZone;
import org.eclipse.linuxtools.internal.pcap.core.packet.BadPacketException;
import org.eclipse.linuxtools.internal.pcap.core.protocol.PcapProtocol;
@@ -42,18 +46,30 @@ import com.google.common.collect.ImmutableMap;
*/
public class PcapPacketTest {
- private static final Map<String, String> EXPECTED_FIELDS = ImmutableMap.of(
- "Frame", "36",
- "Frame Length", "75 bytes",
- "Capture Length", "75 bytes",
- "Capture Time", "2005-07-04 05:33:52.829.277.000"
- );
+ private static final String EXPECTED_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
+ private static final String EXPECTED_GMT_TIME = "2005-07-04 09:33:52.829";
+ private static final Map<String, String> EXPECTED_FIELDS;
private static final String EXPECTED_TOSTRING;
static {
+
+ // Convert known GMT time to default (local) time zone. The local time
+ // is the expected value.
+ String captureTime = "";
+ try {
+ SimpleDateFormat gmtFormat = new SimpleDateFormat(EXPECTED_DATE_FORMAT);
+ gmtFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
+ Date gmtDate = gmtFormat.parse(EXPECTED_GMT_TIME);
+
+ SimpleDateFormat defaultFormat = new SimpleDateFormat(EXPECTED_DATE_FORMAT);
+ captureTime = defaultFormat.format(gmtDate);
+ } catch (ParseException e) {
+ fail("failed to parse date");
+ }
+
StringBuilder sb = new StringBuilder();
sb.append("Packet Capture 36: 75 bytes on wire, 75 bytes captured.\n");
- sb.append("Arrival time: 2005-07-04 05:33:52.829.277.000\n");
+ sb.append("Arrival time: " + captureTime + ".277.000\n");
sb.append("Ethernet II, Source: 00:e0:ed:01:6e:bd, Destination: 00:30:54:00:34:56, Type: Internet Protocol Version 4 (0x0800)\n");
sb.append("Internet Protocol Version 4, Source: 192.168.1.2, Destination: 192.168.1.1\n");
sb.append("Version: 4, Identification: 0x69aa, Header Length: 20 bytes, Total Length: 61 bytes\n");
@@ -66,6 +82,12 @@ public class PcapPacketTest {
sb.append("Payload: ed d4 01 00 00 01 00 00 00 00 00 00 03 66 74 70 07 65 63 69 74 65 6c 65 03 63 6f 6d 00 00 01 00 01");
EXPECTED_TOSTRING = sb.toString();
+ EXPECTED_FIELDS = ImmutableMap.of(
+ "Frame", "36",
+ "Frame Length", "75 bytes",
+ "Capture Length", "75 bytes",
+ "Capture Time", captureTime + ".277.000"
+ );
}
private ByteBuffer fPayload;

Back to the top