public void Test003_AddFiles() { p4.Disconnect(); p4.Charset = "utf16le-bom"; p4.Connect(); string testPath = Path.Combine(p4ClientRootDirectory, "TestUnicode"); //Create some test files Directory.CreateDirectory(testPath); P4PendingChangelist cl = p4.CreatePendingChangelist("TestUnicode"); string[] args = new string[13]; args[0] = "-c"; args[1] = cl.Number.ToString(); args[2] = "-tunicode"; for (int i = 0; i < 10; i++) { string fn = string.Format("File{0}", i); string contents = string.Format("this is file: {0}\nEn español.\nΚαλημέρα κόσμε\nこんにちは 世界", i); StreamWriter sw = new StreamWriter(Path.Combine(testPath, fn), false, System.Text.Encoding.Unicode); sw.Write(contents); sw.Close(); args[i + 3] = Path.Combine(testPath, fn); } P4UnParsedRecordSet r = p4.RunUnParsed("add", args); Assert.AreEqual(r.Messages.Length, 10, "Invalid response from p4 add"); for (int i = 0; i < 10; i++) { Assert.AreEqual(string.Format("//depot/TestUnicode/File{0}#1 - opened for add", i), r.Messages[i], "Invalid response from p4 add"); } r = cl.Submit(); Assert.AreEqual("Submitting change 8.", r.Messages[0], "Unexpected output from p4 submit"); }
/// <summary> /// Add a fileName to Perforce then submit it. /// Used for testing /// </summary> /// <param name="vsFileName">The file name to add then submit.</param> /// <param name="message">The first line of the P4 command result if no error, else the error message.</param> /// <returns>false if error (see message)</returns> public bool AddAndSubmitFile(string vsFileName, out string message) { // Need to do this for unit testing, or we get NullReferenceException in P4API Connect(); Disconnect(); P4PendingChangelist cl = null; try { cl = _p4.CreatePendingChangelist("A testing changelist"); } catch (NullReferenceException ex) { Trace.WriteLine(String.Format("P4Service.AddAndSubmitFile: {0}", ex.Message)); } P4RecordSet recordSet; string p4FileName = GetP4FileName(vsFileName); bool result = SendCommand("add", out message, out recordSet, "-c", cl.Number.ToString(), p4FileName); if (!result) { return(false); } P4UnParsedRecordSet unparsedRecordset = null; try { unparsedRecordset = cl.Submit(); } catch (P4API.Exceptions.RunUnParsedException ex) { message = HandleRunUnParsedExceptionError(ex); return(false); } return(true); }