Example #1
0
    private static void ProcessAssembly(XmlTextWriter oo, MetaData md)
    {
        IDictionary <string, MetaDataObject> tests  = new SortedDictionary <string, MetaDataObject>();
        IDictionary <string, MetaDataObject> suites = new SortedDictionary <string, MetaDataObject>();
        // Look for the annotation that tells us that this assembly is a stand-alone
        // test app.
        MetaDataAssembly mda = (MetaDataAssembly)md.Assemblies[0];

        foreach (MetaDataCustomAttribute attrib in md.CustomAttributes)
        {
            MetaDataObject parent = attrib.Parent;
            //Console.WriteLine("Found: {0} in {1} {2}", attrib.Name, parent.FullName, parent.FullNameWithContext);
            if (!attrib.Name.StartsWith(ATTRIBUTE_PREFIX))
            {
                continue;
            }
            string attribName = attrib.Name.Substring(ATTRIBUTE_PREFIX.Length);
            switch (attribName)
            {
            case "TestAppAttribute":
                break;

            case "TestClassAttribute":
                suites.Add(attrib.Parent.FullName, attrib);
                break;

            case "TestMethodAttribute":
                MetaDataObject m = attrib.Parent;
                tests.Add(attrib.Parent.FullName, attrib);
                break;
            }
        }
        string prevSuite = "";

        foreach (KeyValuePair <string, MetaDataObject> kvp in tests)
        {
            string k = kvp.Key;
            string className;
            string testname = Tail(k, '.', out className);
            if (!suites.ContainsKey(className))
            {
                Console.WriteLine("TestMethod declared outside of a TestClass: {0}", k);
                continue;
            }
            if (!prevSuite.Equals(className))
            {
                if (!prevSuite.Equals(""))
                {
                    oo.WriteEndElement();
                }
                oo.WriteStartElement("Suite");
                string ignored;
                oo.WriteAttributeString("Name", Tail(className, '.', out ignored));
                prevSuite = className;
            }
            oo.WriteStartElement("Test");
            oo.WriteAttributeString("Name", testname);
#if EXTRACT_TIMEOUT
            object timeout = psItem.Fields["Test Timeout"].Value;
            if (timeout != null)
            {
                oo.WriteAttributeString("Timeout", timeout.ToString());
            }
            object knownFailure = psItem.Fields["Test Known Failure"].Value;
            if (knownFailure != null)
            {
                oo.WriteAttributeString("KnownFailure", knownFailure.ToString());
            }
#endif
            oo.WriteEndElement();
        }
        if (!prevSuite.Equals(""))
        {
            oo.WriteEndElement();
        }
    }
Example #2
0
    // create a manifest for an app, without looking at any assemblies
    // this creates the stub manifest into which each assembly's info will
    // go
    public bool CreateNewManifest(string appname, string x86filename)
    {
        warningCount = 0;
        errorCount   = 0;

        // Create this.resolver using this.assemblyfilename
        InitializeResolver();

        // Create the basic XML tree.
        XmlNode application = AddElement(manifest, "application");

        AddAttribute(application, "name", appname);

        process = AddElement(application, "process");
        AddAttribute(process, "id", "0");
        AddAttribute(process, "main", "true");
        AddAttribute(process, "path", StripPathFromPath(x86filename));
        AddAttribute(process, "cache", StripCacheFromPath(x86filename));

        bool    seenPublisher = false;
        XmlNode privileges    = null;
        // here we assume that the first assembly is the app assembly
        // extract the publisher name from there
        MetaData         md0  = (MetaData)resolver.MetaDataList[0];
        MetaDataAssembly mda0 = (MetaDataAssembly)md0.Assemblies[0];

        if (mda0.CustomAttributes != null)
        {
            foreach (MetaDataCustomAttribute ca in mda0.CustomAttributes)
            {
                if (ca.Name == "Microsoft.Singularity.Security.ApplicationPublisherAttribute")
                {
                    if (!seenPublisher && ca.FixedArgs != null && ca.FixedArgs[0] != null)
                    {
                        AddAttribute(application, "publisher", (string)ca.FixedArgs[0]);
                        seenPublisher = true;
                    }
                }
                else if (ca.Name == "Microsoft.Singularity.Security.AssertPrivilegeAttribute")
                {
                    if (ca.FixedArgs != null && ca.FixedArgs[0] != null)
                    {
                        if (privileges == null)
                        {
                            privileges = AddElement(application, "privileges");
                        }
                        XmlNode privilege = AddElement(privileges, "privilege");
                        AddAttribute(privilege, "name", (string)ca.FixedArgs[0]);
                    }
                }
            }
        }

        // Create the list of assemblies.
        XmlNode assemblies = AddElement(process, "assemblies");

        foreach (MetaData md in resolver.MetaDataList)
        {
            MetaDataAssembly mda = (MetaDataAssembly)md.Assemblies[0];

            string file         = md.Name;
            string assemblyname = StripPathFromPath(file);

            XmlNode assembly = AddElement(assemblies, "assembly");
            AddAttribute(assembly, "name", assemblyname);
            if (mda.MajorVersion != 0 || mda.MinorVersion != 0 ||
                mda.BuildNumber != 0 || mda.RevisionNumber != 0)
            {
                AddAttribute(assembly, "version", String.Format("{0}.{1}.{2}.{3}",
                                                                mda.MajorVersion,
                                                                mda.MinorVersion,
                                                                mda.BuildNumber,
                                                                mda.RevisionNumber));
            }
            if (mda.PublicKey != null & mda.PublicKey.Length > 0)
            {
                AddAttribute(assembly, "publickey",
                             String.Format("{0}", KeyToString(mda.PublicKey)));
            }
            if (mda.Locale != null && mda.Locale != "")
            {
                AddAttribute(assembly, "locale", mda.Locale);
            }
            AddAttribute(assembly, "cache", StripCacheFromPath(file));
        }

        // Create a placeholder for

        // now go through every class in the assembly to locate ConsoleCategory,
        // Category, and DriverCategory attributes
        int     categoryIndex = 0;
        XmlNode categories    = null;

        foreach (MetaData md in resolver.MetaDataList)
        {
            // NB: md.TypeDefs is a flat list of all classes in this assembly,
            //     regardless of nesting
            foreach (MetaDataTypeDefinition type in md.TypeDefs)
            {
                for (int i = 0; i < rules.Length; i++)
                {
                    if (ProcessType(type, rules[i], process, ref categoryIndex, ref categories))
                    {
                        break;
                    }
                }
            }
        }

        if (errorCount != 0)
        {
            return(false);
        }
        return(true);
    }
Example #3
0
    private void ProcessAssembly(MetaData md)
    {
        // Look for the annotation that tells us that this assembly is a stand-alone
        // test app.
        MetaDataAssembly mda = (MetaDataAssembly)md.Assemblies[0];

        foreach (MetaDataCustomAttribute attrib in md.CustomAttributes)
        {
            MetaDataObject parent = attrib.Parent;
            //Console.WriteLine("Found: {0} in {1} {2}", attrib.Name, parent.FullName, parent.FullNameWithContext);
            if (!attrib.Name.StartsWith(ATTRIBUTE_PREFIX))
            {
                continue;
            }
            Console.WriteLine("Found: {0} in {1} {2}", attrib.Name, parent.FullName, parent.FullNameWithContext);
            string attribName = attrib.Name.Substring(ATTRIBUTE_PREFIX.Length);
            string className;
            string item = Tail(attrib.Parent, out className);
            if (attribName == "TestClassAttribute")
            {
                m_suites.Add(attrib.Parent.FullName, attrib);
            }
            else if (attribName == "TestMethodAttribute")
            {
                m_module.ProvideSuite(className).tests.Add(item);
            }
            else if (attribName == "ClassInitializeAttribute")
            {
                m_module.ProvideSuite(className).init = item;
            }
            else if (attribName == "ClassCleanupAttribute")
            {
                m_module.ProvideSuite(className).cleanup = item;
            }
            else if (attribName == "TestInitializeAttribute")
            {
                m_module.ProvideSuite(className).testInit = item;
            }
            else if (attribName == "TestCleanupAttribute")
            {
                m_module.ProvideSuite(className).testCleanup = item;
            }
            else if (attribName == "AssemblyInitializeAttribute")
            {
                m_module.init = item;
            }
            else if (attribName == "TestCleanupAttribute")
            {
                m_module.cleanup = item;
            }
            else
            {
                // IGNORE
            }
        }
        StringBuilder suiteStr = new StringBuilder();
        StringBuilder jigsStr  = new StringBuilder();

        foreach (KeyValuePair <string, SuiteDesc> kvp in m_module.suites)
        {
            string fullname = kvp.Key;
            if (!m_suites.ContainsKey(fullname))
            {
                Console.WriteLine("TestMethod declared outside of a TestClass: {0}", fullname);
                continue;
            }
            string    pkg;
            string    className = Tail(fullname, '.', out pkg);
            SuiteDesc desc      = kvp.Value;
            GenTests(className, pkg, desc, suiteStr);
            jigsStr.AppendFormat(SUITE_CASE_TEMPLATE, className, pkg);
        }
        string        modulename = "Foo";
        StringBuilder otherStr   = new StringBuilder();
        //AppendOpt(MODULE_INIT_TEMPLATE, m_module.init, otherStr);
        //AppendOpt(MODULE_INIT_TEMPLATE, m_module.cleanup, otherStr);
        string content = string.Format(FILE_TEMPLATE, modulename, jigsStr, otherStr, suiteStr);

        File.WriteAllText(m_outpath, content);
    }