using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Diagnostics; using System.Collections; using System.Collections.Generic; using Perforce.P4; namespace p4api.net.unit.test { /// ///This is a test class for P4CommandTest and is intended ///to contain all P4CommandTest Unit Tests /// [TestClass()] public class P4CommandTest { String TestDir = "c:\\MyTestDir"; private TestContext testContextInstance; /// ///Gets or sets the test context which provides ///information about and functionality for the current test run. /// public TestContext TestContext { get { return testContextInstance; } set { testContextInstance = value; } } #region Additional test attributes // //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 /// ///A test for Args /// [TestMethod()] public void ArgsTest() { bool unicode = false; string serverAddr = "localhost:6666"; string user = "admin"; string pass = string.Empty; string ws_client = "admin_space"; // turn off exceptions for this test ErrorSeverity oldExceptionLevel = P4Exception.MinThrowLevel; P4Exception.MinThrowLevel = ErrorSeverity.E_NOEXC; for( int i = 0; i < 2; i++ ) // run once for ascii, once for unicode { Process p4d = Utilities.DeployP4TestServer( TestDir, unicode ); try { using( P4Server server = new P4Server( serverAddr, user, pass, ws_client ) ) { if( unicode ) Assert.IsTrue( server.UseUnicode, "Unicode server detected as not supporting Unicode" ); else Assert.IsFalse( server.UseUnicode, "Non Unicode server detected as supporting Unicode" ); P4Command target = new P4Command( server ); StringList expected = new StringList(new string[]{ "a", "b", "c" }); target.Args = expected; StringList actual = target.Args; Assert.AreEqual( expected, actual ); } } finally { Utilities.RemoveTestServer( p4d, TestDir ); } unicode = !unicode; } // reset the exception level P4Exception.MinThrowLevel = oldExceptionLevel; } /// ///A test for Run /// [TestMethod()] public void RunTest() { bool unicode = false; string serverAddr = "localhost:6666"; string user = "admin"; string pass = string.Empty; string ws_client = "admin_space"; // turn off exceptions for this test ErrorSeverity oldExceptionLevel = P4Exception.MinThrowLevel; P4Exception.MinThrowLevel = ErrorSeverity.E_NOEXC; for( int i = 0; i < 2; i++ ) // run once for ascii, once for unicode { Process p4d = Utilities.DeployP4TestServer( TestDir, unicode ); try { using( P4Server server = new P4Server( serverAddr, user, pass, ws_client ) ) { if( unicode ) Assert.IsTrue( server.UseUnicode, "Unicode server detected as not supporting Unicode" ); else Assert.IsFalse( server.UseUnicode, "Non Unicode server detected as supporting Unicode" ); P4Command target = new P4Command( server, "help", false, null ); P4CommandResult results = target.Run(); Assert.IsTrue( results.Success ); } } finally { Utilities.RemoveTestServer( p4d, TestDir ); } unicode = !unicode; } // reset the exception level P4Exception.MinThrowLevel = oldExceptionLevel; } /// ///A test for Run /// [TestMethod()] public void RunTest1() { bool unicode = false; string serverAddr = "localhost:6666"; string user = "admin"; string pass = string.Empty; string ws_client = "admin_space"; // turn off exceptions for this test ErrorSeverity oldExceptionLevel = P4Exception.MinThrowLevel; P4Exception.MinThrowLevel = ErrorSeverity.E_NOEXC; for( int i = 0; i < 2; i++ ) // run once for ascii, once for unicode { Process p4d = Utilities.DeployP4TestServer( TestDir, unicode ); try { using( P4Server server = new P4Server( serverAddr, user, pass, ws_client ) ) { if( unicode ) Assert.IsTrue( server.UseUnicode, "Unicode server detected as not supporting Unicode" ); else Assert.IsFalse( server.UseUnicode, "Non Unicode server detected as supporting Unicode" ); P4Command target = new P4Command( server, "help", false, null ); P4CommandResult results = target.Run(new String[] { "print" }); Assert.IsTrue( results.Success ); InfoList helpTxt = target.InfoOutput; Assert.IsNotNull( helpTxt ); } } finally { Utilities.RemoveTestServer( p4d, TestDir ); } unicode = !unicode; } // reset the exception level P4Exception.MinThrowLevel = oldExceptionLevel; } ///// /////A test for Submit ///// //[TestMethod()] //public void SubmitTest() //{ // bool unicode = false; // string serverAddr = "localhost:6666"; // string user = "admin"; // string pass = string.Empty; // string ws_client = "admin_space"; // // turn off exceptions for this test // ErrorSeverity oldExceptionLevel = P4Exception.MinThrowLevel; // P4Exception.MinThrowLevel = ErrorSeverity.E_NOEXC; // for (int i = 0; i < 1; i++) // run once for ascii, once for unicode (so far only ASCII test server works for theses tests) // { // Process p4d = Utilities.DeployP4TestServer(TestDir, 3, unicode); // try // { // using (P4Server server = new P4Server(serverAddr, user, pass, ws_client)) // { // if (unicode) // Assert.IsTrue(server.UseUnicode, "Unicode server detected as not supporting Unicode"); // else // Assert.IsFalse(server.UseUnicode, "Non Unicode server detected as supporting Unicode"); // P4Command target = new P4Command(server); // P4CommandResult results = target.Submit("Test submit"); // Assert.IsTrue(results.Success); // TaggedObject output = target.TaggedOutput[2]; // Assert.IsTrue(output.ContainsKey("submittedChange")); // } // } // finally // { // Utilities.RemoveTestServer(p4d, TestDir); // } // unicode = !unicode; // } //} ///// /////A test for Submit ///// //[TestMethod()] //public void SubmitTest1() //{ // bool unicode = false; // string serverAddr = "localhost:6666"; // string user = "admin"; // string pass = string.Empty; // string ws_client = "admin_space"; // // turn off exceptions for this test // ErrorSeverity oldExceptionLevel = P4Exception.MinThrowLevel; // P4Exception.MinThrowLevel = ErrorSeverity.E_NOEXC; // for (int i = 0; i < 1; i++) // run once for ascii, once for unicode (so far only ASCII test server works for theses tests) // { // Process p4d = Utilities.DeployP4TestServer(TestDir, 2, unicode); // try // { // using (P4Server server = new P4Server(serverAddr, user, pass, ws_client)) // { // if (unicode) // Assert.IsTrue(server.UseUnicode, "Unicode server detected as not supporting Unicode"); // else // Assert.IsFalse(server.UseUnicode, "Non Unicode server detected as supporting Unicode"); // P4Command target = new P4Command(server); // P4Change change = new P4Change(server, "admin" , "admin_space"); // change.Description = "On the fly built change list"; // change.Files.Add("//depot/TestData/Letters.txt\t#edit"); // //change.Save(); // //change.Fetch(); // //change.Save(); // String spec = change.ToString(); // P4CommandResult results = target.Submit(false, false, null, change); //change.ChangeNumber); // Assert.IsTrue(results.Success); // TaggedObject output = target.TaggedOutput[2]; // Assert.IsTrue(output.ContainsKey("submittedChange")); // } // } // finally // { // Utilities.RemoveTestServer(p4d, TestDir); // } // unicode = !unicode; // } //} ///// /////A test for Submit ///// //[TestMethod()] //public void SubmitTest2() //{ // bool unicode = false; // string serverAddr = "localhost:6666"; // string user = "admin"; // string pass = string.Empty; // string ws_client = "admin_space"; // // turn off exceptions for this test // ErrorSeverity oldExceptionLevel = P4Exception.MinThrowLevel; // P4Exception.MinThrowLevel = ErrorSeverity.E_NOEXC; // for (int i = 0; i < 1; i++) // run once for ascii, once for unicode (so far only ASCII test server works for theses tests) // { // Process p4d = Utilities.DeployP4TestServer(TestDir, 3, unicode); // try // { // using (P4Server server = new P4Server(serverAddr, user, pass, ws_client)) // { // if (unicode) // Assert.IsTrue(server.UseUnicode, "Unicode server detected as not supporting Unicode"); // else // Assert.IsFalse(server.UseUnicode, "Non Unicode server detected as supporting Unicode"); // P4Command target = new P4Command(server); // P4CommandResult results = target.Submit(false, false, null, 5); // Assert.IsTrue(results.Success); // TaggedObject output = target.TaggedOutput[2]; // Assert.IsTrue(output.ContainsKey("submittedChange")); // } // } // finally // { // Utilities.RemoveTestServer(p4d, TestDir); // } // unicode = !unicode; // } //} ///// /////A test for Submit ///// //[TestMethod()] //public void SubmitTest3() //{ // bool unicode = false; // string serverAddr = "localhost:6666"; // string user = "admin"; // string pass = string.Empty; // string ws_client = "admin_space"; // // turn off exceptions for this test // ErrorSeverity oldExceptionLevel = P4Exception.MinThrowLevel; // P4Exception.MinThrowLevel = ErrorSeverity.E_NOEXC; // for (int i = 0; i < 1; i++) // run once for ascii, once for unicode (so far only ASCII test server works for theses tests) // { // Process p4d = Utilities.DeployP4TestServer(TestDir, 2, unicode); // try // { // using (P4Server server = new P4Server(serverAddr, user, pass, ws_client)) // { // if (unicode) // Assert.IsTrue(server.UseUnicode, "Unicode server detected as not supporting Unicode"); // else // Assert.IsFalse(server.UseUnicode, "Non Unicode server detected as supporting Unicode"); // P4Command target = new P4Command(server); // P4CommandResult results = target.Submit(false, false, null, "Test submit", "c:\\MyTestDir\\admin_space\\TestData\\Letters.txt"); // Assert.IsTrue(results.Success); // TaggedObject output = target.TaggedOutput[2]; // Assert.IsTrue(output.ContainsKey("submittedChange")); // } // } // finally // { // Utilities.RemoveTestServer(p4d, TestDir); // } // unicode = !unicode; // } //} ///// /////A test for Resolve ///// //[TestMethod()] //public void ResolveTest() //{ // bool unicode = false; // string serverAddr = "localhost:6666"; // string user = "admin"; // string pass = string.Empty; // string ws_client = "admin_space"; // // turn off exceptions for this test // ErrorSeverity oldExceptionLevel = P4Exception.MinThrowLevel; // P4Exception.MinThrowLevel = ErrorSeverity.E_NOEXC; // for (int i = 0; i < 1; i++) // run once for ascii, once for unicode (so far only ASCII test server works for theses tests) // { // Process p4d = Utilities.DeployP4TestServer(TestDir, 2, unicode); // try // { // using (P4Server server = new P4Server(serverAddr, user, pass, ws_client)) // { // if (unicode) // Assert.IsTrue(server.UseUnicode, "Unicode server detected as not supporting Unicode"); // else // Assert.IsFalse(server.UseUnicode, "Non Unicode server detected as supporting Unicode"); // P4Command target = new P4Command(server); // P4CommandResult results = target.Submit(false, false, null, "Check It In!", // "c:\\MyTestDir\\admin_space\\TestData\\Numbers.txt"); // Assert.IsFalse(results.Success); // Dictionary responses = new Dictionary(); // responses["DefaultResponse"] = "s"; // responses["Accept(a) Edit(e) Diff(d) Merge (m) Skip(s) Help(?) am: "] = "am"; // results = target.Resolve(responses, P4Command.DiffOptions.none, // false, false, false, false, false, // "c:\\MyTestDir\\admin_space\\TestData\\Numbers.txt"); // Assert.IsTrue(results.Success); // InfoList output = results.InfoOutput; // Assert.IsTrue(output[1].Info.Contains("0 conflicting")); // } // } // finally // { // Utilities.RemoveTestServer(p4d, TestDir); // } // unicode = !unicode; // } //} ///// /////A test for Resolve ///// //[TestMethod()] //public void ResolveTest1() //{ // bool unicode = false; // string serverAddr = "localhost:6666"; // string user = "admin"; // string pass = string.Empty; // string ws_client = "admin_space"; // // turn off exceptions for this test // ErrorSeverity oldExceptionLevel = P4Exception.MinThrowLevel; // P4Exception.MinThrowLevel = ErrorSeverity.E_NOEXC; // for (int i = 0; i < 1; i++) // run once for ascii, once for unicode (so far only ASCII test server works for theses tests) // { // Process p4d = Utilities.DeployP4TestServer(TestDir, 2, unicode); // try // { // using (P4Server server = new P4Server(serverAddr, user, pass, ws_client)) // { // if (unicode) // Assert.IsTrue(server.UseUnicode, "Unicode server detected as not supporting Unicode"); // else // Assert.IsFalse(server.UseUnicode, "Non Unicode server detected as supporting Unicode"); // P4Command target = new P4Command(server); // P4CommandResult results = target.Submit(false, false, null, "Check It In!", // "c:\\MyTestDir\\admin_space\\TestData\\Numbers.txt"); // Assert.IsFalse(results.Success); // results = target.Resolve(P4Command.AutomaticResolve.AutoMerge, P4Command.DiffOptions.none, // false, false, false, false, false, // "c:\\MyTestDir\\admin_space\\TestData\\Numbers.txt"); // Assert.IsTrue(results.Success); // InfoList output = results.InfoOutput; // Assert.IsTrue(output[1].Info.Contains("0 conflicting")); // } // } // finally // { // Utilities.RemoveTestServer(p4d, TestDir); // } // unicode = !unicode; // } //} //private String HandlePrompt(String msg, bool displayText) //{ // return "am"; //} ///// /////A test for Resolve ///// //[TestMethod()] //public void ResolveTest2() //{ // bool unicode = false; // string serverAddr = "localhost:6666"; // string user = "admin"; // string pass = string.Empty; // string ws_client = "admin_space"; // // turn off exceptions for this test // ErrorSeverity oldExceptionLevel = P4Exception.MinThrowLevel; // P4Exception.MinThrowLevel = ErrorSeverity.E_NOEXC; // for (int i = 0; i < 1; i++) // run once for ascii, once for unicode (so far only ASCII test server works for theses tests) // { // Process p4d = Utilities.DeployP4TestServer(TestDir, 2, unicode); // try // { // using (P4Server server = new P4Server(serverAddr, user, pass, ws_client)) // { // if (unicode) // Assert.IsTrue(server.UseUnicode, "Unicode server detected as not supporting Unicode"); // else // Assert.IsFalse(server.UseUnicode, "Non Unicode server detected as supporting Unicode"); // P4Command target = new P4Command(server); // P4Server.PromptHandlerDelegate promptHandler = new P4Server.PromptHandlerDelegate(HandlePrompt); // P4CommandResult results = target.Submit(false, false, null, "Check It In!", // "c:\\MyTestDir\\admin_space\\TestData\\Numbers.txt"); // Assert.IsFalse(results.Success); // results = target.Resolve(promptHandler, P4Command.DiffOptions.none, // false, false, false, false, false, // "c:\\MyTestDir\\admin_space\\TestData\\Numbers.txt"); // Assert.IsTrue(results.Success); // InfoList output = results.InfoOutput; // Assert.IsTrue(output[1].Info.Contains("0 conflicting")); // } // } // finally // { // Utilities.RemoveTestServer(p4d, TestDir); // } // unicode = !unicode; // } //} ///// /////A test for Diff ///// //[TestMethod()] //public void DiffTest() //{ // bool unicode = false; // string serverAddr = "localhost:6666"; // string user = "admin"; // string pass = string.Empty; // string ws_client = "admin_space"; // // turn off exceptions for this test // ErrorSeverity oldExceptionLevel = P4Exception.MinThrowLevel; // P4Exception.MinThrowLevel = ErrorSeverity.E_NOEXC; // for (int i = 0; i < 1; i++) // run once for ascii, once for unicode (so far only ASCII test server works for theses tests) // { // Process p4d = Utilities.DeployP4TestServer(TestDir, 2, unicode); // try // { // using (P4Server server = new P4Server(serverAddr, user, pass, ws_client)) // { // if (unicode) // Assert.IsTrue(server.UseUnicode, "Unicode server detected as not supporting Unicode"); // else // Assert.IsFalse(server.UseUnicode, "Non Unicode server detected as supporting Unicode"); // P4Command target = new P4Command(server); // P4Server.PromptHandlerDelegate promptHandler = new P4Server.PromptHandlerDelegate(HandlePrompt); // P4CommandResult results = target.Diff( // P4Command.DiffOptions.IgnoreWhitespace | P4Command.DiffOptions.context, // false, 10, P4Command.DiffFileList.none, false, // "c:\\MyTestDir\\admin_space\\TestData\\Numbers.txt"); // Assert.IsTrue(results.Success); // InfoList output = results.InfoOutput; // Assert.IsTrue(output[0].Info.Contains("//depot/TestData/Numbers.txt#1 ")); // Assert.IsNotNull(results.TextOutput); // } // } // finally // { // Utilities.RemoveTestServer(p4d, TestDir); // } // unicode = !unicode; // } //} } }