1 using System;
2 using System.Collections;
3 using System.Text;
4 
5 namespace Premake.Tests.Framework
6 {
7 	public class Configuration
8 	{
9 		public string Name;
10 		public string BinDir;
11 		public string LibDir;
12 		public string ObjDir;
13 		public string OutDir;
14 		public string Target;
15 		public string OutFile;
16 		public string Kind;
17 		public string Pch;
18 		public string[] IncludePaths;
19 		public string[] Defines;
20 		public string[] LibPaths;
21 		public string[] Links;
22 		public string[] BuildFlags;
23 		public string   BuildOptions;
24 		public string[] LinkFlags;
25 		public string   LinkOptions;
26 		public string[] Dependencies;
27 		public string[] LinkDeps;
28 		public string   ImportLib;
29 		public string PchHeader;
30 		public string PchSource;
31 		public string[] ResDefines;
32 		public string[] ResPaths;
33 		public string ResOptions;
34 
Configuration()35 		public Configuration()
36 		{
37 		}
38 
CompareTo(Configuration actual)39 		public void CompareTo(Configuration actual)
40 		{
41 			Test(this.Name,         actual.Name,         "Configuration name");
42 			Test(this.BinDir,       actual.BinDir,       "BinDir");
43 			Test(this.LibDir,       actual.LibDir,       "LibDir");
44 			Test(this.ObjDir,       actual.ObjDir,       "ObjDir");
45 			Test(this.OutDir,       actual.OutDir,       "Output directory");
46 			Test(this.Target,       actual.Target,       "Target");
47 			Test(this.OutFile,      actual.OutFile,      "Output file");
48 			Test(this.Kind,         actual.Kind,         "Kind");
49 			Test(this.BuildOptions, actual.BuildOptions, "Build options");
50 			Test(this.LinkOptions,  actual.LinkOptions,  "Link options");
51 			Test(this.ImportLib,    actual.ImportLib,    "Import library");
52 			Test(this.PchHeader,    actual.PchHeader,    "PCH Header");
53 			Test(this.PchSource,    actual.PchSource,    "PCH Source");
54 			Test(this.ResOptions,   actual.ResOptions,   "Resource options");
55 			Test(this.Pch,          actual.Pch,          "Precompiled headers");
56 
57 			TestList(this.IncludePaths, actual.IncludePaths, "Include paths");
58 			TestList(this.Defines,      actual.Defines,      "Defined symbols");
59 			TestList(this.LibPaths,     actual.LibPaths,     "Lib paths");
60 			TestList(this.Links,        actual.Links,        "Links");
61 			TestList(this.BuildFlags,   actual.BuildFlags,   "Build flags");
62 			TestList(this.LinkFlags,    actual.LinkFlags,    "Link flags");
63 			TestList(this.Dependencies, actual.Dependencies, "Dependencies");
64 			TestList(this.LinkDeps,     actual.LinkDeps,     "Linker dependencies");
65 			TestList(this.ResDefines,   actual.ResDefines,   "Resource defines");
66 			TestList(this.ResPaths,     actual.ResPaths,     "Resource paths");
67 		}
68 
Test(string expected, string actual, string description)69 		private void Test(string expected, string actual, string description)
70 		{
71 			if (expected != null && expected.CompareTo(actual) != 0)
72 				throw new FormatException(description + " should be '" + expected + "' but is '" + actual + "'");
73 		}
74 
TestList(string[] expected, string[] actual, string description)75 		private void TestList(string[] expected, string[] actual, string description)
76 		{
77 			if (expected == null || (expected.Length == 0 && actual == null))
78 				return;
79 
80 			if (expected.Length != actual.Length)
81 			{
82 				throw new FormatException(description + " list should contain " + expected.Length +
83 					" items but has " + actual.Length + ". List follows:\n" +
84 					BuildListString(actual));
85 			}
86 
87 			foreach (string item in expected)
88 			{
89 				if (Array.IndexOf(actual, item) < 0)
90 				{
91 					throw new FormatException(description + " list missing item '" + item +
92 						"'. List follows:\n" + BuildListString(actual));
93 				}
94 			}
95 		}
96 
BuildListString(string[] list)97 		private string BuildListString(string[] list)
98 		{
99 			StringBuilder msg = new StringBuilder();
100 			foreach (string s in list)
101 				msg.Append(s + "\n");
102 			return msg.ToString();
103 		}
104 	}
105 }
106