Tim Cooper
9 年前
当前提交
5055d67e
共有 7 个文件被更改,包括 645 次插入 和 40 次删除
-
305MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyNodeTests.cs
-
133MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/ShaderGeneratorTests.cs
-
38MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/PixelGraph.cs
-
6MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ColorNode.cs
-
41MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ShaderGenerator.cs
-
103MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/PropertyNodeTests.cs
-
59MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyGeneratorTests.cs
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using NUnit.Framework; |
|||
using UnityEngine; |
|||
using UnityEngine.Graphing; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph.IntegrationTests |
|||
{ |
|||
|
|||
[TestFixture] |
|||
public class PropertyNodeTests |
|||
{ |
|||
private PixelGraph m_Graph; |
|||
private TextureNode m_TextureNode; |
|||
|
|||
[TestFixtureSetUp] |
|||
public void RunBeforeAnyTests() |
|||
{ |
|||
Debug.logger.logHandler = new ConsoleLogHandler(); |
|||
} |
|||
|
|||
[SetUp] |
|||
public void TestSetUp() |
|||
{ |
|||
m_Graph = new PixelGraph(); |
|||
m_TextureNode = new TextureNode(); |
|||
m_Graph.AddNode(m_TextureNode); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestTextureNodeTypeIsCorrect() |
|||
{ |
|||
Assert.AreEqual(PropertyType.Texture2D, m_TextureNode.propertyType); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestTextureNodeReturnsCorrectValue() |
|||
{ |
|||
m_TextureNode.defaultTexture = null; |
|||
Assert.AreEqual(null, m_TextureNode.defaultTexture); |
|||
|
|||
m_TextureNode.textureType = TextureType.Bump; |
|||
Assert.AreEqual(TextureType.Bump, m_TextureNode.textureType); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestTextureNodeReturnsPreviewProperty() |
|||
{ |
|||
var props = new List<PreviewProperty>(); |
|||
m_TextureNode.defaultTexture = null; |
|||
m_TextureNode.CollectPreviewMaterialProperties(props); |
|||
Assert.AreEqual(props.Count, 1); |
|||
Assert.AreEqual(m_TextureNode.propertyName, props[0].m_Name); |
|||
Assert.AreEqual(m_TextureNode.propertyType, props[0].m_PropType); |
|||
Assert.AreEqual(m_TextureNode.defaultTexture, props[0].m_Texture); |
|||
Assert.AreEqual(null, m_TextureNode.defaultTexture); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestTextureNodeGeneratesCorrectPropertyBlock() |
|||
{ |
|||
m_TextureNode.defaultTexture = null; |
|||
m_TextureNode.textureType = TextureType.Bump; |
|||
m_TextureNode.exposedState = PropertyNode.ExposedState.NotExposed; |
|||
var generator = new PropertyGenerator(); |
|||
m_TextureNode.GeneratePropertyBlock(generator, GenerationMode.SurfaceShader); |
|||
Assert.AreEqual(string.Empty, generator.GetShaderString(0)); |
|||
|
|||
var expected = m_TextureNode.propertyName |
|||
+ "(\"" |
|||
+ m_TextureNode.description |
|||
+ "\", Texture) = (" |
|||
|
|||
+ ")" |
|||
+ Environment.NewLine; |
|||
|
|||
m_TextureNode.exposedState = PropertyNode.ExposedState.Exposed; |
|||
m_TextureNode.GeneratePropertyBlock(generator, GenerationMode.SurfaceShader); |
|||
Assert.AreEqual(expected, generator.GetShaderString(0)); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestTextureNodeGeneratesCorrectPropertyUsages() |
|||
{ |
|||
m_TextureNode.defaultTexture = null; |
|||
m_TextureNode.exposedState = PropertyNode.ExposedState.NotExposed; |
|||
var generator = new ShaderGenerator(); |
|||
m_TextureNode.GeneratePropertyUsages(generator, GenerationMode.SurfaceShader); |
|||
Assert.AreEqual(string.Empty, generator.GetShaderString(0)); |
|||
|
|||
var expected = m_TextureNode.precision |
|||
+ "4 " |
|||
+ m_TextureNode.propertyName |
|||
+ ";" |
|||
+ Environment.NewLine; |
|||
|
|||
m_TextureNode.exposedState = PropertyNode.ExposedState.Exposed; |
|||
m_TextureNode.GeneratePropertyUsages(generator, GenerationMode.SurfaceShader); |
|||
Assert.AreEqual(expected, generator.GetShaderString(0)); |
|||
} |
|||
} |
|||
} |
|
|||
using System.Linq; |
|||
using NUnit.Framework; |
|||
using UnityEngine; |
|||
using UnityEngine.Graphing; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph.UnitTests |
|||
{ |
|||
[TestFixture] |
|||
public class PropertyGeneratorTests |
|||
{ |
|||
[TestFixtureSetUp] |
|||
public void RunBeforeAnyTests() |
|||
{ |
|||
Debug.logger.logHandler = new ConsoleLogHandler(); |
|||
} |
|||
|
|||
|
|||
private const string kPropertyName = "ThePropertyName"; |
|||
private const string kPropertyDescription = "ThePropertyDescription"; |
|||
|
|||
[Test] |
|||
public void TestCanAddPropertyChunkToPropertyGenerator() |
|||
{ |
|||
var chunk = new FloatPropertyChunk(kPropertyName, kPropertyDescription, 0.5f, PropertyChunk.HideState.Visible); |
|||
var generator = new PropertyGenerator(); |
|||
generator.AddShaderProperty(chunk); |
|||
|
|||
Assert.AreNotEqual(string.Empty, generator.GetShaderString(0)); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestCanGetShaderStringWithIndentWorks() |
|||
{ |
|||
var chunk = new FloatPropertyChunk(kPropertyName, kPropertyDescription, 0.5f, PropertyChunk.HideState.Visible); |
|||
var generator = new PropertyGenerator(); |
|||
generator.AddShaderProperty(chunk); |
|||
|
|||
Assert.AreEqual(0, generator.GetShaderString(0).Count(x => x == '\t')); |
|||
Assert.AreEqual(1, generator.GetShaderString(1).Count(x => x == '\t')); |
|||
Assert.AreEqual(2, generator.GetShaderString(2).Count(x => x == '\t')); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestCanGetConfiguredTextureInfos() |
|||
{ |
|||
var chunk = new TexturePropertyChunk(kPropertyName, kPropertyDescription, null, TextureType.Bump, PropertyChunk.HideState.Visible, TexturePropertyChunk.ModifiableState.Modifiable); |
|||
var generator = new PropertyGenerator(); |
|||
generator.AddShaderProperty(chunk); |
|||
|
|||
var infos = generator.GetConfiguredTexutres(); |
|||
Assert.AreEqual(1, infos.Count); |
|||
Assert.AreEqual(kPropertyName, infos[0].name); |
|||
Assert.AreEqual(0, infos[0].textureId); |
|||
Assert.AreEqual(TexturePropertyChunk.ModifiableState.Modifiable, infos[0].modifiable); |
|||
|
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue