| 1016 | } |
| 1017 | |
| 1018 | void testPrimitiveArrayElements() { |
| 1019 | // Expanded primitive array should synthesize element lines dynamically |
| 1020 | NodeTree tree; |
| 1021 | tree.baseAddress = 0x1000; |
| 1022 | |
| 1023 | Node root; |
| 1024 | root.kind = NodeKind::Struct; |
| 1025 | root.name = "Root"; |
| 1026 | root.parentId = 0; |
| 1027 | int ri = tree.addNode(root); |
| 1028 | uint64_t rootId = tree.nodes[ri].id; |
| 1029 | |
| 1030 | Node arr; |
| 1031 | arr.kind = NodeKind::Array; |
| 1032 | arr.name = "values"; |
| 1033 | arr.parentId = rootId; |
| 1034 | arr.offset = 0; |
| 1035 | arr.elementKind = NodeKind::UInt32; |
| 1036 | arr.arrayLen = 4; |
| 1037 | tree.addNode(arr); |
| 1038 | |
| 1039 | // Buffer with known values: 0x11, 0x22, 0x33, 0x44 |
| 1040 | QByteArray data(64, '\0'); |
| 1041 | uint32_t v0 = 0x11, v1 = 0x22, v2 = 0x33, v3 = 0x44; |
| 1042 | memcpy(data.data() + 0, &v0, 4); |
| 1043 | memcpy(data.data() + 4, &v1, 4); |
| 1044 | memcpy(data.data() + 8, &v2, 4); |
| 1045 | memcpy(data.data() + 12, &v3, 4); |
| 1046 | BufferProvider prov(data); |
| 1047 | |
| 1048 | ComposeResult result = compose(tree, prov); |
| 1049 | QStringList lines = result.text.split('\n'); |
| 1050 | |
| 1051 | // Find array header |
| 1052 | int headerLine = -1; |
| 1053 | for (int i = 0; i < result.meta.size(); i++) { |
| 1054 | if (result.meta[i].isArrayHeader) { headerLine = i; break; } |
| 1055 | } |
| 1056 | QVERIFY2(headerLine >= 0, "Array header must exist"); |
| 1057 | QVERIFY2(lines[headerLine].contains("uint32_t[4]"), |
| 1058 | qPrintable("Header should contain 'uint32_t[4]': " + lines[headerLine])); |
| 1059 | |
| 1060 | // Count element field lines (depth >= 2, lineKind == Field) |
| 1061 | int elemCount = 0; |
| 1062 | bool found0 = false, found3 = false; |
| 1063 | for (int i = 0; i < result.meta.size(); i++) { |
| 1064 | if (result.meta[i].lineKind == LineKind::Field && result.meta[i].depth >= 2) { |
| 1065 | elemCount++; |
| 1066 | // Type column should have combined type+index: "uint32_t[0]" |
| 1067 | if (lines[i].contains("uint32_t[0]")) found0 = true; |
| 1068 | if (lines[i].contains("uint32_t[3]")) found3 = true; |
| 1069 | // isArrayElement flag must be set |
| 1070 | QVERIFY2(result.meta[i].isArrayElement, |
| 1071 | qPrintable("Element line must have isArrayElement=true: " + lines[i])); |
| 1072 | } |
| 1073 | } |
| 1074 | QCOMPARE(elemCount, 4); |
| 1075 | QVERIFY2(found0, "Should have uint32_t[0] element"); |