public static XElement GetElement(SrcMLArchive archive, SrcMLLocation location) { string fileName = location.SourceFileName; string query = location.XPath; var unit = archive.GetXElementForSourceFile(fileName); var element = unit.XPathSelectElement(query, SrcMLNamespaces.Manager); return element; }
public void CreateArchive(string filesInThisDirectory) { var srcMlArchiveFolder = Path.Combine(_indexPath, "archive"); var srcMLFolder = Path.Combine(".", "SrcML", "CSharp"); Directory.CreateDirectory(srcMlArchiveFolder); var generator = new SrcMLGenerator(TestUtils.SrcMLDirectory); _srcMLArchive = new SrcMLArchive(_indexPath, false, generator); }
public SrcMLCppParser(SrcMLArchive archive) { this.Archive = archive; }
/// <summary> /// Wires all of the properties together /// </summary> protected void SetupMonitor(SrcMLGenerator generator) { // setup the file monitor NonSourceArchive = new LastModifiedArchive(StoragePath, LastModifiedArchive.DEFAULT_FILENAME, Scheduler); var archiveDirectory = Path.Combine(StoragePath, SrcMLArchive.DEFAULT_ARCHIVE_DIRECTORY); SourceArchive = new SrcMLArchive(StoragePath, SrcMLArchive.DEFAULT_ARCHIVE_DIRECTORY, true, generator, new SrcMLFileNameMapping(archiveDirectory), Scheduler); Monitor.RegisterArchive(NonSourceArchive, true); Monitor.RegisterArchive(SourceArchive, false); }
public void GenerateXmlForDirectoryTest() { ManualResetEvent resetEvent = new ManualResetEvent(false); var archive = new SrcMLArchive(ArchiveDirectory, false, new SrcMLGenerator(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation))); FileEventType expectedEventType = FileEventType.FileAdded; FileEventType actualEventType = FileEventType.FileChanged; archive.FileChanged += (sender, e) => { actualEventType = e.EventType; bool shouldHaveSrcML = (e.EventType != FileEventType.FileDeleted); Assert.AreEqual(shouldHaveSrcML, e.HasSrcML); resetEvent.Set(); }; Dictionary<string, string> sourceFiles = new Dictionary<string, string>() { { Path.Combine(SourceDirectory, "foo.c"), String.Format(@"int foo() {{{0}printf(""hello world!"");{0}}}", Environment.NewLine) }, { Path.Combine(SourceDirectory, "bar.c"), String.Format(@"int bar() {{{0} printf(""goodbye, world!"");{0}}}", Environment.NewLine) }, { Path.Combine(SourceDirectory, "subdir1", "foo1.c"), String.Format(@"int foo1() {{{0}printf(""hello world 1!"");{0}}}", Environment.NewLine) }, { Path.Combine(SourceDirectory, "subdir1", "bar1.c"), String.Format(@"int bar1() {{{0} printf(""goodbye, world 1!"");{0}}}", Environment.NewLine) }, { Path.Combine(SourceDirectory, "subdir2", "foo2.c"), String.Format(@"int foo2() {{{0}printf(""hello world 2!"");{0}}}", Environment.NewLine) }, { Path.Combine(SourceDirectory, "subdir2", "bar2.c"), String.Format(@"int bar2() {{{0} printf(""goodbye, world 2!"");{0}}}", Environment.NewLine) }, { Path.Combine(SourceDirectory, "subdir1", "subdir11", "foo11.c"), String.Format(@"int foo11() {{{0}printf(""hello world 11!"");{0}}}", Environment.NewLine) }, { Path.Combine(SourceDirectory, "subdir1", "subdir11", "bar11.c"), String.Format(@"int bar11() {{{0} printf(""goodbye, world 11!"");{0}}}", Environment.NewLine) }, { Path.Combine(SourceDirectory, "subdir1", "subdir12", "foo12.c"), String.Format(@"int foo12() {{{0}printf(""hello world 12!"");{0}}}", Environment.NewLine) }, { Path.Combine(SourceDirectory, "subdir1", "subdir12", "bar12.c"), String.Format(@"int bar12() {{{0} printf(""goodbye, world 12!"");{0}}}", Environment.NewLine) }, { Path.Combine(SourceDirectory, "subdir2", "subdir21", "foo21.c"), String.Format(@"int foo21() {{{0}printf(""hello world 21!"");{0}}}", Environment.NewLine) }, { Path.Combine(SourceDirectory, "subdir2", "subdir21", "bar21.c"), String.Format(@"int bar21() {{{0} printf(""goodbye, world 21!"");{0}}}", Environment.NewLine) }, { Path.Combine(SourceDirectory, "subdir2", "subdir22", "foo22.c"), String.Format(@"int foo22() {{{0}printf(""hello world 22!"");{0}}}", Environment.NewLine) }, { Path.Combine(SourceDirectory, "subdir2", "subdir22", "bar22.c"), String.Format(@"int bar22() {{{0} printf(""goodbye, world 22!"");{0}}}", Environment.NewLine) }, }; foreach(var fileDataPair in sourceFiles) { var directory = Path.GetDirectoryName(fileDataPair.Key); if(!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } File.WriteAllText(fileDataPair.Key, fileDataPair.Value); archive.AddOrUpdateFile(fileDataPair.Key); Assert.That(resetEvent.WaitOne(300)); Assert.AreEqual(expectedEventType, actualEventType); } foreach(var fileName in sourceFiles.Keys) { Assert.That(archive.ContainsFile(fileName), String.Format("Archive should contain {0}", fileName)); } var changedFileName = Path.Combine(SourceDirectory, "foo.c"); var changedFileContents = String.Format(@"int foo() {{{0}printf(""hello world! changed"");{0}}}", Environment.NewLine); expectedEventType = FileEventType.FileChanged; File.WriteAllText(changedFileName, changedFileContents); File.SetLastWriteTime(changedFileName, DateTime.Now); Assert.That(archive.ContainsFile(changedFileName)); Assert.That(archive.IsOutdated(changedFileName)); archive.AddOrUpdateFile(changedFileName); Assert.That(resetEvent.WaitOne(300)); Assert.AreEqual(expectedEventType, actualEventType); expectedEventType = FileEventType.FileDeleted; var deletedFileName = Path.Combine(SourceDirectory, "subdir1", "subdir12", "bar12.c"); File.Delete(deletedFileName); Assert.That(archive.IsOutdated(deletedFileName)); archive.DeleteFile(deletedFileName); Assert.That(resetEvent.WaitOne(300)); Assert.AreEqual(expectedEventType, actualEventType); expectedEventType = FileEventType.FileRenamed; var movedFileName = Path.Combine(SourceDirectory, "subdir1", "subdir11", "foo11.c"); var newNameForMoved = Path.Combine(SourceDirectory, "subdir1", "subdir11", "foo1111111.c"); File.Move(movedFileName, newNameForMoved); Assert.That(archive.IsOutdated(movedFileName)); archive.RenameFile(movedFileName, newNameForMoved); Assert.That(resetEvent.WaitOne(300)); Assert.AreEqual(expectedEventType, actualEventType); Assert.That(archive.ContainsFile(newNameForMoved)); Assert.IsFalse(archive.ContainsFile(movedFileName)); }
/// <summary> /// SrcML service starts to monitor the opened solution. /// </summary> /// <param name="srcMLArchiveDirectory"></param> /// <param name="useExistingSrcML"></param> public void StartMonitoring(bool useExistingSrcML, string srcMLBinaryDirectory) { // Get the path of the folder that storing the srcML archives string srcMLArchiveDirectory = GetSrcMLArchiveFolder(SolutionMonitorFactory.GetOpenSolution()); SrcMLFileLogger.DefaultLogger.Info("SrcMLGlobalService.StartMonitoring( " + srcMLArchiveDirectory + " )"); try { // Create a new instance of SrcML.NET's LastModifiedArchive LastModifiedArchive lastModifiedArchive = new LastModifiedArchive(srcMLArchiveDirectory); // Create a new instance of SrcML.NET's SrcMLArchive SrcMLArchive sourceArchive = new SrcMLArchive(srcMLArchiveDirectory, useExistingSrcML, new SrcMLGenerator(srcMLBinaryDirectory)); CurrentSrcMLArchive = sourceArchive; // Create a new instance of SrcML.NET's solution monitor CurrentMonitor = SolutionMonitorFactory.CreateMonitor(srcMLArchiveDirectory, lastModifiedArchive, sourceArchive); // Subscribe events from Solution Monitor CurrentMonitor.FileChanged += RespondToFileChangedEvent; CurrentMonitor.IsReadyChanged += RespondToIsReadyChangedEvent; CurrentMonitor.MonitoringStopped += RespondToMonitoringStoppedEvent; // Initialize the progress bar. if(statusBar != null) { statusBar.Progress(ref cookie, 1, "", 0, 0); } // Start monitoring duringStartup = true; CurrentMonitor.StartMonitoring(); } catch(Exception e) { SrcMLFileLogger.DefaultLogger.Error(SrcMLExceptionFormatter.CreateMessage(e, "Exception in SrcMLGlobalService.StartMonitoring()")); } }
public void TestDontUseExistingSrcML() { //convert the test files and place in the xml directory ManualResetEvent resetEvent = new ManualResetEvent(false); var archive = new SrcMLArchive(ArchiveDirectory, false, new SrcMLGenerator(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation))); archive.FileChanged += (o, e) => { resetEvent.Set(); }; string[] sourceFiles = new[] { @"..\..\TestInputs\foo.c", @"..\..\TestInputs\baz.cpp", @"..\..\TestInputs\function_def.cpp" }; foreach(var sourceFile in sourceFiles) { archive.AddOrUpdateFile(sourceFile); Assert.That(resetEvent.WaitOne(300), "Timed out waiting for " + sourceFile); } foreach(var sourceFile in sourceFiles) { Assert.That(archive.ContainsFile(sourceFile), sourceFile + " should be in the archive!"); } archive.Dispose(); //make new archive, and ignore existing srcml files in xml directory archive = new SrcMLArchive(ArchiveDirectory, false, new SrcMLGenerator(TestConstants.SrcmlPath)); foreach(var sourceFile in sourceFiles) { Assert.IsFalse(archive.ContainsFile(sourceFile)); } archive.Dispose(); }
public void TestEmptyArchive() { var archive = new SrcMLArchive(ArchiveDirectory, false, new SrcMLGenerator(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation))); Assert.That(archive.IsEmpty); var foo_c = Path.Combine(SourceDirectory, "foo.c"); File.WriteAllText(foo_c, String.Format(@"int foo() {{{0}printf(""hello world!"");{0}}}", Environment.NewLine)); archive.AddOrUpdateFile(foo_c); Assert.That(archive.IsEmpty, Is.False); }
public void GenerateXmlForDirectoryTest() { IFileMonitor watchedFolder = Substitute.For<IFileMonitor>(); var archive = new SrcMLArchive(watchedFolder, ".srcml"); archive.XmlGenerator.ApplicationDirectory = TestConstants.SrcmlPath; var xmlDirectory = new DirectoryInfo(archive.ArchivePath); File.WriteAllText(SOURCEDIRECTORY + "\\foo.c", String.Format(@"int foo() {{{0}printf(""hello world!"");{0}}}", Environment.NewLine)); File.WriteAllText(SOURCEDIRECTORY + "\\bar.c", String.Format(@"int bar() {{{0} printf(""goodbye, world!"");{0}}}", Environment.NewLine)); Directory.CreateDirectory(Path.Combine(SOURCEDIRECTORY, "subdir1")); File.WriteAllText(SOURCEDIRECTORY + "\\subdir1\\foo1.c", String.Format(@"int foo1() {{{0}printf(""hello world 1!"");{0}}}", Environment.NewLine)); File.WriteAllText(SOURCEDIRECTORY + "\\subdir1\\bar1.c", String.Format(@"int bar1() {{{0} printf(""goodbye, world 1!"");{0}}}", Environment.NewLine)); Directory.CreateDirectory(Path.Combine(SOURCEDIRECTORY, "subdir2")); File.WriteAllText(SOURCEDIRECTORY + "\\subdir2\\foo2.c", String.Format(@"int foo2() {{{0}printf(""hello world 2!"");{0}}}", Environment.NewLine)); File.WriteAllText(SOURCEDIRECTORY + "\\subdir2\\bar2.c", String.Format(@"int bar2() {{{0} printf(""goodbye, world 2!"");{0}}}", Environment.NewLine)); Directory.CreateDirectory(Path.Combine(SOURCEDIRECTORY, "subdir1\\subdir11")); File.WriteAllText(SOURCEDIRECTORY + "\\subdir1\\subdir11\\foo11.c", String.Format(@"int foo11() {{{0}printf(""hello world 11!"");{0}}}", Environment.NewLine)); File.WriteAllText(SOURCEDIRECTORY + "\\subdir1\\subdir11\\bar11.c", String.Format(@"int bar11() {{{0} printf(""goodbye, world 11!"");{0}}}", Environment.NewLine)); Directory.CreateDirectory(Path.Combine(SOURCEDIRECTORY, "subdir1\\subdir12")); File.WriteAllText(SOURCEDIRECTORY + "\\subdir1\\subdir12\\foo12.c", String.Format(@"int foo12() {{{0}printf(""hello world 12!"");{0}}}", Environment.NewLine)); File.WriteAllText(SOURCEDIRECTORY + "\\subdir1\\subdir12\\bar12.c", String.Format(@"int bar12() {{{0} printf(""goodbye, world 12!"");{0}}}", Environment.NewLine)); Directory.CreateDirectory(Path.Combine(SOURCEDIRECTORY, "subdir2\\subdir21")); File.WriteAllText(SOURCEDIRECTORY + "\\subdir2\\subdir21\\foo21.c", String.Format(@"int foo21() {{{0}printf(""hello world 21!"");{0}}}", Environment.NewLine)); File.WriteAllText(SOURCEDIRECTORY + "\\subdir2\\subdir21\\bar21.c", String.Format(@"int bar21() {{{0} printf(""goodbye, world 21!"");{0}}}", Environment.NewLine)); Directory.CreateDirectory(Path.Combine(SOURCEDIRECTORY, "subdir2\\subdir22")); File.WriteAllText(SOURCEDIRECTORY + "\\subdir2\\subdir22\\foo22.c", String.Format(@"int foo22() {{{0}printf(""hello world 22!"");{0}}}", Environment.NewLine)); File.WriteAllText(SOURCEDIRECTORY + "\\subdir2\\subdir22\\bar22.c", String.Format(@"int bar22() {{{0} printf(""goodbye, world 22!"");{0}}}", Environment.NewLine)); System.Threading.Thread.Sleep(5000); ////archive.GenerateXmlForDirectory(SOURCEDIRECTORY); /* Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "foo.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "bar.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "subdir1\\foo1.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "subdir1\\bar1.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "subdir2\\foo2.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "subdir2\\bar2.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "subdir1\\subdir11\\foo11.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "subdir1\\subdir11\\bar11.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "subdir1\\subdir12\\foo12.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "subdir1\\subdir12\\bar12.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "subdir2\\subdir21\\foo21.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "subdir2\\subdir21\\bar21.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "subdir2\\subdir22\\foo22.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "subdir2\\subdir22\\bar22.c.xml"))); Assert.That(archive.FileUnits.Count(), Is.EqualTo(14)); */ File.WriteAllText(SOURCEDIRECTORY + "\\foo.c", String.Format(@"int foo() {{{0}printf(""hello world! changed"");{0}}}", Environment.NewLine)); File.WriteAllText(SOURCEDIRECTORY + "\\subdir2\\subdir21\\bar21.c", String.Format(@"int bar21() {{{0} printf(""goodbye, world 21! changed"");{0}}}", Environment.NewLine)); File.Delete("C:\\Users\\USJIZHE\\Documents\\GitHub\\SrcML.NET\\Build\\Debug\\testSourceDir\\subdir1\\subdir12\\bar12.c"); File.Move("C:\\Users\\USJIZHE\\Documents\\GitHub\\SrcML.NET\\Build\\Debug\\testSourceDir\\subdir1\\subdir11\\foo11.c", "C:\\Users\\USJIZHE\\Documents\\GitHub\\SrcML.NET\\Build\\Debug\\testSourceDir\\subdir1\\subdir11\\foo1111111.c"); System.Threading.Thread.Sleep(5000); ////archive.GenerateXmlForDirectory(SOURCEDIRECTORY); /* Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "foo.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "bar.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "subdir1\\foo1.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "subdir1\\bar1.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "subdir2\\foo2.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "subdir2\\bar2.c.xml"))); Assert.That(!File.Exists(Path.Combine(xmlDirectory.FullName, "subdir1\\subdir11\\foo11.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "subdir1\\subdir11\\foo1111111.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "subdir1\\subdir11\\bar11.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "subdir1\\subdir12\\foo12.c.xml"))); Assert.That(!File.Exists(Path.Combine(xmlDirectory.FullName, "subdir1\\subdir12\\bar12.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "subdir2\\subdir21\\foo21.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "subdir2\\subdir21\\bar21.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "subdir2\\subdir22\\foo22.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "subdir2\\subdir22\\bar22.c.xml"))); Assert.That(archive.FileUnits.Count(), Is.EqualTo(13)); */ }
public void FileAddDeleteChangeRenameTest() { int numberOfEventsRaised = 0; IFileMonitor watchedFolder = Substitute.For<IFileMonitor>(); var archive = new SrcMLArchive(watchedFolder, ".srcml"); archive.XmlGenerator.ApplicationDirectory = TestConstants.SrcmlPath; var xmlDirectory = new DirectoryInfo(archive.ArchivePath); ////archive.SourceFileChanged += (o, e) => archive.SourceFileChanged += (o, e) => { numberOfEventsRaised++; Assert.That(e.SourceFilePath, Is.Not.SamePathOrUnder(xmlDirectory.Name)); Console.WriteLine("Event Type '{0}': [{1}]", e.EventType, e.SourceFilePath); }; WriteTextAndRaiseEvent(watchedFolder, "foo.c", @"int foo(int i) { return i + 1; }"); // Base32 encoded filename foo.c.xml Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "2BVUHCFVS6KX3VHC6BBBWFADSZ7EY7FRH48CX7GV627VYYGVEC9WXVFCB8UMWXJSVCGESVDEH4MUXBG4WCJWNM9RKZ9CNJGV6M8C3JFRS2GBXJG4X88LX7RR.xml"))); WriteTextAndRaiseEvent(watchedFolder, "bar.c", @"int bar(int i) { return i - 1; }"); // Base32 encoded filename bar.c.xml Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "2BVUHCFVS6KX3VHC6BBBWFADSZ7EY7FRH48CX7GV627VYYGVEC9WXVFCB8UMWXJSVCGESVDEH4MUXBG4WCJWNM9RKZ9CNJGV6M8C3JFRS2GBXJG4Z4UW37RR.xml"))); Directory.CreateDirectory(Path.Combine(SOURCEDIRECTORY, "subdir")); WriteTextAndRaiseEvent(watchedFolder, Path.Combine("subdir", "component.c"), @"int are_equal(int i, int j) { return i == j; }"); // Base32 encoded filename subdir\component.c.xml Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "2BVUHCFVS6KX3VHC6BBBWFADSZ7EY7FRH48CX7GV627VYYGVEC9WXVFCB8UMWXJSVCGESVDEH4MUXBG4WCJWNM9RKZ9CNJGV6M8C3JFRS2GBXJG4649WXBSFB27XN7HFT88KNBJFY64XX.xml"))); Assert.That(archive.FileUnits.Count(), Is.EqualTo(3)); Assert.That(numberOfFunctions(archive), Is.EqualTo(3)); DeleteSourceAndRaiseEvent(watchedFolder, "bar.c"); // Base32 encoded filename bar.c.xml Assert.That(!File.Exists(Path.Combine(xmlDirectory.FullName, "2BVUHCFVS6KX3VHC6BBBWFADSZ7EY7FRH48CX7GV627VYYGVEC9WXVFCB8UMWXJSVCGESVDEH4MUXBG4WCJWNM9RKZ9CNJGV6M8C3JFRS2GBXJG4Z4UW37RR.xml"))); Assert.That(archive.FileUnits.Count(), Is.EqualTo(2)); Assert.That(numberOfFunctions(archive), Is.EqualTo(2)); WriteTextAndRaiseEvent(watchedFolder, Path.Combine("subdir", "component.c"), @"struct A { int a; char b; }"); // Base32 encoded filename subdir\component.c.xml Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "2BVUHCFVS6KX3VHC6BBBWFADSZ7EY7FRH48CX7GV627VYYGVEC9WXVFCB8UMWXJSVCGESVDEH4MUXBG4WCJWNM9RKZ9CNJGV6M8C3JFRS2GBXJG4649WXBSFB27XN7HFT88KNBJFY64XX.xml"))); Assert.That(archive.FileUnits.Count(), Is.EqualTo(2)); Assert.That(numberOfFunctions(archive), Is.EqualTo(1)); RenameSourceFileAndRaiseEvent(watchedFolder, "foo.c", "foo2.c"); // Base32 encoded filename foo.c.xml Assert.That(!File.Exists(Path.Combine(xmlDirectory.FullName, "2BVUHCFVS6KX3VHC6BBBWFADSZ7EY7FRH48CX7GV627VYYGVEC9WXVFCB8UMWXJSVCGESVDEH4MUXBG4WCJWNM9RKZ9CNJGV6M8C3JFRS2GBXJG4X88LX7RR.xml"))); // Base32 encoded filename foo2.c.xml Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "2BVUHCFVS6KX3VHC6BBBWFADSZ7EY7FRH48CX7GV627VYYGVEC9WXVFCB8UMWXJSVCGESVDEH4MUXBG4WCJWNM9RKZ9CNJGV6M8C3JFRS2GBXJG4X88LXJUS22.xml"))); Assert.That(archive.FileUnits.Count(), Is.EqualTo(2)); Assert.That(numberOfFunctions(archive), Is.EqualTo(1)); Assert.That(numberOfEventsRaised, Is.EqualTo(6)); }
public void GenerateXmlAndXElementForSourceTest() { IFileMonitor watchedFolder = Substitute.For<IFileMonitor>(); var archive = new SrcMLArchive(watchedFolder, ".srcml"); archive.XmlGenerator.ApplicationDirectory = TestConstants.SrcmlPath; var xmlDirectory = new DirectoryInfo(archive.ArchivePath); File.WriteAllText(SOURCEDIRECTORY + "\\foo.c", String.Format(@"int foo() {{{0}printf(""hello world!"");{0}}}", Environment.NewLine)); File.WriteAllText(SOURCEDIRECTORY + "\\bar.c", String.Format(@"int bar() {{{0} printf(""goodbye, world!"");{0}}}", Environment.NewLine)); XElement fooXElement = archive.GenerateXmlAndXElementForSource(SOURCEDIRECTORY + "\\foo.c"); XElement barXElement = archive.GenerateXmlAndXElementForSource(SOURCEDIRECTORY + "\\bar.c"); Assert.IsNotNull(fooXElement); Assert.IsNotNull(barXElement); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "2BVUHCFVS6KX3VHC6BBBWFADSZ7EY7FRH48CX7GV627VYYGVEC9WXVFCB8UMWXJSVCGESVDEH4MUXBG4WCJWNM9RKZ9CNJGV6M8C3JFRS2GBXJG4X88LX7RR.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "2BVUHCFVS6KX3VHC6BBBWFADSZ7EY7FRH48CX7GV627VYYGVEC9WXVFCB8UMWXJSVCGESVDEH4MUXBG4WCJWNM9RKZ9CNJGV6M8C3JFRS2GBXJG4Z4UW37RR.xml"))); }
public void GenerateXmlForSourceTest() { IFileMonitor watchedFolder = Substitute.For<IFileMonitor>(); var archive = new SrcMLArchive(watchedFolder, ".srcml"); archive.XmlGenerator.ApplicationDirectory = TestConstants.SrcmlPath; var xmlDirectory = new DirectoryInfo(archive.ArchivePath); File.WriteAllText(SOURCEDIRECTORY + "\\foo.c", String.Format(@"int foo() {{{0}printf(""hello world!"");{0}}}", Environment.NewLine)); File.WriteAllText(SOURCEDIRECTORY + "\\bar.c", String.Format(@"int bar() {{{0} printf(""goodbye, world!"");{0}}}", Environment.NewLine)); archive.GenerateXmlForSource(SOURCEDIRECTORY + "\\foo.c"); archive.GenerateXmlForSource(SOURCEDIRECTORY + "\\bar.c"); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "foo.c.xml"))); Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "bar.c.xml"))); }
public void ConcurrentGenerateXMLTest() { var archive = new SrcMLArchive(ArchiveDirectory, false, new SrcMLGenerator(TestConstants.SrcmlPath)); //Create the source files List<string> files = new List<string>(); for(int i = 0; i < 100; i++) { File.WriteAllText(SourceDirectory + "\\foo" + i + ".c", String.Format(@"int foo() {{{0}printf(""hello world!"");{0}}}", Environment.NewLine)); files.Add(SourceDirectory + "\\foo" + i.ToString() + ".c"); } //Generate the SrcML int levelOfConcurrency = 7; archive.ConcurrentGenerateXmlForSource(files, levelOfConcurrency); var xmlDirectory = new DirectoryInfo(archive.ArchivePath); for(int i = 0; i < 10; i++) Assert.That(File.Exists(Path.Combine(xmlDirectory.FullName, "foo" + i.ToString() + ".c.1.xml"))); }