コード例 #1
0
        public void EnvironmentVars_Expand_Recursive()
        {
            string cfg1;

            // Old style

            cfg1 =
                @"
var1=HELLO
var2=%var1%
var3=WORLD
var4=%var2% %var3%
";
            EnvironmentVars.Load(cfg1);
            Assert.AreEqual("HELLO", EnvironmentVars.Expand("%var2%"));
            Assert.AreEqual("prefix HELLO suffix", EnvironmentVars.Expand("prefix %var2% suffix"));
            Assert.AreEqual("HELLO WORLD", EnvironmentVars.Expand("%var4%"));

            // New style

            cfg1 =
                @"
var1=HELLO
var2=$(var1)
var3=WORLD
var4=$(var2) $(var3)
";
            EnvironmentVars.Load(cfg1);
            Assert.AreEqual("HELLO", EnvironmentVars.Expand("$(var2)"));
            Assert.AreEqual("prefix HELLO suffix", EnvironmentVars.Expand("prefix $(var2) suffix"));
            Assert.AreEqual("HELLO WORLD", EnvironmentVars.Expand("$(var4)"));
        }
コード例 #2
0
 public void EnvironmentVars_System()
 {
     EnvironmentVars.Load("");
     Assert.AreEqual(Environment.GetEnvironmentVariable("path"), EnvironmentVars.Get("path"));
     Assert.AreEqual(Environment.GetEnvironmentVariable("systemdrive"), EnvironmentVars.Get("systemdrive"));
     Assert.AreEqual(Environment.GetEnvironmentVariable("windir"), EnvironmentVars.Get("windir"));
     Assert.AreEqual(Environment.GetEnvironmentVariable("comspec"), EnvironmentVars.Get("comspec"));
 }
コード例 #3
0
        public void EnvironmentVars_Expand_InfiniteRecursion()
        {
            string cfg1;

            // Old style

            cfg1 =
                @"
var1=%var2%
var2=%var1%
";
            EnvironmentVars.Load(cfg1);

            try
            {
                EnvironmentVars.Expand("%var2%");
                Assert.Fail();  // Expected a StackOverflowException
            }
            catch (StackOverflowException)
            {
            }
            catch
            {
                Assert.Fail();  // Expected a StackOverflowException
            }

            // New style

            cfg1 =
                @"
var1=$(var2)
var2=$(var1)
";
            EnvironmentVars.Load(cfg1);

            try
            {
                EnvironmentVars.Expand("$(var2)");
                Assert.Fail();  // Expected a StackOverflowException
            }
            catch (StackOverflowException)
            {
            }
            catch
            {
                Assert.Fail();  // Expected a StackOverflowException
            }
        }
コード例 #4
0
        public void EnvironmentVars_BuiltIn()
        {
            EnvironmentVars.Load("");

            Assert.AreEqual(Environment.GetEnvironmentVariable("temp"), EnvironmentVars.Get("temp"));
            Assert.AreEqual(Environment.GetEnvironmentVariable("tmp"), EnvironmentVars.Get("tmp"));
            Assert.AreEqual(Environment.GetEnvironmentVariable("SystemRoot"), EnvironmentVars.Get("SystemRoot"));
            Assert.AreEqual((Environment.GetEnvironmentVariable("SystemRoot") + @"\system32").ToLowerInvariant(), EnvironmentVars.Get("SystemDirectory").ToLowerInvariant());
            Assert.AreEqual(Helper.EntryAssemblyFolder, EnvironmentVars.Get("AppPath"));
            Assert.IsNotNull(EnvironmentVars.Get("OS"));
            Assert.IsNotNull(EnvironmentVars.Get("WINFULL"));
            Assert.IsNull(EnvironmentVars.Get("WINCE"));
            Assert.AreEqual(Helper.GetVersionString(Assembly.GetExecutingAssembly()), EnvironmentVars.Get("appversion"));
            Assert.AreEqual(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), EnvironmentVars.ProgramDataPath);
            Assert.IsTrue(!EnvironmentVars.ProgramDataPath.EndsWith("/"));
            Assert.IsTrue(!EnvironmentVars.ProgramDataPath.EndsWith("\\"));
            Assert.AreNotEqual(EnvironmentVars.Get("guid"), EnvironmentVars.Get("Guid"));
            Assert.AreEqual(Helper.MachineName, EnvironmentVars.Get("MachineName"));
            Assert.AreEqual(Dns.GetHostName(), EnvironmentVars.Get("HostName"));
            Assert.AreEqual(EnvironmentVars.ServerID, EnvironmentVars.Get("ServerID"));

            Assert.AreEqual(Environment.GetEnvironmentVariable("temp"), EnvironmentVars.Expand("$(temp)"));
            Assert.AreEqual(Environment.GetEnvironmentVariable("tmp"), EnvironmentVars.Expand("$(tmp)"));
            Assert.AreEqual(Environment.GetEnvironmentVariable("SystemRoot"), EnvironmentVars.Expand("$(SystemRoot)"));
            Assert.AreEqual((Environment.GetEnvironmentVariable("SystemRoot") + @"\system32").ToLowerInvariant(), EnvironmentVars.Expand("$(SystemDirectory)").ToLowerInvariant());
            Assert.AreEqual(Helper.EntryAssemblyFolder, EnvironmentVars.Expand("$(AppPath)"));
            Assert.IsNotNull(EnvironmentVars.Expand("$(OS)"));
            Assert.IsNotNull(EnvironmentVars.Expand("$(WINFULL)"));
            Assert.AreEqual("$(WINCE)", EnvironmentVars.Expand("$(WINCE)"));
            Assert.AreNotEqual(EnvironmentVars.Expand("$(guid)"), EnvironmentVars.Expand("$(Guid)"));
            Assert.AreEqual(Helper.MachineName, EnvironmentVars.Expand("$(MachineName)"));
            Assert.AreEqual(Environment.ProcessorCount.ToString(), EnvironmentVars.Expand("$(ProcessorCount)"));

            Assert.AreEqual(Const.DCCloudEP.ToString(), EnvironmentVars.Expand("$(LillTek.DC.CloudEP)"));
            Assert.AreEqual(Const.DCCloudGroup.ToString(), EnvironmentVars.Expand("$(LillTek.DC.CloudGroup)"));
            Assert.AreEqual(Const.DCCloudPort.ToString(), EnvironmentVars.Expand("$(LillTek.DC.CloudPort)"));
            Assert.AreEqual(Const.DCRootPort.ToString(), EnvironmentVars.Expand("$(LillTek.DC.RootPort)"));
            Assert.AreEqual(Const.DCDefHubName, EnvironmentVars.Expand("$(LillTek.DC.DefHubName)"));
#if DEBUG
            Assert.AreEqual("true", EnvironmentVars.Expand("$(IsDebug)"));
            Assert.AreEqual("false", EnvironmentVars.Expand("$(IsRelease)"));
#else
            Assert.AreEqual("false", EnvironmentVars.Expand("$(IsDebug)"));
            Assert.AreEqual("true", EnvironmentVars.Expand("$(IsRelease)"));
#endif
        }
コード例 #5
0
        public void EnvironmentVars_Basic()
        {
            string cfg1 =
                @"
var1=10
// This is a comment  
   var2  =  20   

VAR3=30

path=$(ProgramDataPath)\Foo
";

            EnvironmentVars.Load(cfg1);
            Assert.AreEqual("10", EnvironmentVars.Get("var1"));
            Assert.AreEqual("20", EnvironmentVars.Get("VAR2"));
            Assert.AreEqual("30", EnvironmentVars.Get("var3"));
            Assert.IsNull(EnvironmentVars.Get("var4"));
            Assert.AreEqual(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Foo"), EnvironmentVars.Expand(EnvironmentVars.Get("path")));
        }
コード例 #6
0
        public void EnvironmentVars_Expand()
        {
            string cfg1 =
                @"
var1=INSERT
";

            EnvironmentVars.Load(cfg1);

            // Old style

            Assert.AreEqual("", EnvironmentVars.Expand(""));
            Assert.AreEqual("INSERT", EnvironmentVars.Expand("INSERT"));
            Assert.AreEqual("INSERT", EnvironmentVars.Expand("%var1%"));
            Assert.AreEqual("prefix INSERT suffix", EnvironmentVars.Expand("prefix %VAR1% suffix"));
            Assert.AreEqual("%none%", EnvironmentVars.Expand("%none%"));
            Assert.AreEqual("prefix %none% suffix", EnvironmentVars.Expand("prefix %none% suffix"));
            Assert.AreEqual("%", EnvironmentVars.Expand("%"));
            Assert.AreEqual("%hello", EnvironmentVars.Expand("%hello"));
            Assert.AreEqual("hello%", EnvironmentVars.Expand("hello%"));
            Assert.AreEqual("hello%world", EnvironmentVars.Expand("hello%world"));

            // New style

            Assert.AreEqual("", EnvironmentVars.Expand(""));
            Assert.AreEqual("INSERT", EnvironmentVars.Expand("INSERT"));
            Assert.AreEqual("INSERT", EnvironmentVars.Expand("$(var1)"));
            Assert.AreEqual("prefix INSERT suffix", EnvironmentVars.Expand("prefix $(VAR1) suffix"));
            Assert.AreEqual("$(none)", EnvironmentVars.Expand("$(none)"));
            Assert.AreEqual("prefix $(none) suffix", EnvironmentVars.Expand("prefix $(none) suffix"));
            Assert.AreEqual("$", EnvironmentVars.Expand("$"));
            Assert.AreEqual("$(", EnvironmentVars.Expand("$("));
            Assert.AreEqual("$hello", EnvironmentVars.Expand("$hello"));
            Assert.AreEqual("$(hello", EnvironmentVars.Expand("$(hello"));
            Assert.AreEqual("$(hello)", EnvironmentVars.Expand("$(hello)"));
            Assert.AreEqual("hello)", EnvironmentVars.Expand("hello)"));
            Assert.AreEqual("hello)world", EnvironmentVars.Expand("hello)world"));
        }