-
Notifications
You must be signed in to change notification settings - Fork 27
Ctf 2 fix draft #367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Ctf 2 fix draft #367
Changes from all commits
5bf37e4
273739a
e6256d2
fb01bcc
de071c5
efdbe7d
b7d9bc4
832e94c
20b35b5
d0914cd
69eff31
78931c5
d99c272
5da2df8
80fe55d
50035a1
6139d4a
9d678d0
c99b993
6550818
3c372e1
c64b45a
c16de88
dd789fd
61e3a27
e687b36
1b08688
89429cf
8f5cacf
3aaab3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2025 Ericsson | ||
| * All rights reserved. This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License 2.0 | ||
| * which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| *******************************************************************************/ | ||
|
|
||
| package org.eclipse.tracecompass.ctf.core.tests.types; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertNotNull; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration; | ||
| import org.eclipse.tracecompass.ctf.core.trace.CTFTrace; | ||
| import org.eclipse.tracecompass.internal.ctf.core.event.metadata.JsonStructureFieldMemberMetadataNode; | ||
| import org.junit.Test; | ||
|
|
||
| import com.google.gson.JsonArray; | ||
| import com.google.gson.JsonObject; | ||
| import com.google.gson.JsonPrimitive; | ||
|
|
||
arfio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** | ||
| * Integration test class for CTF2 parsing functionality | ||
| */ | ||
| public class CTF2IntegrationTest { | ||
|
|
||
| /** | ||
| * Test parsing integer with mappings for enumeration-like behavior | ||
| * | ||
| * @throws Exception if parsing fails | ||
| */ | ||
| @Test | ||
| public void testIntegerWithMappings() throws Exception { | ||
| CTFTrace trace = new CTFTrace(); | ||
|
|
||
| JsonObject fieldClass = new JsonObject(); | ||
| fieldClass.add("type", new JsonPrimitive("fixed-length-unsigned-integer")); | ||
| fieldClass.add("length", new JsonPrimitive(8)); | ||
| fieldClass.add("byte-order", new JsonPrimitive("le")); | ||
|
|
||
| // Add mappings for enumeration-like behavior | ||
| JsonObject mappings = new JsonObject(); | ||
| JsonArray range1 = new JsonArray(); | ||
| range1.add(new JsonPrimitive(0)); | ||
| range1.add(new JsonPrimitive(0)); | ||
| JsonArray ranges1 = new JsonArray(); | ||
| ranges1.add(range1); | ||
| mappings.add("ZERO", ranges1); | ||
|
|
||
| JsonArray range2 = new JsonArray(); | ||
| range2.add(new JsonPrimitive(1)); | ||
| range2.add(new JsonPrimitive(1)); | ||
| JsonArray ranges2 = new JsonArray(); | ||
| ranges2.add(range2); | ||
| mappings.add("ONE", ranges2); | ||
|
|
||
| fieldClass.add("mappings", mappings); | ||
|
|
||
| JsonStructureFieldMemberMetadataNode node = new JsonStructureFieldMemberMetadataNode(null, "fixed-length-unsigned-integer", "test", "int_field", fieldClass); | ||
|
|
||
| IntegerDeclaration result = org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.integer.IntegerDeclarationParser.INSTANCE.parse(node, | ||
| new org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.integer.IntegerDeclarationParser.Param(trace)); | ||
|
|
||
| assertNotNull(result); | ||
| assertEquals(8, result.getLength()); | ||
| assertNotNull(result.getMappings()); | ||
| assertEquals(2, result.getMappings().size()); | ||
| assertTrue(result.getMappings().containsKey("ZERO")); | ||
| assertTrue(result.getMappings().containsKey("ONE")); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2025 Ericsson | ||
| * All rights reserved. This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License 2.0 | ||
| * which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| *******************************************************************************/ | ||
|
|
||
| package org.eclipse.tracecompass.ctf.core.tests.types; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertNotNull; | ||
|
|
||
| import java.nio.ByteOrder; | ||
|
|
||
| import org.eclipse.tracecompass.ctf.core.event.types.FloatDeclaration; | ||
| import org.eclipse.tracecompass.ctf.core.trace.CTFTrace; | ||
| import org.eclipse.tracecompass.internal.ctf.core.event.metadata.JsonStructureFieldMemberMetadataNode; | ||
| import org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.floatingpoint.FloatDeclarationParser; | ||
| import org.junit.Test; | ||
|
|
||
| import com.google.gson.JsonObject; | ||
| import com.google.gson.JsonPrimitive; | ||
|
|
||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** | ||
| * Test class for FloatDeclarationParser CTF2 support | ||
| */ | ||
| public class FloatDeclarationParserTest { | ||
arfio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Test parsing 32-bit floating point from CTF2 JSON | ||
| * | ||
| * @throws Exception if parsing fails | ||
| */ | ||
| @Test | ||
| public void testCTF2Float32Parsing() throws Exception { | ||
| CTFTrace trace = new CTFTrace(); | ||
|
|
||
| JsonObject fieldClass = new JsonObject(); | ||
| fieldClass.add("length", new JsonPrimitive(32)); | ||
| fieldClass.add("byte-order", new JsonPrimitive("le")); | ||
|
|
||
| JsonStructureFieldMemberMetadataNode node = new JsonStructureFieldMemberMetadataNode(null, "test", "test", "float_field", fieldClass); | ||
|
|
||
| FloatDeclaration result = FloatDeclarationParser.INSTANCE.parse(node, | ||
| new FloatDeclarationParser.Param(trace)); | ||
|
|
||
| assertNotNull(result); | ||
| assertEquals(8, result.getExponent()); | ||
| assertEquals(24, result.getMantissa()); | ||
| assertEquals(ByteOrder.LITTLE_ENDIAN, result.getByteOrder()); | ||
| } | ||
|
|
||
| /** | ||
| * Test parsing 64-bit floating point from CTF2 JSON | ||
| * | ||
| * @throws Exception if parsing fails | ||
| */ | ||
| @Test | ||
| public void testCTF2Float64Parsing() throws Exception { | ||
| CTFTrace trace = new CTFTrace(); | ||
|
|
||
| JsonObject fieldClass = new JsonObject(); | ||
| fieldClass.add("length", new JsonPrimitive(64)); | ||
| fieldClass.add("byte-order", new JsonPrimitive("be")); | ||
| fieldClass.add("alignment", new JsonPrimitive(8)); | ||
|
|
||
| JsonStructureFieldMemberMetadataNode node = new JsonStructureFieldMemberMetadataNode(null, "test", "test", "double_field", fieldClass); | ||
|
|
||
| FloatDeclaration result = FloatDeclarationParser.INSTANCE.parse(node, | ||
| new FloatDeclarationParser.Param(trace)); | ||
|
|
||
| assertNotNull(result); | ||
| assertEquals(11, result.getExponent()); | ||
| assertEquals(53, result.getMantissa()); | ||
| assertEquals(ByteOrder.BIG_ENDIAN, result.getByteOrder()); | ||
| assertEquals(8, result.getAlignment()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,71 @@ | ||||||||||||||||||||||
| /******************************************************************************* | ||||||||||||||||||||||
| * Copyright (c) 2025 Ericsson | ||||||||||||||||||||||
| * All rights reserved. This program and the accompanying materials | ||||||||||||||||||||||
| * are made available under the terms of the Eclipse Public License 2.0 | ||||||||||||||||||||||
| * which accompanies this distribution, and is available at | ||||||||||||||||||||||
| * https://www.eclipse.org/legal/epl-2.0/ | ||||||||||||||||||||||
| * | ||||||||||||||||||||||
| * SPDX-License-Identifier: EPL-2.0 | ||||||||||||||||||||||
| *******************************************************************************/ | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| package org.eclipse.tracecompass.ctf.core.tests.types; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| import static org.junit.Assert.assertEquals; | ||||||||||||||||||||||
| import static org.junit.Assert.assertNotNull; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| import org.eclipse.tracecompass.internal.ctf.core.event.metadata.JsonTraceMetadataNode; | ||||||||||||||||||||||
| import org.junit.Test; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| import com.google.gson.JsonObject; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * Test class for JsonTraceMetadataNode environment parsing | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
| public class JsonTraceMetadataNodeTest { | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * Test parsing environment object from CTF2 JSON | ||||||||||||||||||||||
| * | ||||||||||||||||||||||
| * @throws Exception if parsing fails | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
| @Test | ||||||||||||||||||||||
| public void testEnvironmentParsing() throws Exception { | ||||||||||||||||||||||
| JsonTraceMetadataNode node = new JsonTraceMetadataNode(null, "trace-class", "test"); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| JsonObject environment = new JsonObject(); | ||||||||||||||||||||||
| environment.addProperty("hostname", "test-host"); | ||||||||||||||||||||||
| environment.addProperty("domain", "kernel"); | ||||||||||||||||||||||
| environment.addProperty("tracer_name", "lttng-modules"); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Simulate Gson deserialization by setting the field directly | ||||||||||||||||||||||
| java.lang.reflect.Field envField = JsonTraceMetadataNode.class.getDeclaredField("fEnvironment"); | ||||||||||||||||||||||
| envField.setAccessible(true); | ||||||||||||||||||||||
| envField.set(node, environment); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| node.initialize(); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| assertNotNull(node.getEnvironment()); | ||||||||||||||||||||||
| assertEquals("test-host", node.getEnvironment().get("hostname").getAsString()); | ||||||||||||||||||||||
| assertEquals("kernel", node.getEnvironment().get("domain").getAsString()); | ||||||||||||||||||||||
| assertEquals("lttng-modules", node.getEnvironment().get("tracer_name").getAsString()); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * Test UID and packet header parsing | ||||||||||||||||||||||
| * | ||||||||||||||||||||||
| * @throws Exception if parsing fails | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
|
Comment on lines
+53
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stale Javadoc: mentions "packet header" but method only tests UID. The method was correctly renamed from 📝 Suggested fix /**
- * Test UID and packet header parsing
+ * Test UID parsing
*
* `@throws` Exception if parsing fails
*/📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| @Test | ||||||||||||||||||||||
| public void testUidParsing() throws Exception { | ||||||||||||||||||||||
| JsonTraceMetadataNode node = new JsonTraceMetadataNode(null, "trace-class", "test"); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Simulate Gson deserialization | ||||||||||||||||||||||
| java.lang.reflect.Field uidField = JsonTraceMetadataNode.class.getDeclaredField("fUid"); | ||||||||||||||||||||||
| uidField.setAccessible(true); | ||||||||||||||||||||||
| uidField.set(node, "test-uid-123"); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| node.initialize(); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| assertEquals("test-uid-123", node.getUid()); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,107 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /******************************************************************************* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Copyright (c) 2025 Ericsson | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * All rights reserved. This program and the accompanying materials | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * are made available under the terms of the Eclipse Public License 2.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * which accompanies this distribution, and is available at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * https://www.eclipse.org/legal/epl-2.0/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * SPDX-License-Identifier: EPL-2.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| *******************************************************************************/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| package org.eclipse.tracecompass.ctf.core.tests.types; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static org.junit.Assert.assertNotNull; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static org.junit.Assert.assertTrue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.eclipse.tracecompass.ctf.core.event.metadata.DeclarationScope; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.eclipse.tracecompass.ctf.core.event.types.FloatDeclaration; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.eclipse.tracecompass.ctf.core.event.types.IDeclaration; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.eclipse.tracecompass.ctf.core.trace.CTFTrace; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.eclipse.tracecompass.internal.ctf.core.event.metadata.JsonStructureFieldMemberMetadataNode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.TypeAliasParser; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.junit.Test; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.google.gson.JsonObject; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.google.gson.JsonPrimitive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Test class for TypeAliasParser CTF2 field type support | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public class TypeAliasParserTest { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Test parsing fixed-length floating point field class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @throws Exception if parsing fails | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void testFixedLengthFloatingPointParsing() throws Exception { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CTFTrace trace = new CTFTrace(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DeclarationScope scope = new DeclarationScope(null, "test"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| JsonObject fieldClass = new JsonObject(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fieldClass.add("type", new JsonPrimitive("fixed-length-floating-point-number")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fieldClass.add("length", new JsonPrimitive(32)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fieldClass.add("byte-order", new JsonPrimitive("le")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| JsonStructureFieldMemberMetadataNode node = new JsonStructureFieldMemberMetadataNode(null, "fixed-length-floating-point-number", "test", "float_field", fieldClass); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IDeclaration result = TypeAliasParser.INSTANCE.parse(node, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new TypeAliasParser.Param(trace, scope)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertNotNull(result); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertTrue(result instanceof FloatDeclaration); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FloatDeclaration floatDecl = (FloatDeclaration) result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertTrue(floatDecl.getExponent() > 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertTrue(floatDecl.getMantissa() > 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Test parsing static-length string field class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @throws Exception if parsing fails | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void testStaticLengthStringParsing() throws Exception { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CTFTrace trace = new CTFTrace(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DeclarationScope scope = new DeclarationScope(null, "test"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| JsonObject fieldClass = new JsonObject(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fieldClass.add("type", new JsonPrimitive("static-length-string")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fieldClass.add("length", new JsonPrimitive(16)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fieldClass.add("encoding", new JsonPrimitive("utf-8")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| JsonStructureFieldMemberMetadataNode node = new JsonStructureFieldMemberMetadataNode(null, "static-length-string", "test", "string_field", fieldClass); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IDeclaration result = TypeAliasParser.INSTANCE.parse(node, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new TypeAliasParser.Param(trace, scope)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertNotNull(result); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Test parsing dynamic-length string field class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @throws Exception if parsing fails | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void testDynamicLengthStringParsing() throws Exception { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Test that the parser doesn't throw an exception for dynamic length strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // The actual parsing logic may not be fully implemented yet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CTFTrace trace = new CTFTrace(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DeclarationScope scope = new DeclarationScope(null, "test"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| JsonObject fieldClass = new JsonObject(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fieldClass.add("type", new JsonPrimitive("dynamic-length-string")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fieldClass.add("encoding", new JsonPrimitive("utf-8")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| JsonStructureFieldMemberMetadataNode node = new JsonStructureFieldMemberMetadataNode(null, "dynamic-length-string", "test", "dyn_string_field", fieldClass); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IDeclaration result = TypeAliasParser.INSTANCE.parse(node, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new TypeAliasParser.Param(trace, scope)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // If we get here without exception, the basic parsing works | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertNotNull(result); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+88
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dynamic-length string test is missing The current test triggers the failure: “Dynamic-length string requires length-field-location property”. Add a minimal 🛠️ Proposed fix JsonObject fieldClass = new JsonObject();
fieldClass.add("type", new JsonPrimitive("dynamic-length-string"));
fieldClass.add("encoding", new JsonPrimitive("utf-8"));
+ JsonObject lengthFieldLocation = new JsonObject();
+ lengthFieldLocation.add("path", new JsonPrimitive("len")); // or a JsonArray path if required
+ fieldClass.add("length-field-location", lengthFieldLocation);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.