| 22 | namespace ValdiTest { |
| 23 | |
| 24 | TEST(JavaScriptHeapDumpParser, canParseHeapDump) { |
| 25 | std::string_view json = |
| 26 | R"({"snapshot":{"meta":{"node_fields":["type","name","id","self_size","edge_count","trace_node_id","detachedness"],"node_types":[["hidden","array","string","object","code","closure","regexp","number","native","synthetic","symbol","bigint","object shape"],"string","number","number","number","number","number"],"edge_fields":["type","name_or_index","to_node"],"edge_types":[["context","element","property","internal","hidden","shortcut","weak"],"string_or_number","node"]},"node_count":3,"edge_count":2,"trace_function_count":0}, |
| 27 | "nodes":[3,0,1,40,1,0,0, |
| 28 | 1,2,2,100,1,0,0, |
| 29 | 2,3,3,11,0,0,0], |
| 30 | "edges":[2,1,7, |
| 31 | 1,0,14], |
| 32 | "trace_function_infos":[], |
| 33 | "trace_tree":[], |
| 34 | "samples":[], |
| 35 | "locations":[], |
| 36 | "strings":[ |
| 37 | "Object", |
| 38 | "items", |
| 39 | "Array", |
| 40 | "Hello World"]} |
| 41 | )"; |
| 42 | |
| 43 | SimpleExceptionTracker exceptionTracker; |
| 44 | JavaScriptHeapDumpParser parser(reinterpret_cast<const Byte*>(json.data()), json.size(), exceptionTracker); |
| 45 | |
| 46 | ASSERT_NO_EXCEPTION(exceptionTracker); |
| 47 | |
| 48 | auto nodes = parser.getNodes(); |
| 49 | |
| 50 | ASSERT_EQ(static_cast<size_t>(3), nodes.size()); |
| 51 | |
| 52 | ASSERT_EQ(JavaScriptHeapDumpNodeType::OBJECT, nodes[0].getType()); |
| 53 | ASSERT_EQ(STRING_LITERAL("Object"), nodes[0].getName()); |
| 54 | ASSERT_EQ(static_cast<uint64_t>(1), nodes[0].getId()); |
| 55 | ASSERT_EQ(static_cast<size_t>(40), nodes[0].getSelfSizeBytes()); |
| 56 | |
| 57 | auto edges1 = nodes[0].getEdges(); |
| 58 | ASSERT_EQ(static_cast<size_t>(1), edges1.size()); |
| 59 | |
| 60 | ASSERT_EQ(JavaScriptHeapDumpEdgeType::PROPERTY, edges1[0].getType()); |
| 61 | ASSERT_EQ(JavaScriptHeapEdgeIdentifier::named(STRING_LITERAL("items")), edges1[0].getIdentifier()); |
| 62 | ASSERT_EQ(static_cast<uint64_t>(2), edges1[0].getNode().getId()); |
| 63 | |
| 64 | ASSERT_EQ(JavaScriptHeapDumpNodeType::ARRAY, nodes[1].getType()); |
| 65 | ASSERT_EQ(STRING_LITERAL("Array"), nodes[1].getName()); |
| 66 | ASSERT_EQ(static_cast<uint64_t>(2), nodes[1].getId()); |
| 67 | ASSERT_EQ(static_cast<size_t>(100), nodes[1].getSelfSizeBytes()); |
| 68 | |
| 69 | auto edges2 = nodes[1].getEdges(); |
| 70 | ASSERT_EQ(static_cast<size_t>(1), edges2.size()); |
| 71 | |
| 72 | ASSERT_EQ(JavaScriptHeapDumpEdgeType::ELEMENT, edges2[0].getType()); |
| 73 | ASSERT_EQ(JavaScriptHeapEdgeIdentifier::indexed(0), edges2[0].getIdentifier()); |
| 74 | ASSERT_EQ(static_cast<uint64_t>(3), edges2[0].getNode().getId()); |
| 75 | |
| 76 | ASSERT_EQ(JavaScriptHeapDumpNodeType::STRING, nodes[2].getType()); |
| 77 | ASSERT_EQ(STRING_LITERAL("Hello World"), nodes[2].getName()); |
| 78 | ASSERT_EQ(static_cast<uint64_t>(3), nodes[2].getId()); |
| 79 | |
| 80 | auto edges3 = nodes[2].getEdges(); |
| 81 |
nothing calls this directly
no test coverage detected