public static bool Run(string outputdirname, string xmePath, string absPath, bool copycomponents = true) { xmePath = Path.GetFullPath(xmePath); outputdirname = Path.GetFullPath(outputdirname); bool status = true; string ProjectConnStr; CyPhyGUIs.CyPhyDirectory.EnsureEmptyDirectory(outputdirname); MgaUtils.ImportXMEForTest(xmePath, Path.Combine(outputdirname, Path.GetFileNameWithoutExtension(xmePath) + "_CADtest.mga"), out ProjectConnStr); MgaProject project = new MgaProject(); bool ro_mode; project.Open(ProjectConnStr, out ro_mode); try { var terr = project.BeginTransactionInNewTerr(); var testObj = project.ObjectByPath[absPath] as MgaFCO; project.AbortTransaction(); return(Run(Path.GetDirectoryName(xmePath), project, testObj, copycomponents)); } catch (Exception) { status = false; } finally { project.Close(); } return(status); }
public string ImportXME2Mga() { string projectConnStr; MgaUtils.ImportXMEForTest(xmeFilename, out projectConnStr); return(projectConnStr.Substring("MGA=".Length)); }
/// <summary> /// Call this method for each test-case. /// </summary> /// <param name="projectDir"> e.g. DriveTrain_v3</param> /// <param name="xmeFileName">e.g. DriveLine_v3.xme</param> /// <returns>e.g. C:\META\meta_trunk\models\DynamicsTeam\DriveTrain_v3\DriveLine_v3_test.mga</returns> public static string ImportXME2Mga(string projectDir, string xmeFileName) { var xmePath = Path.Combine("..", "..", "..", "..", "models", "DynamicsTeam", projectDir, xmeFileName); string projectConnStr; MgaUtils.ImportXMEForTest(xmePath, out projectConnStr); return(projectConnStr.Substring("MGA=".Length)); }
public static string ImportXME2Mga() { var xmePath = Path.Combine("..", "..", "SubTreeMergeModel.xme"); string projectConnStr; MgaUtils.ImportXMEForTest(xmePath, out projectConnStr); return(projectConnStr.Substring("MGA=".Length)); }
public void DupIDs() { var fullTestPath = Path.Combine(_exportModelDirectory, "DupIDs"); var xmeFilePath = Path.Combine(fullTestPath, "DupIDs.xme"); string connStr; MgaUtils.ImportXMEForTest(xmeFilePath, out connStr); var mgaFile = connStr.Substring("MGA=".Length); Assert.True(RunCyPhyDesignExporter(mgaFile) == 0, "Design Export Failed"); var exportedADMs = Directory.GetFiles(fullTestPath, "*.adm"); var results = new Dictionary <String, String>(); foreach (var adm in exportedADMs) { var doc = new XmlDocument(); using (var reader = new XmlTextReader(adm)) { doc.Load(reader); XmlNode root = doc.DocumentElement; var ls_EncounteredIDs = new List <String>(); foreach (XmlAttribute node in root.SelectNodes("//@ID")) { ls_EncounteredIDs.Add(node.Value); } // Get all duplicate IDs that aren't empty/whitespace var duplicates = ls_EncounteredIDs.Where(s => !String.IsNullOrWhiteSpace(s)) .GroupBy(s => s) .Where(g => g.Count() > 1) .Select(g => g.Key) .ToList(); if (duplicates.Any()) { String msg = "Duplicate IDs found in exported design: "; foreach (var dupe in duplicates) { msg += String.Format("{0}\"{1}\", ", Environment.NewLine, dupe); } results.Add(Path.GetFileName(adm), msg); } } } if (results.Any()) { String finalMsg = String.Format("{0} exported ADM files had duplicate IDs" + Environment.NewLine, results.Count); foreach (var kvp in results) { finalMsg += String.Format("{0}: {1}" + Environment.NewLine, kvp.Key, kvp.Value); } Assert.True(false, finalMsg); } }
public string ImportXME2Mga() { string projectConnStr; MgaUtils.ImportXMEForTest(Path.Combine( Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetAssembly(typeof(XmeImportFixture)).CodeBase).LocalPath), "..", "..", "..", "..", "models", "DynamicsTeam", xmeFilename), out projectConnStr); return(projectConnStr.Substring("MGA=".Length)); }
public LayoutFixture() { String connString; MgaUtils.ImportXMEForTest(xmePath, out connString); mgaPath = connString.Substring("MGA=".Length); Assert.True(File.Exists(mgaPath), "Input model not found; import may have failed."); project = CommonFunctions.GetProject(mgaPath); }
public void SetUnit() { File.Copy(orgXmePathInputModel, xmePathInputModel, true); String connString; MgaUtils.ImportXMEForTest(xmePathInputModel, out connString); var mgaPath = connString.Substring("MGA=".Length); Assert.True(File.Exists(mgaPath), "Input model not found; import may have failed."); var project = GetProject(mgaPath); var importer = new CyPhyComponentImporter.CyPhyComponentImporterInterpreter(); importer.Initialize(project); project.BeginTransactionInNewTerr(); try { var fco = importer.ImportFile(project, testPath, acmPath); ISIS.GME.Dsml.CyPhyML.Interfaces.Component comp = ISIS.GME.Dsml.CyPhyML.Classes.Component.Cast(fco); var millimeter = comp.Children.PropertyCollection .First(p => p.Name.Equals("mm")) .Referred.unit; Assert.NotNull(millimeter); Assert.Equal("Millimeter", millimeter.Name); var henry = comp.Children.PropertyCollection .First(p => p.Name.Equals("Henry")) .Referred.unit; Assert.NotNull(henry); Assert.Equal("Henry", henry.Name); var acre = comp.Children.PropertyCollection .First(p => p.Name.Equals("acre")) .Referred.unit; Assert.NotNull(acre); Assert.Equal("Acre", acre.Name); } finally { project.CommitTransaction(); } project.Save(); project.Close(); }
public void Refports() { var fullTestPath = Path.Combine(_exportModelDirectory, "Refports"); var xmeFilePath = Path.Combine(fullTestPath, "Refports.xme"); string connstr; MgaUtils.ImportXMEForTest(xmeFilePath, out connstr); var mgaFile = connstr.Substring("MGA=".Length); var designName = "CA"; Assert.True(RunCyPhyDesignExporter(mgaFile, designName) == 0, "Design Export failed"); var exportedXml = Path.Combine(fullTestPath, designName + ".adm"); var design = XSD2CSharp.AvmXmlSerializer.Deserialize <avm.Design>(File.ReadAllText(exportedXml)); var valueExpression = design.RootContainer.Property.Cast <avm.PrimitiveProperty>().First().Value.ValueExpression; Assert.True(valueExpression is avm.FixedValue, valueExpression.GetType().Name); }
public DSFixtureBase(string xmePath) { try { string connection; MgaUtils.ImportXMEForTest( Path.Combine(Path.GetDirectoryName(Assembly.GetAssembly(this.GetType()).CodeBase.Substring("file:///".Length)), xmePath), out connection); Type type = Type.GetTypeFromProgID("Mga.MgaProject"); proj_ = Activator.CreateInstance(type) as MgaProject; proj_.OpenEx(connection, "CyPhyML", null); } catch (Exception e) { this.exception = e; } }
public void Connector() { var fullTestPath = Path.Combine(_exportModelDirectory, "Connector"); var xmeFilePath = Path.Combine(fullTestPath, "Connector.xme"); string connStr; MgaUtils.ImportXMEForTest(xmeFilePath, out connStr); var mgaFile = connStr.Substring("MGA=".Length); Assert.True(RunCyPhyDesignExporter(mgaFile) == 0, "Design Export failed"); var exportedADMs = Directory.GetFiles(fullTestPath, "*expected.adm"); foreach (var p_expected in exportedADMs) { var p_output = p_expected.Replace(".expected", ""); Assert.True(File.Exists(p_output), "Output file missing: " + p_output); Assert.True(RunXmlComparator(p_expected, p_output) == 0, "Output did not match expected for " + p_expected); } }
public void Connectors_Invalid() { string XmePath = Path.GetFullPath(@"..\..\..\..\models\CADTeam\MSD_CAD.xme"); string OutputDir = Path.Combine(Path.GetDirectoryName(XmePath), "Connectors_Invalid"); var generatedAsmPath = Path.Combine(OutputDir, generatedAsmFile); CyPhyGUIs.CyPhyDirectory.EnsureEmptyDirectory(OutputDir); string ProjectConnStr; MgaUtils.ImportXMEForTest(XmePath, Path.Combine(OutputDir, Path.GetFileNameWithoutExtension(XmePath) + "_CADtest.mga"), out ProjectConnStr); CyPhy2CADRun.CopyDirectory(Path.Combine(Path.GetDirectoryName(XmePath), "components"), Path.Combine(Path.Combine(OutputDir, "components"))); MgaProject project = new MgaProject(); bool ro_mode; project.Open(ProjectConnStr, out ro_mode); try { // testbenchpath doesn't work:( var terr = project.BeginTransactionInNewTerr(); var testObj = project.RootFolder.GetObjectByPathDisp("/@Generated_configurations/MyMassSpringDamper/Config1/MyMassSpringDamper_cfg_broken"); project.AbortTransaction(); bool status = CyPhy2CADRun.Run(Path.GetDirectoryName(XmePath), project, (MgaFCO)testObj, false); string logfilename = Path.Combine(OutputDir, "log", CyPhy2CAD_CSharp.Logger.LogFileName); StreamReader r = new StreamReader(logfilename); string logcontent = r.ReadToEnd(); Assert.True(logcontent.Contains("badname")); } finally { project.Close(abort: true); } }
//[Fact] public void TestCodeSample() { string ProjectConnStr; MgaUtils.ImportXMEForTest(Path.GetFullPath(@"..\..\..\..\models\DynamicsTeam\MasterInterpreter\MasterInterpreter.xme"), out ProjectConnStr); MgaProject project = new MgaProject(); bool ro_mode; project.Open(ProjectConnStr, out ro_mode); MgaHelper.CheckParadigmVersionUpgrade(project); try { List <IMgaFCO> objectsToCheck = null; project.BeginTransactionInNewTerr(); try { // discover objects var allObjects = project .RootFolder .ChildFolders .Cast <MgaFolder>() .Where(x => x.Name.StartsWith("0")) .SelectMany(x => x.GetDescendantFCOs(project.CreateFilter()).Cast <IMgaFCO>()) .Where(x => x.RootFCO == x); // get all objects from folders starts with 0 within the root folder. objectsToCheck = allObjects.Where(x => x.AbsPath.Contains("TestingContextChecker") && x.Name.Contains("ReadOnly") == false).ToList(); objectsToCheck.Sort((x, y) => { return(x.Meta.Name.CompareTo(y.Meta.Name) != 0 ? x.Meta.Name.CompareTo(y.Meta.Name) : x.AbsPath.CompareTo(y.AbsPath)); }); } finally { project.AbortTransaction(); } Assert.True(objectsToCheck != null, "There are no object in the project that has to be checked."); int numContexts = objectsToCheck.Count; int numSuccess = 0; int numFailures = 0; bool success = true; foreach (var subject in objectsToCheck) { // single test using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project)) { CyPhyMasterInterpreter.Rules.ContextCheckerResult[] contextCheckerResults = null; // check context var checkerSuccess = masterInterpreter.TryCheckContext(subject as MgaModel, out contextCheckerResults); List <CyPhyMasterInterpreter.Rules.ContextCheckerResult> sortedResults = contextCheckerResults.ToList(); // sort results Passed, Failed, then alphabetically based on message. sortedResults.Sort((x, y) => { return(x.Success == y.Success ? x.Message.CompareTo(y.Message) : y.Success.CompareTo(x.Success)); }); project.BeginTransactionInNewTerr(); try { MgaObject parent = null; GME.MGA.Meta.objtype_enum type; subject.GetParent(out parent, out type); var successExpected = parent.Name.ToLowerInvariant() == "invalid" ? false : true; if (successExpected == checkerSuccess) { numSuccess++; //GMEConsole.Info.WriteLine("OK"); } else { success = false; foreach (var result in sortedResults) { TextWriter tw = null; StringBuilder sb = new StringBuilder(); if (result.Success) { sb.Append("[Passed]"); tw = Console.Out; } else { sb.Append("[Failed]"); tw = Console.Error; } sb.AppendFormat(" {0} - {1} ", result.Subject.Name, result.Subject.AbsPath); sb.Append(result.Message); tw.WriteLine(sb); } numFailures++; Console.Error.WriteLine("========= FAILED =========="); Console.Error.WriteLine("= {0}", subject.Name); Console.Error.WriteLine("= {0}", subject.AbsPath); Console.Error.WriteLine("==========================="); } } finally { project.AbortTransaction(); } } } if (success) { Console.Out.WriteLine("[OK] Checked contexts: {0}, Success: {1}, Failed: {2}", numContexts, numSuccess, numFailures); } else { Console.Error.WriteLine("[FAILED] Checked contexts: {0}, Success: {1}, Failed: {2}", numContexts, numSuccess, numFailures); } Assert.True(success, "At least one context was failed to check against the expected results."); } finally { project.Close(true); } }
//[Fact] public void TestCodeSample() { string ProjectConnStr; MgaUtils.ImportXMEForTest(Path.GetFullPath(@"..\..\..\..\models\DynamicsTeam\MasterInterpreter\MasterInterpreter.xme"), out ProjectConnStr); MgaProject project = new MgaProject(); bool ro_mode; project.Open(ProjectConnStr, out ro_mode); MgaHelper.CheckParadigmVersionUpgrade(project); try { List <IMgaFCO> objectsToCheck = null; project.BeginTransactionInNewTerr(); try { // discover objects var allObjects = project .RootFolder .ChildFolders .Cast <MgaFolder>() .Where(x => x.Name.StartsWith("0")) .SelectMany(x => x.GetDescendantFCOs(project.CreateFilter()).Cast <IMgaFCO>()) .Where(x => x.RootFCO == x); // get all objects from folders starts with 0 within the root folder. objectsToCheck = allObjects.Where(x => x.AbsPath.Contains("ProcessorTypesForContexts")).ToList(); objectsToCheck.Sort((x, y) => { return(x.Meta.Name.CompareTo(y.Meta.Name) != 0 ? x.Meta.Name.CompareTo(y.Meta.Name) : x.AbsPath.CompareTo(y.AbsPath)); }); } finally { project.AbortTransaction(); } Assert.True(objectsToCheck != null, "There are no object in the project that has to be checked."); int numContexts = objectsToCheck.Count; int numSuccess = 0; int numFailures = 0; bool success = true; foreach (var subject in objectsToCheck) { // single test CyPhyMasterInterpreter.AnalysisModelProcessor analysisModelProcessor = null; project.BeginTransactionInNewTerr(); try { Assert.ThrowsDelegate d = () => { analysisModelProcessor = CyPhyMasterInterpreter.AnalysisModelProcessor.GetAnalysisModelProcessor(subject as MgaModel); }; MgaObject parent = null; GME.MGA.Meta.objtype_enum type; subject.GetParent(out parent, out type); var contextSupportExpected = parent.Name.ToLowerInvariant() == "invalid" ? false : true; if (contextSupportExpected) { Assert.DoesNotThrow(d); Assert.True(analysisModelProcessor != null, string.Format("Analysis model processor was not able to create the model processor for {0} {1}.", subject.Name, subject.Meta.Name)); if (subject.Name.Contains(analysisModelProcessor.GetType().Name)) { numSuccess++; Console.Out.WriteLine("[Passed] {0} was created for test bench {1} [{2}]", analysisModelProcessor.GetType().Name, subject.Name, subject.Meta.Name); } else { success = false; numFailures++; Console.Out.WriteLine("[Failed] {0} was created for test bench {1} [{2}]", analysisModelProcessor.GetType().Name, subject.Name, subject.Meta.Name); } } else { Assert.Throws <CyPhyMasterInterpreter.AnalysisModelContextNotSupportedException>(d); numSuccess++; Console.Out.WriteLine("[Passed] Context not supported {0} [{1}]", subject.Name, subject.Meta.Name); } } finally { project.AbortTransaction(); } } if (success) { Console.Out.WriteLine("[OK] Analysis model processor creation was checked for: {0}, Success: {1}, Failed: {2}", numContexts, numSuccess, numFailures); } else { Console.Error.WriteLine("[FAILED] Analysis model processor creation was checked for: {0}, Success: {1}, Failed: {2}", numContexts, numSuccess, numFailures); } Assert.True(success, "At least one analysis model processor was not instantiated as expected."); } finally { project.Close(true); } }
//[Fact] public void TestCodeSample() { string ProjectConnStr; MgaUtils.ImportXMEForTest(Path.GetFullPath(@"..\..\..\..\models\DynamicsTeam\MasterInterpreter\MasterInterpreter.xme"), out ProjectConnStr); MgaProject project = new MgaProject(); bool ro_mode; project.Open(ProjectConnStr, out ro_mode); MgaHelper.CheckParadigmVersionUpgrade(project); try { List <IMgaFCO> objectsToGetConfigurations = null; project.BeginTransactionInNewTerr(); try { // discover objects var allObjects = project .RootFolder .ChildFolders .Cast <MgaFolder>() .Where(x => x.Name.StartsWith("0")) .SelectMany(x => x.GetDescendantFCOs(project.CreateFilter()).Cast <IMgaFCO>()) .Where(x => x.RootFCO == x); // get all objects from folders starts with 0 within the root folder. objectsToGetConfigurations = allObjects.Where(x => x.AbsPath.Contains("TestingGetConfigurations")).ToList(); objectsToGetConfigurations.Sort((x, y) => { return(x.Meta.Name.CompareTo(y.Meta.Name) != 0 ? x.Meta.Name.CompareTo(y.Meta.Name) : x.AbsPath.CompareTo(y.AbsPath)); }); } finally { project.AbortTransaction(); } Assert.True(objectsToGetConfigurations != null, "There are no object in the project that has to be checked."); int numContexts = objectsToGetConfigurations.Count; int numSuccess = 0; int numFailures = 0; bool success = true; foreach (var subject in objectsToGetConfigurations) { // single test using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project)) { IMgaFCOs configurations = null; Assert.ThrowsDelegate d = () => { configurations = masterInterpreter.GetConfigurations(subject as MgaModel); }; Assert.DoesNotThrow(d); //Assert.True(configurations != null, "GetConfiguration returned with null."); if (configurations == null) { numFailures++; } else { numSuccess++; } // print out nicely in the GME console project.BeginTransactionInNewTerr(); try { Console.Out.WriteLine("{0} [{1}] has {2} configurations.", subject.Name, subject.Meta.Name, configurations.Count); foreach (IMgaFCO configuration in configurations) { Console.Out.WriteLine(" > {0} - {1}", configuration.Name, configuration.ID); } } finally { project.AbortTransaction(); } } } if (success) { Console.Out.WriteLine("[OK] Got configurations for: {0} test benches. Success: {1}, Failed {2}", numContexts, numSuccess, numFailures); } else { Console.Error.WriteLine("[FAILED] Tried to get configurations for: {0} test benches. Success: {1}, Failed {2}", numContexts, numSuccess, numFailures); } Assert.True(success, "At least one context was failed to check against the expected results."); } finally { project.Close(true); } }