Introduce CSSNodeGetInstanceCount API
Summary: - Add CSSNodeGetInstanceCount API to get the number of native instances. - It makes testing easy. Reviewed By: emilsjolander Differential Revision: D3981990 fbshipit-source-id: 98005ae1fc21d4c8802f24030fff9ffb00bd292d
This commit is contained in:
committed by
Facebook Github Bot
parent
b57abb2f60
commit
c233bafeb2
@@ -129,9 +129,12 @@ computedEdgeValue(const float edges[CSSEdgeCount], const CSSEdge edge, const flo
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t gNodeInstanceCount = 0;
|
||||||
|
|
||||||
CSSNodeRef CSSNodeNew() {
|
CSSNodeRef CSSNodeNew() {
|
||||||
const CSSNodeRef node = calloc(1, sizeof(CSSNode));
|
const CSSNodeRef node = calloc(1, sizeof(CSSNode));
|
||||||
CSS_ASSERT(node, "Could not allocate memory for node");
|
CSS_ASSERT(node, "Could not allocate memory for node");
|
||||||
|
gNodeInstanceCount++;
|
||||||
|
|
||||||
CSSNodeInit(node);
|
CSSNodeInit(node);
|
||||||
return node;
|
return node;
|
||||||
@@ -140,6 +143,7 @@ CSSNodeRef CSSNodeNew() {
|
|||||||
void CSSNodeFree(const CSSNodeRef node) {
|
void CSSNodeFree(const CSSNodeRef node) {
|
||||||
CSSNodeListFree(node->children);
|
CSSNodeListFree(node->children);
|
||||||
free(node);
|
free(node);
|
||||||
|
gNodeInstanceCount--;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSSNodeFreeRecursive(const CSSNodeRef root) {
|
void CSSNodeFreeRecursive(const CSSNodeRef root) {
|
||||||
@@ -151,6 +155,10 @@ void CSSNodeFreeRecursive(const CSSNodeRef root) {
|
|||||||
CSSNodeFree(root);
|
CSSNodeFree(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t CSSNodeGetInstanceCount() {
|
||||||
|
return gNodeInstanceCount;
|
||||||
|
}
|
||||||
|
|
||||||
void CSSNodeInit(const CSSNodeRef node) {
|
void CSSNodeInit(const CSSNodeRef node) {
|
||||||
node->parent = NULL;
|
node->parent = NULL;
|
||||||
node->children = CSSNodeListNew(4);
|
node->children = CSSNodeListNew(4);
|
||||||
|
@@ -127,6 +127,7 @@ WIN_EXPORT CSSNodeRef CSSNodeNew();
|
|||||||
WIN_EXPORT void CSSNodeInit(const CSSNodeRef node);
|
WIN_EXPORT void CSSNodeInit(const CSSNodeRef node);
|
||||||
WIN_EXPORT void CSSNodeFree(const CSSNodeRef node);
|
WIN_EXPORT void CSSNodeFree(const CSSNodeRef node);
|
||||||
WIN_EXPORT void CSSNodeFreeRecursive(const CSSNodeRef node);
|
WIN_EXPORT void CSSNodeFreeRecursive(const CSSNodeRef node);
|
||||||
|
WIN_EXPORT int32_t CSSNodeGetInstanceCount();
|
||||||
|
|
||||||
WIN_EXPORT void CSSNodeInsertChild(const CSSNodeRef node, const CSSNodeRef child, const uint32_t index);
|
WIN_EXPORT void CSSNodeInsertChild(const CSSNodeRef node, const CSSNodeRef child, const uint32_t index);
|
||||||
WIN_EXPORT void CSSNodeRemoveChild(const CSSNodeRef node, const CSSNodeRef child);
|
WIN_EXPORT void CSSNodeRemoveChild(const CSSNodeRef node, const CSSNodeRef child);
|
||||||
|
@@ -711,5 +711,10 @@ namespace Facebook.CSSLayout
|
|||||||
{
|
{
|
||||||
return ((IEnumerable<CSSNode>)_children).GetEnumerator();
|
return ((IEnumerable<CSSNode>)_children).GetEnumerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int GetInstanceCount()
|
||||||
|
{
|
||||||
|
return Native.CSSNodeGetInstanceCount();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -29,6 +29,9 @@ namespace Facebook.CSSLayout
|
|||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern void CSSNodeFree(IntPtr cssNode);
|
public static extern void CSSNodeFree(IntPtr cssNode);
|
||||||
|
|
||||||
|
[DllImport(DllName)]
|
||||||
|
public static extern int CSSNodeGetInstanceCount();
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern void CSSNodeInsertChild(IntPtr node, IntPtr child, uint index);
|
public static extern void CSSNodeInsertChild(IntPtr node, IntPtr child, uint index);
|
||||||
|
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using System;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link CSSNode}.
|
* Tests for {@link CSSNode}.
|
||||||
@@ -87,16 +88,53 @@ namespace Facebook.CSSLayout
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestDispose()
|
public void TestDispose()
|
||||||
{
|
{
|
||||||
|
ForceGC();
|
||||||
|
Assert.AreEqual(0, CSSNode.GetInstanceCount());
|
||||||
CSSNode node = new CSSNode();
|
CSSNode node = new CSSNode();
|
||||||
|
Assert.AreEqual(0, CSSNode.GetInstanceCount());
|
||||||
node.Initialize();
|
node.Initialize();
|
||||||
|
Assert.AreEqual(1, CSSNode.GetInstanceCount());
|
||||||
node.Dispose();
|
node.Dispose();
|
||||||
|
Assert.AreEqual(0, CSSNode.GetInstanceCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestDisposeWithUsing()
|
||||||
|
{
|
||||||
|
ForceGC();
|
||||||
|
Assert.AreEqual(0, CSSNode.GetInstanceCount());
|
||||||
|
using (CSSNode node = new CSSNode())
|
||||||
|
{
|
||||||
|
Assert.AreEqual(0, CSSNode.GetInstanceCount());
|
||||||
|
node.Initialize();
|
||||||
|
Assert.AreEqual(1, CSSNode.GetInstanceCount());
|
||||||
|
}
|
||||||
|
Assert.AreEqual(0, CSSNode.GetInstanceCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestDestructor()
|
public void TestDestructor()
|
||||||
|
{
|
||||||
|
ForceGC();
|
||||||
|
Assert.AreEqual(0, CSSNode.GetInstanceCount());
|
||||||
|
TestDestructorFunc();
|
||||||
|
ForceGC();
|
||||||
|
Assert.AreEqual(0, CSSNode.GetInstanceCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TestDestructorFunc()
|
||||||
{
|
{
|
||||||
CSSNode node = new CSSNode();
|
CSSNode node = new CSSNode();
|
||||||
|
Assert.AreEqual(0, CSSNode.GetInstanceCount());
|
||||||
node.Initialize();
|
node.Initialize();
|
||||||
|
Assert.AreEqual(1, CSSNode.GetInstanceCount());
|
||||||
|
node = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ForceGC()
|
||||||
|
{
|
||||||
|
GC.Collect(GC.MaxGeneration);
|
||||||
|
GC.WaitForPendingFinalizers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user