using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework.Graphics; 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): 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 : CompilerIncludeHandler { public CustomHeaderWithError() { } public override System.IO.Stream Open(CompilerIncludeHandlerType includeType, string filename) { return new System.IO.MemoryStream(Encoding.ASCII.GetBytes("int x = 10\n void Fxn() { }")); } } public void ErrorInHeader() { string text = @" #include ""test.h"" void Function() { int x = 0; x *= 10; }"; CheckEqual("test.h(2): 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); } } }