summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorSimon Marchi2013-02-19 15:23:05 (EST)
committer Matthew Khouzam2013-02-20 16:52:31 (EST)
commit81afd6cd8aa192455b5b9207f5fbcacaa3aca9fb (patch)
tree2874b63965d1b79c196a32e893a95bdf1e6b17c7
parent92b9d7d6f6ae06a8f9b4d465e6080c4b302a3859 (diff)
downloadorg.eclipse.linuxtools-81afd6cd8aa192455b5b9207f5fbcacaa3aca9fb.zip
org.eclipse.linuxtools-81afd6cd8aa192455b5b9207f5fbcacaa3aca9fb.tar.gz
org.eclipse.linuxtools-81afd6cd8aa192455b5b9207f5fbcacaa3aca9fb.tar.bz2
Add or fix CTF types toStringrefs/changes/90/10490/9
* struct: add field names * variant: print the current field * enum: print value and container value Change-Id: I45d9a2fd900a29cd2ef99f15d2d58d4d01151ee1 Reviewed-on: https://git.eclipse.org/r/10490 Tested-by: Hudson CI Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com> IP-Clean: Matthew Khouzam <matthew.khouzam@ericsson.com> Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EnumDefinitionTest.java13
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java21
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/VariantDefinitionTest.java20
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDefinition.java6
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java18
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDefinition.java6
6 files changed, 68 insertions, 16 deletions
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EnumDefinitionTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EnumDefinitionTest.java
index 39f8091..faf4435 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EnumDefinitionTest.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EnumDefinitionTest.java
@@ -45,6 +45,8 @@ public class EnumDefinitionTest {
EnumDeclaration declaration = new EnumDeclaration(
new IntegerDeclaration(1, true, 1, ByteOrder.BIG_ENDIAN,
Encoding.ASCII, null, 8));
+ declaration.add(0, 10, "a"); //$NON-NLS-1$
+ declaration.add(11, 20, "b"); //$NON-NLS-1$
String fieldName = ""; //$NON-NLS-1$
fixture = new EnumDefinition(declaration, null, fieldName);
@@ -109,4 +111,15 @@ public class EnumDefinitionTest {
fixture.read(input);
}
+
+ /**
+ * Run the String toString() method test.
+ */
+ @Test
+ public void testToString() {
+ fixture.setIntegerValue(16);
+ String result = fixture.toString();
+
+ assertEquals("{ value = b, container = 16 }", result); //$NON-NLS-1$
+ }
} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java
index b2795eb..d3e772a 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java
@@ -1,5 +1,6 @@
package org.eclipse.linuxtools.ctf.core.tests.types;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -56,6 +57,10 @@ public class StructDefinitionTest {
private StructDefinition fixture;
+ private StructDefinition emptyStruct;
+
+ private StructDefinition simpleStruct;
+
private static final String VAR_FIELD_NAME = "SomeVariant"; //$NON-NLS-1$
/**
@@ -98,6 +103,16 @@ public class StructDefinitionTest {
VariantDefinition vd = varDec.createDefinition(fixture,VAR_FIELD_NAME );
vd.setTagDefinition(eDef);
+ // Create an empty struct
+ StructDeclaration esDec = new StructDeclaration(32);
+ emptyStruct = esDec.createDefinition(null, TEST_STRUCT_ID);
+
+ // Create a simple struct with two items
+ StructDeclaration ssDec = new StructDeclaration(32);
+ ssDec.addField(INT_ID, id);
+ ssDec.addField(STRING_ID, sd);
+ simpleStruct = ssDec.createDefinition(null, TEST_STRUCT_ID);
+
}
/**
@@ -240,5 +255,11 @@ public class StructDefinitionTest {
public void testToString() {
String result = fixture.toString();
assertNotNull(result);
+
+ result = emptyStruct.toString();
+ assertEquals("{ }", result); //$NON-NLS-1$
+
+ result = simpleStruct.toString();
+ assertEquals("{ _id = 0, _args = \"\" }", result); //$NON-NLS-1$
}
} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/VariantDefinitionTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/VariantDefinitionTest.java
index 58c1bc6..96eceee 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/VariantDefinitionTest.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/VariantDefinitionTest.java
@@ -1,5 +1,6 @@
package org.eclipse.linuxtools.ctf.core.tests.types;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -116,11 +117,7 @@ public class VariantDefinitionTest {
varDec.setTag(TAG_ID);
structDefinition = sDec.createDefinition(null, TEST_STRUCT_ID);
-
- EnumDefinition eDef = tagDec.createDefinition(structDefinition, TAG_ID);
- fixture = varDec.createDefinition(structDefinition,VAR_FIELD_NAME );
- fixture.setTagDefinition(eDef);
-
+ fixture = (VariantDefinition) structDefinition.getDefinitions().get(VAR_FIELD_NAME);
}
/**
@@ -332,4 +329,17 @@ public class VariantDefinitionTest {
fixture.setTagDefinition(tagDefinition);
}
+
+ /**
+ * Run the String toString() method test.
+ */
+ @Test
+ public void testToString() {
+ String result = fixture.toString();
+ assertEquals("{ null = null }", result); //$NON-NLS-1$
+
+ fixture.setCurrentField(ENUM_2);
+ result = fixture.toString();
+ assertEquals("{ b = 0 }", result); //$NON-NLS-1$
+ }
}
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDefinition.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDefinition.java
index 1fc57fa..0fc3d3c 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDefinition.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDefinition.java
@@ -114,4 +114,10 @@ public class EnumDefinition extends SimpleDatatypeDefinition {
value = declaration.query(val);
}
+ @Override
+ public String toString() {
+ return "{ value = " + getValue() + //$NON-NLS-1$
+ ", container = " + integerValue.toString() + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ }
}
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java
index 7a837a2..52fb8f1 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java
@@ -220,28 +220,24 @@ public class StructDefinition extends Definition implements IDefinitionScope {
public String toString() {
StringBuilder builder = new StringBuilder();
- int size = this.declaration.getFieldsList().size();
- int n = 0;
-
- if (size > 1) {
- builder.append("{ "); //$NON-NLS-1$
- }
+ builder.append("{ "); //$NON-NLS-1$
ListIterator<String> listIterator = this.declaration.getFieldsList()
.listIterator();
while (listIterator.hasNext()) {
String field = listIterator.next();
+
+ builder.append(field);
+ builder.append(" = "); //$NON-NLS-1$
builder.append(lookupDefinition(field).toString());
- n++;
- if (n != size) {
+
+ if (listIterator.hasNext()) {
builder.append(", "); //$NON-NLS-1$
}
}
- if (size > 1) {
- builder.append(" }"); //$NON-NLS-1$
- }
+ builder.append(" }"); //$NON-NLS-1$
return builder.toString();
}
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDefinition.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDefinition.java
index 7f1144b..4d5df8e 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDefinition.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDefinition.java
@@ -267,4 +267,10 @@ public class VariantDefinition extends Definition implements IDefinitionScope {
: null);
}
+ @Override
+ public String toString() {
+ return "{ " + getCurrentFieldName() + //$NON-NLS-1$
+ " = " + getCurrentField() + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ }
}