using System.Reflection; using System; using System.Text.RegularExpressions; using UnityEngine; using Perforce.P4; using NUnit.Framework; using log4net; namespace P4Connect { [TestFixture] public class P4ConnectTest { private static readonly ILog log = LogManager.GetLogger(typeof(P4ConnectTest)); static string test_dir; static string test_file; [TestFixtureSetUp] public void Init() { string assets_dir = Main.DataPath; test_dir = TestUtils.getTestDirectory(assets_dir); test_file = TestUtils.getTestFilename(test_dir, ".txt"); System.IO.Directory.CreateDirectory(test_dir); log.Debug("asset_dir: " + assets_dir); log.Debug("test_dir: " + test_dir); log.Debug("test_file: " + test_file); } [TestFixtureTearDown] public void Dispose() { } [Test] public void TestAddFile() { string[] files = new string[] { test_file }; System.Collections.Generic.List<FileAndMeta> results; TestUtils.CreateFile(test_file, "test file content"); results = Engine.CreateAssets(files); Assert.AreEqual(results.Count, 1); FileAndMeta f = results[0]; log.Debug("Test: AddTextFile - FileAndMeta:"); log.Debug(" " + f.File.ToString()); log.Debug(" " + f.Meta.ToString()); } [Test] public void TestRevertFile() { string[] files = new string[] { test_file }; System.Collections.Generic.List<FileAndMeta> results; TestUtils.CreateFile(test_file, "test file content"); // Create the file results = Engine.CreateAssets(files); Assert.AreEqual(results.Count, 1); FileAndMeta f = results[0]; Assert.AreEqual(test_file, f.File.LocalPath.ToString()); // Check file status (should be MarkedForAdd) FileState state; using (PerforceConnection con = new PerforceConnection()) { state = Engine.GetFileState(test_file, con); } UnityEngine.Debug.Log("state now1: " + state.ToString()); Assert.AreEqual(state.ToString(), "MarkedForAdd"); // Now revert the file results = Engine.RevertAssets(files, true); Assert.AreEqual(results.Count, 1); // Get file status using(PerforceConnection con = new PerforceConnection()) { state = Engine.GetFileState(test_file, con); } UnityEngine.Debug.Log("state now2: " + state.ToString()); Assert.AreEqual("None", state.ToString()); } [Test] public void TestAddAndSubmit() { string[] files = new string[] { test_file }; System.Collections.Generic.List<FileAndMeta> results; TestUtils.CreateFile(test_file, "test file content"); // Create the file results = Engine.CreateAssets(files); Assert.AreEqual(results.Count, 1); FileAndMeta f = results[0]; Assert.AreEqual(test_file.Replace('/', System.IO.Path.DirectorySeparatorChar), f.File.LocalPath.ToString().Replace('/', System.IO.Path.DirectorySeparatorChar)); // Check file status (should be MarkedForAdd) FileState state; using (PerforceConnection con = new PerforceConnection()) { state = Engine.GetFileState(test_file, con); } Assert.AreEqual(state.ToString(), "MarkedForAdd"); System.Collections.Generic.List<FileSpec> list = new System.Collections.Generic.List<FileSpec>(); list.Add(f.File.LocalPath); // Now submit the change Engine.PerformConnectionOperation(con => Engine.SubmitFiles(con, "A change list TEST" , list)); // Get file status using (PerforceConnection con = new PerforceConnection()) { state = Engine.GetFileState(test_file, con); } UnityEngine.Debug.Log("state now: " + state.ToString()); Assert.AreEqual("InDepot", state.ToString()); } [Test] public void TestEdit() { string[] files = new string[] { test_file }; System.Collections.Generic.List<FileAndMeta> results; //System.Collections.Generic.List<FileAndMeta> files; TestUtils.CreateFile(test_file, "test file content"); // Create the file results = Engine.CreateAssets(files); Assert.AreEqual(results.Count, 1); FileAndMeta f = results[0]; Assert.AreEqual(test_file.Replace('/', System.IO.Path.DirectorySeparatorChar), f.File.LocalPath.ToString().Replace('/', System.IO.Path.DirectorySeparatorChar)); // Check file status (should be MarkedForAdd) FileState state; using (PerforceConnection con = new PerforceConnection()) { state = Engine.GetFileState(test_file, con); } Assert.AreEqual(state.ToString(), "MarkedForAdd"); System.Collections.Generic.List<FileSpec> list = new System.Collections.Generic.List<FileSpec>(); list.Add(f.File.LocalPath); // Now submit the change Engine.PerformConnectionOperation(con => Engine.SubmitFiles(con, "A change list TEST", list)); // Get file status using (PerforceConnection con = new PerforceConnection()) { state = Engine.GetFileState(test_file, con); } Assert.AreEqual("InDepot", state.ToString()); // Check the file out results = Engine.CheckoutAssets(files); Assert.AreEqual(1, results.Count); // Modify the file TestUtils.CreateFile(test_file, "new test file content"); // Get file status using (PerforceConnection con = new PerforceConnection()) { state = Engine.GetFileState(test_file, con); } UnityEngine.Debug.Log("2state now: " + state.ToString()); Assert.AreEqual("MarkedForEdit", state.ToString()); } } // Test utilities public class TestUtils { // Create a unique test directory within Assets public static string getTestDirectory(string directory) { string path; do { path = System.IO.Path.Combine(directory, GenerateName("testdir")); } while (System.IO.Directory.Exists(path) || System.IO.File.Exists(path)); return (path); } // Create a unique filename within the TestDirectory public static string getTestFilename(string directory, string extension) { string path; do { path = System.IO.Path.Combine(directory,GenerateFileName("testfile",".txt")); } while (System.IO.File.Exists(path)); return (path); } public static string GenerateFileName(string context, string extension) { return GenerateName(context) + extension; } public static string GenerateName(string context) { return context + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + "_" + Guid.NewGuid().ToString("N").Substring(0,10); } // Create a file with the provided string as content public static void CreateFile(string path, string content) { System.IO.File.WriteAllText(path, content); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 21095 | artofcode |
Populate -o //guest/perforce_software/p4connect/... //guest/artofcode/dev/p4connect/.... |
||
//guest/perforce_software/p4connect/main/src/P4Connect/P4Connect/P4Connect.Tests.cs | |||||
#1 | 16209 | Norman Morse | Move entire source tree into "main" branch so workshop code will act correctly. | ||
//guest/perforce_software/p4connect/src/P4Connect/P4Connect/P4Connect.Tests.cs | |||||
#1 | 12512 | Norman Morse | Integrate from Dev branch, preparing for Beta3 release | ||
//guest/norman_morse/dev/p4connect/src/P4Connect/P4Connect/P4Connect.Tests.cs | |||||
#5 | 12511 | Norman Morse | Split Unit Tests into a seperate Assembly | ||
#4 | 12473 | Norman Morse | More minor fixes to logging and config | ||
#3 | 12467 | Norman Morse |
Many minor changes to improve logging Added a filter for Console log display where you can select a level Hooked the log file location to the Configuration Log Entry. |
||
#2 | 12445 | Norman Morse |
Integrated log4net and nunit into P4Connect. Still need cleanup and debugging, good enough for dev tree Also added ChangeManager and ChangeLists Classes for future use with multiple changes. |
||
#1 | 12424 | Norman Morse | More Logging and Testing in dev branch |