예제 #1
0
        static int Main(string[] args)
        {
            if (args.Length <= 0)
            {
                Console.WriteLine("Please supply an hmd properties file");
                return(-1);
            }
            if (args.Length > 1)
            {
                Console.WriteLine("Too many arguments...please only supply an hmd properties file");
                return(-1);
            }
            String hmdPropertiesFile = args[0];

            HmdProperties hmdProperties = HmdFileParser.ParsePropertiesFile(
                hmdPropertiesFile, Path.GetDirectoryName(hmdPropertiesFile));

            hmdProperties.ResolveChildParentReferences();

            CodeGenerator codeGenerator = new CodeGenerator(CSharpLanguageGenerator.Instance, Console.Out,
                                                            "DefaultHmdNamespace", "DefaultRootClassName", "HmdType");

            codeGenerator.Generate(hmdProperties);

            return(0);
        }
예제 #2
0
        public void TestConcreteExample()
        {
            //
            // Parse Properties File
            //
            TextReader    propertiesReader = new System.IO.StringReader("%enum:ExecuteEnum Local Remote Ignore Unsupported;Script{%props:1;Source:enum(File Remote);File:0-1;ListenPort:0-1 int4;}RebootCommand {%props:1;Execute:1 enum(Ignore Unsupported Emulator);RemoteHost:0-1;RemotePort:0-1 int4;}UsbSwitchCommand {	%props:1;	Execute:1 enum ExecuteEnum;	Platform:0-1 enum(Windows Linux);	RemoteHost:0-1;	RemotePort:0-1 int4;}TestCommands {	%props:1;	Execute:1 enum ExecuteEnum;	RemoteHost:0-1;	RemotePort:0-1 int4;}");
            HmdProperties properties       = HmdFileParser.ParsePropertiesFile(propertiesReader, null);

            properties.ResolveChildParentReferences();
            properties.Print(Console.Out);


            HmdEnum hmdEnum;

            hmdEnum = properties.TryGetEnum("ExecuteEnum");
            Assert.IsNotNull(hmdEnum);
            Assert.IsTrue(hmdEnum.IsValidEnumValue("local"));
            Assert.IsTrue(hmdEnum.IsValidEnumValue("remote"));
            Assert.IsTrue(hmdEnum.IsValidEnumValue("IGNORE"));
            Assert.IsTrue(hmdEnum.IsValidEnumValue("unsupported"));

            hmdEnum = properties.TryGetEnum("script.source");
            Assert.IsNotNull(hmdEnum);
            Assert.IsTrue(hmdEnum.IsValidEnumValue("FILE"));
            Assert.IsTrue(hmdEnum.IsValidEnumValue("remote"));

            HmdBlockID fileRoot = new HmdBlockID("THE_ROOT!", null);

            HmdBlockID script = new HmdBlockID("script", fileRoot);

            Assert.IsNotNull(properties.GetProperties(script));

            HmdValueID scriptSource = new HmdValueID("source", "file", script);

            Assert.IsNotNull(properties.GetProperties(scriptSource));



            //
            // Parse Hmd File
            //
            TextReader hmdReader = new System.IO.StringReader("Script {Source:Remote;}RebootCommand {Execute:Unsupported;}UsbSwitchCommand {Execute:Unsupported;}TestCommands {Execute:Local;}");
            HmdBlockID rootID    = new HmdBlockID(String.Empty, null);

            HmdFileParser.Parse(rootID, hmdReader, "", null);


            //HmdValidator.ValidateStatic(rootID, properties);
        }
예제 #3
0
        public void SimpleTest()
        {
            String testString = "ABlockID { AValueID: value; AnotherValue: value2; } OtherValue: v; ";

            HmdSingleIDTokenizer tokenizer = new HmdSingleIDTokenizer(new StringReader(testString));
            HmdBlockID           root      = new HmdBlockID(String.Empty, null);

            HmdFileParser.Parse(root, tokenizer, null, null);


            Assert.AreEqual(1, root.ChildCount);
            Assert.IsTrue(root.GetChild(0).isBlock);

            Assert.AreEqual("ABlockID", root.GetChild(0).idOriginalCase);

            HmdBlockID childBlock = root.GetChild(0).CastAsBlockID;

            Assert.AreEqual(2, childBlock.ChildCount);

            Assert.IsFalse(childBlock.GetChild(0).CastAsValueID.isBlock);
            Assert.AreEqual("AValueID", childBlock.GetChild(0).idOriginalCase);
            Assert.AreEqual(" value", childBlock.GetChild(0).CastAsValueID.value);

            Assert.IsFalse(childBlock.GetChild(1).CastAsValueID.isBlock);
            Assert.AreEqual("AnotherValue", childBlock.GetChild(1).idOriginalCase);
            Assert.AreEqual(" value2", childBlock.GetChild(1).CastAsValueID.value);


            root = new HmdBlockID(String.Empty, null);
            tokenizer.Reset();
            HmdFileParser.Parse(root, tokenizer, null, null);

            Assert.AreEqual(1, root.ChildCount);
            Assert.IsFalse(root.GetChild(0).isBlock);

            Assert.AreEqual("OtherValue", root.GetChild(0).idOriginalCase);
            Assert.AreEqual(" v", root.GetChild(0).CastAsValueID.value);
        }