using System; using System.Collections.Generic; using System.Linq; using System.Text; using SharpDX.D3DCompiler; using System.IO; namespace UnitTestSharpHLSLTests { public class CompilerTests : UnitTestSharp.TestFixture { public void NoErrorsOrWarnings() { string text = @" void Function() { int x = 0; x *= 10; }"; CheckEqual("", UnitTestSharpHLSL.Compiler.TestForCompileErrors(text, "dummy.fx")); } public void SyntaxError() { string text = @" void Function() { int x = 0 x *= 10; }"; CheckEqual("dummy.fx(5,5): error X3000: syntax error: unexpected token 'x'", UnitTestSharpHLSL.Compiler.TestForCompileErrors(text, "dummy.fx")); } public void Empty() { string text = @""; CheckEqual("", UnitTestSharpHLSL.Compiler.TestForCompileErrors(text, "dummy.fx")); } public class CustomHeaderWithError : Include { public CustomHeaderWithError() { } public Stream Open(IncludeType type, string fileName, Stream parentStream) { return new System.IO.MemoryStream(Encoding.ASCII.GetBytes("int x = 10\n void Fxn() { }")); } public void Close(System.IO.Stream stream) { } public void Dispose() { Shadow.Dispose(); } public IDisposable Shadow { get; set; } } public void ErrorInHeader() { string text = @" #include ""test.h"" void Function() { int x = 0; x *= 10; }"; CheckEqual("test.h(2,1): error X3000: syntax error: unexpected token 'void'", UnitTestSharpHLSL.Compiler.TestForCompileErrors(text, "dummy.fx", new CustomHeaderWithError())); } public void WeirdPossibleErrors() { string error = "(7): error X3000: syntax error: unexpected token '('"; string parsed = UnitTestSharpHLSL.Compiler.ParseXNAWarningsAndErrors(error, "something.fx"); CheckEqual("something.fx(7): error X3000: syntax error: unexpected token '('", parsed); } public void ParentheticalFilenames() { string error = "Z:/stuff(3)/stuff(4)/stuff(5)/something.(9)(7): error X3000: syntax error: unexpected token '('"; string parsed = UnitTestSharpHLSL.Compiler.ParseXNAWarningsAndErrors(error, "something.fx"); CheckEqual("Z:/stuff(3)/stuff(4)/stuff(5)/something.(9)(7): error X3000: syntax error: unexpected token '('", parsed); } } }