SerializesEdgeNames.cpp (1555B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 // Test that edge names get serialized correctly. 7 8 #include "DevTools.h" 9 10 using testing::Field; 11 using testing::IsNull; 12 using testing::Property; 13 using testing::Return; 14 15 DEF_TEST(SerializesEdgeNames, { 16 FakeNode node; 17 FakeNode referent; 18 19 const char16_t edgeName[] = u"edge name"; 20 const char16_t emptyStr[] = u""; 21 22 AddEdge(node, referent, edgeName); 23 AddEdge(node, referent, emptyStr); 24 AddEdge(node, referent, nullptr); 25 26 ::testing::NiceMock<MockWriter> writer; 27 28 // Should get the node with edges once. 29 EXPECT_CALL( 30 writer, 31 writeNode( 32 AllOf(EdgesLength(cx, 3), 33 Edge(cx, 0, 34 Field(&JS::ubi::Edge::name, UniqueUTF16StrEq(edgeName))), 35 Edge(cx, 1, 36 Field(&JS::ubi::Edge::name, UniqueUTF16StrEq(emptyStr))), 37 Edge(cx, 2, Field(&JS::ubi::Edge::name, UniqueIsNull()))), 38 _)) 39 .Times(1) 40 .WillOnce(Return(true)); 41 42 // Should get the referent node that doesn't have any edges once. 43 ExpectWriteNode(writer, referent); 44 45 JS::AutoCheckCannotGC noGC(cx); 46 ASSERT_TRUE(WriteHeapGraph(cx, JS::ubi::Node(&node), writer, 47 /* wantNames = */ true, 48 /* zones = */ nullptr, noGC)); 49 });