/* * P4.Net * Copyright (c) 2007 Shawn Hladky Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ using System; using NUnit.Framework; using P4API; using System.IO; using System.Threading; using System.Diagnostics; using System.Collections.Generic; namespace P4.Net.TestDriver { /// <summary>Some simple Tests.</summary> /// [TestFixture] public class MapTest { [Test] public void TestIncludes() { using (P4Map map = new P4Map()) { map.Insert("//shawn/was/here.txt //shawn/was/not/here.txt"); Assert.AreEqual(true, map.Includes("//shawn/was/here.txt")); Assert.AreEqual(false, map.Includes("//shawn/fubar/here.txt")); } } [Test] public void TestCountClearIsEmpty() { using (P4Map map = new P4Map()) { Assert.AreEqual(0, map.Count); Assert.AreEqual(true, map.IsEmpty()); map.Insert("//shawn/was/here.txt //shawn/was/not/here.txt"); Assert.AreEqual(1, map.Count); Assert.AreEqual(false, map.IsEmpty()); map.Clear(); Assert.AreEqual(0, map.Count); Assert.AreEqual(true, map.IsEmpty()); map.Insert("//shawn/was/here.txt //shawn/was/not/here.txt"); map.Insert("//shawn/was2/here.txt //shawn/was2/not/here.txt"); Assert.AreEqual(2, map.Count); Assert.AreEqual(false, map.IsEmpty()); map.Clear(); Assert.AreEqual(0, map.Count); Assert.AreEqual(true, map.IsEmpty()); } } [Test] public void TestInsertConstructors() { using (P4Map map = new P4Map("//shawn/was/here.txt //shawn/was/not/here.txt")) { //Console.WriteLine(map.ToString()); Assert.AreEqual(1, map.Count); Assert.AreEqual(false, map.IsEmpty()); map.Insert("//shawn/was2/here.txt //shawn/was2/not/here.txt"); Assert.AreEqual(2, map.Count); Assert.AreEqual(false, map.IsEmpty()); //Console.WriteLine(map.ToString()); map.Clear(); Assert.AreEqual(0, map.Count); Assert.AreEqual(true, map.IsEmpty()); } using (P4Map map = new P4Map("//shawn/was/here.txt")) { //Console.WriteLine(map.ToString()); Assert.AreEqual(1, map.Count); Assert.AreEqual(false, map.IsEmpty()); map.Insert("//shawn/was2/here.txt"); Assert.AreEqual(2, map.Count); Assert.AreEqual(false, map.IsEmpty()); //Console.WriteLine(map.ToString()); map.Clear(); Assert.AreEqual(0, map.Count); Assert.AreEqual(true, map.IsEmpty()); } using (P4Map map = new P4Map()) { Assert.AreEqual(0, map.Count); Assert.AreEqual(true, map.IsEmpty()); map.Insert2("//shawn/was/here.txt", "//shawn/was/not/here.txt"); //Console.WriteLine(map.ToString()); Assert.AreEqual(1, map.Count); Assert.AreEqual(false, map.IsEmpty()); map.Insert2("//shawn/was2/here.txt", "//shawn/was2/not/here.txt"); //Console.WriteLine(map.ToString()); Assert.AreEqual(2, map.Count); Assert.AreEqual(false, map.IsEmpty()); map.Clear(); Assert.AreEqual(0, map.Count); Assert.AreEqual(true, map.IsEmpty()); } using (P4Map map = new P4Map()) { List<string> rhs = new List<string>(); List<string> lhs = new List<string>(); for (int i = 0; i < 10; i++) { rhs.Add(string.Format("//right/{0}/file.txt", i)); lhs.Add(string.Format("//left/{0}/file.txt", i)); } Assert.AreEqual(0, map.Count); Assert.AreEqual(true, map.IsEmpty()); map.Insert2(lhs, rhs); //Console.WriteLine(map.ToString()); Assert.AreEqual(10, map.Count); Assert.AreEqual(false, map.IsEmpty()); map.Insert2("//shawn/was2/here.txt", "//shawn/was2/not/here.txt"); //Console.WriteLine(map.ToString()); Assert.AreEqual(11, map.Count); Assert.AreEqual(false, map.IsEmpty()); map.Clear(); Assert.AreEqual(0, map.Count); Assert.AreEqual(true, map.IsEmpty()); } using (P4Map map = new P4Map()) { //Console.WriteLine(map.ToString()); Assert.AreEqual(0, map.Count); Assert.AreEqual(true, map.IsEmpty()); map.Insert("//shawn/was1/here.txt", "//shawn/was2/here.txt", "//shawn/was3/here.txt"); Assert.AreEqual(3, map.Count); Assert.AreEqual(false, map.IsEmpty()); //Console.WriteLine(map.ToString()); map.Clear(); Assert.AreEqual(0, map.Count); Assert.AreEqual(true, map.IsEmpty()); map.Clear(); map.Insert("//shawn/was1/here.txt //shawn/wasnot1/here.txt", "//shawn/was2/here.txt //shawn/wasnot2/here.txt", "//shawn/was3/here.txt //shawn/wasnot3/here.txt"); //Console.WriteLine(map.ToString()); Assert.AreEqual(3, map.Count); Assert.AreEqual(false, map.IsEmpty()); map.Clear(); Assert.AreEqual(0, map.Count); Assert.AreEqual(true, map.IsEmpty()); } using (P4Map map = new P4Map("//shawn/was1/here.txt", "//shawn/was2/here.txt", "//shawn/was3/here.txt")) { Assert.AreEqual(3, map.Count); Assert.AreEqual(false, map.IsEmpty()); //Console.WriteLine(map.ToString()); map.Clear(); Assert.AreEqual(0, map.Count); Assert.AreEqual(true, map.IsEmpty()); } using (P4Map map = new P4Map("//shawn/was1/here.txt //shawn/wasnot1/here.txt", "//shawn/was2/here.txt //shawn/wasnot2/here.txt", "//shawn/was3/here.txt //shawn/wasnot3/here.txt")) { Assert.AreEqual(3, map.Count); Assert.AreEqual(false, map.IsEmpty()); //Console.WriteLine(map.ToString()); map.Clear(); Assert.AreEqual(0, map.Count); Assert.AreEqual(true, map.IsEmpty()); } } [Test] public void TestJoin() { using (P4Map map = new P4Map()) { string[] a = {"//depot/main/... //ws/main/..." , "//depot/main/doc/... //ws/doc/..."}; map.Insert(a); //Console.WriteLine(map.ToString()); string[] exp = {"//depot/main/... //ws/main/..." , "-//depot/main/doc/... //ws/main/doc/...", "//depot/main/doc/... //ws/doc/..."}; Assert.AreEqual(exp, map.ToArray()); P4Map map2 = new P4Map(); map2.Insert2("//ws/...", @"C:\Work\..."); //Console.WriteLine(map2.ToString()); P4Map map3 = P4Map.Join(map, map2); string[] exp3 = {@"//depot/main/... C:\Work\main/..." , @"-//depot/main/doc/... C:\Work\main/doc/...", @"//depot/main/doc/... C:\Work\doc/..."}; Assert.AreEqual(exp3, map3.ToArray()); //Console.WriteLine(map3.ToString()); map2.Dispose(); map3.Dispose(); } } [Test] public void TestTranslate() { using (P4Map map = new P4Map()) { string[] a = {"//depot/main/... //ws/main/..." , "//depot/main/doc/... //ws/doc/..."}; map.Insert(a); //Console.WriteLine(map.ToString()); string[] exp = {"//depot/main/... //ws/main/..." , "-//depot/main/doc/... //ws/main/doc/...", "//depot/main/doc/... //ws/doc/..."}; Assert.AreEqual(exp, map.ToArray()); P4Map map2 = new P4Map(); map2.Insert2("//ws/...", @"C:\Work\..."); //Console.WriteLine(map2.ToString()); P4Map map3 = P4Map.Join(map, map2); string[] exp3 = {@"//depot/main/... C:\Work\main/..." , @"-//depot/main/doc/... C:\Work\main/doc/...", @"//depot/main/doc/... C:\Work\doc/..."}; Assert.AreEqual(exp3, map3.ToArray()); //Console.WriteLine(map3.ToString()); Assert.AreEqual(@"C:\Work\main/test.file", map3.Translate(@"//depot/main/test.file")); Assert.AreEqual(@"C:\Work\doc/test.file", map3.Translate(@"//depot/main/doc/test.file")); Assert.AreEqual(@"//depot/main/test.file", map3.Translate(@"C:\Work\main/test.file")); Assert.AreEqual(@"//depot/main/doc/test.file", map3.Translate(@"C:\Work\doc/test.file")); map2.Dispose(); map3.Dispose(); } } [Test] public void TestTranslateMany() { using (P4Map map = new P4Map()) { string[] a = {"//depot/main/... //ws/main/..." , "//depot/main/doc/... //ws/doc/..."}; map.Insert(a); //Console.WriteLine(map.ToString()); string[] exp = {"//depot/main/... //ws/main/..." , "-//depot/main/doc/... //ws/main/doc/...", "//depot/main/doc/... //ws/doc/..."}; Assert.AreEqual(exp, map.ToArray()); P4Map map2 = new P4Map(); map2.Insert2("//ws/...", @"C:\Work\..."); //Console.WriteLine(map2.ToString()); P4Map map3 = P4Map.Join(map, map2); string[] exp3 = {@"//depot/main/... C:\Work\main/..." , @"-//depot/main/doc/... C:\Work\main/doc/...", @"//depot/main/doc/... C:\Work\doc/..."}; Assert.AreEqual(exp3, map3.ToArray()); //Console.WriteLine(map3.ToString()); string[] files = {@"//depot/main/test.file", @"//depot/main/doc/test.file"}; string[] exp4 = {@"C:\Work\main/test.file", @"C:\Work\doc/test.file"}; IList<String> ret = map3.Translate(files); for (int i = 0; i < 2; i++) { Assert.AreEqual(exp4[i], ret[i]); } map2.Dispose(); map3.Dispose(); } } [Test] public void TestRhsLhs() { using (P4Map map = new P4Map()) { string[] a = {"//depot/main/... //ws/main/..." , "//depot/main/doc/... //ws/doc/..."}; map.Insert(a); //Console.WriteLine(map.ToString()); string[] exp = {"//depot/main/..." , "-//depot/main/doc/...", "//depot/main/doc/..."}; Assert.AreEqual(exp, map.Lhs()); string[] exp2 = {"//ws/main/..." , "//ws/main/doc/...", "//ws/doc/..."}; Assert.AreEqual(exp2, map.Rhs()); } using (P4Map map = new P4Map("//test/file.txt", "//test/file2.txt")) { string[] exp = {"//test/file.txt" , "//test/file2.txt"}; Assert.AreEqual(exp, map.Rhs()); Assert.AreEqual(exp, map.Lhs()); } } [Test] public void TestIncludesAllAny() { using (P4Map map = new P4Map()) { string[] a = {"//depot/main/... //ws/main/..." , "//depot/main/doc/... //ws/doc/..."}; map.Insert(a); string[] list1 = {"//depot/main/test.txt" , "//depot/main/doc/test2.txt", "//depot/main/test3.txt"}; Assert.AreEqual(true, map.IncludesAll(list1)); Assert.AreEqual(true, map.IncludesAny(list1)); string[] list2 = {"//depot/main/test.txt" , "//depot/main2/test2.txt", "//depot/main/test3.txt"}; Assert.AreEqual(false, map.IncludesAll(list2)); Assert.AreEqual(true, map.IncludesAny(list2)); string[] list3 = {"//depot/main2/test.txt" , "//depot/main2/doc/test2.txt", "//depot/main2/test3.txt"}; Assert.AreEqual(false, map.IncludesAll(list3)); Assert.AreEqual(false, map.IncludesAny(list3)); } } [Test] public void TestCaseSensitive() { using (P4Map map = new P4Map()) { string[] a = {"//depot/main/... //ws/main/..." , "//depot/main/doc/... //ws/doc/..."}; map.Insert(a); Assert.AreEqual(true, map.Includes("//DEPOT/main/test.txt")); Assert.AreEqual(true, map.Includes("//depot/main/test.txt")); Assert.AreEqual(false, map.Includes("//DEPOT/none/test.txt")); Assert.AreEqual(false, map.Includes("//depot/none/test.txt")); } } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 7889 | Johan Nilsson |
Branch from Shawn Hladky's original P4.Net (main branch). Changed file type for StandardTest.cs and UnicodeTest.cs in order to be able to check them in. |
||
//guest/shawn_hladky/P4.Net/main/test/src/P4.NetTestDriver/MapTest.cs | |||||
#2 | 7709 | Shawn Hladky | P4.Net: Cleanup, documentation, and a a start for implementing an object-based output for filelog. | ||
#1 | 7204 | Shawn Hladky | P4.Net: Added Map functionality |