public void EqualsTest() { PathSpec left = new DepotPath("//depot/main/test.txt"); PathSpec rightpos = new DepotPath("//depot/main/test.txt"); PathSpec rightneg1 = new DepotPath("//depot/main/empty.bmp"); PathSpec rightneg2 = new ClientPath("//depot/main/test/txt"); PathSpec rightnull = null; Assert.IsTrue(left.Equals(rightpos)); Assert.IsFalse(left.Equals(rightneg1)); Assert.IsFalse(left.Equals(rightneg2)); Assert.IsFalse(left.Equals(rightnull)); left = new ClientPath("//user_workspace/main/test.txt"); rightpos = new ClientPath("//user_workspace/main/test.txt"); rightneg1 = new ClientPath("//user_workspace/main/empty.bmp"); rightneg2 = new DepotPath("//user_workspace/main/test.txt"); rightnull = null; Assert.IsTrue(left.Equals(rightpos)); Assert.IsFalse(left.Equals(rightneg1)); Assert.IsFalse(left.Equals(rightneg2)); Assert.IsFalse(left.Equals(rightnull)); left = new LocalPath(@"C:\workspace_root\test.txt"); rightpos = new LocalPath(@"C:\workspace_root\test.txt"); rightneg1 = new LocalPath(@"C:\workspace_root\empty.bmp"); rightneg2 = new DepotPath(@"C:\workspace_root\test.txt"); rightnull = null; Assert.IsTrue(left.Equals(rightpos)); Assert.IsFalse(left.Equals(rightneg1)); Assert.IsFalse(left.Equals(rightneg2)); Assert.IsFalse(left.Equals(rightnull)); }
// //You can use the following additional attributes as you write your tests: // //Use ClassInitialize to run code before running the first test in the class //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //Use ClassCleanup to run code after all tests in a class have run //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //Use TestInitialize to run code before running each test //[TestInitialize()] //public void MyTestInitialize() //{ //} // //Use TestCleanup to run code after each test has run //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion internal virtual PathSpec CreatePathSpec() { // TODO: Instantiate an appropriate concrete class. PathSpec target = null; return(target); }
private void assertFileLink(PathSpec linkPath, PathSpec targetPath) { linkPath.CreateSymlinkTo(targetPath); var symlinkedText = linkPath.ReadAllText(); var text = targetPath.ReadAllText(); symlinkedText.Should().Be(text, "Because the first file is linked to the second file"); linkPath.IsSymlink().Should().BeTrue(); }
public void SetUp() { _workingDirectory = PathUtility.CreateTemporaryPath(PathType.Folder); _testFolderPath = _workingDirectory.Join("foo".ToPathSpec().Value).Value; _testFolderPath.Create(PathType.Folder); _testFilePath = _testFolderPath.Join("bar.txt".ToPathSpec().Value).Value; _testFilePath.WriteAllText("Test123"); }
/// <summary> Returns the segment specified in the given segment_path_spec. </summary> public virtual ISegment getSegment(String segSpec) { ISegment seg = null; if (segSpec.Substring(0, (1) - (0)).Equals("/")) { Finder.reset(); } SupportClass.Tokenizer tok = new SupportClass.Tokenizer(segSpec, "/", false); SegmentFinder finder = Finder; while (tok.HasMoreTokens()) { String pathSpec = tok.NextToken(); PathSpec ps = parsePathSpec(pathSpec); if (tok.HasMoreTokens()) { ps.isGroup = true; } else { ps.isGroup = false; } if (ps.isGroup) { IGroup g = null; if (ps.find) { g = finder.findGroup(ps.pattern, ps.rep); } else { g = finder.getGroup(ps.pattern, ps.rep); } finder = new SegmentFinder(g); } else { if (ps.find) { seg = finder.findSegment(ps.pattern, ps.rep); } else { seg = finder.getSegment(ps.pattern, ps.rep); } } } return(seg); }
private void assertDirLink(PathSpec linkPath, PathSpec targetPath) { linkPath.CreateSymlinkTo(targetPath); linkPath.GetPathType().Should().Be(targetPath.GetPathType(), $"because the symlink {linkPath} should point to {targetPath}"); var symlinkedText = linkPath.Join("bar.txt".ToPathSpec().Value).Value.ReadAllText(); var text = targetPath.Join("bar.txt".ToPathSpec().Value).Value.ReadAllText(); symlinkedText.Should().Be(text, "Because the first file is linked to the second file"); linkPath.IsSymlink().Should().BeTrue(); linkPath.IsJunctionPoint().Should().BeFalse(); linkPath.GetSymlinkTarget().Value.ShouldBeEquivalentTo(targetPath); }
public void ToEscapedPathTest() { string target = @"C:\workspace@root\test#1%2.txt"; FileSpec LocalSpec = new FileSpec(null, null, new LocalPath(target), new NoneRevision()); string expected = @"c:\workspace%40root\test%231%252.txt#none"; string actual = LocalSpec.ToEscapedString(); Assert.AreEqual(expected, actual); target = @"c:\workspace%40root\test%231%252.txt"; actual = PathSpec.UnescapePath(target); expected = @"c:\workspace@root\test#1%2.txt"; Assert.AreEqual(expected, actual); }
/// <summary>Gets path information from a path spec. </summary> private PathSpec ParsePathSpec(string spec) { var ps = new PathSpec(this); if (spec.StartsWith(".")) { ps.Find = true; spec = spec.Substring(1); } else { ps.Find = false; } if (spec.Length == 0) { throw new HL7Exception("Invalid path (some path element is either empty or contains only a dot)"); } var tok = new SupportClass.Tokenizer(spec, "()", false); ps.Pattern = tok.NextToken(); if (tok.HasMoreTokens()) { var repString = tok.NextToken(); try { ps.Rep = int.Parse(repString); } catch (FormatException) { throw new HL7Exception(repString + " is not a valid rep #", ErrorCode.APPLICATION_INTERNAL_ERROR); } } else { ps.Rep = 0; } return(ps); }
public void ChangelistIdTest() { int revision = 0; // TODO: Initialize to an appropriate value int changelistid = 12345; FileAction action = new FileAction(); // TODO: Initialize to an appropriate value DateTime date = new DateTime(); // TODO: Initialize to an appropriate value string username = string.Empty; // TODO: Initialize to an appropriate value FileType filetype = null; // TODO: Initialize to an appropriate value string description = string.Empty; // TODO: Initialize to an appropriate value string digest = string.Empty; int filesize = 0; PathSpec depotpath = null; // TODO: Initialize to an appropriate value string clientname = string.Empty; // TODO: Initialize to an appropriate value List <RevisionIntegrationSummary> integrationsummaries = null; // TODO: Initialize to an appropriate value FileHistory target = new FileHistory(revision, changelistid, action, date, username, filetype, description, digest, filesize, depotpath, clientname, integrationsummaries); // TODO: Initialize to an appropriate value int expected = changelistid; int actual; target.ChangelistId = expected; actual = target.ChangelistId; Assert.AreEqual(expected, actual); }
/// <summary>Gets path information from a path spec. </summary> private PathSpec parsePathSpec(System.String spec) { PathSpec ps = new PathSpec(this); if (spec.StartsWith(".")) { ps.find = true; spec = spec.Substring(1); } else { ps.find = false; } if (spec.Length == 0) { throw new HL7Exception("Invalid path (some path element is either empty or contains only a dot)"); } Tokenizer tok = new Tokenizer(spec, "()", false); ps.pattern = tok.NextToken(); if (tok.HasMoreTokens) { System.String repString = tok.NextToken(); try { ps.rep = System.Int32.Parse(repString); } catch (System.FormatException) { throw new HL7Exception(repString + " is not a valid rep #", HL7Exception.APPLICATION_INTERNAL_ERROR); } } else { ps.rep = 0; } return(ps); }
public void IntegrationSummariesTest() { int revision = 0; // TODO: Initialize to an appropriate value int changelistid = 0; // TODO: Initialize to an appropriate value FileAction action = new FileAction(); // TODO: Initialize to an appropriate value DateTime date = new DateTime(); // TODO: Initialize to an appropriate value string username = string.Empty; // TODO: Initialize to an appropriate value FileType filetype = null; // TODO: Initialize to an appropriate value string description = string.Empty; // TODO: Initialize to an appropriate value string digest = string.Empty; int filesize = 0; PathSpec depotpath = null; // TODO: Initialize to an appropriate value string clientname = string.Empty; // TODO: Initialize to an appropriate value List <RevisionIntegrationSummary> integrationsummaries = new List <RevisionIntegrationSummary>(); RevisionIntegrationSummary Summary1 = new RevisionIntegrationSummary( new FileSpec(new LocalPath("c:\rev_int_sum"), new VersionRange(new LabelNameVersion("my_label"), new LabelNameVersion("my_old_label"))), "how"); FileHistory target = new FileHistory(revision, changelistid, action, date, username, filetype, description, digest, filesize, depotpath, clientname, integrationsummaries); // TODO: Initialize to an appropriate value target.IntegrationSummaries.Add(Summary1); Assert.AreEqual(Summary1, target.IntegrationSummaries[0]); }
public void FileTypeTest() { int revision = 0; // TODO: Initialize to an appropriate value int changelistid = 0; // TODO: Initialize to an appropriate value FileAction action = new FileAction(); // TODO: Initialize to an appropriate value DateTime date = new DateTime(); // TODO: Initialize to an appropriate value string username = string.Empty; // TODO: Initialize to an appropriate value FileType filetype = null; // TODO: Initialize to an appropriate value string description = string.Empty; // TODO: Initialize to an appropriate value string digest = string.Empty; int filesize = 0; PathSpec depotpath = null; // TODO: Initialize to an appropriate value string clientname = string.Empty; // TODO: Initialize to an appropriate value List <RevisionIntegrationSummary> integrationsummaries = null; // TODO: Initialize to an appropriate value FileHistory target = new FileHistory(revision, changelistid, action, date, username, filetype, description, digest, filesize, depotpath, clientname, integrationsummaries); // TODO: Initialize to an appropriate value List <FileTypeModifier> ftm = new List <FileTypeModifier>(); FileType expected = new FileType(BaseFileType.Apple, FileTypeModifier.None, 16); FileType actual; target.FileType = expected; actual = target.FileType; Assert.AreEqual(expected, actual); }
static void Main(string[] args) { if (args.Length < 1) { Console.Out.WriteLine("Usage TranslatedWordsCountEstimator <report CSV file> [<p4 server address> <user name> <workspace name> [<password>]]"); return; } try { var reportFilePath = args[0]; var p4Port = GetP4Setting(args, 1, P4Setting.P4PORT); var p4User = GetP4Setting(args, 2, P4Setting.P4USER); var p4Workspace = GetP4Setting(args, 3, P4Setting.P4CLIENT); Console.Out.Write("Connecting to P4 "); var p4Server = new Server(new ServerAddress(p4Port)); var p4Repository = new Repository(p4Server); var p4Connection = p4Repository.Connection; p4Connection.UserName = p4User; p4Connection.Client = new Client { Name = p4Workspace }; p4Connection.Connect(null); if (args.Length >= 5) { p4Connection.Login(args[4]); } Console.WriteLine("[done]"); Console.Out.Write("Getting latest changelist: "); var latestChangelist = p4Repository.GetChangelists(new Options { { "-m", "1" } }).First(); Console.Out.WriteLine(latestChangelist.Id); var currentDate = DateTime.Now; // detect depot based on EXE path string DepotPath = DefaultDepotPath; IList <FileMetaData> ExeMetaData = p4Repository.GetFileMetaData(new Options(), new FileSpec(null, new ClientPath(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName), null, null)); if (ExeMetaData.Count > 0) { string Path = ExeMetaData[0].DepotPath.ToString(); int i = Path.IndexOf("/Engine/Binaries"); if (i != -1) { DepotPath = Path.Substring(0, i); } } string DocumentationDepotPath = DepotPath + DefaultDocumentationPath; var filesSpec = new List <FileSpec> { new FileSpec( new DepotPath(DocumentationDepotPath), new ChangelistIdVersion(latestChangelist.Id)) }; Console.Out.Write("Synchronizing " + DocumentationDepotPath); p4Connection.Client.SyncFiles(filesSpec, null); Console.Out.WriteLine("[done]"); Console.Out.Write("Getting files info "); var files = p4Repository.GetFileMetaData(filesSpec, null).Where(md => !ExcludedAction(md.HeadAction)).ToList(); Console.Out.WriteLine("[done]"); var locLangs = DetectLocalizationLanguages(files); Console.Out.WriteLine("Found languages: [{0}]", string.Join(", ", locLangs)); Console.Out.Write("Counting total words: "); var intFiles = files.Where(f => f.DepotPath.Path.ToLower().EndsWith(".int.udn")).ToList(); var intWordCount = new WordCountCache(); var totalWords = (double)intFiles.Sum(intFile => intWordCount.Get(intFile)); Console.Out.WriteLine(totalWords); var data = new Dictionary <string, double> { { "int", totalWords } }; foreach (var lang in locLangs) { var locFiles = files.Where(f => f.DepotPath.Path.ToLower().EndsWith("." + lang.ToLower() + ".udn")).ToList(); var wordCount = totalWords; Console.Out.Write("Calculating {0} language: ", lang, 0); foreach (var intFile in intFiles) { var filteredLocFiles = locFiles.Where( file => file.DepotPath.Path.ToLower() == UDNFilesHelper.ChangeLanguage(intFile.DepotPath.Path, lang.ToUpper()).ToLower()) .ToArray(); if (filteredLocFiles.Count() != 1) { wordCount -= intWordCount.Get(intFile); continue; } var locFile = filteredLocFiles[0]; var match = ChangelistNumberPattern.Match(UDNFilesHelper.Get(locFile)); IList <DepotFileDiff> diffs = null; DateTime?diffDate = null; if (match.Success) { var cl = int.Parse(match.Groups["number"].Value); if (cl == 0) { wordCount -= intWordCount.Get(intFile); continue; } if (intFile.HeadChange > cl) { diffDate = p4Repository.GetChangelist(cl).ModifiedDate; } } else { if (intFile.HeadTime > locFile.HeadTime) { diffDate = locFile.HeadTime; } } if (!diffDate.HasValue) { continue; } diffs = p4Repository.GetDepotFileDiffs( string.Format("{0}@{1}", intFile.DepotPath.Path, diffDate.Value.ToString("yyyy\\/MM\\/dd\\:HH\\:mm\\:ss")), new FileSpec(intFile.DepotPath, new ChangelistIdVersion(latestChangelist.Id)).ToString(), new Options() { { "-d", "" }, { "-u", "" } }); if (diffs != null && diffs[0] != null && string.IsNullOrEmpty(diffs[0].LeftFile.DepotPath.Path)) { PathSpec P4Loc = TraceP4Location(p4Repository, new FileSpec(intFile.DepotPath, new ChangelistIdVersion(latestChangelist.Id)), diffDate.Value); // some wired case which the ModifiedDate for intFile from locFile's Changelist pattern is earlier than the first version Date. // maybe caused by server time adjustment. if (P4Loc == null) { continue; } diffs = p4Repository.GetDepotFileDiffs( string.Format("{0}@{1}", P4Loc, diffDate.Value.ToString("yyyy\\/MM\\/dd\\:HH\\:mm\\:ss")), new FileSpec(intFile.DepotPath, new ChangelistIdVersion(latestChangelist.Id)).ToString(), new Options() { { "-d", "" }, { "-u", "" } }); } if (diffs[0].Type == DiffType.Identical) { continue; } var lines = diffs[0].Diff.Split('\n'); var addedWords = UDNFilesHelper.GetWordCount(string.Join("\n", lines.Where(l => l.StartsWith(">")))); var removedWords = UDNFilesHelper.GetWordCount(string.Join("\n", lines.Where(l => l.StartsWith("<")))); wordCount -= addedWords; wordCount -= 0.05 * removedWords; } Console.Out.Write("{1:0.00}\n", lang, wordCount); data.Add(lang.ToLower(), wordCount); } p4Connection.Disconnect(null); var reportFile = new ReportFile(reportFilePath); reportFile.AppendData(currentDate, data); reportFile.Save(); } catch (InvalidCastException e) { Console.Error.WriteLine("Unrecognized error: {0}\nCall stack: {1}\n", e.Message, e.StackTrace); } }
public void CreateTempFolder() { _tempFolder = PathUtility.CreateTemporaryPath(PathType.Folder); }
/// <summary>Gets path information from a path spec. </summary> private PathSpec parsePathSpec(System.String spec) { PathSpec ps = new PathSpec(this); if (spec.StartsWith(".")) { ps.find = true; spec = spec.Substring(1); } else { ps.find = false; } if (spec.Length == 0) { throw new HL7Exception("Invalid path (some path element is either empty or contains only a dot)"); } SupportClass.Tokenizer tok = new SupportClass.Tokenizer(spec, "()", false); ps.pattern = tok.NextToken(); if (tok.HasMoreTokens()) { System.String repString = tok.NextToken(); try { ps.rep = System.Int32.Parse(repString); } catch (System.FormatException) { throw new HL7Exception(repString + " is not a valid rep #", HL7Exception.APPLICATION_INTERNAL_ERROR); } } else { ps.rep = 0; } return ps; }