Пример #1
0
        public void TestCreateSrcMLArchiveFtF()
        {
            using (Archive srcmlArchive = new Archive(), srcmlArchive2 = new Archive()) {
                using (Unit srcmlUnit = new Unit()) {
                    srcmlUnit.SetUnitFilename(Path.Combine(TestInputPath, "input.cpp"));
                    srcmlArchive.SetArchiveLanguage(LibSrcMLRunner.SrcMLLanguages.SRCML_LANGUAGE_CXX);
                    srcmlArchive.AddUnit(srcmlUnit);
                    srcmlArchive.SetOutputFile("output");
                    srcmlArchive.ArchivePack();

                    srcmlUnit.SetUnitFilename(Path.Combine(TestInputPath, "input2.cpp"));
                    srcmlArchive2.SetArchiveLanguage(LibSrcMLRunner.SrcMLLanguages.SRCML_LANGUAGE_CXX);
                    srcmlArchive2.AddUnit(srcmlUnit);
                    srcmlArchive2.SetOutputFile("output");

                    srcmlArchive2.ArchivePack();

                    IntPtr structPtr  = srcmlArchive.GetPtrToStruct();
                    IntPtr structPtr2 = srcmlArchive2.GetPtrToStruct();

                    List <IntPtr> structArrayPtr = new List <IntPtr>();
                    structArrayPtr.Add(structPtr);
                    structArrayPtr.Add(structPtr2);

                    try {
                        Assert.True(LibSrcMLRunner.SrcmlCreateArchiveFtF(structArrayPtr.ToArray(), structArrayPtr.Count()) == IntPtr.Zero);
                    }
                    catch (SrcMLException e) {
                        Console.WriteLine(e.Message);
                    }
                }
                {
                    Assert.True(File.Exists("output0.cpp.xml"));
                    SrcMLFile srcFile = new SrcMLFile("output0.cpp.xml");
                    Assert.IsNotNull(srcFile);

                    var files = srcFile.FileUnits.ToList();
                    Assert.AreEqual(1, files.Count());

                    string file = Path.Combine(TestInputPath, "input.cpp");
                    var    f1   = (from ele in files
                                   where ele.Attribute("filename").Value == file
                                   select ele);
                    Assert.AreEqual(file, f1.FirstOrDefault().Attribute("filename").Value);
                }
                {
                    Assert.True(File.Exists("output1.cpp.xml"));
                    SrcMLFile srcFile = new SrcMLFile("output1.cpp.xml");
                    Assert.IsNotNull(srcFile);

                    var files = srcFile.FileUnits.ToList();
                    Assert.AreEqual(1, files.Count());

                    string file1 = Path.Combine(TestInputPath, "input2.cpp");
                    var    f2    = (from ele in files
                                    where ele.Attribute("filename").Value == file1
                                    select ele);
                    Assert.AreEqual(file1, f2.FirstOrDefault().Attribute("filename").Value);
                }
            }
        }