Restructure things to fit upcoming diff
This commit is contained in:
53
java/csharp/Facebook.CSSLayout.Tests/CSSNodeTest.cs
Normal file
53
java/csharp/Facebook.CSSLayout.Tests/CSSNodeTest.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Facebook.CSSLayout.Tests
|
||||
{
|
||||
/**
|
||||
* Tests for {@link CSSNode}.
|
||||
*/
|
||||
public class CSSNodeTest
|
||||
{
|
||||
|
||||
[Test]
|
||||
public void testAddChildGetParent()
|
||||
{
|
||||
CSSNode parent = new CSSNode();
|
||||
CSSNode child = new CSSNode();
|
||||
|
||||
Assert.IsNull(child.getParent());
|
||||
Assert.AreEqual(0, parent.getChildCount());
|
||||
|
||||
parent.addChildAt(child, 0);
|
||||
|
||||
Assert.AreEqual(1, parent.getChildCount());
|
||||
Assert.AreEqual(child, parent.getChildAt(0));
|
||||
Assert.AreEqual(parent, child.getParent());
|
||||
|
||||
parent.removeChildAt(0);
|
||||
|
||||
Assert.IsNull(child.getParent());
|
||||
Assert.AreEqual(0, parent.getChildCount());
|
||||
}
|
||||
|
||||
[Test, ExpectedException(typeof(InvalidOperationException))]
|
||||
public void testCannotAddChildToMultipleParents()
|
||||
{
|
||||
CSSNode parent1 = new CSSNode();
|
||||
CSSNode parent2 = new CSSNode();
|
||||
CSSNode child = new CSSNode();
|
||||
|
||||
parent1.addChildAt(child, 0);
|
||||
parent2.addChildAt(child, 0);
|
||||
}
|
||||
}
|
||||
}
|
70
java/csharp/Facebook.CSSLayout.Tests/Facebook.CSSLayout.Tests.csproj
Executable file
70
java/csharp/Facebook.CSSLayout.Tests/Facebook.CSSLayout.Tests.csproj
Executable file
@@ -0,0 +1,70 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{E687C8FD-0A0D-450F-853D-EC301BE1C038}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Facebook.CSSLayout.Tests</RootNamespace>
|
||||
<AssemblyName>Facebook.CSSLayout.Tests</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CSSNodeTest.cs" />
|
||||
<Compile Include="LayoutCachingTest.cs" />
|
||||
<Compile Include="LayoutEngineTest.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="TestConstants.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Facebook.CSSLayout\Facebook.CSSLayout.csproj">
|
||||
<Project>{d534fb4b-a7d4-4a29-96d3-f39a91a259bd}</Project>
|
||||
<Name>Facebook.CSSLayout</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
240
java/csharp/Facebook.CSSLayout.Tests/LayoutCachingTest.cs
Normal file
240
java/csharp/Facebook.CSSLayout.Tests/LayoutCachingTest.cs
Normal file
@@ -0,0 +1,240 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Facebook.CSSLayout.Tests
|
||||
{
|
||||
|
||||
/**
|
||||
* Tests for {@link LayoutEngine} and {@link CSSNode} to make sure layouts are only generated when
|
||||
* needed.
|
||||
*/
|
||||
public class LayoutCachingTest
|
||||
{
|
||||
|
||||
private void assertTreeHasNewLayout(bool expectedHasNewLayout, CSSNode root)
|
||||
{
|
||||
Assert.AreEqual(expectedHasNewLayout, root.HasNewLayout);
|
||||
|
||||
for (int i = 0; i < root.getChildCount(); i++)
|
||||
{
|
||||
assertTreeHasNewLayout(expectedHasNewLayout, root.getChildAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
private void markLayoutAppliedForTree(CSSNode root)
|
||||
{
|
||||
root.MarkLayoutSeen();
|
||||
for (int i = 0; i < root.getChildCount(); i++)
|
||||
{
|
||||
markLayoutAppliedForTree(root.getChildAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void testCachesFullTree()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
CSSNode c0 = new CSSNode();
|
||||
CSSNode c1 = new CSSNode();
|
||||
CSSNode c0c0 = new CSSNode();
|
||||
root.addChildAt(c0, 0);
|
||||
root.addChildAt(c1, 1);
|
||||
c0.addChildAt(c0c0, 0);
|
||||
|
||||
root.calculateLayout();
|
||||
assertTreeHasNewLayout(true, root);
|
||||
markLayoutAppliedForTree(root);
|
||||
|
||||
root.calculateLayout();
|
||||
Assert.IsTrue(root.HasNewLayout);
|
||||
assertTreeHasNewLayout(false, c0);
|
||||
assertTreeHasNewLayout(false, c1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void testInvalidatesCacheWhenChildAdded()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
CSSNode c0 = new CSSNode();
|
||||
CSSNode c1 = new CSSNode();
|
||||
CSSNode c0c0 = new CSSNode();
|
||||
CSSNode c0c1 = new CSSNode();
|
||||
CSSNode c1c0 = new CSSNode();
|
||||
c0c1.Width = 200;
|
||||
c0c1.Height = 200;
|
||||
root.addChildAt(c0, 0);
|
||||
root.addChildAt(c1, 1);
|
||||
c0.addChildAt(c0c0, 0);
|
||||
c0c0.addChildAt(c1c0, 0);
|
||||
|
||||
root.calculateLayout();
|
||||
markLayoutAppliedForTree(root);
|
||||
|
||||
c0.addChildAt(c0c1, 1);
|
||||
|
||||
root.calculateLayout();
|
||||
Assert.IsTrue(root.HasNewLayout);
|
||||
Assert.IsTrue(c0.HasNewLayout);
|
||||
Assert.IsTrue(c0c1.HasNewLayout);
|
||||
|
||||
Assert.IsTrue(c0c0.HasNewLayout);
|
||||
Assert.IsTrue(c1.HasNewLayout);
|
||||
|
||||
Assert.IsTrue(c1c0.HasNewLayout);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void testInvalidatesCacheWhenEnumPropertyChanges()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
CSSNode c0 = new CSSNode();
|
||||
CSSNode c1 = new CSSNode();
|
||||
CSSNode c0c0 = new CSSNode();
|
||||
root.addChildAt(c0, 0);
|
||||
root.addChildAt(c1, 1);
|
||||
c0.addChildAt(c0c0, 0);
|
||||
|
||||
root.calculateLayout();
|
||||
markLayoutAppliedForTree(root);
|
||||
|
||||
c1.AlignSelf = CSSAlign.Center;
|
||||
root.calculateLayout();
|
||||
|
||||
Assert.IsTrue(root.HasNewLayout);
|
||||
Assert.IsTrue(c1.HasNewLayout);
|
||||
|
||||
Assert.IsTrue(c0.HasNewLayout);
|
||||
Assert.IsFalse(c0c0.HasNewLayout);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void testInvalidatesCacheWhenFloatPropertyChanges()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
CSSNode c0 = new CSSNode();
|
||||
CSSNode c1 = new CSSNode();
|
||||
CSSNode c0c0 = new CSSNode();
|
||||
root.addChildAt(c0, 0);
|
||||
root.addChildAt(c1, 1);
|
||||
c0.addChildAt(c0c0, 0);
|
||||
|
||||
root.calculateLayout();
|
||||
markLayoutAppliedForTree(root);
|
||||
|
||||
c1.SetMargin(CSSSpacingType.Left, 10);
|
||||
root.calculateLayout();
|
||||
|
||||
Assert.IsTrue(root.HasNewLayout);
|
||||
Assert.IsTrue(c1.HasNewLayout);
|
||||
|
||||
Assert.IsTrue(c0.HasNewLayout);
|
||||
Assert.IsTrue(c0c0.HasNewLayout);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void testInvalidatesFullTreeWhenParentWidthChanges()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
CSSNode c0 = new CSSNode();
|
||||
CSSNode c1 = new CSSNode();
|
||||
CSSNode c0c0 = new CSSNode();
|
||||
CSSNode c1c0 = new CSSNode();
|
||||
root.addChildAt(c0, 0);
|
||||
root.addChildAt(c1, 1);
|
||||
c0.addChildAt(c0c0, 0);
|
||||
c1.addChildAt(c1c0, 0);
|
||||
|
||||
root.calculateLayout();
|
||||
markLayoutAppliedForTree(root);
|
||||
|
||||
c0.Width = 200;
|
||||
root.calculateLayout();
|
||||
|
||||
Assert.IsTrue(root.HasNewLayout);
|
||||
Assert.IsTrue(c0.HasNewLayout);
|
||||
Assert.IsTrue(c0c0.HasNewLayout);
|
||||
|
||||
Assert.IsTrue(c1.HasNewLayout);
|
||||
Assert.IsTrue(c1c0.HasNewLayout);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void testDoesNotInvalidateCacheWhenPropertyIsTheSame()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
CSSNode c0 = new CSSNode();
|
||||
CSSNode c1 = new CSSNode();
|
||||
CSSNode c0c0 = new CSSNode();
|
||||
root.addChildAt(c0, 0);
|
||||
root.addChildAt(c1, 1);
|
||||
c0.addChildAt(c0c0, 0);
|
||||
root.Width = 200;
|
||||
|
||||
root.calculateLayout();
|
||||
markLayoutAppliedForTree(root);
|
||||
|
||||
root.Width = 200;
|
||||
root.calculateLayout();
|
||||
|
||||
Assert.IsTrue(root.HasNewLayout);
|
||||
assertTreeHasNewLayout(false, c0);
|
||||
assertTreeHasNewLayout(false, c1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void testInvalidateCacheWhenHeightChangesPosition()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
CSSNode c0 = new CSSNode();
|
||||
CSSNode c1 = new CSSNode();
|
||||
CSSNode c1c0 = new CSSNode();
|
||||
root.addChildAt(c0, 0);
|
||||
root.addChildAt(c1, 1);
|
||||
c1.addChildAt(c1c0, 0);
|
||||
|
||||
root.calculateLayout();
|
||||
markLayoutAppliedForTree(root);
|
||||
|
||||
c0.Height = 100;
|
||||
root.calculateLayout();
|
||||
|
||||
Assert.IsTrue(root.HasNewLayout);
|
||||
Assert.IsTrue(c0.HasNewLayout);
|
||||
Assert.IsTrue(c1.HasNewLayout);
|
||||
Assert.IsFalse(c1c0.HasNewLayout);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void testInvalidatesOnNewMeasureFunction()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
CSSNode c0 = new CSSNode();
|
||||
CSSNode c1 = new CSSNode();
|
||||
CSSNode c0c0 = new CSSNode();
|
||||
root.addChildAt(c0, 0);
|
||||
root.addChildAt(c1, 1);
|
||||
c0.addChildAt(c0c0, 0);
|
||||
|
||||
root.calculateLayout();
|
||||
markLayoutAppliedForTree(root);
|
||||
|
||||
c1.setMeasureFunction((node, width, widthMode, height, heightMode) => new MeasureOutput(100, 20));
|
||||
|
||||
root.calculateLayout();
|
||||
|
||||
Assert.IsTrue(root.HasNewLayout);
|
||||
Assert.IsTrue(c1.HasNewLayout);
|
||||
|
||||
Assert.IsTrue(c0.HasNewLayout);
|
||||
Assert.IsTrue(c0c0.HasNewLayout);
|
||||
}
|
||||
}
|
||||
}
|
9900
java/csharp/Facebook.CSSLayout.Tests/LayoutEngineTest.cs
Normal file
9900
java/csharp/Facebook.CSSLayout.Tests/LayoutEngineTest.cs
Normal file
File diff suppressed because it is too large
Load Diff
27
java/csharp/Facebook.CSSLayout.Tests/Properties/AssemblyInfo.cs
Executable file
27
java/csharp/Facebook.CSSLayout.Tests/Properties/AssemblyInfo.cs
Executable file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("Facebook.CSSLayout.Tests")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Facebook.CSSLayout.Tests")]
|
||||
[assembly: AssemblyCopyright("Copyright © Facebook 2015")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
[assembly: Guid("c186053a-741f-477d-b031-4d343fb20d1d")]
|
||||
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
30
java/csharp/Facebook.CSSLayout.Tests/TestConstants.cs
Normal file
30
java/csharp/Facebook.CSSLayout.Tests/TestConstants.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
namespace Facebook.CSSLayout.Tests
|
||||
{
|
||||
/**
|
||||
* Generated constants used in {@link LayoutEngineTest}.
|
||||
*/
|
||||
public class TestConstants
|
||||
{
|
||||
|
||||
/** START_GENERATED **/
|
||||
public static readonly float SMALL_WIDTH = 35f;
|
||||
public static readonly float SMALL_HEIGHT = 18f;
|
||||
public static readonly float BIG_WIDTH = 172f;
|
||||
public static readonly float BIG_HEIGHT = 36f;
|
||||
public static readonly float BIG_MIN_WIDTH = 100f;
|
||||
public static readonly string SMALL_TEXT = "small";
|
||||
public static readonly string LONG_TEXT = "loooooooooong with space";
|
||||
public static readonly string MEASURE_WITH_RATIO_2 = "measureWithRatio2";
|
||||
public static readonly string MEASURE_WITH_MATCH_PARENT = "measureWithMatchParent";
|
||||
/** END_GENERATED **/
|
||||
}
|
||||
}
|
4
java/csharp/Facebook.CSSLayout.Tests/packages.config
Executable file
4
java/csharp/Facebook.CSSLayout.Tests/packages.config
Executable file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="NUnit" version="2.6.4" targetFramework="net45" />
|
||||
</packages>
|
Reference in New Issue
Block a user