Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Cortell2012-02-24 14:16:17 -0500
committerJohn Cortell2012-02-24 14:16:17 -0500
commitb4da3bb8f027a1c99a7e99e14d0136becf291c81 (patch)
treeb625ef476e8151c65ff91f4e33a3fd6769575f93 /core/org.eclipse.cdt.core.tests
parent117792fba6cda97254ea7ae878659c2c451e4d2a (diff)
downloadorg.eclipse.cdt-b4da3bb8f027a1c99a7e99e14d0136becf291c81.tar.gz
org.eclipse.cdt-b4da3bb8f027a1c99a7e99e14d0136becf291c81.tar.xz
org.eclipse.cdt-b4da3bb8f027a1c99a7e99e14d0136becf291c81.zip
Bug 356519 - ELF header reader makeShort() bug
Diffstat (limited to 'core/org.eclipse.cdt.core.tests')
-rw-r--r--core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/utils/ByteUtilsTest.java148
1 files changed, 148 insertions, 0 deletions
diff --git a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/utils/ByteUtilsTest.java b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/utils/ByteUtilsTest.java
new file mode 100644
index 0000000000..94a25b3dc0
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/utils/ByteUtilsTest.java
@@ -0,0 +1,148 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Freescale Semiconductor and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Freescale Semiconductor - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.utils;
+
+import static org.eclipse.cdt.internal.core.ByteUtils.makeInt;
+import static org.eclipse.cdt.internal.core.ByteUtils.makeLong;
+import static org.eclipse.cdt.internal.core.ByteUtils.makeShort;
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class ByteUtilsTest extends TestCase {
+
+ public static Test suite() {
+ return new TestSuite(ByteUtilsTest.class);
+ }
+
+ // Allows us to avoid ugly misalignment in the source
+ private static byte Ox80 = (byte)0x80;
+ private static byte Oxff = (byte)0xff;
+
+ public void testMakeShort() throws Exception {
+ Assert.assertEquals((short)0x0000, makeShort(new byte[]{0x00,0x00}, 0, false));
+ Assert.assertEquals((short)0x7f00, makeShort(new byte[]{0x7f,0x00}, 0, false));
+ Assert.assertEquals((short)0x007f, makeShort(new byte[]{0x00,0x7f}, 0, false));
+ Assert.assertEquals((short)0x8000, makeShort(new byte[]{Ox80,0x00}, 0, false));
+ Assert.assertEquals((short)0x0080, makeShort(new byte[]{0x00,Ox80}, 0, false));
+ Assert.assertEquals((short)0xff00, makeShort(new byte[]{Oxff,0x00}, 0, false));
+ Assert.assertEquals((short)0x00ff, makeShort(new byte[]{0x00,Oxff}, 0, false));
+ Assert.assertEquals((short)0xffff, makeShort(new byte[]{Oxff,Oxff}, 0, false));
+
+ Assert.assertEquals((short)0x0000, makeShort(new byte[]{0x00,0x00}, 0, true));
+ Assert.assertEquals((short)0x007f, makeShort(new byte[]{0x7f,0x00}, 0, true));
+ Assert.assertEquals((short)0x7f00, makeShort(new byte[]{0x00,0x7f}, 0, true));
+ Assert.assertEquals((short)0x0080, makeShort(new byte[]{Ox80,0x00}, 0, true));
+ Assert.assertEquals((short)0x8000, makeShort(new byte[]{0x00,Ox80}, 0, true));
+ Assert.assertEquals((short)0x00ff, makeShort(new byte[]{Oxff,0x00}, 0, true));
+ Assert.assertEquals((short)0xff00, makeShort(new byte[]{0x00,Oxff}, 0, true));
+ Assert.assertEquals((short)0xffff, makeShort(new byte[]{Oxff,Oxff}, 0, true));
+
+ Assert.assertEquals(0x0102, makeShort(new byte[]{0,0,0,0x01,0x02}, 3, false));
+ Assert.assertEquals(0x0201, makeShort(new byte[]{0,0,0,0x01,0x02}, 3, true));
+ }
+
+ public void testMakeInt() throws Exception {
+ Assert.assertEquals(0x00000000, makeInt(new byte[]{0x00,0x00,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x7f000000, makeInt(new byte[]{0x7f,0x00,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x007f0000, makeInt(new byte[]{0x00,0x7f,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x00007f00, makeInt(new byte[]{0x00,0x00,0x7f,0x00}, 0, false));
+ Assert.assertEquals(0x0000007f, makeInt(new byte[]{0x00,0x00,0x00,0x7f}, 0, false));
+ Assert.assertEquals(0x80000000, makeInt(new byte[]{Ox80,0x00,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x00800000, makeInt(new byte[]{0x00,Ox80,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x00008000, makeInt(new byte[]{0x00,0x00,Ox80,0x00}, 0, false));
+ Assert.assertEquals(0x00000080, makeInt(new byte[]{0x00,0x00,0x00,Ox80}, 0, false));
+ Assert.assertEquals(0xff000000, makeInt(new byte[]{Oxff,0x00,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x00ff0000, makeInt(new byte[]{0x00,Oxff,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x0000ff00, makeInt(new byte[]{0x00,0x00,Oxff,0x00}, 0, false));
+ Assert.assertEquals(0x000000ff, makeInt(new byte[]{0x00,0x00,0x00,Oxff}, 0, false));
+ Assert.assertEquals(0xffffffff, makeInt(new byte[]{Oxff,Oxff,Oxff,Oxff}, 0, false));
+
+ Assert.assertEquals(0x00000000, makeInt(new byte[]{0x00,0x00,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x0000007f, makeInt(new byte[]{0x7f,0x00,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x00007f00, makeInt(new byte[]{0x00,0x7f,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x007f0000, makeInt(new byte[]{0x00,0x00,0x7f,0x00}, 0, true));
+ Assert.assertEquals(0x7f000000, makeInt(new byte[]{0x00,0x00,0x00,0x7f}, 0, true));
+ Assert.assertEquals(0x00000080, makeInt(new byte[]{Ox80,0x00,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x00008000, makeInt(new byte[]{0x00,Ox80,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x00800000, makeInt(new byte[]{0x00,0x00,Ox80,0x00}, 0, true));
+ Assert.assertEquals(0x80000000, makeInt(new byte[]{0x00,0x00,0x00,Ox80}, 0, true));
+ Assert.assertEquals(0x000000ff, makeInt(new byte[]{Oxff,0x00,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x0000ff00, makeInt(new byte[]{0x00,Oxff,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x00ff0000, makeInt(new byte[]{0x00,0x00,Oxff,0x00}, 0, true));
+ Assert.assertEquals(0xff000000, makeInt(new byte[]{0x00,0x00,0x00,Oxff}, 0, true));
+ Assert.assertEquals(0xffffffff, makeInt(new byte[]{Oxff,Oxff,Oxff,Oxff}, 0, true));
+
+ Assert.assertEquals(0x01020304, makeInt(new byte[]{0,0,0,0x01,0x02,0x03,0x04}, 3, false));
+ Assert.assertEquals(0x04030201, makeInt(new byte[]{0,0,0,0x01,0x02,0x03,0x04}, 3, true));
+ }
+
+ public void testMakeLong() throws Exception {
+ Assert.assertEquals(0x0000000000000000L, makeLong(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x7f00000000000000L, makeLong(new byte[]{0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x007f000000000000L, makeLong(new byte[]{0x00,0x7f,0x00,0x00,0x00,0x00,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x00007f0000000000L, makeLong(new byte[]{0x00,0x00,0x7f,0x00,0x00,0x00,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x0000007f00000000L, makeLong(new byte[]{0x00,0x00,0x00,0x7f,0x00,0x00,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x000000007f000000L, makeLong(new byte[]{0x00,0x00,0x00,0x00,0x7f,0x00,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x00000000007f0000L, makeLong(new byte[]{0x00,0x00,0x00,0x00,0x00,0x7f,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x0000000000007f00L, makeLong(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x00}, 0, false));
+ Assert.assertEquals(0x000000000000007fL, makeLong(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f}, 0, false));
+ Assert.assertEquals(0x8000000000000000L, makeLong(new byte[]{Ox80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x0080000000000000L, makeLong(new byte[]{0x00,Ox80,0x00,0x00,0x00,0x00,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x0000800000000000L, makeLong(new byte[]{0x00,0x00,Ox80,0x00,0x00,0x00,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x0000008000000000L, makeLong(new byte[]{0x00,0x00,0x00,Ox80,0x00,0x00,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x0000000080000000L, makeLong(new byte[]{0x00,0x00,0x00,0x00,Ox80,0x00,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x0000000000800000L, makeLong(new byte[]{0x00,0x00,0x00,0x00,0x00,Ox80,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x0000000000008000L, makeLong(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,Ox80,0x00}, 0, false));
+ Assert.assertEquals(0x0000000000000080L, makeLong(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,Ox80}, 0, false));
+ Assert.assertEquals(0xff00000000000000L, makeLong(new byte[]{Oxff,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x00ff000000000000L, makeLong(new byte[]{0x00,Oxff,0x00,0x00,0x00,0x00,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x0000ff0000000000L, makeLong(new byte[]{0x00,0x00,Oxff,0x00,0x00,0x00,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x000000ff00000000L, makeLong(new byte[]{0x00,0x00,0x00,Oxff,0x00,0x00,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x00000000ff000000L, makeLong(new byte[]{0x00,0x00,0x00,0x00,Oxff,0x00,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x0000000000ff0000L, makeLong(new byte[]{0x00,0x00,0x00,0x00,0x00,Oxff,0x00,0x00}, 0, false));
+ Assert.assertEquals(0x000000000000ff00L, makeLong(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,Oxff,0x00}, 0, false));
+ Assert.assertEquals(0x00000000000000ffL, makeLong(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,Oxff}, 0, false));
+ Assert.assertEquals(0xffffffffffffffffL, makeLong(new byte[]{Oxff,Oxff,Oxff,Oxff,Oxff,Oxff,Oxff,Oxff}, 0, false));
+
+ Assert.assertEquals(0x0000000000000000L, makeLong(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x000000000000007fL, makeLong(new byte[]{0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x0000000000007f00L, makeLong(new byte[]{0x00,0x7f,0x00,0x00,0x00,0x00,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x00000000007f0000L, makeLong(new byte[]{0x00,0x00,0x7f,0x00,0x00,0x00,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x000000007f000000L, makeLong(new byte[]{0x00,0x00,0x00,0x7f,0x00,0x00,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x0000007f00000000L, makeLong(new byte[]{0x00,0x00,0x00,0x00,0x7f,0x00,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x00007f0000000000L, makeLong(new byte[]{0x00,0x00,0x00,0x00,0x00,0x7f,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x007f000000000000L, makeLong(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x00}, 0, true));
+ Assert.assertEquals(0x7f00000000000000L, makeLong(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f}, 0, true));
+ Assert.assertEquals(0x0000000000000080L, makeLong(new byte[]{Ox80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x0000000000008000L, makeLong(new byte[]{0x00,Ox80,0x00,0x00,0x00,0x00,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x0000000000800000L, makeLong(new byte[]{0x00,0x00,Ox80,0x00,0x00,0x00,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x0000000080000000L, makeLong(new byte[]{0x00,0x00,0x00,Ox80,0x00,0x00,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x0000008000000000L, makeLong(new byte[]{0x00,0x00,0x00,0x00,Ox80,0x00,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x0000800000000000L, makeLong(new byte[]{0x00,0x00,0x00,0x00,0x00,Ox80,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x0080000000000000L, makeLong(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,Ox80,0x00}, 0, true));
+ Assert.assertEquals(0x8000000000000000L, makeLong(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,Ox80}, 0, true));
+ Assert.assertEquals(0x00000000000000ffL, makeLong(new byte[]{Oxff,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x000000000000ff00L, makeLong(new byte[]{0x00,Oxff,0x00,0x00,0x00,0x00,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x0000000000ff0000L, makeLong(new byte[]{0x00,0x00,Oxff,0x00,0x00,0x00,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x00000000ff000000L, makeLong(new byte[]{0x00,0x00,0x00,Oxff,0x00,0x00,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x000000ff00000000L, makeLong(new byte[]{0x00,0x00,0x00,0x00,Oxff,0x00,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x0000ff0000000000L, makeLong(new byte[]{0x00,0x00,0x00,0x00,0x00,Oxff,0x00,0x00}, 0, true));
+ Assert.assertEquals(0x00ff000000000000L, makeLong(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,Oxff,0x00}, 0, true));
+ Assert.assertEquals(0xff00000000000000L, makeLong(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,Oxff}, 0, true));
+ Assert.assertEquals(0xffffffffffffffffL, makeLong(new byte[]{Oxff,Oxff,Oxff,Oxff,Oxff,Oxff,Oxff,Oxff}, 0, true));
+
+ Assert.assertEquals(0x0102030405060708L, makeLong(new byte[]{0,0,0,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08}, 3, false));
+ Assert.assertEquals(0x0807060504030201L, makeLong(new byte[]{0,0,0,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08}, 3, true));
+ }
+}

Back to the top