protected override ICollection NonGenericICollectionFactory(int count) { HybridDictionary list = new HybridDictionary(); int seed = 13453; for (int i = 0; i < count; i++) list.Add(CreateT(seed++), CreateT(seed++)); return list.Values; }
public void Ctor_Int(int initialSize) { HybridDictionary hybridDictionary = new HybridDictionary(initialSize); VerifyCtor(hybridDictionary, caseInsensitive: false); Ctor_Int_Bool(initialSize, true); Ctor_Int_Bool(initialSize, false); }
public static HybridDictionary CreateHybridDictionary(int count, bool caseInsensitive = false) { HybridDictionary hybridDictionary = new HybridDictionary(caseInsensitive); for (int i = 0; i < count; i++) { hybridDictionary.Add("Key_" + i, "Value_" + i); } return hybridDictionary; }
public void Add(int size) { string[] values = TestValues(size); string[] keys = TestKeys(size); HybridDictionary hd = new HybridDictionary(true); for (int i = 0; i < size; i++) { hd.Add(keys[i], values[i]); Assert.Equal(hd[keys[i].ToLower()], values[i]); Assert.Equal(hd[keys[i].ToUpper()], values[i]); } }
public void Add_EdgeCases() { string[] values = Test_EdgeCases(); string[] keys = Test_EdgeCases(); HybridDictionary hd = new HybridDictionary(true); for (int i = 0; i < values.Length; i++) { hd.Add(keys[i], values[i]); Assert.Equal(hd[keys[i].ToLower()], values[i]); Assert.Equal(hd[keys[i].ToUpper()], values[i]); } }
// Add a stream to the list of streams to intercept. // // Parameters: // alwaysIntercept - If true, then don't check whether the old stream and the new stream are the same. // SaveAs() will set this to true if oldStreamname is actually referring to a stream // on a remote machine. internal void AddStreamname(string oldStreamname, string newStreamname, bool alwaysIntercept) { // TODO: // After reviewing all the code path, oldStreamname shouldn't be Null or Empty. It actually // doesnt' make much sense if we're asked to intercept an null or empty stream. // However, since we're shipping Whidbey RC soon it is too risky to remove that code. // But I'll add Debug.Assert(!String.IsNullOrEmpty(oldStreamname)) to make sure my // analysis is correct. Debug.Assert(!string.IsNullOrEmpty(oldStreamname)); if (string.IsNullOrEmpty(oldStreamname)) return; if (!alwaysIntercept && StringUtil.EqualsIgnoreCase(oldStreamname, newStreamname)) return; if (_streams == null) _streams = new HybridDictionary(true); _streams[oldStreamname] = new StreamUpdate(newStreamname); }
public static void VerifyCtor(HybridDictionary hybridDictionary, bool caseInsensitive) { Assert.Equal(0, hybridDictionary.Count); Assert.Equal(0, hybridDictionary.Keys.Count); Assert.Equal(0, hybridDictionary.Values.Count); Assert.False(hybridDictionary.IsFixedSize); Assert.False(hybridDictionary.IsReadOnly); Assert.False(hybridDictionary.IsSynchronized); if (caseInsensitive) { hybridDictionary["key"] = "value"; Assert.Equal("value", hybridDictionary["KEY"]); } else { hybridDictionary["key"] = "value"; Assert.Null(hybridDictionary["KEY"]); } }
public void Add(int count, bool caseInsensitive) { HybridDictionary hybridDictionary = new HybridDictionary(caseInsensitive); for (int i = 0; i < count; i++) { string key = "Key_" + i; string value = "Value_" + i; hybridDictionary.Add(key, value); Assert.Equal(i + 1, hybridDictionary.Count); Assert.Equal(i + 1, hybridDictionary.Keys.Count); Assert.Equal(i + 1, hybridDictionary.Values.Count); Assert.Contains(key, hybridDictionary.Keys.Cast<object>()); Assert.Contains(value, hybridDictionary.Values.Cast<object>()); Assert.Equal(value, hybridDictionary[key]); Assert.True(hybridDictionary.Contains(key)); // Keys should be case insensitive Assert.Equal(caseInsensitive, hybridDictionary.Contains(key.ToUpperInvariant())); Assert.Equal(caseInsensitive, hybridDictionary.Contains(key.ToLowerInvariant())); if (caseInsensitive) { Assert.Equal(value, hybridDictionary[key.ToUpperInvariant()]); Assert.Equal(value, hybridDictionary[key.ToLowerInvariant()]); } else { Assert.Null(hybridDictionary[key.ToUpperInvariant()]); Assert.Null(hybridDictionary[key.ToLowerInvariant()]); } } }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; const int BIG_LENGTH = 100; String strLoc = "Loc_000oo"; HybridDictionary hd; string [] valuesShort = { "", " ", "$%^#", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; string [] keysShort = { Int32.MaxValue.ToString(), " ", System.DateTime.Today.ToString(), "", "$%^#" }; string [] valuesLong = new string[BIG_LENGTH]; string [] keysLong = new string[BIG_LENGTH]; Array arr; ICollection ks; int ind; try { for (int i = 0; i < BIG_LENGTH; i++) { valuesLong[i] = "Item" + i; keysLong[i] = "keY" + i; } Console.WriteLine("--- create dictionary ---"); strLoc = "Loc_001oo"; iCountTestcases++; hd = new HybridDictionary(); Console.WriteLine("1. get Keys for empty dictionary"); iCountTestcases++; if (hd.Count > 0) { hd.Clear(); } if (hd.Keys.Count != 0) { iCountErrors++; Console.WriteLine("Err_0001, returned Keys.Count = {0}", hd.Keys.Count); } Console.WriteLine("2. get Keys on short filled dictionary"); strLoc = "Loc_002oo"; int len = valuesShort.Length; iCountTestcases++; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysShort[i], valuesShort[i]); } Console.WriteLine(" Count = " + hd.Count); if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0002a, count is {0} instead of {1}", hd.Count, len); } ks = hd.Keys; if (ks.Count != len) { iCountErrors++; Console.WriteLine("Err_0002a, returned Keys.Count = {0}", ks.Count); } arr = Array.CreateInstance(typeof(Object), len); ks.CopyTo(arr, 0); for (int i = 0; i < len; i++) { iCountTestcases++; ind = Array.IndexOf(arr, keysShort[i]); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0002b_{0}, Keys doesn't contain \"{1}\" key. Search result: {2}", i, keysShort[i], ind); } } Console.WriteLine("3. get Keys on long filled dictionary"); strLoc = "Loc_003oo"; len = valuesLong.Length; iCountTestcases++; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } Console.WriteLine(" Count = " + hd.Count); if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", hd.Count, len); } ks = hd.Keys; if (ks.Count != len) { iCountErrors++; Console.WriteLine("Err_0003a, returned Keys.Count = {0}", ks.Count); } arr = Array.CreateInstance(typeof(Object), len); ks.CopyTo(arr, 0); for (int i = 0; i < len; i++) { iCountTestcases++; ind = Array.IndexOf(arr, keysLong[i]); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0003b_{0}, Keys doesn't contain \"{1}\" key. Search result: {2}", i, keysLong[i], ind); } } Console.WriteLine("4. get Keys on short dictionary with different_in_casing_only keys "); strLoc = "Loc_004oo"; iCountTestcases++; hd.Clear(); string intlStr = "intlStr"; hd.Add("keykey", intlStr); hd.Add("keyKey", intlStr); if (hd.Count != 2) { iCountErrors++; Console.WriteLine("Err_0004a, count is {0} instead of {1}", hd.Count, 2); } Console.WriteLine(" Count = " + hd.Count); iCountTestcases++; ks = hd.Keys; if (ks.Count != hd.Count) { iCountErrors++; Console.WriteLine("Err_0003b, returned Keys.Count = {0}", ks.Count); } arr = Array.CreateInstance(typeof(Object), 2); ks.CopyTo(arr, 0); iCountTestcases++; ind = Array.IndexOf(arr, "keykey"); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0003c, Keys doesn't contain {0} value", "keykey"); } iCountTestcases++; ind = Array.IndexOf(arr, "keyKey"); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0003d, Keys doesn't contain {0} value", "keyKey"); } Console.WriteLine("5. get Keys on long dictionary with different_in_casing_only keys "); strLoc = "Loc_005oo"; iCountTestcases++; hd.Clear(); hd.Add("keykey", intlStr); for (int i = 0; i < BIG_LENGTH; i++) { hd.Add(keysLong[i], valuesLong[i]); } hd.Add("keyKey", intlStr); if (hd.Count != BIG_LENGTH + 2) { iCountErrors++; Console.WriteLine("Err_0005a, count is {0} instead of {1}", hd.Count, BIG_LENGTH + 2); } Console.WriteLine(" Count = " + hd.Count); iCountTestcases++; ks = hd.Keys; if (ks.Count != hd.Count) { iCountErrors++; Console.WriteLine("Err_0005b, returned Keys.Count = {0}", ks.Count); } arr = Array.CreateInstance(typeof(Object), BIG_LENGTH + 2); ks.CopyTo(arr, 0); for (int i = 0; i < BIG_LENGTH; i++) { iCountTestcases++; if (Array.IndexOf(arr, keysLong[i]) < 0) { iCountErrors++; Console.WriteLine("Err_0005c_{1}, Keys doesn't contain {0} key", keysLong[i], i); } } iCountTestcases++; ind = Array.IndexOf(arr, "keykey"); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0005d, Keys doesn't contain {0} key", "keykey"); } iCountTestcases++; ind = Array.IndexOf(arr, "keyKey"); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0005e, Keys doesn't contain {0} key", "keyKey"); } Console.WriteLine("6. Change long dictinary"); strLoc = "Loc_006oo"; iCountTestcases++; hd.Clear(); len = valuesLong.Length; for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } Console.WriteLine(" Count = " + hd.Count); if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0006a, count is {0} instead of {1}", hd.Count, len); } ks = hd.Keys; if (ks.Count != len) { iCountErrors++; Console.WriteLine("Err_0006a, returned Keys.Count = {0}", ks.Count); } Console.WriteLine(" - remove element from the dictionary"); hd.Remove(keysLong[0]); if (hd.Count != len - 1) { iCountErrors++; Console.WriteLine("Err_0006b, didn't remove element"); } if (ks.Count != len - 1) { iCountErrors++; Console.WriteLine("Err_0006c, Keys were not updated after removal"); } iCountTestcases++; arr = Array.CreateInstance(typeof(Object), hd.Count); ks.CopyTo(arr, 0); ind = Array.IndexOf(arr, keysLong[0]); if (ind >= 0) { iCountErrors++; Console.WriteLine("Err_0006d, Keys still contains removed value " + ind); } Console.WriteLine(" - add element to the dictionary"); hd.Add(keysLong[0], "new item"); if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0006e, didn't add element"); } if (ks.Count != len) { iCountErrors++; Console.WriteLine("Err_0006f, Keys were not updated after addition"); } iCountTestcases++; arr = Array.CreateInstance(typeof(Object), hd.Count); ks.CopyTo(arr, 0); ind = Array.IndexOf(arr, keysLong[0]); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0006g, Keys doesn't contain added value "); } Console.WriteLine("7. Change short dictinary"); strLoc = "Loc_007oo"; iCountTestcases++; hd.Clear(); len = valuesShort.Length; for (int i = 0; i < len; i++) { hd.Add(keysShort[i], valuesShort[i]); } Console.WriteLine(" Count = " + hd.Count); if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0007a, count is {0} instead of {1}", hd.Count, len); } ks = hd.Keys; if (ks.Count != len) { iCountErrors++; Console.WriteLine("Err_0007a, returned Keys.Count = {0}", ks.Count); } Console.WriteLine(" - remove element from the dictionary"); hd.Remove(keysShort[0]); if (hd.Count != len - 1) { iCountErrors++; Console.WriteLine("Err_0007b, didn't remove element"); } if (ks.Count != len - 1) { iCountErrors++; Console.WriteLine("Err_0007c, Keys were not updated after removal"); } iCountTestcases++; arr = Array.CreateInstance(typeof(Object), hd.Count); ks.CopyTo(arr, 0); ind = Array.IndexOf(arr, keysShort[0]); if (ind >= 0) { iCountErrors++; Console.WriteLine("Err_0007d, Keys still contains removed value " + ind); } Console.WriteLine(" - add element to the dictionary"); hd.Add(keysShort[0], "new item"); if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0007e, didn't add element"); } if (ks.Count != len) { iCountErrors++; Console.WriteLine("Err_0007f, Keys were not updated after addition"); } iCountTestcases++; arr = Array.CreateInstance(typeof(Object), hd.Count); ks.CopyTo(arr, 0); ind = Array.IndexOf(arr, keysShort[0]); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0007g, Keys doesn't contain added value "); } } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_general! strLoc==" + strLoc + ", exc_general==\n" + exc_general.ToString()); } if (iCountErrors == 0) { Console.WriteLine("Pass. " + s_strTFPath + " " + s_strTFName + " ,iCountTestcases==" + iCountTestcases); return(true); } else { Console.WriteLine("Fail! " + s_strTFPath + " " + s_strTFName + " ,iCountErrors==" + iCountErrors + " , BugNums?: " + s_strActiveBugNums); return(false); } }
//-------------------------------------------------------------------- // // private Properties // //--------------------------------------------------------------------- #region Private Properties #endregion Private Properties //-------------------------------------------------------------------- // // Private Methods // //--------------------------------------------------------------------- #region Private Methods private void _Init() { InheritanceBehavior = InheritanceBehavior.SkipToAppNow; _pendingStreams = new HybridDictionary(); }
public void Test01() { IntlStrings intl; HybridDictionary hd; const int BIG_LENGTH = 100; // simple string values string[] valuesShort = { "", " ", "$%^#", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; // keys for simple string values string[] keysShort = { Int32.MaxValue.ToString(), " ", System.DateTime.Today.ToString(), "", "$%^#" }; string[] valuesLong = new string[BIG_LENGTH]; string[] keysLong = new string[BIG_LENGTH]; int cnt = 0; // Count // initialize IntStrings intl = new IntlStrings(); for (int i = 0; i < BIG_LENGTH; i++) { valuesLong[i] = "Item" + i; keysLong[i] = "keY" + i; } // [] HybridDictionary is constructed as expected //----------------------------------------------------------------- // [] simple strings hd = new HybridDictionary(); for (int i = 0; i < valuesShort.Length; i++) { cnt = hd.Count; hd.Add(keysShort[i], valuesShort[i]); if (hd.Count != cnt + 1) { Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, hd.Count, cnt + 1)); } // access the item // if (String.Compare(hd[keysShort[i]].ToString(), valuesShort[i]) != 0) { Assert.False(true, string.Format("Error, returned item \"{1}\" instead of \"{2}\"", i, hd[keysShort[i]], valuesShort[i])); } } // increase the number of items for (int i = 0; i < valuesLong.Length; i++) { cnt = hd.Count; hd.Add(keysLong[i], valuesLong[i]); if (hd.Count != cnt + 1) { Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, hd.Count, cnt + 1)); } // access the item // if (String.Compare(hd[keysLong[i]].ToString(), valuesLong[i]) != 0) { Assert.False(true, string.Format("Error, returned item \"{1}\" instead of \"{2}\"", i, hd[keysLong[i]], valuesLong[i])); } } // // [] Intl strings // int len = valuesShort.Length; hd.Clear(); string[] intlValues = new string[len * 2]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { string val = intl.GetRandomString(MAX_LEN); while (Array.IndexOf(intlValues, val) != -1) { val = intl.GetRandomString(MAX_LEN); } intlValues[i] = val; } Boolean caseInsensitive = false; for (int i = 0; i < len * 2; i++) { if (intlValues[i].Length != 0 && intlValues[i].ToLower() == intlValues[i].ToUpper()) { caseInsensitive = true; } } // // will use first half of array as valuesShort and second half as keysShort // for (int i = 0; i < len; i++) { cnt = hd.Count; hd.Add(intlValues[i + len], intlValues[i]); if (hd.Count != cnt + 1) { Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, hd.Count, cnt + 1)); } // access the item // if (String.Compare(hd[intlValues[i + len]].ToString(), intlValues[i]) != 0) { Assert.False(true, string.Format("Error, returned item \"{1}\" instead of \"{2}\"", i, hd[intlValues[i + len]], intlValues[i])); } } // increase the number of items for (int i = 0; i < valuesLong.Length; i++) { cnt = hd.Count; hd.Add(keysLong[i], intlValues[1]); if (hd.Count != cnt + 1) { Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, hd.Count, cnt + 1)); } // access the item // if (String.Compare(hd[keysLong[i]].ToString(), intlValues[1]) != 0) { Assert.False(true, string.Format("Error, returned item \"{1}\" instead of \"{2}\"", i, hd[keysLong[i]], intlValues[1])); } } // // [] Case sensitivity // Casing doesn't change ( keysShort are not converted to lower!) // string[] intlValuesLower = new string[len * 2]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { intlValues[i] = intlValues[i].ToUpper(); } for (int i = 0; i < len * 2; i++) { intlValuesLower[i] = intlValues[i].ToLower(); } hd.Clear(); // // will use first half of array as valuesShort and second half as keysShort // for (int i = 0; i < len; i++) { cnt = hd.Count; hd.Add(intlValues[i + len], intlValues[i]); if (hd.Count != cnt + 1) { Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, hd.Count, cnt + 1)); } // access the item // if (hd[intlValues[i + len]] == null) { Assert.False(true, string.Format("Error, returned null", i)); } else { if (!hd[intlValues[i + len]].Equals(intlValues[i])) { Assert.False(true, string.Format("Error, returned item \"{1}\" instead of \"{2}\"", i, hd[intlValues[i + len]], intlValues[i])); } } // verify that dictionary doesn't contains lowercase item // if (!caseInsensitive && hd[intlValuesLower[i + len]] != null) { Assert.False(true, string.Format("Error, returned non-null", i)); } } // // [] Add multiple valuesShort with the same key // Add multiple valuesShort with the same key - ArgumentException expected // hd.Clear(); len = valuesShort.Length; string k = "keykey"; hd.Add(k, "value"); Assert.Throws <ArgumentException>(() => { hd.Add(k, "newvalue"); }); // // [] Add null value // cnt = hd.Count; k = "kk"; hd.Add(k, null); if (hd.Count != cnt + 1) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, cnt + 1)); } // verify that dictionary contains null // if (hd[k] != null) { Assert.False(true, string.Format("Error, returned non-null on place of null")); } // // [] Add item with null key // Add item with null key - ArgumentNullException expected // cnt = hd.Count; Assert.Throws <ArgumentNullException>(() => { hd.Add(null, "item"); }); // // [] Add duplicate values // hd.Clear(); for (int i = 0; i < valuesShort.Length; i++) { cnt = hd.Count; hd.Add(keysShort[i], "value"); if (hd.Count != cnt + 1) { Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, hd.Count, cnt + 1)); } // access the item // if (!hd[keysShort[i]].Equals("value")) { Assert.False(true, string.Format("Error, returned item \"{1}\" instead of \"{2}\"", i, hd[keysShort[i]], "value")); } } // verify Keys and Values if (hd.Keys.Count != valuesShort.Length) { Assert.False(true, string.Format("Error, Keys contains {0} instead of {1}", hd.Keys.Count, valuesShort.Length)); } if (hd.Values.Count != valuesShort.Length) { Assert.False(true, string.Format("Error, Values contains {0} instead of {1}", hd.Values.Count, valuesShort.Length)); } // // [] add many simple strings // hd = new HybridDictionary(); for (int i = 0; i < valuesLong.Length; i++) { cnt = hd.Count; hd.Add(keysLong[i], valuesLong[i]); if (hd.Count != cnt + 1) { Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, hd.Count, cnt + 1)); } // access the item // if (String.Compare(hd[keysLong[i]].ToString(), valuesLong[i]) != 0) { Assert.False(true, string.Format("Error, returned item \"{1}\" instead of \"{2}\"", i, hd[keysLong[i]], valuesLong[i])); } } // increase the number of items for (int i = 0; i < valuesLong.Length; i++) { cnt = hd.Count; hd.Add(keysLong[i] + "_", valuesLong[i] + i); if (hd.Count != cnt + 1) { Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, hd.Count, cnt + 1)); } // access the item // if (String.Compare(hd[keysLong[i] + "_"].ToString(), valuesLong[i] + i) != 0) { Assert.False(true, string.Format("Error, returned item \"{1}\" instead of \"{2}\"", i, hd[keysLong[i] + "_"], valuesLong[i] + i)); } } }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; HybridDictionary hd; const int BIG_LENGTH = 100; string [] valuesLong = new string[BIG_LENGTH]; string [] keysLong = new string[BIG_LENGTH]; int len; try { for (int i = 0; i < BIG_LENGTH; i++) { valuesLong[i] = "Item" + i; keysLong[i] = "keY" + i; } Console.WriteLine("--- ctor (false) ---"); strLoc = "Loc_001ooA-false"; iCountTestcases++; Console.WriteLine(" A. ctor(0, false)"); strLoc = "Loc_000ooA"; hd = new HybridDictionary(0, false); Console.WriteLine("1. compare to null"); iCountTestcases++; if (hd == null) { iCountErrors++; Console.WriteLine("Err_0001, dictionary is null after default ctor"); } Console.WriteLine("2. check Count"); iCountTestcases++; if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0002, Count = {0} after default ctor", hd.Count); } Console.WriteLine("3. check Item(some_key)"); iCountTestcases++; if (hd["key"] != null) { iCountErrors++; Console.WriteLine("Err_0003, Item(some_key) returned non-null after default ctor"); } Console.WriteLine("4. check ToString()"); iCountTestcases++; string temp = hd.ToString(); Console.WriteLine(" ToString(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0004, ToString() doesn't contain \"HybridDictionary\""); } Console.WriteLine("5. check returned Type"); iCountTestcases++; temp = hd.GetType().ToString().Trim(); Console.WriteLine(" GetType(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0005: returned type doesn't contain \"HybridDictionary\""); } Console.WriteLine("6. Add(name, value)"); iCountTestcases++; hd.Add("Name", "Value"); if (hd.Count != 1) { iCountErrors++; Console.WriteLine("Err_0006a: Count returned {0} instead of 1", hd.Count); } if (String.Compare(hd["Name"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0006b: Item() returned unexpected value"); } hd.Add("NaMe", "Value"); if (hd.Count != 2) { iCountErrors++; Console.WriteLine("Err_0006c: Count returned {0} instead of 2", hd.Count); } if (String.Compare(hd["NaMe"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0006d: Item() returned unexpected value"); } if (hd["NAME"] != null) { iCountErrors++; Console.WriteLine("Err_0006e: Item() returned non-null value for uppercase key"); } Console.WriteLine("7. Clear() short dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0007a: Count returned {0} instead of 0 after Clear()", hd.Count); } if (hd["Name"] != null) { iCountErrors++; Console.WriteLine("Err_0007b: Item() returned non-null value after Clear()"); } Console.WriteLine("8. multiple Add(name, value)"); iCountTestcases++; len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } iCountTestcases++; if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_008a: Count returned {0} instead of {1}", hd.Count, len); } for (int i = 0; i < len; i++) { iCountTestcases++; if (String.Compare(hd[keysLong[i]].ToString(), valuesLong[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_008b_{0}: Item() returned unexpected value", i); } if (hd[keysLong[i].ToUpper()] != null) { iCountErrors++; Console.WriteLine("Err_008c_{0}: Item() returned non-null for uppercase key", i); } } Console.WriteLine("9. Clear() long dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0009: Count returned {0} instead of 0 after Clear()", hd.Count); } Console.WriteLine(" B. ctor(10, false)"); strLoc = "Loc_000ooB-false"; hd = new HybridDictionary(10, false); Console.WriteLine("1. compare to null"); iCountTestcases++; if (hd == null) { iCountErrors++; Console.WriteLine("Err_0001, dictionary is null after default ctor"); } Console.WriteLine("2. check Count"); iCountTestcases++; if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0002, Count = {0} after default ctor", hd.Count); } Console.WriteLine("3. check Item(some_key)"); iCountTestcases++; if (hd["key"] != null) { iCountErrors++; Console.WriteLine("Err_0003, Item(some_key) returned non-null after default ctor"); } Console.WriteLine("4. check ToString()"); iCountTestcases++; temp = hd.ToString(); Console.WriteLine(" ToString(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0004, ToString() doesn't contain \"HybridDictionary\""); } Console.WriteLine("5. check returned Type"); iCountTestcases++; temp = hd.GetType().ToString().Trim(); Console.WriteLine(" GetType(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0005: returned type doesn't contain \"HybridDictionary\""); } Console.WriteLine("6. Add(name, value)"); iCountTestcases++; hd.Add("Name", "Value"); if (hd.Count != 1) { iCountErrors++; Console.WriteLine("Err_0006a: Count returned {0} instead of 1", hd.Count); } if (String.Compare(hd["Name"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0006b: Item() returned unexpected value"); } hd.Add("NaMe", "Value"); if (hd.Count != 2) { iCountErrors++; Console.WriteLine("Err_0006c: Count returned {0} instead of 2", hd.Count); } if (String.Compare(hd["NaMe"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0006d: Item() returned unexpected value"); } if (hd["NAME"] != null) { iCountErrors++; Console.WriteLine("Err_0006e: Item() returned non-null value for uppercase key"); } Console.WriteLine("7. Clear() short dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0007a: Count returned {0} instead of 0 after Clear()", hd.Count); } if (hd["Name"] != null) { iCountErrors++; Console.WriteLine("Err_0007b: Item() returned non-null value after Clear()"); } Console.WriteLine("8. multiple Add(name, value)"); iCountTestcases++; len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } iCountTestcases++; if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_008a: Count returned {0} instead of {1}", hd.Count, len); } for (int i = 0; i < len; i++) { iCountTestcases++; if (String.Compare(hd[keysLong[i]].ToString(), valuesLong[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_008b_{0}: Item() returned unexpected value", i); } if (hd[keysLong[i].ToUpper()] != null) { iCountErrors++; Console.WriteLine("Err_008c_{0}: Item() returned non-null for uppercase key", i); } } Console.WriteLine("9. Clear() long dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0009: Count returned {0} instead of 0 after Clear()", hd.Count); } Console.WriteLine(" C. ctor(100, false)"); strLoc = "Loc_000ooC-false"; hd = new HybridDictionary(100, false); Console.WriteLine("1. compare to null"); iCountTestcases++; if (hd == null) { iCountErrors++; Console.WriteLine("Err_0001, dictionary is null after default ctor"); } Console.WriteLine("2. check Count"); iCountTestcases++; if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0002, Count = {0} after default ctor", hd.Count); } Console.WriteLine("3. check Item(some_key)"); iCountTestcases++; if (hd["key"] != null) { iCountErrors++; Console.WriteLine("Err_0003, Item(some_key) returned non-null after default ctor"); } Console.WriteLine("4. check ToString()"); iCountTestcases++; temp = hd.ToString(); Console.WriteLine(" ToString(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0004, ToString() doesn't contain \"HybridDictionary\""); } Console.WriteLine("5. check returned Type"); iCountTestcases++; temp = hd.GetType().ToString().Trim(); Console.WriteLine(" GetType(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0005: returned type doesn't contain \"HybridDictionary\""); } Console.WriteLine("6. Add(name, value)"); iCountTestcases++; hd.Add("Name", "Value"); if (hd.Count != 1) { iCountErrors++; Console.WriteLine("Err_0006a: Count returned {0} instead of 1", hd.Count); } if (String.Compare(hd["Name"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0006b: Item() returned unexpected value"); } hd.Add("NaMe", "Value"); if (hd.Count != 2) { iCountErrors++; Console.WriteLine("Err_0006c: Count returned {0} instead of 2", hd.Count); } if (String.Compare(hd["NaMe"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0006d: Item() returned unexpected value"); } if (hd["NAME"] != null) { iCountErrors++; Console.WriteLine("Err_0006e: Item() returned non-null value for uppercase key"); } Console.WriteLine("7. Clear() short dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0007a: Count returned {0} instead of 0 after Clear()", hd.Count); } if (hd["Name"] != null) { iCountErrors++; Console.WriteLine("Err_0007b: Item() returned non-null value after Clear()"); } Console.WriteLine("8. multiple Add(name, value)"); iCountTestcases++; len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } iCountTestcases++; if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_008a: Count returned {0} instead of {1}", hd.Count, len); } for (int i = 0; i < len; i++) { iCountTestcases++; if (String.Compare(hd[keysLong[i]].ToString(), valuesLong[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_008b_{0}: Item() returned unexpected value", i); } if (hd[keysLong[i].ToUpper()] != null) { iCountErrors++; Console.WriteLine("Err_008c_{0}: Item() returned non-null for uppercase key", i); } } Console.WriteLine("9. Clear() long dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0009: Count returned {0} instead of 0 after Clear()", hd.Count); } Console.WriteLine(""); Console.WriteLine("--- ctor (true) ---"); strLoc = "Loc_000ooA-true"; iCountTestcases++; Console.WriteLine(" A. ctor(0, true)"); hd = new HybridDictionary(0, true); Console.WriteLine("1. compare to null"); iCountTestcases++; if (hd == null) { iCountErrors++; Console.WriteLine("Err_0001, dictionary is null after default ctor"); } Console.WriteLine("2. check Count"); iCountTestcases++; if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0002, Count = {0} after default ctor", hd.Count); } Console.WriteLine("3. check Item(some_key)"); iCountTestcases++; if (hd["key"] != null) { iCountErrors++; Console.WriteLine("Err_0003, Item(some_key) returned non-null after default ctor"); } Console.WriteLine("4. check ToString()"); iCountTestcases++; temp = hd.ToString(); Console.WriteLine(" ToString(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0004, ToString() doesn't contain \"HybridDictionary\""); } Console.WriteLine("5. check returned Type"); iCountTestcases++; temp = hd.GetType().ToString().Trim(); Console.WriteLine(" GetType(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0005: returned type doesn't contain \"HybridDictionary\""); } Console.WriteLine("6. Add(name, value)"); iCountTestcases++; hd.Add("Name", "Value"); if (hd.Count != 1) { iCountErrors++; Console.WriteLine("Err_0006a: Count returned {0} instead of 1", hd.Count); } if (String.Compare(hd["Name"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0006b: Item() returned unexpected value"); } try { hd.Add("NaMe", "vl"); iCountErrors++; Console.WriteLine("Err_0006Noex: no exception"); } catch (ArgumentException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0006ex: unexpected exception: {0}", e.ToString()); } if (hd.Count != 1) { iCountErrors++; Console.WriteLine("Err_0006a: Count returned {0} instead of 1", hd.Count); } if (String.Compare(hd["NAME"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0006b: Item() returned unexpected value for uppercase key"); } Console.WriteLine("7. Clear() short dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0007a: Count returned {0} instead of 0 after Clear()", hd.Count); } if (hd["Name"] != null) { iCountErrors++; Console.WriteLine("Err_0007b: Item() returned non-null value after Clear()"); } Console.WriteLine("8. multiple Add(name, value)"); iCountTestcases++; len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } iCountTestcases++; if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_008a: Count returned {0} instead of {1}", hd.Count, len); } for (int i = 0; i < len; i++) { iCountTestcases++; if (String.Compare(hd[keysLong[i]].ToString(), valuesLong[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_008b_{0}: Item() returned unexpected value", i); } if (String.Compare(hd[keysLong[i].ToUpper()].ToString(), valuesLong[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_008c_{0}: Item() returned unexpected value for uppercase key", i); } } Console.WriteLine("9. Clear() long dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0009: Count returned {0} instead of 0 after Clear()", hd.Count); } Console.WriteLine("--- ctor (true) ---"); strLoc = "Loc_000ooB-true"; iCountTestcases++; Console.WriteLine(" B. ctor(10, true)"); hd = new HybridDictionary(10, true); Console.WriteLine("1. compare to null"); iCountTestcases++; if (hd == null) { iCountErrors++; Console.WriteLine("Err_0001, dictionary is null after default ctor"); } Console.WriteLine("2. check Count"); iCountTestcases++; if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0002, Count = {0} after default ctor", hd.Count); } Console.WriteLine("3. check Item(some_key)"); iCountTestcases++; if (hd["key"] != null) { iCountErrors++; Console.WriteLine("Err_0003, Item(some_key) returned non-null after default ctor"); } Console.WriteLine("4. check ToString()"); iCountTestcases++; temp = hd.ToString(); Console.WriteLine(" ToString(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0004, ToString() doesn't contain \"HybridDictionary\""); } Console.WriteLine("5. check returned Type"); iCountTestcases++; temp = hd.GetType().ToString().Trim(); Console.WriteLine(" GetType(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0005: returned type doesn't contain \"HybridDictionary\""); } Console.WriteLine("6. Add(name, value)"); iCountTestcases++; hd.Add("Name", "Value"); if (hd.Count != 1) { iCountErrors++; Console.WriteLine("Err_0006a: Count returned {0} instead of 1", hd.Count); } if (String.Compare(hd["Name"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0006b: Item() returned unexpected value"); } try { hd.Add("NaMe", "vl"); iCountErrors++; Console.WriteLine("Err_0006Noex: no exception"); } catch (ArgumentException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0006ex: unexpected exception: {0}", e.ToString()); } if (hd.Count != 1) { iCountErrors++; Console.WriteLine("Err_0006a: Count returned {0} instead of 1", hd.Count); } if (String.Compare(hd["NAME"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0006b: Item() returned unexpected value for uppercase key"); } Console.WriteLine("7. Clear() short dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0007a: Count returned {0} instead of 0 after Clear()", hd.Count); } if (hd["Name"] != null) { iCountErrors++; Console.WriteLine("Err_0007b: Item() returned non-null value after Clear()"); } Console.WriteLine("8. multiple Add(name, value)"); iCountTestcases++; len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } iCountTestcases++; if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_008a: Count returned {0} instead of {1}", hd.Count, len); } for (int i = 0; i < len; i++) { iCountTestcases++; if (String.Compare(hd[keysLong[i]].ToString(), valuesLong[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_008b_{0}: Item() returned unexpected value", i); } if (String.Compare(hd[keysLong[i].ToUpper()].ToString(), valuesLong[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_008c_{0}: Item() returned unexpected value for uppercase key", i); } } Console.WriteLine("9. Clear() long dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0009: Count returned {0} instead of 0 after Clear()", hd.Count); } Console.WriteLine("--- ctor (true) ---"); strLoc = "Loc_000ooC-true"; iCountTestcases++; Console.WriteLine(" C. ctor(100, true)"); hd = new HybridDictionary(100, true); Console.WriteLine("1. compare to null"); iCountTestcases++; if (hd == null) { iCountErrors++; Console.WriteLine("Err_0001, dictionary is null after default ctor"); } Console.WriteLine("2. check Count"); iCountTestcases++; if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0002, Count = {0} after default ctor", hd.Count); } Console.WriteLine("3. check Item(some_key)"); iCountTestcases++; if (hd["key"] != null) { iCountErrors++; Console.WriteLine("Err_0003, Item(some_key) returned non-null after default ctor"); } Console.WriteLine("4. check ToString()"); iCountTestcases++; temp = hd.ToString(); Console.WriteLine(" ToString(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0004, ToString() doesn't contain \"HybridDictionary\""); } Console.WriteLine("5. check returned Type"); iCountTestcases++; temp = hd.GetType().ToString().Trim(); Console.WriteLine(" GetType(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0005: returned type doesn't contain \"HybridDictionary\""); } Console.WriteLine("6. Add(name, value)"); iCountTestcases++; hd.Add("Name", "Value"); if (hd.Count != 1) { iCountErrors++; Console.WriteLine("Err_0006a: Count returned {0} instead of 1", hd.Count); } if (String.Compare(hd["Name"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0006b: Item() returned unexpected value"); } try { hd.Add("NaMe", "vl"); iCountErrors++; Console.WriteLine("Err_0006Noex: no exception"); } catch (ArgumentException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0006ex: unexpected exception: {0}", e.ToString()); } if (hd.Count != 1) { iCountErrors++; Console.WriteLine("Err_0006a: Count returned {0} instead of 1", hd.Count); } if (String.Compare(hd["NAME"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0006b: Item() returned unexpected value for uppercase key"); } Console.WriteLine("7. Clear() short dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0007a: Count returned {0} instead of 0 after Clear()", hd.Count); } if (hd["Name"] != null) { iCountErrors++; Console.WriteLine("Err_0007b: Item() returned non-null value after Clear()"); } Console.WriteLine("8. multiple Add(name, value)"); iCountTestcases++; len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } iCountTestcases++; if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_008a: Count returned {0} instead of {1}", hd.Count, len); } for (int i = 0; i < len; i++) { iCountTestcases++; if (String.Compare(hd[keysLong[i]].ToString(), valuesLong[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_008b_{0}: Item() returned unexpected value", i); } if (String.Compare(hd[keysLong[i].ToUpper()].ToString(), valuesLong[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_008c_{0}: Item() returned unexpected value for uppercase key", i); } } Console.WriteLine("9. Clear() long dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0009: Count returned {0} instead of 0 after Clear()", hd.Count); } } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_general! strLoc==" + strLoc + ", exc_general==\n" + exc_general.ToString()); } if (iCountErrors == 0) { Console.WriteLine("Pass. " + s_strTFPath + " " + s_strTFName + " ,iCountTestcases==" + iCountTestcases); return(true); } else { Console.WriteLine("Fail! " + s_strTFPath + " " + s_strTFName + " ,iCountErrors==" + iCountErrors + " , BugNums?: " + s_strActiveBugNums); return(false); } }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; HybridDictionary hd; const int BIG_LENGTH = 100; string [] valuesLong = new string[BIG_LENGTH]; string [] keysLong = new string[BIG_LENGTH]; int len; try { for (int i = 0; i < BIG_LENGTH; i++) { valuesLong[i] = "Item" + i; keysLong[i] = "keY" + i; } Console.WriteLine("--- ctor (false) ---"); strLoc = "Loc_001ooA-false"; iCountTestcases++; Console.WriteLine(" A. ctor(0, false)"); strLoc = "Loc_000ooA"; hd = new HybridDictionary(0, false); Console.WriteLine("1. compare to null"); iCountTestcases++; if (hd == null) { iCountErrors++; Console.WriteLine("Err_0001, dictionary is null after default ctor"); } Console.WriteLine("2. check Count"); iCountTestcases++; if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0002, Count = {0} after default ctor", hd.Count); } Console.WriteLine("3. check Item(some_key)"); iCountTestcases++; if (hd["key"] != null) { iCountErrors++; Console.WriteLine("Err_0003, Item(some_key) returned non-null after default ctor"); } Console.WriteLine("4. check ToString()"); iCountTestcases++; string temp = hd.ToString(); Console.WriteLine(" ToString(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0004, ToString() doesn't contain \"HybridDictionary\""); } Console.WriteLine("5. check returned Type"); iCountTestcases++; temp = hd.GetType().ToString().Trim(); Console.WriteLine(" GetType(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0005: returned type doesn't contain \"HybridDictionary\""); } Console.WriteLine("6. Add(name, value)"); iCountTestcases++; hd.Add("Name", "Value"); if (hd.Count != 1) { iCountErrors++; Console.WriteLine("Err_0006a: Count returned {0} instead of 1", hd.Count); } if (String.Compare(hd["Name"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0006b: Item() returned unexpected value"); } hd.Add("NaMe", "Value"); if (hd.Count != 2) { iCountErrors++; Console.WriteLine("Err_0006c: Count returned {0} instead of 2", hd.Count); } if (String.Compare(hd["NaMe"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0006d: Item() returned unexpected value"); } if (hd["NAME"] != null) { iCountErrors++; Console.WriteLine("Err_0006e: Item() returned non-null value for uppercase key"); } Console.WriteLine("7. Clear() short dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0007a: Count returned {0} instead of 0 after Clear()", hd.Count); } if (hd["Name"] != null) { iCountErrors++; Console.WriteLine("Err_0007b: Item() returned non-null value after Clear()"); } Console.WriteLine("8. multiple Add(name, value)"); iCountTestcases++; len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } iCountTestcases++; if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_008a: Count returned {0} instead of {1}", hd.Count, len); } for (int i = 0; i < len; i++) { iCountTestcases++; if (String.Compare(hd[keysLong[i]].ToString(), valuesLong[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_008b_{0}: Item() returned unexpected value", i); } if (hd[keysLong[i].ToUpper()] != null) { iCountErrors++; Console.WriteLine("Err_008c_{0}: Item() returned non-null for uppercase key", i); } } Console.WriteLine("9. Clear() long dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0009: Count returned {0} instead of 0 after Clear()", hd.Count); } Console.WriteLine(" B. ctor(10, false)"); strLoc = "Loc_000ooB-false"; hd = new HybridDictionary(10, false); Console.WriteLine("1. compare to null"); iCountTestcases++; if (hd == null) { iCountErrors++; Console.WriteLine("Err_0001, dictionary is null after default ctor"); } Console.WriteLine("2. check Count"); iCountTestcases++; if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0002, Count = {0} after default ctor", hd.Count); } Console.WriteLine("3. check Item(some_key)"); iCountTestcases++; if (hd["key"] != null) { iCountErrors++; Console.WriteLine("Err_0003, Item(some_key) returned non-null after default ctor"); } Console.WriteLine("4. check ToString()"); iCountTestcases++; temp = hd.ToString(); Console.WriteLine(" ToString(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0004, ToString() doesn't contain \"HybridDictionary\""); } Console.WriteLine("5. check returned Type"); iCountTestcases++; temp = hd.GetType().ToString().Trim(); Console.WriteLine(" GetType(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0005: returned type doesn't contain \"HybridDictionary\""); } Console.WriteLine("6. Add(name, value)"); iCountTestcases++; hd.Add("Name", "Value"); if (hd.Count != 1) { iCountErrors++; Console.WriteLine("Err_0006a: Count returned {0} instead of 1", hd.Count); } if (String.Compare(hd["Name"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0006b: Item() returned unexpected value"); } hd.Add("NaMe", "Value"); if (hd.Count != 2) { iCountErrors++; Console.WriteLine("Err_0006c: Count returned {0} instead of 2", hd.Count); } if (String.Compare(hd["NaMe"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0006d: Item() returned unexpected value"); } if (hd["NAME"] != null) { iCountErrors++; Console.WriteLine("Err_0006e: Item() returned non-null value for uppercase key"); } Console.WriteLine("7. Clear() short dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0007a: Count returned {0} instead of 0 after Clear()", hd.Count); } if (hd["Name"] != null) { iCountErrors++; Console.WriteLine("Err_0007b: Item() returned non-null value after Clear()"); } Console.WriteLine("8. multiple Add(name, value)"); iCountTestcases++; len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } iCountTestcases++; if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_008a: Count returned {0} instead of {1}", hd.Count, len); } for (int i = 0; i < len; i++) { iCountTestcases++; if (String.Compare(hd[keysLong[i]].ToString(), valuesLong[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_008b_{0}: Item() returned unexpected value", i); } if (hd[keysLong[i].ToUpper()] != null) { iCountErrors++; Console.WriteLine("Err_008c_{0}: Item() returned non-null for uppercase key", i); } } Console.WriteLine("9. Clear() long dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0009: Count returned {0} instead of 0 after Clear()", hd.Count); } Console.WriteLine(" C. ctor(100, false)"); strLoc = "Loc_000ooC-false"; hd = new HybridDictionary(100, false); Console.WriteLine("1. compare to null"); iCountTestcases++; if (hd == null) { iCountErrors++; Console.WriteLine("Err_0001, dictionary is null after default ctor"); } Console.WriteLine("2. check Count"); iCountTestcases++; if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0002, Count = {0} after default ctor", hd.Count); } Console.WriteLine("3. check Item(some_key)"); iCountTestcases++; if (hd["key"] != null) { iCountErrors++; Console.WriteLine("Err_0003, Item(some_key) returned non-null after default ctor"); } Console.WriteLine("4. check ToString()"); iCountTestcases++; temp = hd.ToString(); Console.WriteLine(" ToString(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0004, ToString() doesn't contain \"HybridDictionary\""); } Console.WriteLine("5. check returned Type"); iCountTestcases++; temp = hd.GetType().ToString().Trim(); Console.WriteLine(" GetType(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0005: returned type doesn't contain \"HybridDictionary\""); } Console.WriteLine("6. Add(name, value)"); iCountTestcases++; hd.Add("Name", "Value"); if (hd.Count != 1) { iCountErrors++; Console.WriteLine("Err_0006a: Count returned {0} instead of 1", hd.Count); } if (String.Compare(hd["Name"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0006b: Item() returned unexpected value"); } hd.Add("NaMe", "Value"); if (hd.Count != 2) { iCountErrors++; Console.WriteLine("Err_0006c: Count returned {0} instead of 2", hd.Count); } if (String.Compare(hd["NaMe"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0006d: Item() returned unexpected value"); } if (hd["NAME"] != null) { iCountErrors++; Console.WriteLine("Err_0006e: Item() returned non-null value for uppercase key"); } Console.WriteLine("7. Clear() short dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0007a: Count returned {0} instead of 0 after Clear()", hd.Count); } if (hd["Name"] != null) { iCountErrors++; Console.WriteLine("Err_0007b: Item() returned non-null value after Clear()"); } Console.WriteLine("8. multiple Add(name, value)"); iCountTestcases++; len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } iCountTestcases++; if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_008a: Count returned {0} instead of {1}", hd.Count, len); } for (int i = 0; i < len; i++) { iCountTestcases++; if (String.Compare(hd[keysLong[i]].ToString(), valuesLong[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_008b_{0}: Item() returned unexpected value", i); } if (hd[keysLong[i].ToUpper()] != null) { iCountErrors++; Console.WriteLine("Err_008c_{0}: Item() returned non-null for uppercase key", i); } } Console.WriteLine("9. Clear() long dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0009: Count returned {0} instead of 0 after Clear()", hd.Count); } Console.WriteLine(""); Console.WriteLine("--- ctor (true) ---"); strLoc = "Loc_000ooA-true"; iCountTestcases++; Console.WriteLine(" A. ctor(0, true)"); hd = new HybridDictionary(0, true); Console.WriteLine("1. compare to null"); iCountTestcases++; if (hd == null) { iCountErrors++; Console.WriteLine("Err_0001, dictionary is null after default ctor"); } Console.WriteLine("2. check Count"); iCountTestcases++; if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0002, Count = {0} after default ctor", hd.Count); } Console.WriteLine("3. check Item(some_key)"); iCountTestcases++; if (hd["key"] != null) { iCountErrors++; Console.WriteLine("Err_0003, Item(some_key) returned non-null after default ctor"); } Console.WriteLine("4. check ToString()"); iCountTestcases++; temp = hd.ToString(); Console.WriteLine(" ToString(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0004, ToString() doesn't contain \"HybridDictionary\""); } Console.WriteLine("5. check returned Type"); iCountTestcases++; temp = hd.GetType().ToString().Trim(); Console.WriteLine(" GetType(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0005: returned type doesn't contain \"HybridDictionary\""); } Console.WriteLine("6. Add(name, value)"); iCountTestcases++; hd.Add("Name", "Value"); if (hd.Count != 1) { iCountErrors++; Console.WriteLine("Err_0006a: Count returned {0} instead of 1", hd.Count); } if (String.Compare(hd["Name"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0006b: Item() returned unexpected value"); } try { hd.Add("NaMe", "vl"); iCountErrors++; Console.WriteLine("Err_0006Noex: no exception"); } catch (ArgumentException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0006ex: unexpected exception: {0}", e.ToString()); } if (hd.Count != 1) { iCountErrors++; Console.WriteLine("Err_0006a: Count returned {0} instead of 1", hd.Count); } if (String.Compare(hd["NAME"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0006b: Item() returned unexpected value for uppercase key"); } Console.WriteLine("7. Clear() short dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0007a: Count returned {0} instead of 0 after Clear()", hd.Count); } if (hd["Name"] != null) { iCountErrors++; Console.WriteLine("Err_0007b: Item() returned non-null value after Clear()"); } Console.WriteLine("8. multiple Add(name, value)"); iCountTestcases++; len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } iCountTestcases++; if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_008a: Count returned {0} instead of {1}", hd.Count, len); } for (int i = 0; i < len; i++) { iCountTestcases++; if (String.Compare(hd[keysLong[i]].ToString(), valuesLong[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_008b_{0}: Item() returned unexpected value", i); } if (String.Compare(hd[keysLong[i].ToUpper()].ToString(), valuesLong[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_008c_{0}: Item() returned unexpected value for uppercase key", i); } } Console.WriteLine("9. Clear() long dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0009: Count returned {0} instead of 0 after Clear()", hd.Count); } Console.WriteLine("--- ctor (true) ---"); strLoc = "Loc_000ooB-true"; iCountTestcases++; Console.WriteLine(" B. ctor(10, true)"); hd = new HybridDictionary(10, true); Console.WriteLine("1. compare to null"); iCountTestcases++; if (hd == null) { iCountErrors++; Console.WriteLine("Err_0001, dictionary is null after default ctor"); } Console.WriteLine("2. check Count"); iCountTestcases++; if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0002, Count = {0} after default ctor", hd.Count); } Console.WriteLine("3. check Item(some_key)"); iCountTestcases++; if (hd["key"] != null) { iCountErrors++; Console.WriteLine("Err_0003, Item(some_key) returned non-null after default ctor"); } Console.WriteLine("4. check ToString()"); iCountTestcases++; temp = hd.ToString(); Console.WriteLine(" ToString(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0004, ToString() doesn't contain \"HybridDictionary\""); } Console.WriteLine("5. check returned Type"); iCountTestcases++; temp = hd.GetType().ToString().Trim(); Console.WriteLine(" GetType(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0005: returned type doesn't contain \"HybridDictionary\""); } Console.WriteLine("6. Add(name, value)"); iCountTestcases++; hd.Add("Name", "Value"); if (hd.Count != 1) { iCountErrors++; Console.WriteLine("Err_0006a: Count returned {0} instead of 1", hd.Count); } if (String.Compare(hd["Name"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0006b: Item() returned unexpected value"); } try { hd.Add("NaMe", "vl"); iCountErrors++; Console.WriteLine("Err_0006Noex: no exception"); } catch (ArgumentException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0006ex: unexpected exception: {0}", e.ToString()); } if (hd.Count != 1) { iCountErrors++; Console.WriteLine("Err_0006a: Count returned {0} instead of 1", hd.Count); } if (String.Compare(hd["NAME"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0006b: Item() returned unexpected value for uppercase key"); } Console.WriteLine("7. Clear() short dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0007a: Count returned {0} instead of 0 after Clear()", hd.Count); } if (hd["Name"] != null) { iCountErrors++; Console.WriteLine("Err_0007b: Item() returned non-null value after Clear()"); } Console.WriteLine("8. multiple Add(name, value)"); iCountTestcases++; len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } iCountTestcases++; if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_008a: Count returned {0} instead of {1}", hd.Count, len); } for (int i = 0; i < len; i++) { iCountTestcases++; if (String.Compare(hd[keysLong[i]].ToString(), valuesLong[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_008b_{0}: Item() returned unexpected value", i); } if (String.Compare(hd[keysLong[i].ToUpper()].ToString(), valuesLong[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_008c_{0}: Item() returned unexpected value for uppercase key", i); } } Console.WriteLine("9. Clear() long dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0009: Count returned {0} instead of 0 after Clear()", hd.Count); } Console.WriteLine("--- ctor (true) ---"); strLoc = "Loc_000ooC-true"; iCountTestcases++; Console.WriteLine(" C. ctor(100, true)"); hd = new HybridDictionary(100, true); Console.WriteLine("1. compare to null"); iCountTestcases++; if (hd == null) { iCountErrors++; Console.WriteLine("Err_0001, dictionary is null after default ctor"); } Console.WriteLine("2. check Count"); iCountTestcases++; if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0002, Count = {0} after default ctor", hd.Count); } Console.WriteLine("3. check Item(some_key)"); iCountTestcases++; if (hd["key"] != null) { iCountErrors++; Console.WriteLine("Err_0003, Item(some_key) returned non-null after default ctor"); } Console.WriteLine("4. check ToString()"); iCountTestcases++; temp = hd.ToString(); Console.WriteLine(" ToString(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0004, ToString() doesn't contain \"HybridDictionary\""); } Console.WriteLine("5. check returned Type"); iCountTestcases++; temp = hd.GetType().ToString().Trim(); Console.WriteLine(" GetType(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0005: returned type doesn't contain \"HybridDictionary\""); } Console.WriteLine("6. Add(name, value)"); iCountTestcases++; hd.Add("Name", "Value"); if (hd.Count != 1) { iCountErrors++; Console.WriteLine("Err_0006a: Count returned {0} instead of 1", hd.Count); } if (String.Compare(hd["Name"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0006b: Item() returned unexpected value"); } try { hd.Add("NaMe", "vl"); iCountErrors++; Console.WriteLine("Err_0006Noex: no exception"); } catch (ArgumentException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0006ex: unexpected exception: {0}", e.ToString()); } if (hd.Count != 1) { iCountErrors++; Console.WriteLine("Err_0006a: Count returned {0} instead of 1", hd.Count); } if (String.Compare(hd["NAME"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0006b: Item() returned unexpected value for uppercase key"); } Console.WriteLine("7. Clear() short dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0007a: Count returned {0} instead of 0 after Clear()", hd.Count); } if (hd["Name"] != null) { iCountErrors++; Console.WriteLine("Err_0007b: Item() returned non-null value after Clear()"); } Console.WriteLine("8. multiple Add(name, value)"); iCountTestcases++; len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } iCountTestcases++; if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_008a: Count returned {0} instead of {1}", hd.Count, len); } for (int i = 0; i < len; i++) { iCountTestcases++; if (String.Compare(hd[keysLong[i]].ToString(), valuesLong[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_008b_{0}: Item() returned unexpected value", i); } if (String.Compare(hd[keysLong[i].ToUpper()].ToString(), valuesLong[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_008c_{0}: Item() returned unexpected value for uppercase key", i); } } Console.WriteLine("9. Clear() long dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0009: Count returned {0} instead of 0 after Clear()", hd.Count); } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_general! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "Pass. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("Fail! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
public Node CreateNode(string lang, string role, int level, string currentId, Node parentNode, LocatorRelationshipInfo relation, PresentationLink pLink, bool recursive, Dimension dimensionInfo) { Node current = null; if (e == null && pLink != null) { /* Something went wrong during mergePresentation because we should have an element at * this point. Go to the presentationLink and try to get the element. */ PresentationLocator loc = null; pLink.TryGetLocator(this.HRef, out loc); if (loc != null && loc.MyElement != null) { //update the element and the child locators e = loc.MyElement; this.childLocatorsByHRef = loc.childLocatorsByHRef; } } if (e == null) { //it is a locator to an invalid element //just return null at this point... return(null); } //make sure we have the right element if there's a parent (there could be clones) Element elementToUse = e; if (dimensionInfo != null && elementToUse != null) { if (elementToUse.IsDimensionItem()) { //get the parent node if (parentNode != null) { //DimensionNode hierNode; //if (dimensionInfo.TryGetHypercubeNode(lang, // role, pLink.Role, parentNode.Id, out hierNode)) //{ // foreach (DimensionNode dn in hierNode.Children) // { // if (dn.Id == elementToUse.Id) // { // if (parentNode != null) // { // and add it // parentNode.AddChild(dn); // } // return dn; // } // } //} DimensionNode hierNode; if (dimensionInfo.TryGetHypercubeNode(lang, role, pLink.Role, parentNode.Id, true, out hierNode)) { if (hierNode.Children != null) { foreach (DimensionNode dn in hierNode.Children) { if (dn.Id == elementToUse.Id) { if (parentNode != null) { // and add it parentNode.AddChild(dn); } return(dn); } } } return(null); //strange ..could not find the correct hierarchy.. } else { return(null); } } } } current = elementToUse == null ? new Node(href) : elementToUse.CreateNode(lang, role, false); if (relation != null) { current.SetOrder(relation.Order); current.CalculationWeight = relation.CalculationWeight; if (preferredLabelRole.Equals(role)) { if (relation.PrefLabel != null) { current.UpdatePreferredLabel(lang, relation.PrefLabel); } } // now check to see if it's prohibited current.IsProhibited = relation.IsProhibited; } if (parentNode != null) { // and add it parentNode.AddChild(current); } if (childLocatorsByHRef != null && recursive) { foreach (ChildPresentationLocator cpl in childLocatorsByHRef.Values) { PresentationLocator childLocator; if (!pLink.TryGetLocator(cpl.HRef, out childLocator)) { continue; } bool innerRecursive = true; if (parentNode != null && parentNode.GetParent(cpl.HRef) != null) { //this might be ok if one of the links is a prohibitted link... innerRecursive = false; //looks like we have a recursion... } //organize locators by base order //we should have only one valid LocatorRelationshipInfo for each non xlink information... LocatorRelationshipInfo currentRelationShip = null; for (int i = cpl.LocatorRelationshipInfos.Count - 1; i >= 0; i--) { LocatorRelationshipInfo lri = cpl.LocatorRelationshipInfos[i] as LocatorRelationshipInfo; if (currentRelationShip != null && lri.IsNonXlinkEquivalentRelationship(currentRelationShip)) { continue; } currentRelationShip = lri; // always create the child childLocator.CreateNode(lang, role, level + 1, cpl.HRef, current, lri, pLink, innerRecursive, dimensionInfo); } } //need to sort the nodes if (current.Children != null) { current.Children.Sort(new NodeOrderSorter()); } } return(current); }
public void Test01() { IntlStrings intl; HybridDictionary hd; const int BIG_LENGTH = 100; // simple string values string[] valuesShort = { "", " ", "$%^#", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; // keys for simple string values string[] keysShort = { Int32.MaxValue.ToString(), " ", System.DateTime.Today.ToString(), "", "$%^#" }; string[] valuesLong = new string[BIG_LENGTH]; string[] keysLong = new string[BIG_LENGTH]; int cnt = 0; // Count // initialize IntStrings intl = new IntlStrings(); for (int i = 0; i < BIG_LENGTH; i++) { valuesLong[i] = "Item" + i; keysLong[i] = "keY" + i; } // [] HybridDictionary is constructed as expected //----------------------------------------------------------------- hd = new HybridDictionary(); // [] Contains on empty dictionary Assert.Throws <ArgumentNullException>(() => { hd.Contains(null); }); if (hd.Contains("some_string")) { Assert.False(true, string.Format("Error, empty dictionary contains some_object")); } if (hd.Contains(new Hashtable())) { Assert.False(true, string.Format("Error, empty dictionary contains some_object")); } // [] simple strings and Contains() // cnt = hd.Count; int len = valuesShort.Length; for (int i = 0; i < len; i++) { hd.Add(keysShort[i], valuesShort[i]); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, valuesShort.Length)); } // for (int i = 0; i < len; i++) { if (!hd.Contains(keysShort[i])) { Assert.False(true, string.Format("Error, doesn't contain \"{1}\"", i, keysShort[i])); } } cnt = hd.Count; len = valuesLong.Length; for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } if (hd.Count != len + cnt) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len + cnt)); } // verify new keys for (int i = 0; i < len; i++) { if (!hd.Contains(keysLong[i])) { Assert.False(true, string.Format("Error, doesn't contain \"{1}\"", i, keysLong[i])); } } // verify old keys for (int i = 0; i < valuesShort.Length; i++) { if (!hd.Contains(keysShort[i])) { Assert.False(true, string.Format("Error, doesn't contain \"{1}\"", i, keysShort[i])); } } // // [] Intl strings and Contains() // string[] intlValues = new string[len * 2]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { string val = intl.GetRandomString(MAX_LEN); while (Array.IndexOf(intlValues, val) != -1) { val = intl.GetRandomString(MAX_LEN); } intlValues[i] = val; } hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(intlValues[i + len], intlValues[i]); } if (hd.Count != (len)) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } for (int i = 0; i < len; i++) { // if (!hd.Contains(intlValues[i + len])) { Assert.False(true, string.Format("Error, doesn't contain \"{1}\"", i, intlValues[i + len])); } } // // [] Case sensitivity // by default HybridDictionary is case-sensitive // hd.Clear(); len = valuesLong.Length; // // will use first half of array as valuesShort and second half as keysShort // for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); // adding uppercase strings } // for (int i = 0; i < len; i++) { // uppercase key if (!hd.Contains(keysLong[i])) { Assert.False(true, string.Format("Error, doesn't contain added uppercase \"{1}\"", i, keysLong[i])); } // lowercase key if (hd.Contains(keysLong[i].ToUpper())) { Assert.False(true, string.Format("Error, contains uppercase \"{1}\" - should not", i, keysLong[i].ToUpper())); } } // [] different_in_casing_only keys and Contains() // hd.Clear(); string[] ks = { "Key", "kEy", "keY" }; len = ks.Length; for (int i = 0; i < len; i++) { hd.Add(ks[i], "Value" + i); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } if (hd.Contains("Value0")) { Assert.False(true, string.Format("Error, returned true when should not")); } for (int i = 0; i < len; i++) { if (!hd.Contains(ks[i])) { Assert.False(true, string.Format("Error, returned false when true expected", i)); } } cnt = hd.Count; len = valuesLong.Length; for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } if (hd.Count != len + cnt) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len + cnt)); } // verify new keys for (int i = 0; i < len; i++) { if (!hd.Contains(keysLong[i])) { Assert.False(true, string.Format("Error, doesn't contain \"{1}\"", i, keysLong[i])); } } // verify old keys for (int i = 0; i < ks.Length; i++) { if (!hd.Contains(ks[i])) { Assert.False(true, string.Format("Error, doesn't contain \"{1}\"", i, ks[i])); } } // // [] Contains(null) - for filled dictionary // len = valuesShort.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysShort[i], valuesShort[i]); } Assert.Throws <ArgumentNullException>(() => { hd.Contains(null); }); // [] Contains() for case-insensitive comparer dictionary // hd = new HybridDictionary(true); hd.Clear(); len = ks.Length; hd.Add(ks[0], "Value0"); for (int i = 1; i < len; i++) { Assert.Throws <ArgumentException>(() => { hd.Add(ks[i], "Value" + i); }); } if (hd.Count != 1) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, 1)); } if (hd.Contains("Value0")) { Assert.False(true, string.Format("Error, returned true when should not")); } for (int i = 0; i < len; i++) { if (!hd.Contains(ks[i])) { Assert.False(true, string.Format("Error, returned false when true expected", i)); } } if (!hd.Contains("KEY")) { Assert.False(true, string.Format("Error, returned false non-existing-cased key")); } // [] few not_overriding_Equals objects and Contains() // hd = new HybridDictionary(); hd.Clear(); Hashtable[] lbl = new Hashtable[2]; lbl[0] = new Hashtable(); lbl[1] = new Hashtable(); ArrayList[] b = new ArrayList[2]; b[0] = new ArrayList(); b[1] = new ArrayList(); hd.Add(lbl[0], b[0]); hd.Add(lbl[1], b[1]); Assert.Throws <ArgumentException>(() => { hd.Add(lbl[0], "Hello"); }); if (hd.Count != 2) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, 2)); } if (!hd.Contains(lbl[0])) { Assert.False(true, string.Format("Error, returned false when true expected")); } if (!hd.Contains(lbl[1])) { Assert.False(true, string.Format("Error, returned false when true expected")); } if (hd.Contains(new Hashtable())) { Assert.False(true, string.Format("Error, returned true when false expected")); } // [] many not_overriding_Equals objects and Contains() // hd = new HybridDictionary(); hd.Clear(); int num = 40; lbl = new Hashtable[num]; b = new ArrayList[num]; for (int i = 0; i < num; i++) { lbl[i] = new Hashtable(); b[i] = new ArrayList(); hd.Add(lbl[i], b[i]); } Assert.Throws <ArgumentException>(() => { hd.Add(lbl[0], "Hello"); }); if (hd.Count != num) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, num)); } for (int i = 0; i < num; i++) { if (!hd.Contains(lbl[i])) { Assert.False(true, string.Format("Error, returned false when true expected", i)); } } if (hd.Contains(new Hashtable())) { Assert.False(true, string.Format("Error, returned true when false expected")); } // [] few not_overriding_Equals structs and Contains() hd = new HybridDictionary(); SpecialStruct s = new SpecialStruct(); s.Num = 1; s.Wrd = "one"; SpecialStruct s1 = new SpecialStruct(); s1.Num = 1; s1.Wrd = "one"; hd.Add(s, "first"); hd.Add(s1, "second"); if (hd.Count != 2) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, 2)); } if (!hd.Contains(s)) { Assert.False(true, string.Format("Error, returned false when true expected")); } if (!hd.Contains(s1)) { Assert.False(true, string.Format("Error, returned false when true expected")); } // [] many not_overriding_Equals structs and Contains() hd = new HybridDictionary(); SpecialStruct[] ss = new SpecialStruct[num]; for (int i = 0; i < num; i++) { ss[i] = new SpecialStruct(); ss[i].Num = i; ss[i].Wrd = "value" + i; hd.Add(ss[i], "item" + i); } if (hd.Count != num) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, num)); } for (int i = 0; i < num; i++) { if (!hd.Contains(ss[i])) { Assert.False(true, string.Format("Error, returned false when true expected", i)); } } s = new SpecialStruct(); s.Num = 1; s.Wrd = "value1"; if (hd.Contains(s)) { Assert.False(true, string.Format("Error, returned true when false expected")); } }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; IntlStrings intl; String strLoc = "Loc_000oo"; HybridDictionary hd; const int BIG_LENGTH = 100; string [] valuesShort = { "", " ", "$%^#", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; string [] keysShort = { Int32.MaxValue.ToString(), " ", System.DateTime.Today.ToString(), "", "$%^#" }; string [] valuesLong = new string[BIG_LENGTH]; string [] keysLong = new string[BIG_LENGTH]; int cnt = 0; try { intl = new IntlStrings(); for (int i = 0; i < BIG_LENGTH; i++) { valuesLong[i] = "Item" + i; keysLong[i] = "keY" + i; } Console.WriteLine("--- create dictionary ---"); strLoc = "Loc_001oo"; iCountTestcases++; hd = new HybridDictionary(); Console.WriteLine("1. add few simple strings"); for (int i = 0; i < valuesShort.Length; i++) { iCountTestcases++; cnt = hd.Count; hd.Add(keysShort[i], valuesShort[i]); if (hd.Count != cnt+1) { iCountErrors++; Console.WriteLine("Err_0001_{0}a, count is {1} instead of {2}", i, hd.Count, cnt+1); } iCountTestcases++; if (String.Compare(hd[keysShort[i]].ToString(), valuesShort[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_0001_{0}b, returned item \"{1}\" instead of \"{2}\"", i, hd[keysShort[i]], valuesShort[i]); } } Console.WriteLine(" .. increase number of items"); for (int i = 0; i < valuesLong.Length; i++) { iCountTestcases++; cnt = hd.Count; hd.Add(keysLong[i], valuesLong[i]); if (hd.Count != cnt+1) { iCountErrors++; Console.WriteLine("Err_0001_{0}c, count is {1} instead of {2}", i, hd.Count, cnt+1); } iCountTestcases++; if (String.Compare(hd[keysLong[i]].ToString(), valuesLong[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_0001_{0}d, returned item \"{1}\" instead of \"{2}\"", i, hd[keysLong[i]], valuesLong[i]); } } Console.WriteLine("2. add few intl strings"); int len = valuesShort.Length; hd.Clear(); string [] intlValues = new string [len * 2]; for (int i = 0; i < len * 2; i++) { string val = intl.GetString(MAX_LEN, true, true, true); while (Array.IndexOf(intlValues, val) != -1 ) val = intl.GetString(MAX_LEN, true, true, true); intlValues[i] = val; } Boolean caseInsensitive = false; for (int i = 0; i < len * 2; i++) { if(intlValues[i].Length!=0 && intlValues[i].ToLower()==intlValues[i].ToUpper()) caseInsensitive = true; } Console.WriteLine(" initial number of items: " + hd.Count); strLoc = "Loc_002oo"; for (int i = 0; i < len; i++) { iCountTestcases++; cnt = hd.Count; hd.Add(intlValues[i+len], intlValues[i]); if (hd.Count != cnt+1) { iCountErrors++; Console.WriteLine("Err_0002_{0}a, count is {1} instead of {2}", i, hd.Count, cnt+1); } iCountTestcases++; if (String.Compare(hd[intlValues[i+len]].ToString(), intlValues[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_0002_{0}b, returned item \"{1}\" instead of \"{2}\"", i, hd[intlValues[i+len]], intlValues[i]); } } Console.WriteLine(" .. increase number of items"); for (int i = 0; i < valuesLong.Length; i++) { iCountTestcases++; cnt = hd.Count; hd.Add(keysLong[i], intlValues[1]); if (hd.Count != cnt+1) { iCountErrors++; Console.WriteLine("Err_0002_{0}c, count is {1} instead of {2}", i, hd.Count, cnt+1); } iCountTestcases++; if (String.Compare(hd[keysLong[i]].ToString(), intlValues[1], false) != 0) { iCountErrors++; Console.WriteLine("Err_0002_{0}d, returned item \"{1}\" instead of \"{2}\"", i, hd[keysLong[i]], intlValues[1]); } } Console.WriteLine("3. Case sensitivity"); string [] intlValuesLower = new string [len * 2]; for (int i = 0; i < len * 2; i++) { intlValues[i] = intlValues[i].ToUpper(); } for (int i = 0; i < len * 2; i++) { intlValuesLower[i] = intlValues[i].ToLower(); } hd.Clear(); Console.WriteLine(" initial number of items: " + hd.Count); strLoc = "Loc_003oo"; for (int i = 0; i < len; i++) { iCountTestcases++; cnt = hd.Count; hd.Add(intlValues[i+len], intlValues[i]); if (hd.Count != cnt+1) { iCountErrors++; Console.WriteLine("Err_0003_{0}a, count is {1} instead of {2}", i, hd.Count, cnt+1); } iCountTestcases++; if ( hd[intlValues[i+len]] == null ) { iCountErrors++; Console.WriteLine("Err_0002_{0}b, returned null", i); } else { if ( ! hd[intlValues[i+len]].Equals(intlValues[i]) ) { iCountErrors++; Console.WriteLine("Err_0002_{0}c, returned item \"{1}\" instead of \"{2}\"", i, hd[intlValues[i+len]], intlValues[i]); } } if ( !caseInsensitive && hd[intlValuesLower[i+len]] != null ) { iCountErrors++; Console.WriteLine("Err_0002_{0}d, returned non-null", i); } } Console.WriteLine("4. multiple string with the same key"); hd.Clear(); len = valuesShort.Length; string k = "keykey"; hd.Add(k, "value"); try { hd.Add(k, "newvalue"); iCountErrors++; Console.WriteLine("Err_0004a, no exception"); } catch (ArgumentException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0004b, unexpected exception: {0}", e.ToString()); } Console.WriteLine("5. Add (string, null) "); Console.WriteLine(" initial number of items: " + hd.Count); strLoc = "Loc_005oo"; iCountTestcases++; cnt = hd.Count; k = "kk"; hd.Add(k, null); iCountTestcases++; if (hd.Count != cnt+1) { iCountErrors++; Console.WriteLine("Err_0005a, count is {0} instead of {1}", hd.Count, cnt+1); } iCountTestcases++; if (hd[k] != null) { iCountErrors++; Console.WriteLine("Err_0005c, returned non-null on place of null"); } Console.WriteLine("6. Add (null, string) "); Console.WriteLine(" initial number of items: " + hd.Count); strLoc = "Loc_006oo"; cnt = hd.Count; iCountTestcases++; try { hd.Add(null, "item"); iCountErrors++; Console.WriteLine("Err_0006a, no exception"); } catch (ArgumentNullException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0006b, unexpected exception: {0}", e.ToString()); } Console.WriteLine("7. add duplicate values"); hd.Clear(); for (int i = 0; i < valuesShort.Length; i++) { iCountTestcases++; cnt = hd.Count; hd.Add(keysShort[i], "value"); if (hd.Count != cnt+1) { iCountErrors++; Console.WriteLine("Err_0007_{0}a, count is {1} instead of {2}", i, hd.Count, cnt+1); } iCountTestcases++; if (! hd[keysShort[i]].Equals("value") ) { iCountErrors++; Console.WriteLine("Err_0007_{0}b, returned item \"{1}\" instead of \"{2}\"", i, hd[keysShort[i]], "value"); } } iCountTestcases++; if ( hd.Keys.Count != valuesShort.Length ) { iCountErrors++; Console.WriteLine("Err_0007_c, Keys contains {0} instead of {1}", hd.Keys.Count, valuesShort.Length); } iCountTestcases++; if ( hd.Values.Count != valuesShort.Length ) { iCountErrors++; Console.WriteLine("Err_0007_c, Values contains {0} instead of {1}", hd.Values.Count, valuesShort.Length); } Console.WriteLine("8. add many simple strings"); hd = new HybridDictionary(); for (int i = 0; i < valuesLong.Length; i++) { iCountTestcases++; cnt = hd.Count; hd.Add(keysLong[i], valuesLong[i]); if (hd.Count != cnt+1) { iCountErrors++; Console.WriteLine("Err_0008_{0}a, count is {1} instead of {2}", i, hd.Count, cnt+1); } iCountTestcases++; if (String.Compare(hd[keysLong[i]].ToString(), valuesLong[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_0008_{0}b, returned item \"{1}\" instead of \"{2}\"", i, hd[keysLong[i]], valuesLong[i]); } } Console.WriteLine(" .. add more items"); for (int i = 0; i < valuesLong.Length; i++) { iCountTestcases++; cnt = hd.Count; hd.Add(keysLong[i]+"_", valuesLong[i]+i); if (hd.Count != cnt+1) { iCountErrors++; Console.WriteLine("Err_0008_{0}c, count is {1} instead of {2}", i, hd.Count, cnt+1); } iCountTestcases++; if (String.Compare(hd[keysLong[i]+"_"].ToString(), valuesLong[i]+i, false) != 0) { iCountErrors++; Console.WriteLine("Err_0008_{0}d, returned item \"{1}\" instead of \"{2}\"", i, hd[keysLong[i]+"_"], valuesLong[i]+i); } } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_general! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "Pass. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("Fail! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
private static bool AreItemsEqual(HybridDictionary <NodeIndex, ObjectReference> items1, HybridDictionary <NodeIndex, ObjectReference> items2) { if (ReferenceEquals(items1, items2)) { return(true); } if (items1 == null || items2 == null) { return(false); } if (items1.Count != items2.Count) { return(false); } foreach (var item in items1) { ObjectReference otherValue; if (!items2.TryGetValue(item.Key, out otherValue)) { return(false); } if (!otherValue.Index.Equals(item.Value.Index)) { return(false); } if (otherValue.ObjectValue == null && item.Value.ObjectValue != null) { return(false); } if (otherValue.ObjectValue != null && !otherValue.ObjectValue.Equals(item.Value.ObjectValue)) { return(false); } } return(true); }
public void Refresh(IGraphNode ownerNode, NodeContainer nodeContainer) { var newObjectValue = ownerNode.Retrieve(); if (!(newObjectValue is IEnumerable)) { throw new ArgumentException(@"The object is not an IEnumerable", nameof(newObjectValue)); } ObjectValue = newObjectValue; var newReferences = new HybridDictionary <NodeIndex, ObjectReference>(); if (IsDictionary) { foreach (var item in (IEnumerable)ObjectValue) { var key = GetKey(item); var value = (ObjectReference)Reference.CreateReference(GetValue(item), ElementType, key, true); newReferences.Add(key, value); } } else { var i = 0; foreach (var item in (IEnumerable)ObjectValue) { var key = new NodeIndex(i); var value = (ObjectReference)Reference.CreateReference(item, ElementType, key, true); newReferences.Add(key, value); ++i; } } // The reference need to be updated if it has never been initialized, if the number of items is different, or if any index or any value is different. var needUpdate = items == null || newReferences.Count != items.Count || !AreItemsEqual(items, newReferences); if (needUpdate) { // We create a mapping values of the old list of references to their corresponding target node. We use a list because we can have multiple times the same target in items. var oldReferenceMapping = new List <KeyValuePair <object, ObjectReference> >(); if (items != null) { var existingIndices = GraphNodeBase.GetIndices(ownerNode).ToList(); foreach (var item in items) { var boxedTarget = item.Value.TargetNode as BoxedNode; // For collection of struct, we need to update the target nodes first so equity comparer will work. Careful tho, we need to skip removed items! if (boxedTarget != null && existingIndices.Contains(item.Key)) { // If we are boxing a struct, we reuse the same nodes if they are type-compatible and just overwrite the struct value. var value = ownerNode.Retrieve(item.Key); if (value?.GetType() == item.Value.TargetNode?.Type) { boxedTarget.UpdateFromOwner(ownerNode.Retrieve(item.Key)); } } if (item.Value.ObjectValue != null) { oldReferenceMapping.Add(new KeyValuePair <object, ObjectReference>(item.Value.ObjectValue, item.Value)); } } } foreach (var newReference in newReferences) { if (newReference.Value.ObjectValue != null) { var found = false; var i = 0; foreach (var item in oldReferenceMapping) { if (Equals(newReference.Value.ObjectValue, item.Key)) { // If this value was already present in the old list of reference, just use the same target node in the new list. newReference.Value.SetTarget(item.Value.TargetNode); // Remove consumed existing reference so if there is a second entry with the same "key", it will be the other reference that will be used. oldReferenceMapping.RemoveAt(i); found = true; break; } ++i; } if (!found) { // Otherwise, do a full update that will properly initialize the new reference. newReference.Value.Refresh(ownerNode, nodeContainer, newReference.Key); } } } items = newReferences; // Remark: this works because both KeyCollection and List implements IReadOnlyCollection. Any internal change to HybridDictionary might break this! Indices = (IReadOnlyCollection <NodeIndex>)newReferences.Keys; } }
// retrieve the value, using the cache if necessary internal object GetValue(object item, PropertyDescriptor pd, bool indexerIsNext) { if (!ShouldCache(item, pd)) { // normal case - just get the value the old-fashioned way return(pd.GetValue(item)); } else { // lazy creation of the cache if (_table == null) { _table = new HybridDictionary(); } // look up the value in the cache bool isXLinqCollectionProperty = SystemXmlLinqHelper.IsXLinqCollectionProperty(pd); ValueTableKey key = new ValueTableKey(item, pd); object value = _table[key]; Action FetchAndCacheValue = () => { // if there's no entry, fetch the value and cache it if (value == null) { if (SystemDataHelper.IsDataSetCollectionProperty(pd)) { // intercept GetValue calls for certain ADO properties value = SystemDataHelper.GetValue(item, pd, !FrameworkAppContextSwitches.DoNotUseFollowParentWhenBindingToADODataRelation); } else if (isXLinqCollectionProperty) { // interpose our own value for special XLinq properties value = new XDeferredAxisSource(item, pd); } else { value = pd.GetValue(item); } if (value == null) { value = CachedNull; // distinguish a null value from no entry } // for DataSet properties, store a weak reference to avoid // a memory leak (DDVSO 297912) if (SystemDataHelper.IsDataSetCollectionProperty(pd)) { value = new WeakReference(value); } _table[key] = value; } if (SystemDataHelper.IsDataSetCollectionProperty(pd)) { // we stored a weak reference - decode it now WeakReference wr = value as WeakReference; if (wr != null) { value = wr.Target; } } }; FetchAndCacheValue(); if (value == null) { // we can only get here if we cached a weak reference // whose target has since been GC'd. Repeating the call // will refetch the value from the item, and is guaranteed // to set value to non-null. FetchAndCacheValue(); } // decode null, if necessary if (value == CachedNull) { value = null; } else if (isXLinqCollectionProperty && !indexerIsNext) { // The XLinq properties need special help. When the path // contains "Elements[Foo]", we should return the interposed // XDeferredAxisSource; the path worker will then call the XDAS's // indexer with argument "Foo", and obtain the desired // ObservableCollection. But when the path contains "Elements" // with no indexer, we should return an ObservableCollection // corresponding to the full set of children. // [All this applies to "Descendants" as well.] XDeferredAxisSource xdas = (XDeferredAxisSource)value; value = xdas.FullCollection; } return(value); } }
internal ConfigurationPropertyBag() { properties = new HybridDictionary(); }
/// <summary> /// Initializes the specified database client. /// </summary> /// <param name="dbClient">The database client.</param> internal void Initialize(IQueryAdapter dbClient) { Categories = new HybridDictionary(); Offers = new HybridDictionary(); FlatOffers = new Dictionary <uint, uint>(); EcotronRewards = new List <EcotronReward>(); EcotronLevels = new List <int>(); HabboClubItems = new List <CatalogItem>(); dbClient.SetQuery("SELECT * FROM catalog_items ORDER BY id ASC"); DataTable itemsTable = dbClient.GetTable(); dbClient.SetQuery("SELECT * FROM catalog_pages ORDER BY id ASC"); DataTable pagesTable = dbClient.GetTable(); dbClient.SetQuery("SELECT * FROM catalog_ecotron_items ORDER BY reward_level ASC"); DataTable ecotronItems = dbClient.GetTable(); dbClient.SetQuery("SELECT * FROM catalog_items WHERE special_name LIKE 'HABBO_CLUB_VIP%'"); DataTable habboClubItems = dbClient.GetTable(); if (itemsTable != null) { foreach (DataRow dataRow in itemsTable.Rows) { if (string.IsNullOrEmpty(dataRow["item_names"].ToString()) || string.IsNullOrEmpty(dataRow["amounts"].ToString())) { continue; } string source = dataRow["item_names"].ToString(); string firstItem = dataRow["item_names"].ToString().Split(';')[0]; Item item; if (!Yupi.GetGame().GetItemManager().GetItem(firstItem, out item)) { continue; } uint num = !source.Contains(';') ? item.FlatId : 0; if (!dataRow.IsNull("special_name")) { item.PublicName = (string)dataRow["special_name"]; } CatalogItem catalogItem = new CatalogItem(dataRow, item.PublicName); if (catalogItem.GetFirstBaseItem() == null) { continue; } Offers.Add(catalogItem.Id, catalogItem); if (!FlatOffers.ContainsKey(num)) { FlatOffers.Add(num, catalogItem.Id); } } } if (pagesTable != null) { foreach (DataRow dataRow2 in pagesTable.Rows) { bool visible = false; bool enabled = false; if (dataRow2["visible"].ToString() == "1") { visible = true; } if (dataRow2["enabled"].ToString() == "1") { enabled = true; } Categories.Add((uint)dataRow2["id"], new CatalogPage((uint)dataRow2["id"], short.Parse(dataRow2["parent_id"].ToString()), (string)dataRow2["code_name"], (string)dataRow2["caption"], visible, enabled, false, (uint)dataRow2["min_rank"], (int)dataRow2["icon_image"], (string)dataRow2["page_layout"], (string)dataRow2["page_headline"], (string)dataRow2["page_teaser"], (string)dataRow2["page_special"], (string)dataRow2["page_text1"], (string)dataRow2["page_text2"], (string)dataRow2["page_text_details"], (string)dataRow2["page_text_teaser"], (string)dataRow2["page_link_description"], (string)dataRow2["page_link_pagename"], (int)dataRow2["order_num"], ref Offers)); } } if (ecotronItems != null) { foreach (DataRow dataRow3 in ecotronItems.Rows) { EcotronRewards.Add(new EcotronReward(Convert.ToUInt32(dataRow3["display_id"]), Convert.ToUInt32(dataRow3["item_id"]), Convert.ToUInt32(dataRow3["reward_level"]))); if (!EcotronLevels.Contains(Convert.ToInt16(dataRow3["reward_level"]))) { EcotronLevels.Add(Convert.ToInt16(dataRow3["reward_level"])); } } } if (habboClubItems != null) { foreach (DataRow row in habboClubItems.Rows) { HabboClubItems.Add(new CatalogItem(row, row.IsNull("special_name") ? "Habbo VIP" : (string)row["special_name"])); } } }
public void Ctor_Bool(bool caseInsensitive) { HybridDictionary hybridDictionary = new HybridDictionary(caseInsensitive); VerifyCtor(hybridDictionary, caseInsensitive: caseInsensitive); }
private void FillPropertiesInformation() { MemberInfo[] tmpElements = _emptyChildNodeInfos; MemberInfo[] tmpAttributes = _emptyChildNodeInfos; if (IsSimpleType) { return; } ArrayList elements = new ArrayList(); ArrayList attributes = new ArrayList(); _attributesNamed = new HybridDictionary(); int elementIndex = 0; int attributeIndex = 0; R.MemberInfo[] members = _type.FindMembers(MemberTypes.Property | MemberTypes.Field, BindingFlags.Instance | BindingFlags.Public, null, null); SortMembersArray(members); foreach (R.MemberInfo mi in members) { // Create member info R.PropertyInfo pi = mi as R.PropertyInfo; R.MethodInfo piGetMethod = null; MemberInfo nodeInfo = null; if (pi != null) { piGetMethod = pi.GetGetMethod(); if (piGetMethod != null && piGetMethod.GetParameters().Length == 0) { nodeInfo = new PropertyInfo(pi); } else { // This is not a property without arguments. continue; } } else { R.FieldInfo fi = (R.FieldInfo)mi; nodeInfo = new FieldInfo(fi); } nodeInfo._nodeName = mi.Name; // Get decorations for the original MemberInfo nodeInfo.GetDecorations(mi); if (pi != null) { // Check for interface's attributes if the member is property foreach (Type iface in _type.GetInterfaces()) { int accessorIndex = -1; InterfaceMapping map = _type.GetInterfaceMap(iface); for (int i = 0; i < map.TargetMethods.Length; i++) { if (map.TargetMethods[i] == piGetMethod) { accessorIndex = i; break; } } if (accessorIndex != -1) { R.MethodInfo ifaceMember = map.InterfaceMethods[accessorIndex]; foreach (R.PropertyInfo ifaceProperty in iface.GetProperties()) { if (ifaceProperty.GetGetMethod() == ifaceMember) { nodeInfo.GetDecorations(ifaceProperty); break; } } break; } } } // Check for XmlIgnore attribute if (nodeInfo.XmlIgnore != null) { continue; } nodeInfo.ProcessDecorations(); TypeInfo declTypeInfo = TypeInfoCache.Instance.GetTypeInfo(mi.DeclaringType); string declSchemaNs = declTypeInfo.Namespace; if (declTypeInfo.XmlType != null && declTypeInfo.XmlType.Namespace != null) { declSchemaNs = declTypeInfo.XmlType.Namespace; } // Add member to the collection switch (nodeInfo.NodeType) { case XPathNodeType.Element: { if ((nodeInfo.Form == XmlSchemaForm.None || nodeInfo.Form == XmlSchemaForm.Qualified) && nodeInfo._namespace == null) { // Take NS from declaring type nodeInfo._namespace = declSchemaNs; } goto case XPathNodeType.Text; } case XPathNodeType.Text: { // Add to array of elements nodeInfo.Index = elementIndex++; elements.Add(nodeInfo); break; } default: // Attribute { if (nodeInfo.Form == XmlSchemaForm.None) { if (nodeInfo._namespace == declSchemaNs) { nodeInfo._namespace = null; } } else if (nodeInfo.Form == XmlSchemaForm.Qualified && nodeInfo._namespace == null) { // Take NS from declaring type nodeInfo._namespace = declSchemaNs; } // Add to array of attributes nodeInfo.Index = attributeIndex++; attributes.Add(nodeInfo); _attributesNamed.Add(new XmlQualifiedName(nodeInfo.Name, nodeInfo.Namespace), nodeInfo); break; } } } if (elements.Count > 0) { tmpElements = (MemberInfo[])elements.ToArray(typeof(MemberInfo)); } if (attributes.Count > 0) { tmpAttributes = (MemberInfo[])attributes.ToArray(typeof(MemberInfo)); } _elements = tmpElements; _attributes = tmpAttributes; }
public void Test01() { IntlStrings intl; HybridDictionary hd; // simple string values string[] valuesShort = Test_EdgeCases(); // keys for simple string values string[] keysShort = Test_EdgeCases(); string[] valuesLong = TestValues(100); string[] keysLong = TestKeys(100); int cnt = 0; // Count Object itm; // Item // initialize IntStrings intl = new IntlStrings(); // [] HybridDictionary is constructed as expected //----------------------------------------------------------------- hd = new HybridDictionary(); // [] get Item() on empty dictionary // cnt = hd.Count; Assert.Throws<ArgumentNullException>(() => { itm = hd[null]; }); cnt = hd.Count; itm = hd["some_string"]; if (itm != null) { Assert.False(true, string.Format("Error, returned non-null for Item(some_string)")); } cnt = hd.Count; itm = hd[new Hashtable()]; if (itm != null) { Assert.False(true, string.Format("Error, returned non-null for Item(some_object)")); } // [] get Item() on short dictionary with simple strings // cnt = hd.Count; int len = valuesShort.Length; for (int i = 0; i < len; i++) { hd.Add(keysShort[i], valuesShort[i]); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, valuesShort.Length)); } // for (int i = 0; i < len; i++) { cnt = hd.Count; itm = hd[keysShort[i]]; if (String.Compare(itm.ToString(), valuesShort[i]) != 0) { Assert.False(true, string.Format("Error, returned wrong item", i)); } } // [] get Item() on long dictionary with simple strings // hd.Clear(); cnt = hd.Count; len = valuesLong.Length; for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } // for (int i = 0; i < len; i++) { cnt = hd.Count; itm = hd[keysLong[i]]; if (String.Compare(itm.ToString(), valuesLong[i]) != 0) { Assert.False(true, string.Format("Error, returned wrong item", i)); } } // [] get Item() on long dictionary with Intl strings // Intl strings // len = valuesLong.Length; string[] intlValues = new string[len * 2]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { string val = intl.GetRandomString(MAX_LEN); while (Array.IndexOf(intlValues, val) != -1) val = intl.GetRandomString(MAX_LEN); intlValues[i] = val; } cnt = hd.Count; for (int i = 0; i < len; i++) { hd.Add(intlValues[i + len], intlValues[i]); } if (hd.Count != (cnt + len)) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, cnt + len)); } for (int i = 0; i < len; i++) { // cnt = hd.Count; itm = hd[intlValues[i + len]]; if (string.Compare(itm.ToString(), intlValues[i]) != 0) { Assert.False(true, string.Format("Error, returned wrong item", i)); } } // [] get Item() on short dictionary with Intl strings // len = valuesShort.Length; hd.Clear(); cnt = hd.Count; for (int i = 0; i < len; i++) { hd.Add(intlValues[i + len], intlValues[i]); } if (hd.Count != (cnt + len)) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, cnt + len)); } for (int i = 0; i < len; i++) { // cnt = hd.Count; itm = hd[intlValues[i + len]]; if (String.Compare(itm.ToString(), intlValues[i]) != 0) { Assert.False(true, string.Format("Error, returned wrong item", i)); } } // // [] Case sensitivity - hashtable // len = valuesLong.Length; hd.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToUpper(), valuesLong[i].ToUpper()); // adding uppercase strings } // for (int i = 0; i < len; i++) { // uppercase key itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), valuesLong[i].ToUpper()) != 0) { Assert.False(true, string.Format("Error, returned wrong item", i)); } if (String.Compare(itm.ToString(), valuesLong[i].ToLower()) == 0) { Assert.False(true, string.Format("Error, returned lowercase when added uppercase", i)); } } hd.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToUpper(), valuesLong[i].ToUpper()); // adding uppercase strings } // LD is case-sensitive by default for (int i = 0; i < len; i++) { // lowercase key itm = hd[keysLong[i].ToLower()]; if (itm != null) { Assert.False(true, string.Format("Error, returned non-null for lowercase key", i)); } } // // [] Case sensitivity - list // len = valuesShort.Length; hd.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToUpper(), valuesLong[i].ToUpper()); // adding uppercase strings } // for (int i = 0; i < len; i++) { // uppercase key itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), valuesLong[i].ToUpper()) != 0) { Assert.False(true, string.Format("Error, returned wrong item", i)); } if (String.Compare(itm.ToString(), valuesLong[i].ToLower()) == 0) { Assert.False(true, string.Format("Error, returned lowercase when added uppercase", i)); } } hd.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToUpper(), valuesLong[i].ToUpper()); // adding uppercase strings } // LD is case-sensitive by default for (int i = 0; i < len; i++) { // lowercase key itm = hd[keysLong[i].ToLower()]; if (itm != null) { Assert.False(true, string.Format("Error, returned non-null for lowercase key", i)); } } // // [] get Item() in case-insensitive HD - list // hd = new HybridDictionary(true); len = valuesShort.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToLower(), valuesLong[i].ToLower()); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } for (int i = 0; i < len; i++) { itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), valuesLong[i].ToLower()) != 0) { Assert.False(true, string.Format("Error, returned wrong item for uppercase key", i)); } itm = hd[keysLong[i].ToLower()]; if (String.Compare(itm.ToString(), valuesLong[i].ToLower()) != 0) { Assert.False(true, string.Format("Error, returned wrong item - for lowercase key", i)); } } // [] get Item() in case-insensitive HD - hashtable // hd = new HybridDictionary(true); len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToLower(), valuesLong[i].ToLower()); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } for (int i = 0; i < len; i++) { itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), valuesLong[i].ToLower()) != 0) { Assert.False(true, string.Format("Error, returned wrong item for uppercase key", i)); } itm = hd[keysLong[i].ToLower()]; if (String.Compare(itm.ToString(), valuesLong[i].ToLower()) != 0) { Assert.False(true, string.Format("Error, returned wrong item for lowercase key", i)); } } // // [] get Item(null) on filled HD - list // hd = new HybridDictionary(); len = valuesShort.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysShort[i], valuesShort[i]); } Assert.Throws<ArgumentNullException>(() => { itm = hd[null]; }); // [] get Item(null) on filled HD - hashtable // hd = new HybridDictionary(); len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } Assert.Throws<ArgumentNullException>(() => { itm = hd[null]; }); // // [] get Item(special_object) on filled HD - list // hd = new HybridDictionary(); hd.Clear(); len = 2; ArrayList[] b = new ArrayList[len]; Hashtable[] lbl = new Hashtable[len]; for (int i = 0; i < len; i++) { lbl[i] = new Hashtable(); b[i] = new ArrayList(); hd.Add(lbl[i], b[i]); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } for (int i = 0; i < len; i++) { itm = hd[lbl[i]]; if (!itm.Equals(b[i])) { Assert.False(true, string.Format("Error, returned wrong special object")); } } // [] get Item(special_object) on filled HD - hashtable // hd = new HybridDictionary(); hd.Clear(); len = 40; b = new ArrayList[len]; lbl = new Hashtable[len]; for (int i = 0; i < len; i++) { lbl[i] = new Hashtable(); b[i] = new ArrayList(); hd.Add(lbl[i], b[i]); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } for (int i = 0; i < len; i++) { itm = hd[lbl[i]]; if (!itm.Equals(b[i])) { Assert.False(true, string.Format("Error, returned wrong special object")); } } }
public void Test01() { IntlStrings intl; HybridDictionary hd; const int BIG_LENGTH = 100; // simple string values string[] valuesShort = { "", " ", "$%^#", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; // keys for simple string values string[] keysShort = { Int32.MaxValue.ToString(), " ", System.DateTime.Today.ToString(), "", "$%^#" }; string[] valuesLong = new string[BIG_LENGTH]; string[] keysLong = new string[BIG_LENGTH]; int cnt = 0; // Count Object itm; // Item // initialize IntStrings intl = new IntlStrings(); for (int i = 0; i < BIG_LENGTH; i++) { valuesLong[i] = "Item" + i; keysLong[i] = "keY" + i; } // [] HybridDictionary is constructed as expected //----------------------------------------------------------------- hd = new HybridDictionary(); // [] set Item() on empty dictionary // cnt = hd.Count; try { hd[null] = valuesShort[0]; Assert.False(true, string.Format("Error, no exception")); } catch (ArgumentNullException) { } catch (Exception e) { Assert.False(true, string.Format("Error, unexpected exception: {0}", e.ToString())); } cnt = hd.Count; hd["some_string"] = valuesShort[0]; if (hd.Count != cnt + 1) { Assert.False(true, string.Format("Error, failed to add Item(some_string)")); } itm = hd["some_string"]; if (String.Compare(itm.ToString(), valuesShort[0]) != 0) { Assert.False(true, string.Format("Error, added wrong Item(some_string)")); } cnt = hd.Count; Hashtable l = new Hashtable(); ArrayList bb = new ArrayList(); hd[l] = bb; if (hd.Count != cnt + 1) { Assert.False(true, string.Format("Error, failed to add Item(some_object)")); } itm = hd[l]; if (!itm.Equals(bb)) { Assert.False(true, string.Format("Error, returned wrong Item(some_object)")); } // [] set Item() on short dictionary with simple strings // hd.Clear(); cnt = hd.Count; int len = valuesShort.Length; for (int i = 0; i < len; i++) { hd.Add(keysShort[i], valuesShort[i]); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, valuesShort.Length)); } // for (int i = 0; i < len; i++) { cnt = hd.Count; hd[keysShort[i]] = valuesLong[0]; if (hd.Count != cnt) { Assert.False(true, string.Format("Error, added item instead of setting", i)); } itm = hd[keysShort[i]]; if (String.Compare(itm.ToString(), valuesLong[0]) != 0) { Assert.False(true, string.Format("Error, failed to set item", i)); } } // should add non-existing item cnt = hd.Count; hd[keysLong[0]] = valuesLong[0]; if (hd.Count != cnt + 1) { Assert.False(true, string.Format("Error, didn't add non-existing item")); } itm = hd[keysLong[0]]; if (String.Compare(itm.ToString(), valuesLong[0]) != 0) { Assert.False(true, string.Format("Error, failed to set item")); } // [] set Item() on long dictionary with simple strings // hd.Clear(); cnt = hd.Count; len = valuesLong.Length; for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } // for (int i = 0; i < len; i++) { cnt = hd.Count; hd[keysLong[i]] = valuesShort[0]; if (hd.Count != cnt) { Assert.False(true, string.Format("Error, added item instead of setting", i)); } itm = hd[keysLong[i]]; if (String.Compare(itm.ToString(), valuesShort[0]) != 0) { Assert.False(true, string.Format("Error, failed to set item", i)); } } // should add non-existing item cnt = hd.Count; hd[keysShort[0]] = valuesShort[0]; if (hd.Count != cnt + 1) { Assert.False(true, string.Format("Error, didn't add non-existing item")); } itm = hd[keysShort[0]]; if (String.Compare(itm.ToString(), valuesShort[0]) != 0) { Assert.False(true, string.Format("Error, failed to set item")); } // // [] set Item() on long dictionary with Intl strings // Intl strings // len = valuesLong.Length; string[] intlValues = new string[len * 2 + 1]; // fill array with unique strings // for (int i = 0; i < len * 2 + 1; i++) { string val = intl.GetRandomString(MAX_LEN); while (Array.IndexOf(intlValues, val) != -1) { val = intl.GetRandomString(MAX_LEN); } intlValues[i] = val; } string toSet = intlValues[len * 2]; // string to set cnt = hd.Count; for (int i = 0; i < len; i++) { hd.Add(intlValues[i + len], intlValues[i]); } if (hd.Count != (cnt + len)) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, cnt + len)); } for (int i = 0; i < len; i++) { // cnt = hd.Count; hd[intlValues[i + len]] = toSet; if (hd.Count != cnt) { Assert.False(true, string.Format("Error, added item instead of setting", i)); } itm = hd[intlValues[i + len]]; if (String.Compare(itm.ToString(), toSet) != 0) { Assert.False(true, string.Format("Error, failed to set item", i)); } } // [] set Item() on short dictionary with Intl strings // len = valuesShort.Length; hd.Clear(); cnt = hd.Count; for (int i = 0; i < len; i++) { hd.Add(intlValues[i + len], intlValues[i]); } if (hd.Count != (cnt + len)) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, cnt + len)); } for (int i = 0; i < len; i++) { // cnt = hd.Count; hd[intlValues[i + len]] = toSet; if (hd.Count != cnt) { Assert.False(true, string.Format("Error, added item instead of setting", i)); } itm = hd[intlValues[i + len]]; if (String.Compare(itm.ToString(), toSet) != 0) { Assert.False(true, string.Format("Error, returned wrong item", i)); } } // // Case sensitivity // [] Case sensitivity - hashtable // len = valuesLong.Length; hd.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToUpper(), valuesLong[i].ToUpper()); // adding uppercase strings } // for (int i = 0; i < len; i++) { // uppercase key hd[keysLong[i].ToUpper()] = toSet; itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), toSet) != 0) { Assert.False(true, string.Format("Error, failed to set", i)); } } hd.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToUpper(), valuesLong[i].ToUpper()); // adding uppercase strings } // LD is case-sensitive by default - should add lowercase key for (int i = 0; i < len; i++) { // lowercase key cnt = hd.Count; hd[keysLong[i].ToLower()] = toSet; if (hd.Count != cnt + 1) { Assert.False(true, string.Format("Error, failed to add when setting", i)); } itm = hd[keysLong[i].ToLower()]; if (String.Compare(itm.ToString(), toSet) != 0) { Assert.False(true, string.Format("Error, failed to set item", i)); } itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), valuesLong[i].ToUpper()) != 0) { Assert.False(true, string.Format("Error, failed to preserve item", i)); } } // // [] Case sensitivity - list len = valuesShort.Length; hd.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToUpper(), valuesLong[i].ToUpper()); // adding uppercase strings } // for (int i = 0; i < len; i++) { // uppercase key hd[keysLong[i].ToUpper()] = toSet; itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), toSet) != 0) { Assert.False(true, string.Format("Error, failed to set", i)); } } hd.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToUpper(), valuesLong[i].ToUpper()); // adding uppercase strings } // LD is case-sensitive by default - should add lowercase key for (int i = 0; i < len; i++) { // lowercase key cnt = hd.Count; hd[keysLong[i].ToLower()] = toSet; if (hd.Count != cnt + 1) { Assert.False(true, string.Format("Error, failed to add when setting", i)); } itm = hd[keysLong[i].ToLower()]; if (String.Compare(itm.ToString(), toSet) != 0) { Assert.False(true, string.Format("Error, failed to set item", i)); } itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), valuesLong[i].ToUpper()) != 0) { Assert.False(true, string.Format("Error, failed to preserve item", i)); } } // [] set Item() on case-insensitive HD - list // hd = new HybridDictionary(true); len = valuesShort.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToLower(), valuesLong[i].ToLower()); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } for (int i = 0; i < len; i++) { hd[keysLong[i].ToUpper()] = toSet; itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), toSet) != 0) { Assert.False(true, string.Format("Error, failed to set via uppercase key", i)); } hd[keysLong[i].ToLower()] = valuesLong[0]; itm = hd[keysLong[i].ToLower()]; if (String.Compare(itm.ToString(), valuesLong[0]) != 0) { Assert.False(true, string.Format("Error, failed to set via lowercase key", i)); } } // [] set Item() on case-insensitive HD - hashtable // hd = new HybridDictionary(true); len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToLower(), valuesLong[i].ToLower()); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } for (int i = 0; i < len; i++) { hd[keysLong[i].ToUpper()] = toSet; itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), toSet) != 0) { Assert.False(true, string.Format("Error, failed to set via uppercase key", i)); } hd[keysLong[i].ToLower()] = valuesLong[0]; itm = hd[keysLong[i].ToLower()]; if (String.Compare(itm.ToString(), valuesLong[0]) != 0) { Assert.False(true, string.Format("Error, failed to set via lowercase key", i)); } } // // [] set Item(null) on filled HD - list // hd = new HybridDictionary(); len = valuesShort.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysShort[i], valuesShort[i]); } try { hd[null] = toSet; Assert.False(true, string.Format("Error, no exception")); } catch (ArgumentNullException) { } catch (Exception e) { Assert.False(true, string.Format("Error, unexpected exception: {0}", e.ToString())); } // [] set Item(null) on filled HD - hashtable // hd = new HybridDictionary(); len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } try { hd[null] = toSet; Assert.False(true, string.Format("Error, no exception")); } catch (ArgumentNullException) { } catch (Exception e) { Assert.False(true, string.Format("Error, unexpected exception: {0}", e.ToString())); } // [] set Item(special_object) on filled HD - list // hd = new HybridDictionary(); hd.Clear(); len = 2; ArrayList[] b = new ArrayList[len]; Hashtable[] lbl = new Hashtable[len]; SortedList cb = new SortedList(); for (int i = 0; i < len; i++) { lbl[i] = new Hashtable(); b[i] = new ArrayList(); hd.Add(lbl[i], b[i]); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } for (int i = 0; i < len; i++) { cnt = hd.Count; hd[lbl[i]] = cb; if (hd.Count != cnt) { Assert.False(true, string.Format("Error, added special object instead of setting")); } itm = hd[lbl[i]]; if (!itm.Equals(cb)) { Assert.False(true, string.Format("Error, failed to set special object")); } } cnt = hd.Count; hd[cb] = lbl[0]; if (hd.Count != cnt + 1) { Assert.False(true, string.Format("Error, failed to add non-existing special object")); } itm = hd[cb]; if (!itm.Equals(lbl[0])) { Assert.False(true, string.Format("Error, failed to set special object")); } // [] set Item(special_object) on filled HD - hashtable // hd = new HybridDictionary(); hd.Clear(); len = 40; b = new ArrayList[len]; lbl = new Hashtable[len]; for (int i = 0; i < len; i++) { lbl[i] = new Hashtable(); b[i] = new ArrayList(); hd.Add(lbl[i], b[i]); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } for (int i = 0; i < len; i++) { cnt = hd.Count; hd[lbl[i]] = cb; if (hd.Count != cnt) { Assert.False(true, string.Format("Error, added special object instead of setting")); } itm = hd[lbl[i]]; if (!itm.Equals(cb)) { Assert.False(true, string.Format("Error, failed to set special object")); } } cnt = hd.Count; hd[cb] = lbl[0]; if (hd.Count != cnt + 1) { Assert.False(true, string.Format("Error, failed to add non-existing special object")); } itm = hd[cb]; if (!itm.Equals(lbl[0])) { Assert.False(true, string.Format("Error, failed to set special object")); } // [] set Item() to null on filled HD - list // hd = new HybridDictionary(); hd.Clear(); len = valuesShort.Length; for (int i = 0; i < len; i++) { hd.Add(keysShort[i], valuesShort[i]); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } cnt = hd.Count; hd[keysShort[0]] = null; if (hd.Count != cnt) { Assert.False(true, string.Format("Error, added entry instead of setting")); } itm = hd[keysShort[0]]; if (itm != null) { Assert.False(true, string.Format("Error, failed to set to null")); } // [] set Item() to null on filled HD - hashtable // hd.Clear(); len = valuesLong.Length; for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } cnt = hd.Count; hd[keysLong[0]] = null; if (hd.Count != cnt) { Assert.False(true, string.Format("Error, added entry instead of setting")); } itm = hd[keysLong[0]]; if (itm != null) { Assert.False(true, string.Format("Error, failed to set to null")); } }
/// <summary> /// Initializes the text colors, creates dictionaries for RTF colors and /// font families, and stores the horizontal and vertical resolution of /// the RichTextBox's graphics context. /// </summary> public ExRichTextBox() : base() { // Initialize default text and background colors m_textColor = RtfColor.Black; highlightColor = RtfColor.White; // Initialize the dictionary mapping color codes to definitions rtfColor = new System.Collections.Specialized.HybridDictionary(); rtfColor.Add(RtfColor.Aqua, RtfColorDef.Aqua); rtfColor.Add(RtfColor.Black, RtfColorDef.Black); rtfColor.Add(RtfColor.Blue, RtfColorDef.Blue); rtfColor.Add(RtfColor.Fuchsia, RtfColorDef.Fuchsia); rtfColor.Add(RtfColor.Gray, RtfColorDef.Gray); rtfColor.Add(RtfColor.Green, RtfColorDef.Green); rtfColor.Add(RtfColor.Lime, RtfColorDef.Lime); rtfColor.Add(RtfColor.Maroon, RtfColorDef.Maroon); rtfColor.Add(RtfColor.Navy, RtfColorDef.Navy); rtfColor.Add(RtfColor.Olive, RtfColorDef.Olive); rtfColor.Add(RtfColor.Purple, RtfColorDef.Purple); rtfColor.Add(RtfColor.Red, RtfColorDef.Red); rtfColor.Add(RtfColor.Silver, RtfColorDef.Silver); rtfColor.Add(RtfColor.Teal, RtfColorDef.Teal); rtfColor.Add(RtfColor.White, RtfColorDef.White); rtfColor.Add(RtfColor.Yellow, RtfColorDef.Yellow); // Initialize the dictionary mapping default Framework font families to // RTF font families rtfFontFamily = new HybridDictionary(); rtfFontFamily.Add(FontFamily.GenericMonospace.Name, RtfFontFamilyDef.Modern); rtfFontFamily.Add(FontFamily.GenericSansSerif, RtfFontFamilyDef.Swiss); rtfFontFamily.Add(FontFamily.GenericSerif, RtfFontFamilyDef.Roman); rtfFontFamily.Add(FF_UNKNOWN, RtfFontFamilyDef.Unknown); // Get the horizontal and vertical resolutions at which the object is // being displayed using (Graphics _graphics = this.CreateGraphics()) { xDpi = _graphics.DpiX; yDpi = _graphics.DpiY; } }
internal ActionDemuxer() { _map = new HybridDictionary(); }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; const int BIG_LENGTH = 100; String strLoc = "Loc_000oo"; HybridDictionary hd; string [] valuesShort = { "", " ", "$%^#", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; string [] keysShort = { Int32.MaxValue.ToString(), " ", System.DateTime.Today.ToString(), "", "$%^#" }; string [] valuesLong = new string[BIG_LENGTH]; string [] keysLong = new string[BIG_LENGTH]; Array arr; ICollection ks; int ind; try { for (int i = 0; i < BIG_LENGTH; i++) { valuesLong[i] = "Item" + i; keysLong[i] = "keY" + i; } Console.WriteLine("--- create dictionary ---"); strLoc = "Loc_001oo"; iCountTestcases++; hd = new HybridDictionary(); Console.WriteLine("1. get Keys for empty dictionary"); iCountTestcases++; if (hd.Count > 0) hd.Clear(); if (hd.Keys.Count != 0) { iCountErrors++; Console.WriteLine("Err_0001, returned Keys.Count = {0}", hd.Keys.Count); } Console.WriteLine("2. get Keys on short filled dictionary"); strLoc = "Loc_002oo"; int len = valuesShort.Length; iCountTestcases++; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysShort[i], valuesShort[i]); } Console.WriteLine(" Count = " + hd.Count); if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0002a, count is {0} instead of {1}", hd.Count, len); } ks = hd.Keys; if (ks.Count != len) { iCountErrors++; Console.WriteLine("Err_0002a, returned Keys.Count = {0}", ks.Count); } arr = Array.CreateInstance(typeof(Object), len); ks.CopyTo(arr, 0); for (int i = 0; i < len; i++) { iCountTestcases++; ind = Array.IndexOf(arr, keysShort[i]); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0002b_{0}, Keys doesn't contain \"{1}\" key. Search result: {2}", i, keysShort[i], ind); } } Console.WriteLine("3. get Keys on long filled dictionary"); strLoc = "Loc_003oo"; len = valuesLong.Length; iCountTestcases++; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } Console.WriteLine(" Count = " + hd.Count); if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", hd.Count, len); } ks = hd.Keys; if (ks.Count != len) { iCountErrors++; Console.WriteLine("Err_0003a, returned Keys.Count = {0}", ks.Count); } arr = Array.CreateInstance(typeof(Object), len); ks.CopyTo(arr, 0); for (int i = 0; i < len; i++) { iCountTestcases++; ind = Array.IndexOf(arr, keysLong[i]); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0003b_{0}, Keys doesn't contain \"{1}\" key. Search result: {2}", i, keysLong[i], ind); } } Console.WriteLine("4. get Keys on short dictionary with different_in_casing_only keys "); strLoc = "Loc_004oo"; iCountTestcases++; hd.Clear(); string intlStr = "intlStr"; hd.Add("keykey", intlStr); hd.Add("keyKey", intlStr); if (hd.Count != 2) { iCountErrors++; Console.WriteLine("Err_0004a, count is {0} instead of {1}", hd.Count, 2); } Console.WriteLine(" Count = " + hd.Count); iCountTestcases++; ks = hd.Keys; if (ks.Count != hd.Count) { iCountErrors++; Console.WriteLine("Err_0003b, returned Keys.Count = {0}", ks.Count); } arr = Array.CreateInstance(typeof(Object), 2); ks.CopyTo(arr, 0); iCountTestcases++; ind = Array.IndexOf(arr, "keykey"); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0003c, Keys doesn't contain {0} value", "keykey"); } iCountTestcases++; ind = Array.IndexOf(arr, "keyKey"); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0003d, Keys doesn't contain {0} value", "keyKey"); } Console.WriteLine("5. get Keys on long dictionary with different_in_casing_only keys "); strLoc = "Loc_005oo"; iCountTestcases++; hd.Clear(); hd.Add("keykey", intlStr); for (int i = 0; i < BIG_LENGTH; i++) { hd.Add(keysLong[i], valuesLong[i]); } hd.Add("keyKey", intlStr); if (hd.Count != BIG_LENGTH + 2) { iCountErrors++; Console.WriteLine("Err_0005a, count is {0} instead of {1}", hd.Count, BIG_LENGTH + 2); } Console.WriteLine(" Count = " + hd.Count); iCountTestcases++; ks = hd.Keys; if (ks.Count != hd.Count) { iCountErrors++; Console.WriteLine("Err_0005b, returned Keys.Count = {0}", ks.Count); } arr = Array.CreateInstance(typeof(Object), BIG_LENGTH + 2); ks.CopyTo(arr, 0); for (int i = 0 ; i < BIG_LENGTH; i++) { iCountTestcases++; if ( Array.IndexOf(arr, keysLong[i]) < 0) { iCountErrors++; Console.WriteLine("Err_0005c_{1}, Keys doesn't contain {0} key", keysLong[i], i); } } iCountTestcases++; ind = Array.IndexOf(arr, "keykey"); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0005d, Keys doesn't contain {0} key", "keykey"); } iCountTestcases++; ind = Array.IndexOf(arr, "keyKey"); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0005e, Keys doesn't contain {0} key", "keyKey"); } Console.WriteLine("6. Change long dictinary"); strLoc = "Loc_006oo"; iCountTestcases++; hd.Clear(); len = valuesLong.Length; for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } Console.WriteLine(" Count = " + hd.Count); if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0006a, count is {0} instead of {1}", hd.Count, len); } ks = hd.Keys; if (ks.Count != len) { iCountErrors++; Console.WriteLine("Err_0006a, returned Keys.Count = {0}", ks.Count); } Console.WriteLine(" - remove element from the dictionary"); hd.Remove(keysLong[0]); if (hd.Count != len-1) { iCountErrors++; Console.WriteLine("Err_0006b, didn't remove element"); } if (ks.Count != len-1) { iCountErrors++; Console.WriteLine("Err_0006c, Keys were not updated after removal"); } iCountTestcases++; arr = Array.CreateInstance(typeof(Object), hd.Count); ks.CopyTo(arr, 0); ind = Array.IndexOf(arr, keysLong[0]); if (ind >= 0) { iCountErrors++; Console.WriteLine("Err_0006d, Keys still contains removed value " + ind); } Console.WriteLine(" - add element to the dictionary"); hd.Add(keysLong[0], "new item"); if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0006e, didn't add element"); } if (ks.Count != len) { iCountErrors++; Console.WriteLine("Err_0006f, Keys were not updated after addition"); } iCountTestcases++; arr = Array.CreateInstance(typeof(Object), hd.Count); ks.CopyTo(arr, 0); ind = Array.IndexOf(arr, keysLong[0]); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0006g, Keys doesn't contain added value "); } Console.WriteLine("7. Change short dictinary"); strLoc = "Loc_007oo"; iCountTestcases++; hd.Clear(); len = valuesShort.Length; for (int i = 0; i < len; i++) { hd.Add(keysShort[i], valuesShort[i]); } Console.WriteLine(" Count = " + hd.Count); if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0007a, count is {0} instead of {1}", hd.Count, len); } ks = hd.Keys; if (ks.Count != len) { iCountErrors++; Console.WriteLine("Err_0007a, returned Keys.Count = {0}", ks.Count); } Console.WriteLine(" - remove element from the dictionary"); hd.Remove(keysShort[0]); if (hd.Count != len-1) { iCountErrors++; Console.WriteLine("Err_0007b, didn't remove element"); } if (ks.Count != len-1) { iCountErrors++; Console.WriteLine("Err_0007c, Keys were not updated after removal"); } iCountTestcases++; arr = Array.CreateInstance(typeof(Object), hd.Count); ks.CopyTo(arr, 0); ind = Array.IndexOf(arr, keysShort[0]); if (ind >= 0) { iCountErrors++; Console.WriteLine("Err_0007d, Keys still contains removed value " + ind); } Console.WriteLine(" - add element to the dictionary"); hd.Add(keysShort[0], "new item"); if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0007e, didn't add element"); } if (ks.Count != len) { iCountErrors++; Console.WriteLine("Err_0007f, Keys were not updated after addition"); } iCountTestcases++; arr = Array.CreateInstance(typeof(Object), hd.Count); ks.CopyTo(arr, 0); ind = Array.IndexOf(arr, keysShort[0]); if (ind < 0) { iCountErrors++; Console.WriteLine("Err_0007g, Keys doesn't contain added value "); } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_general! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "Pass. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("Fail! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
public static T CreateItem <T>(DataRow oRow) { string sColumnName; string sPropertyName; T oObject = default(T); PropertyInfo oProp; Object oValue; Regex sRegex; string sColumnNamePK; if (oRow != null) { oObject = Activator.CreateInstance <T>(); foreach (DataColumn column in oRow.Table.Columns) { sColumnName = column.ColumnName.ToLower(); //Verifica se é a coluna (PK) neste caso coloca o nome padrão da propriedade para id sRegex = new Regex("(?<=[A-Z])(?=[A-Z][a-z]) |" + "(?<=[^A-Z])(?=[A-Z]) |" + "(?<=[A-Za-z])(?=[^A-Za-z])", RegexOptions.IgnorePatternWhitespace); //Se o nome da coluna do datarow for igual a coluna pk, então deve salvar na propriedade Id sColumnNamePK = "id_" + sRegex.Replace(oObject.GetType().Name, " ").Replace(" ", "_").ToLower(); sRegex = null; if (sColumnName.Equals(sColumnNamePK)) { sPropertyName = "Id"; } else { //Se não monta o nome padrão sPropertyName = Strings.StrConv(column.ColumnName.Replace("_", " "), VbStrConv.ProperCase).Replace(" ", ""); //Pega a propriedade com a mesma coluna oProp = oObject.GetType().GetProperty(sPropertyName); if (oProp != null) { try { oValue = null; //Pega o valor da coluna oValue = oRow[sColumnName].GetType() == typeof(DBNull) ? null : oRow[sColumnName]; if (oProp.PropertyType.Name.Equals("HybridDictionary")) { HybridDictionary oDic = new HybridDictionary(); foreach (string sValue in oValue.ToString().Split('|')) { oDic.Add(sValue.Split(':')[0], sValue.Split(':')[1]); } oProp.SetValue(oObject, oDic, null); } else { oProp.SetValue(oObject, oValue, null); } } catch { throw; } } oProp = null; } } } return(oObject); }
internal static void decrypt(string user_password, string backup_path_in, string dest_path_out) { Console.WriteLine("getting files and folders from: " + backup_path_in); if (!Directory.Exists(backup_path_in)) { Console.WriteLine("input backup folder does not exist!"); return; } Console.WriteLine("using output folder: " + dest_path_out); if (Directory.Exists(dest_path_out)) { List <string> files = Directory.GetFiles(dest_path_out, "*.*", SearchOption.AllDirectories).ToList(); if (files.Count > 0) { Console.WriteLine("output folder contains {0} files, cannot overwrite them!", files.Count); return; } } List <string> backup_all_files = Directory.GetFiles(backup_path_in, "*.*", SearchOption.AllDirectories).ToList(); List <string> xml_files = new List <string>(); List <string> apk_files = new List <string>(); List <string> tar_files = new List <string>(); List <string> db_files = new List <string>(); List <string> enc_files = new List <string>(); List <string> unk_files = new List <string>(); List <string> done_list; foreach (string entry in backup_all_files) { string extension = Path.GetExtension(entry).ToLower(); switch (extension) { case ".xml": xml_files.Add(entry); break; case ".apk": apk_files.Add(entry); break; case ".tar": tar_files.Add(entry); break; case ".db": db_files.Add(entry); break; case ".enc": enc_files.Add(entry); break; default: unk_files.Add(entry); break; } } HybridDictionary decrypt_material_dict = new HybridDictionary(); Decryptor decryptor = new Decryptor(user_password); Console.WriteLine("parsing XML files..."); foreach (string entry in xml_files) { string filename = Path.GetFileName(entry); Console.WriteLine("parsing xml " + filename); if (filename.ToLower() == "info.xml") { decrypt_material_dict = parse_info_xml(entry, ref decryptor, decrypt_material_dict); } else { decrypt_material_dict = parse_xml(entry, decrypt_material_dict); } } decryptor.crypto_init(); if (decryptor.good == false) { Console.WriteLine("decryption key is not good..."); return; } if (apk_files.Count > 0) { Console.WriteLine("copying APK to destination..."); string data_apk_dir = Path.Combine(dest_path_out, @"data\app"); Directory.CreateDirectory(data_apk_dir); done_list = new List <string>(); foreach (string entry in apk_files) { string filename = Path.GetFileName(entry); Console.WriteLine("working on " + filename); string dest_file = Path.Combine(data_apk_dir, filename + "-1"); Directory.CreateDirectory(dest_file); dest_file = Path.Combine(dest_file, "base.apk"); File.Copy(entry, dest_file); done_list.Add(entry); } foreach (string entry in done_list) { apk_files.Remove(entry); } } if (tar_files.Count > 0) { Console.WriteLine("decrypting and un-TAR-ing packages to destination..."); string data_app_dir = Path.Combine(dest_path_out, @"data\data"); Directory.CreateDirectory(data_app_dir); done_list = new List <string>(); foreach (string entry in tar_files) { Console.WriteLine("working on " + Path.GetFileName(entry)); byte[] cleartext = null; string directory = Path.GetDirectoryName(entry); string filename = Path.GetFileNameWithoutExtension(entry); string skey = Path.Combine(directory, filename); if (decrypt_material_dict.Contains(skey)) { done_list.Add(entry); DecryptMaterial dec_material = (DecryptMaterial)decrypt_material_dict[skey]; cleartext = decryptor.decrypt_package(dec_material, File.ReadAllBytes(entry)); } else { Console.WriteLine("entry '{0}' has no decrypt material!", skey); } if (cleartext != null) { using (MemoryStream ms = new MemoryStream(cleartext)) { TAR_Extract(ms, data_app_dir); } } else if (File.Exists(entry)) { using (StreamReader sr = new StreamReader(entry)) { TAR_Extract(sr.BaseStream, data_app_dir); } } } foreach (string entry in done_list) { tar_files.Remove(entry); } } if (db_files.Count > 0) { Console.WriteLine("decrypting database DB files to destination..."); string data_app_dir = Path.Combine(dest_path_out, "db"); Directory.CreateDirectory(data_app_dir); done_list = new List <string>(); foreach (string entry in db_files) { Console.WriteLine("working on " + Path.GetFileName(entry)); byte[] cleartext = null; string directory = Path.GetDirectoryName(entry); string filename = Path.GetFileNameWithoutExtension(entry); string skey = Path.Combine(directory, filename); if (decrypt_material_dict.Contains(skey)) { done_list.Add(entry); DecryptMaterial dec_material = (DecryptMaterial)decrypt_material_dict[skey]; cleartext = decryptor.decrypt_package(dec_material, File.ReadAllBytes(entry)); } else { Console.WriteLine("entry '{0}' has no decrypt material!", skey); } if (cleartext != null) { string dest_file = Path.Combine(data_app_dir, Path.GetFileName(entry)); File.WriteAllBytes(dest_file, cleartext); } } foreach (string entry in done_list) { db_files.Remove(entry); } } if (enc_files.Count > 0) { Console.WriteLine("decrypting multimedia ENC files to destination..."); string asterisk = @"|/-\-"; done_list = new List <string>(); for (int i = 1; i <= enc_files.Count; i++) { string entry = enc_files[i - 1]; byte[] cleartext = null; DecryptMaterial dec_material = null; string directory = Path.GetDirectoryName(entry); string filename = Path.GetFileNameWithoutExtension(entry); string skey = Path.Combine(directory, filename); if (decrypt_material_dict.Contains(skey)) { done_list.Add(entry); dec_material = (DecryptMaterial)decrypt_material_dict[skey]; string aString = String.Format("{0} of {1}: {2}", i, enc_files.Count, Path.GetFileName(dec_material.path)); aString = aString.PadRight(Console.WindowWidth - 2).Substring(0, Console.WindowWidth - 2); Console.Write("\r{0}{1}", aString, asterisk[i % asterisk.Length]); cleartext = decryptor.decrypt_file(dec_material, File.ReadAllBytes(entry)); } else { Console.WriteLine("entry '{0}' has no decrypt material!", skey); } if (cleartext != null && dec_material != null) { string dest_file = dest_path_out; string tmp_path = dec_material.path.TrimStart(new char[] { '\\', '/' }); dest_file = Path.Combine(dest_file, tmp_path); string dest_dir = Directory.GetParent(dest_file).FullName; Directory.CreateDirectory(dest_dir); File.WriteAllBytes(dest_file, cleartext); } } if (enc_files.Count > 0) { Console.Write("\r"); } foreach (string entry in done_list) { enc_files.Remove(entry); } } if (unk_files.Count > 0) { Console.WriteLine("copying unmanaged files to destination..."); string data_unk_dir = Path.Combine(dest_path_out, "misc"); Directory.CreateDirectory(data_unk_dir); done_list = new List <string>(); foreach (string entry in unk_files) { string common_path = FindCommonPath(new List <string>() { entry, backup_path_in }); string relative_path = entry.Replace(common_path, ""); relative_path = relative_path.TrimStart(new char[] { '\\', '/' }); string dest_file = Path.Combine(data_unk_dir, relative_path); Directory.CreateDirectory(Directory.GetParent(dest_file).FullName); File.Copy(entry, dest_file); done_list.Add(entry); } foreach (string entry in done_list) { unk_files.Remove(entry); } } foreach (string entry in apk_files) { string filename = Path.GetFileName(entry); Console.WriteLine("APK file not handled: " + filename); } foreach (string entry in tar_files) { string filename = Path.GetFileName(entry); Console.WriteLine("TAR file not handled: " + filename); } foreach (string entry in db_files) { string filename = Path.GetFileName(entry); Console.WriteLine("DB file not handled: " + filename); } foreach (string entry in enc_files) { string filename = Path.GetFileName(entry); Console.WriteLine("ENC file not handled: " + filename); } foreach (string entry in unk_files) { string filename = Path.GetFileName(entry); Console.WriteLine("UNK file not handled: " + filename); } Console.WriteLine("DONE!"); }
public CountComparer(HybridDictionary count) { this.count = count; }
public void Medley() { string keys = "AAAAAAABCDEFGabcdefg"; Random rand = new Random(); for (int capacity = 0; capacity < HybridDictionary <string, string> .MaxListSize + 2; capacity++) { var dict = new HybridDictionary <string, string>(capacity, StringComparer.OrdinalIgnoreCase); var shadow = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); for (int i = 0; i < 2000; i++) { switch (rand.Next(10 + 1)) { case 0: // Set something if (shadow.Count < HybridDictionary <string, string> .MaxListSize + 2) // Don't bother exploring above here { string key = new String(keys[rand.Next(keys.Length)], 1); string value = rand.Next(10).ToString(); dict[key] = value; shadow[key] = value.ToString(); AssertDictionariesIdentical(dict, shadow); } break; case 1: // Remove something existing if (shadow.Count > 0) { var entry = shadow.ElementAt(rand.Next(shadow.Count - 1)).Key; Assert.Equal(dict.Remove(entry), shadow.Remove(entry)); AssertDictionariesIdentical(dict, shadow); } break; case 2: // Remove something nonexistent AssertBothOrNeitherThrew <bool>(delegate() { return(dict.Remove("ZZ")); }, delegate() { return(shadow.Remove("ZZ")); }); AssertDictionariesIdentical(dict, shadow); break; case 3: // Look up something existing if (shadow.Count > 0) { var entry2 = shadow.ElementAt(rand.Next(shadow.Count - 1)).Key; Assert.Equal(dict[entry2], shadow[entry2]); AssertDictionariesIdentical(dict, shadow); } break; case 4: // Look up something non existing AssertBothOrNeitherThrew <string>(delegate() { return(dict["ZZ"]); }, delegate() { return(shadow["ZZ"]); }); AssertDictionariesIdentical(dict, shadow); break; case 5: // Try look up something existing if (shadow.Count > 0) { var entry2 = shadow.ElementAt(rand.Next(shadow.Count - 1)).Key; string value1; string value2; Assert.Equal(dict.TryGetValue(entry2, out value1), shadow.TryGetValue(entry2, out value2)); Assert.Equal(value1, value2); AssertDictionariesIdentical(dict, shadow); } break; case 6: // Try look up something non existing string value3; string value4; Assert.Equal(dict.TryGetValue("ZZ", out value3), shadow.TryGetValue("ZZ", out value4)); AssertDictionariesIdentical(dict, shadow); break; case 7: dict.Clear(); shadow.Clear(); break; case 8: // Add something existing key same value if (shadow.Count > 0) { var entry = shadow.ElementAt(rand.Next(shadow.Count - 1)); AssertBothOrNeitherThrew(delegate() { dict.Add(entry.Key, entry.Value); }, delegate() { shadow.Add(entry.Key, entry.Value); }); AssertDictionariesIdentical(dict, shadow); } break; case 9: // Add something existing key different value if (shadow.Count > 0) { var key = shadow.ElementAt(rand.Next(shadow.Count - 1)).Key; string value = rand.Next(10).ToString(); AssertBothOrNeitherThrew(delegate() { dict.Add(key, value); }, delegate() { shadow.Add(key, value); }); AssertDictionariesIdentical(dict, shadow); } break; case 10: // Add something non existing string key2 = new String(keys[rand.Next(keys.Length)], 1); string value5 = rand.Next(10).ToString(); AssertBothOrNeitherThrew(delegate() { dict.Add(key2, value5); }, delegate() { shadow.Add(key2, value5); }); AssertDictionariesIdentical(dict, shadow); break; } } dict.Clear(); Assert.Equal(0, dict.Count); } }
// GET api/sm24/5 public List <SM24BO> Get(string ProjectName, string CabinetName, string AreaName, string LocationName, string CabinetTypeName, int ModelView) { List <SM24BO> objPHSM24BO = new List <SM24BO>(); List <GeneralClass> objIDCBO = new List <GeneralClass>(); List <GeneralClass> objHeatDissBO = new List <GeneralClass>(); try { DatabaseContext objDBContext = new DatabaseContext(); HybridDictionary objHybirdTemplate = new HybridDictionary(true); objHybirdTemplate.Add("@ProjectName", ProjectName); objHybirdTemplate.Add("@CabinetName", CabinetName); objHybirdTemplate.Add("@AreaName", AreaName); objHybirdTemplate.Add("@LocationName", LocationName); objHybirdTemplate.Add("@CabinetTypeName", CabinetTypeName); objHybirdTemplate.Add("@ModelView", ModelView); DataSet dsTemplate = objDBContext.DownloadDataFromDB(GlobalConstants.GETPHSM24VDCps, objHybirdTemplate); PHControllerBO objStaffingfirmInfo = new PHControllerBO(); string Name = ""; if (dsTemplate != null && dsTemplate.Tables != null && dsTemplate.Tables.Count > 0 && dsTemplate.Tables[0].Rows != null && dsTemplate.Tables[0].Rows.Count > 0) { foreach (DataRow dr in dsTemplate.Tables[0].Rows) { objIDCBO = new List <GeneralClass>(); objHeatDissBO = new List <GeneralClass>(); if (ModelView == 0) { objIDCBO.Add(new GeneralClass { Name = "CurrentRating", Value = Formatter.ConvertToDecimal(dr["CurrentRating"]) }); objIDCBO.Add(new GeneralClass { Name = "IDC", Value = Formatter.ConvertToDecimal(dr["IDC"]) }); objHeatDissBO.Add(new GeneralClass { Name = "HeatDiss", Value = Formatter.ConvertToDecimal(dr["HeatDiss"]) }); Name = Formatter.ConvertToString(dr["CabinetName"]); } else { //objIDCBO.Add(new GeneralClass { Name = "CurrentRating", Value = Formatter.ConvertToDecimal(dr["CurrentRating"]) }); objIDCBO.Add(new GeneralClass { Name = "IDC", Value = Formatter.ConvertToDecimal(dr["IDC"]) }); objHeatDissBO.Add(new GeneralClass { Name = "HeatDiss", Value = Formatter.ConvertToDecimal(dr["HeatDiss"]) }); if (CabinetName == null || CabinetName == "") { Name = Formatter.ConvertToString(dr["CabinetName"]) + "/" + Formatter.ConvertToString(dr["ModuleName"]); } else { Name = Formatter.ConvertToString(dr["ModuleName"]); } } objPHSM24BO.Add(new SM24BO { ProjectName = Formatter.ConvertToString(dr["ProjectName"]), ModuleName = Formatter.ConvertToString(dr["ModuleName"]), Date = Name, Categories = objIDCBO, LineCategory = objHeatDissBO, IDC = Formatter.ConvertToDecimal(dr["IDC"]), CurrentRating = Formatter.ConvertToDecimal(dr["CurrentRating"]), HeatDiss = Formatter.ConvertToDecimal(dr["HeatDiss"]) }); } } } catch (Exception ex) { throw ex; } return(objPHSM24BO); }
static void Main(string[] args) { Hashtable hashTable = new Hashtable(); ListDictionary listDicti = new ListDictionary(); HybridDictionary hybDicti = new HybridDictionary(); Stopwatch stopWatchHashTable = new Stopwatch(); Stopwatch stopWatchListDicti = new Stopwatch(); Stopwatch stopWatchHybDicti = new Stopwatch(); int cnt = 1000, hashCnt = 0, listCnt = 0, hybCnt = 0; for (int k = 0; k < 999; k++) { stopWatchHashTable.Start(); for (int i = 0; i < cnt; i++) { hashTable.Add(i, "DesDevIn_dotNET"); } hashTable.Clear(); stopWatchHashTable.Stop(); TimeSpan tsHashTable = stopWatchHashTable.Elapsed; hashCnt += tsHashTable.Milliseconds; } Console.WriteLine("RunTime HashTable " + hashCnt / 1000); for (int k = 0; k < 999; k++) { stopWatchListDicti.Start(); for (int i = 0; i < cnt; i++) { listDicti.Add(i, "DesDevIn_dotNET"); } listDicti.Clear(); stopWatchListDicti.Stop(); TimeSpan tsListDicti = stopWatchListDicti.Elapsed; listCnt += tsListDicti.Milliseconds; } Console.WriteLine("RunTime ListDicti " + listCnt / 1000); for (int k = 0; k < 999; k++) { stopWatchHybDicti.Start(); for (int i = 0; i < cnt; i++) { hybDicti.Add(i, "DesDevIn_dotNET"); } hybDicti.Clear(); stopWatchHybDicti.Stop(); TimeSpan tsHybDicti = stopWatchHybDicti.Elapsed; hybCnt += tsHybDicti.Milliseconds; } Console.WriteLine("RunTime HybDicti " + hybCnt / 1000); Console.ReadKey(); }
public void Test01() { const int BIG_LENGTH = 100; HybridDictionary hd; // simple string values string[] valuesShort = { "", " ", "$%^#", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; // keys for simple string values string[] keysShort = { Int32.MaxValue.ToString(), " ", System.DateTime.Today.ToString(), "", "$%^#" }; string[] valuesLong = new string[BIG_LENGTH]; string[] keysLong = new string[BIG_LENGTH]; Array arr; ICollection vs; // Values collection int ind; for (int i = 0; i < BIG_LENGTH; i++) { valuesLong[i] = "Item" + i; keysLong[i] = "keY" + i; } // [] HybridDictionary is constructed as expected //----------------------------------------------------------------- hd = new HybridDictionary(); // [] for empty dictionary // if (hd.Count > 0) { hd.Clear(); } if (hd.Values.Count != 0) { Assert.False(true, string.Format("Error, returned Values.Count = {0}", hd.Values.Count)); } // [] for short filled dictionary // int len = valuesShort.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysShort[i], valuesShort[i]); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } vs = hd.Values; if (vs.Count != len) { Assert.False(true, string.Format("Error, returned Values.Count = {0}", vs.Count)); } arr = Array.CreateInstance(typeof(Object), len); vs.CopyTo(arr, 0); for (int i = 0; i < len; i++) { ind = Array.IndexOf(arr, valuesShort[i]); if (ind < 0) { Assert.False(true, string.Format("Error, Values doesn't contain \"{1}\" value. Search result: {2}", i, valuesShort[i], ind)); } } // [] for long filled dictionary // len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } vs = hd.Values; if (vs.Count != len) { Assert.False(true, string.Format("Error, returned Values.Count = {0}", vs.Count)); } arr = Array.CreateInstance(typeof(Object), len); vs.CopyTo(arr, 0); for (int i = 0; i < len; i++) { ind = Array.IndexOf(arr, valuesLong[i]); if (ind < 0) { Assert.False(true, string.Format("Error, Values doesn't contain \"{1}\" value. Search result: {2}", i, valuesLong[i], ind)); } } // // [] get Values on dictionary with different_in_casing_only keys - list // hd.Clear(); string intlStr = "intlStr"; hd.Add("keykey", intlStr); // 1st key hd.Add("keyKey", intlStr); // 2nd key if (hd.Count != 2) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, 2)); } // get Values // vs = hd.Values; if (vs.Count != hd.Count) { Assert.False(true, string.Format("Error, returned Values.Count = {0}", vs.Count)); } arr = Array.CreateInstance(typeof(Object), 2); vs.CopyTo(arr, 0); ind = Array.IndexOf(arr, intlStr); if (ind < 0) { Assert.False(true, string.Format("Error, Values doesn't contain {0} value", intlStr)); } // // [] get Values on dictionary with different_in_casing_only keys - hashtable // hd.Clear(); hd.Add("keykey", intlStr); // 1st key for (int i = 0; i < BIG_LENGTH; i++) { hd.Add(keysLong[i], valuesLong[i]); } hd.Add("keyKey", intlStr); // 2nd key if (hd.Count != BIG_LENGTH + 2) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, BIG_LENGTH + 2)); } // get Values // vs = hd.Values; if (vs.Count != hd.Count) { Assert.False(true, string.Format("Error, returned Values.Count = {0}", vs.Count)); } arr = Array.CreateInstance(typeof(Object), BIG_LENGTH + 2); vs.CopyTo(arr, 0); for (int i = 0; i < BIG_LENGTH; i++) { if (Array.IndexOf(arr, valuesLong[i]) < 0) { Assert.False(true, string.Format("Error, Values doesn't contain {0} value", valuesLong[i], i)); } } ind = Array.IndexOf(arr, intlStr); if (ind < 0) { Assert.False(true, string.Format("Error, Values doesn't contain {0} value", intlStr)); } // // [] Change long dictionary and check Values // hd.Clear(); len = valuesLong.Length; for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } vs = hd.Values; if (vs.Count != len) { Assert.False(true, string.Format("Error, returned Values.Count = {0}", vs.Count)); } hd.Remove(keysLong[0]); if (hd.Count != len - 1) { Assert.False(true, string.Format("Error, didn't remove element")); } if (vs.Count != len - 1) { Assert.False(true, string.Format("Error, Values were not updated after removal")); } arr = Array.CreateInstance(typeof(Object), hd.Count); vs.CopyTo(arr, 0); ind = Array.IndexOf(arr, valuesLong[0]); if (ind >= 0) { Assert.False(true, string.Format("Error, Values still contains removed value " + ind)); } hd.Add(keysLong[0], "new item"); if (hd.Count != len) { Assert.False(true, string.Format("Error, didn't add element")); } if (vs.Count != len) { Assert.False(true, string.Format("Error, Values were not updated after addition")); } arr = Array.CreateInstance(typeof(Object), hd.Count); vs.CopyTo(arr, 0); ind = Array.IndexOf(arr, "new item"); if (ind < 0) { Assert.False(true, string.Format("Error, Values doesn't contain added value ")); } // // [] Change short dictionary and check Values // hd.Clear(); len = valuesShort.Length; for (int i = 0; i < len; i++) { hd.Add(keysShort[i], valuesShort[i]); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } vs = hd.Values; if (vs.Count != len) { Assert.False(true, string.Format("Error, returned Values.Count = {0}", vs.Count)); } hd.Remove(keysShort[0]); if (hd.Count != len - 1) { Assert.False(true, string.Format("Error, didn't remove element")); } if (vs.Count != len - 1) { Assert.False(true, string.Format("Error, Values were not updated after removal")); } arr = Array.CreateInstance(typeof(Object), hd.Count); vs.CopyTo(arr, 0); ind = Array.IndexOf(arr, valuesShort[0]); if (ind >= 0) { Assert.False(true, string.Format("Error, Values still contains removed value " + ind)); } hd.Add(keysShort[0], "new item"); if (hd.Count != len) { Assert.False(true, string.Format("Error, didn't add element")); } if (vs.Count != len) { Assert.False(true, string.Format("Error, Values were not updated after addition")); } arr = Array.CreateInstance(typeof(Object), hd.Count); vs.CopyTo(arr, 0); ind = Array.IndexOf(arr, "new item"); if (ind < 0) { Assert.False(true, string.Format("Error, Values doesn't contain added value ")); } }
//public void databind() //{ // MySqlConnection mysqlcon = msq.getmysqlcon(); // DataSet ds = MySqlHelper.ExecuteDataset(mysqlcon, str111); // DataView dv = new DataView(ds.Tables[0]); // benfactorFrom.DataSource = dv; // benfactorFrom.DataTextField = "benfactorFrom"; // benfactorFrom.DataBind(); //} protected void submit_Click(object sender, EventArgs e) { labError.Text = ""; string strID = txtID.Text.Trim(); if (strID == "") { labError.ForeColor = System.Drawing.Color.Red; labError.Text = "请输入用户名!"; txtID.BackColor = Color.FromArgb((int)0xFFE1FF); txtID.Focus(); return; } else { txtID.BackColor = Color.White; } string strName = txtName.Text.Trim(); if (strName == "") { labError.ForeColor = System.Drawing.Color.Red; labError.Text = "请输入姓名!"; txtName.BackColor = Color.FromArgb((int)0xFFE1FF); txtName.Focus(); return; } else { txtName.BackColor = Color.White; } //string strFrom = benfactorFrom.Text.Trim(); string errMsg = ""; if (!luyunfei.lyf_validate.isAZaz09_Ch(strName, 1, 20, out errMsg)) { labError.Text = "输入的" + PAGE_NAME + "名称有误!" + errMsg; return; } string strTEL = TEL.Text.Trim(); if (strTEL == "") { labError.ForeColor = System.Drawing.Color.Red; labError.Text = "请输入联系方式!"; TEL.BackColor = Color.FromArgb((int)0xFFE1FF); TEL.Focus(); return; } else { TEL.BackColor = Color.White; } string strPwdOld = txtPWDOld.Text.Trim(); if (strPwdOld == "") { labError.ForeColor = System.Drawing.Color.Red; labError.Text = "请输入旧密码!"; txtPWDOld.BackColor = Color.FromArgb((int)0xFFE1FF); txtPWD.BackColor = Color.White; txtPWD2.BackColor = Color.White; txtPWDOld.Focus(); return; } else { txtPWDOld.BackColor = Color.White; } //if (!luyunfei.lyf_validate.isAZaz09_(strPwdOld, 5, 20, out errMsg)) //{ // labError.Text = "输入的旧密码有误!" + errMsg; // txtPWDOld.Focus(); // return; //} string strPwd = txtPWD.Text.Trim(); if (strPwd == "") { labError.ForeColor = System.Drawing.Color.Red; labError.Text = "请输入新密码!"; txtPWDOld.BackColor = Color.FromArgb((int)0xFFE1FF); txtPWD.BackColor = Color.FromArgb((int)0xFFE1FF); txtPWD2.BackColor = Color.FromArgb((int)0xFFE1FF); txtPWDOld.Focus(); return; } else { txtPWDOld.BackColor = Color.White; txtPWD.BackColor = Color.White; txtPWD2.BackColor = Color.White; } //string errMsg = ""; if (!luyunfei.lyf_validate.isAZaz09_(strPwd, 5, 20, out errMsg)) { labError.Text = "新密码由5~20位的数字、英文字母或下划线组成!"; txtPWDOld.BackColor = Color.FromArgb((int)0xFFE1FF); txtPWD.BackColor = Color.FromArgb((int)0xFFE1FF); txtPWD2.BackColor = Color.FromArgb((int)0xFFE1FF); txtPWDOld.Focus(); return; } else { txtPWDOld.BackColor = Color.White; txtPWD.BackColor = Color.White; txtPWD2.BackColor = Color.White; } string strPwd2 = txtPWD2.Text.Trim(); if (strPwd2 == "") { labError.ForeColor = System.Drawing.Color.Red; labError.Text = "需要确认新密码!"; txtPWDOld.BackColor = Color.FromArgb((int)0xFFE1FF); txtPWD.BackColor = Color.FromArgb((int)0xFFE1FF); txtPWD2.BackColor = Color.FromArgb((int)0xFFE1FF); txtPWDOld.Focus(); return; } else { txtPWDOld.BackColor = Color.White; txtPWD.BackColor = Color.White; txtPWD2.BackColor = Color.White; } if (!luyunfei.lyf_validate.isAZaz09_(strPwd2, 5, 20, out errMsg)) { labError.Text = "再次输入的新密码有误!" + errMsg; return; } if (strPwd != strPwd2) { labError.ForeColor = System.Drawing.Color.Red; labError.Text = "两次输入的新密码不一致!"; txtPWDOld.BackColor = Color.FromArgb((int)0xFFE1FF); txtPWD.BackColor = Color.FromArgb((int)0xFFE1FF); txtPWD2.BackColor = Color.FromArgb((int)0xFFE1FF); txtPWDOld.Focus(); return; } else { txtPWDOld.BackColor = Color.White; txtPWD.BackColor = Color.White; txtPWD2.BackColor = Color.White; } //HybridDictionary hd = new HybridDictionary(); //hd.Add(sPMS_CTG_ID, strID); //tableUsers = entityUsers.ExecuteDataTable2(CommandType.Text, "SelectById", hd); //DataView dv = new DataView(tableUsers); mysqlconn msq = new mysqlconn(); string str = string.Format("select * from e_user where user='******'", strID); DataSet ds = MySqlHelper.ExecuteDataset(msq.getmysqlcon(), str); DataView dv = new DataView(ds.Tables[0]); txtName.Text = dv[0][sPMS_CTG_NAME].ToString(); if (dv.Count == 0) { labError.ForeColor = System.Drawing.Color.Red; labError.Text = "用户不存在!"; return; } string s = dv[0]["password"].ToString(); if (strPwdOld != s) { labError.ForeColor = System.Drawing.Color.Red; labError.Text = "输入的旧密码不正确!"; txtPWDOld.BackColor = Color.FromArgb((int)0xFFE1FF); txtPWD.BackColor = Color.White; txtPWD2.BackColor = Color.White; txtPWDOld.Focus(); return; } else { txtPWDOld.BackColor = Color.White; } try { HybridDictionary myHd = new HybridDictionary(); myHd.Add(sPMS_CTG_ID, strID); myHd.Add(sPMS_CTG_NAME, strName); myHd.Add(sPwd, strPwd); myHd.Add(sUPD_DATE, DateTime.Now); string str1 = string.Format("update e_user set name='{0}',password='******',TEL='{2}' where user='******'", strName, strPwd, strTEL, strID); int result = msq.getmysqlcom(str1); //bool result = Convert.ToBoolean(entityUsers.Update(myHd)); if (result > 0) { labError.ForeColor = System.Drawing.Color.Blue; labError.Text = "资料修改成功! 请牢记!"; // wl.WriteLogData(PAGE_NAME, "修改", strName, System.Diagnostics.EventLogEntryType.Information); NLogTest nlog = new NLogTest(); string sss = "修改了用户" + Session["UserName"].ToString() + "的信息"; nlog.WriteLog(Session["UserName"].ToString(), sss); } else { labError.ForeColor = System.Drawing.Color.Red; labError.Text = "未找到对应记录,修改资料失败"; // wl.WriteLogData(PAGE_NAME, "修改", strName + "未找到对应记录,修改记录失败", System.Diagnostics.EventLogEntryType.Warning); } } catch (Exception ex) { labError.ForeColor = System.Drawing.Color.Red; labError.Text = "修改资料失败" + ui.ExceptionMsg(ex); // wl.WriteLogData(PAGE_NAME, "修改", strName + ":" + ex.Message + ex.StackTrace, System.Diagnostics.EventLogEntryType.Error); } loadBaseInf(); }
public GetMemberCommand() { MemberType = PSMemberTypes.All; _membersCollection = new HybridDictionary(); }
/// <summary> /// Constructs a new DOLEventHandler collection /// </summary> public RoadEventHandlerCollection() { m_lock = new System.Threading.ReaderWriterLock(); m_events = new HybridDictionary(); }
/// <summary> /// Resolves this managed collection at runtime. /// </summary> /// <param name="objectName"> /// The name of the top level object that is having the value of one of it's /// collection properties resolved. /// </param> /// <param name="definition"> /// The definition of the named top level object. /// </param> /// <param name="propertyName"> /// The name of the property the value of which is being resolved. /// </param> /// <param name="resolver"> /// The callback that will actually do the donkey work of resolving /// this managed collection. /// </param> /// <returns>A fully resolved collection.</returns> public ICollection Resolve( string objectName, IObjectDefinition definition, string propertyName, ManagedCollectionElementResolver resolver) { IDictionary dictionary; Type keyType = null; if (StringUtils.HasText(this.keyTypeName)) { keyType = TypeResolutionUtils.ResolveType(this.keyTypeName); } Type valueType = null; if (StringUtils.HasText(this.valueTypeName)) { valueType = TypeResolutionUtils.ResolveType(this.valueTypeName); } if ((keyType == null) && (valueType == null)) { dictionary = new HybridDictionary(); } else { Type type = typeof(Dictionary <,>); Type[] genericArgs = new Type[2] { (keyType == null) ? typeof(object) : keyType, (valueType == null) ? typeof(object) : valueType }; type = type.MakeGenericType(genericArgs); dictionary = (IDictionary)ObjectUtils.InstantiateType(type); } foreach (object key in this.Keys) { string elementName = string.Format(CultureInfo.InvariantCulture, "{0}[{1}]", propertyName, key); object resolvedKey = resolver(objectName, definition, elementName, key); object resolvedValue = resolver(objectName, definition, elementName, this[key]); if (keyType != null) { try { resolvedKey = TypeConversionUtils.ConvertValueIfNecessary(keyType, resolvedKey, propertyName); } catch (TypeMismatchException) { throw new TypeMismatchException( String.Format( "Unable to convert managed dictionary key '{0}' from [{1}] into [{2}] during initialization" + " of property '{3}' for object '{4}'. Do you have an appropriate type converter registered?", resolvedKey, resolvedKey.GetType(), keyType, propertyName, objectName)); } } if (valueType != null) { try { resolvedValue = TypeConversionUtils.ConvertValueIfNecessary(valueType, resolvedValue, propertyName + "[" + resolvedKey + "]"); } catch (TypeMismatchException) { throw new TypeMismatchException( String.Format( "Unable to convert managed dictionary value '{0}' from [{1}] into [{2}] during initialization" + " of property '{3}' for object '{4}'. Do you have an appropriate type converter registered?", resolvedValue, resolvedValue.GetType(), valueType, propertyName, objectName)); } } dictionary.Add(resolvedKey, resolvedValue); } return(dictionary); }
public void Ctor_Empty() { HybridDictionary hybridDictionary = new HybridDictionary(); VerifyCtor(hybridDictionary, caseInsensitive: false); }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; IntlStrings intl; String strLoc = "Loc_000oo"; HybridDictionary hd; const int BIG_LENGTH = 100; string [] valuesShort = { "", " ", "$%^#", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; string [] keysShort = { Int32.MaxValue.ToString(), " ", System.DateTime.Today.ToString(), "", "$%^#" }; string [] valuesLong = new string[BIG_LENGTH]; string [] keysLong = new string[BIG_LENGTH]; int cnt = 0; Object itm; try { intl = new IntlStrings(); for (int i = 0; i < BIG_LENGTH; i++) { valuesLong[i] = "Item" + i; keysLong[i] = "keY" + i; } Console.WriteLine("--- create dictionary ---"); strLoc = "Loc_001oo"; iCountTestcases++; hd = new HybridDictionary(); Console.WriteLine("1. set Item() on empty dictionary"); iCountTestcases++; cnt = hd.Count; Console.WriteLine(" - Item(null)"); try { hd[null] = valuesShort[0]; iCountErrors++; Console.WriteLine("Err_0001a, no exception"); } catch (ArgumentNullException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0001b, unexpected exception: {0}", e.ToString()); } iCountTestcases++; cnt = hd.Count; Console.WriteLine(" - Item(some_string)"); hd["some_string"] = valuesShort[0]; if (hd.Count != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0001c, failed to add Item(some_string)"); } iCountTestcases++; itm = hd["some_string"]; if (String.Compare(itm.ToString(), valuesShort[0], false) != 0) { iCountErrors++; Console.WriteLine("Err_0001d, added wrong Item(some_string)"); } Console.WriteLine("2. add few simple strings, set Item(Object)"); strLoc = "Loc_002oo"; iCountTestcases++; hd.Clear(); cnt = hd.Count; int len = valuesShort.Length; for (int i = 0; i < len; i++) { hd.Add(keysShort[i], valuesShort[i]); } if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0002a, count is {0} instead of {1}", hd.Count, valuesShort.Length); } for (int i = 0; i < len; i++) { iCountTestcases++; cnt = hd.Count; hd[keysShort[i]] = valuesLong[0]; if (hd.Count != cnt ) { iCountErrors++; Console.WriteLine("Err_0002_{0}*, added item instead of setting", i); } itm = hd[keysShort[i]]; if (String.Compare(itm.ToString(), valuesLong[0], false) != 0) { iCountErrors++; Console.WriteLine("Err_0002_{0}b, failed to set item", i); } } cnt = hd.Count; iCountTestcases++; hd[keysLong[0]] = valuesLong[0]; if (hd.Count != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0002_c, didn't add non-existing item"); } iCountTestcases++; itm = hd[keysLong[0]]; if (String.Compare(itm.ToString(), valuesLong[0], false) != 0) { iCountErrors++; Console.WriteLine("Err_0002_d, failed to set item"); } Console.WriteLine("3. add many simple strings, set Item(Object)"); strLoc = "Loc_003oo"; iCountTestcases++; hd.Clear(); cnt = hd.Count; len = valuesLong.Length; for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", hd.Count, len); } for (int i = 0; i < len; i++) { cnt = hd.Count; iCountTestcases++; hd[keysLong[i]] = valuesShort[0]; if (hd.Count != cnt ) { iCountErrors++; Console.WriteLine("Err_0003_{0}*, added item instead of setting", i); } itm = hd[keysLong[i]]; if (String.Compare(itm.ToString(), valuesShort[0], false) != 0) { iCountErrors++; Console.WriteLine("Err_0003_{0}b, failed to set item", i); } } cnt = hd.Count; iCountTestcases++; hd[keysShort[0]] = valuesShort[0]; if (hd.Count != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0003_c, didn't add non-existing item"); } iCountTestcases++; itm = hd[keysShort[0]]; if (String.Compare(itm.ToString(), valuesShort[0], false) != 0) { iCountErrors++; Console.WriteLine("Err_0003_d, failed to set item"); } Console.WriteLine("4. add many intl strings and set Item()"); strLoc = "Loc_004oo"; iCountTestcases++; len = valuesLong.Length; string [] intlValues = new string [len * 2 + 1]; for (int i = 0; i < len*2+1; i++) { string val = intl.GetString(MAX_LEN, true, true, true); while (Array.IndexOf(intlValues, val) != -1 ) val = intl.GetString(MAX_LEN, true, true, true); intlValues[i] = val; } string toSet = intlValues[len*2]; iCountTestcases++; cnt = hd.Count; for (int i = 0; i < len; i++) { hd.Add(intlValues[i+len], intlValues[i]); } if ( hd.Count != (cnt+len) ) { iCountErrors++; Console.WriteLine("Err_0004a, count is {0} instead of {1}", hd.Count, cnt+len); } for (int i = 0; i < len; i++) { cnt = hd.Count; iCountTestcases++; hd[intlValues[i+len]] = toSet; if (hd.Count != cnt) { iCountErrors++; Console.WriteLine("Err_0004_{0}b, added item instead of setting", i); } itm = hd[intlValues[i+len]]; if (string.Compare(itm.ToString(), toSet, false) != 0) { iCountErrors++; Console.WriteLine("Err_0004_{0}c, failed to set item", i); } } Console.WriteLine("5. add few intl strings and set Item()"); strLoc = "Loc_005oo"; iCountTestcases++; len = valuesShort.Length; iCountTestcases++; hd.Clear(); cnt = hd.Count; for (int i = 0; i < len; i++) { hd.Add(intlValues[i+len], intlValues[i]); } if ( hd.Count != (cnt+len) ) { iCountErrors++; Console.WriteLine("Err_0005a, count is {0} instead of {1}", hd.Count, cnt+len); } for (int i = 0; i < len; i++) { cnt = hd.Count; iCountTestcases++; hd[intlValues[i+len]] = toSet; if (hd.Count != cnt) { iCountErrors++; Console.WriteLine("Err_0005_{0}b, added item instead of setting", i); } iCountTestcases++; itm = hd[intlValues[i+len]]; if (String.Compare(itm.ToString(), toSet, false) != 0) { iCountErrors++; Console.WriteLine("Err_0005_{0}c, returned wrong item", i); } } Console.WriteLine("6. case sensitivity - hashtable"); strLoc = "Loc_006oo"; len = valuesLong.Length; hd.Clear(); Console.WriteLine(" - add uppercase and set via uppercase"); for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToUpper(), valuesLong[i].ToUpper()); } for (int i = 0; i < len; i++) { iCountTestcases++; hd[keysLong[i].ToUpper()] = toSet; itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), toSet, false) != 0) { iCountErrors++; Console.WriteLine("Err_0006_{0}b, failed to set", i); } } hd.Clear(); Console.WriteLine(" - add uppercase but set via lowercase"); for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToUpper(), valuesLong[i].ToUpper()); } for (int i = 0; i < len; i++) { iCountTestcases++; cnt = hd.Count; hd[keysLong[i].ToLower()] = toSet; if (hd.Count != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0006_{0}b, failed to add when setting", i); } iCountTestcases++; itm = hd[keysLong[i].ToLower()]; if (String.Compare(itm.ToString(), toSet, false) != 0) { iCountErrors++; Console.WriteLine("Err_0006_{0}c, failed to set item", i); } iCountTestcases++; itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), valuesLong[i].ToUpper(), false) != 0) { iCountErrors++; Console.WriteLine("Err_0006_{0}d, failed to preserve item", i); } } Console.WriteLine("7. case sensitivity - list"); strLoc = "Loc_007oo"; len = valuesShort.Length; Console.WriteLine(" ** fill with {0} elements", len); hd.Clear(); Console.WriteLine(" - add uppercase and set via uppercase"); for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToUpper(), valuesLong[i].ToUpper()); } for (int i = 0; i < len; i++) { iCountTestcases++; hd[keysLong[i].ToUpper()] = toSet; itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), toSet, false) != 0) { iCountErrors++; Console.WriteLine("Err_0007_{0}b, failed to set", i); } } hd.Clear(); Console.WriteLine(" - add uppercase but set via lowercase"); for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToUpper(), valuesLong[i].ToUpper()); } for (int i = 0; i < len; i++) { iCountTestcases++; cnt = hd.Count; hd[keysLong[i].ToLower()] = toSet; if (hd.Count != cnt + 1) { iCountErrors++; Console.WriteLine("Err_0007_{0}b, failed to add when setting", i); } iCountTestcases++; itm = hd[keysLong[i].ToLower()]; if (String.Compare(itm.ToString(), toSet, false) != 0) { iCountErrors++; Console.WriteLine("Err_0007_{0}c, failed to set item", i); } iCountTestcases++; itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), valuesLong[i].ToUpper(), false) != 0) { iCountErrors++; Console.WriteLine("Err_0007_{0}d, failed to preserve item", i); } } Console.WriteLine("8. set Item() on case-insensitive HD - list"); hd = new HybridDictionary(true); strLoc = "Loc_008oo"; iCountTestcases++; len = valuesShort.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToLower(), valuesLong[i].ToLower()); } if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0008a, count is {0} instead of {1}", hd.Count, len); } for (int i = 0; i < len; i++) { iCountTestcases++; hd[keysLong[i].ToUpper()] = toSet; itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), toSet, false) != 0) { iCountErrors++; Console.WriteLine("Err_0008b_{0}, failed to set via uppercase key", i); } iCountTestcases++; hd[keysLong[i].ToLower()] = valuesLong[0]; itm = hd[keysLong[i].ToLower()]; if (String.Compare(itm.ToString(), valuesLong[0], false) != 0) { iCountErrors++; Console.WriteLine("Err_0008b_{0}, failed to set via lowercase key", i); } } Console.WriteLine("9. set Item() on case-insensitive HD - hashtable"); hd = new HybridDictionary(true); strLoc = "Loc_009oo"; iCountTestcases++; len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i].ToLower(), valuesLong[i].ToLower()); } if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0009a, count is {0} instead of {1}", hd.Count, len); } for (int i = 0; i < len; i++) { iCountTestcases++; hd[keysLong[i].ToUpper()] = toSet; itm = hd[keysLong[i].ToUpper()]; if (String.Compare(itm.ToString(), toSet, false) != 0) { iCountErrors++; Console.WriteLine("Err_0009b_{0}, failed to set via uppercase key", i); } iCountTestcases++; hd[keysLong[i].ToLower()] = valuesLong[0]; itm = hd[keysLong[i].ToLower()]; if (String.Compare(itm.ToString(), valuesLong[0], false) != 0) { iCountErrors++; Console.WriteLine("Err_0009c_{0}, failed to set via lowercase key", i); } } Console.WriteLine("10. set Item(null) for filled HD - list"); hd = new HybridDictionary(); strLoc = "Loc_0010oo"; iCountTestcases++; len = valuesShort.Length; hd.Clear(); for (int i = 0; i < len; i ++) { hd.Add(keysShort[i], valuesShort[i]); } iCountTestcases++; try { hd[null] = toSet; iCountErrors++; Console.WriteLine("Err_0010a, no exception"); } catch (ArgumentNullException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0010b, unexpected exception: {0}", e.ToString()); } Console.WriteLine("11. seet Item(null) for filled HD - hashtable"); hd = new HybridDictionary(); strLoc = "Loc_0011oo"; iCountTestcases++; len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i ++) { hd.Add(keysLong[i], valuesLong[i]); } iCountTestcases++; try { hd[null] = toSet; iCountErrors++; Console.WriteLine("Err_0011a, no exception"); } catch (ArgumentNullException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0011b, unexpected exception: {0}", e.ToString()); } Console.WriteLine("15. set Item() to null - list"); hd = new HybridDictionary(); strLoc = "Loc_0015oo"; iCountTestcases++; hd.Clear(); len = valuesShort.Length; for (int i = 0; i < len; i++) { hd.Add(keysShort[i], valuesShort[i]); } if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0015a, count is {0} instead of {1}", hd.Count, len); } iCountTestcases++; cnt = hd.Count; hd[keysShort[0]] =null; if (hd.Count != cnt ) { iCountErrors++; Console.WriteLine("Err_0015b, added entry instead of setting"); } itm = hd[keysShort[0]]; if ( itm != null) { iCountErrors++; Console.WriteLine("Err_0015c, failed to set to null"); } Console.WriteLine("16. set Item() to null - hashtable"); hd.Clear(); strLoc = "Loc_0016oo"; iCountTestcases++; len = valuesLong.Length; for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0016a, count is {0} instead of {1}", hd.Count, len); } iCountTestcases++; cnt = hd.Count; hd[keysLong[0]] =null; if (hd.Count != cnt ) { iCountErrors++; Console.WriteLine("Err_0016b, added entry instead of setting"); } itm = hd[keysLong[0]]; if ( itm != null) { iCountErrors++; Console.WriteLine("Err_0016c, failed to set to null"); } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_general! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "Pass. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("Fail! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
void LoadBrowser(string rpLayoutEngine) { if (!r_BrowsersDirectory.Exists) throw new DirectoryNotFoundException(r_BrowsersDirectory.FullName); foreach (var rFile in r_BrowsersDirectory.EnumerateFiles("*.dll", SearchOption.AllDirectories)) FileSystem.Unblock(rFile.FullName); var rInfos = r_BrowsersDirectory.EnumerateFiles("*.json").Select(r => { using (var rReader = new JsonTextReader(File.OpenText(r.FullName))) return JObject.Load(rReader).ToObject<LayoutEngineInfo>(); }).ToArray(); var rInfo = rInfos.SingleOrDefault(r => r.Name == rpLayoutEngine); if (rInfo == null) throw new Exception($"Assigned layout engine not found.{Environment.NewLine}Current layout engine: {rpLayoutEngine}{Environment.NewLine}Installed layout engine(s):{Environment.NewLine}{rInfos.Select(r => r.Name).Join(Environment.NewLine)}"); if (rInfo.Dependencies != null) r_LayoutEngineDependencies = rInfo.Dependencies.ToHybridDictionary(r => r.AssemblyName, r => r.Path); var rAssembly = Assembly.LoadFile(Path.Combine(r_BrowsersDirectory.FullName, rInfo.EntryFile)); var rType = rAssembly.GetTypes().Where(r => r.GetInterface(typeof(IBrowserProvider).FullName) != null).FirstOrDefault(); if (rType == null) throw new Exception($"IBrowserProvider not found in {rAssembly.FullName}."); r_BrowserProvider = (IBrowserProvider)rAssembly.CreateInstance(rType.FullName); }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; HybridDictionary hd; const int BIG_LENGTH = 100; string [] valuesShort = { "", " ", "$%^#", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; string [] keysShort = { Int32.MaxValue.ToString(), " ", System.DateTime.Today.ToString(), "", "$%^#" }; string [] valuesLong = new string[BIG_LENGTH]; string [] keysLong = new string[BIG_LENGTH]; int cnt = 0; try { for (int i = 0; i < BIG_LENGTH; i++) { valuesLong[i] = "Item" + i; keysLong[i] = "keY" + i; } Console.WriteLine("--- create dictionary ---"); strLoc = "Loc_001_oo"; iCountTestcases++; hd = new HybridDictionary(); cnt = hd.Count; if ( cnt != 0) { iCountErrors++; Console.WriteLine("Err_0001_, count is {0} instead of {1} after default ctor", hd.Count, 0); } Console.WriteLine("1. call Clear() on empty dictionary and check Count"); strLoc = "Loc_001oo"; iCountTestcases++; hd.Clear(); cnt = hd.Count; if ( cnt != 0) { iCountErrors++; Console.WriteLine("Err_0001a, count is {0} instead of {1} after Clear()", hd.Count, 0); } iCountTestcases++; cnt = hd.Keys.Count; if ( cnt != 0) { iCountErrors++; Console.WriteLine("Err_0001b, Keys.Count is {0} instead of {1} after Clear()", cnt, 0); } iCountTestcases++; cnt = hd.Values.Count; if ( cnt != 0) { iCountErrors++; Console.WriteLine("Err_0001c, Values.Count is {0} instead of {1} after Clear()", cnt, 0); } Console.WriteLine("2. add simple strings and get Count - list"); strLoc = "Loc_002oo"; iCountTestcases++; cnt = hd.Count; for (int i = 0; i < valuesShort.Length; i++) { hd.Add(keysShort[i], valuesShort[i]); } if (hd.Count != valuesShort.Length) { iCountErrors++; Console.WriteLine("Err_0002a, count is {0} instead of {1}", hd.Count, valuesShort.Length); } iCountTestcases++; hd.Clear(); cnt = hd.Count; if ( cnt != 0) { iCountErrors++; Console.WriteLine("Err_0002b, count is {0} instead of {1} after Clear()", hd.Count, 0); } iCountTestcases++; cnt = hd.Keys.Count; if ( cnt != 0) { iCountErrors++; Console.WriteLine("Err_0002c, Keys.Count is {0} instead of {1} after Clear()", cnt, 0); } iCountTestcases++; cnt = hd.Values.Count; if ( cnt != 0) { iCountErrors++; Console.WriteLine("Err_0002d, Values.Count is {0} instead of {1} after Clear()", cnt, 0); } Console.WriteLine("3. add simple strings and get Count - hashtable"); strLoc = "Loc_003oo"; iCountTestcases++; cnt = hd.Count; for (int i = 0; i < valuesLong.Length; i++) { hd.Add(keysLong[i], valuesLong[i]); } if (hd.Count != valuesLong.Length) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", hd.Count, valuesLong.Length); } iCountTestcases++; hd.Clear(); cnt = hd.Count; if ( cnt != 0) { iCountErrors++; Console.WriteLine("Err_0003b, count is {0} instead of {1} after Clear()", hd.Count, 0); } iCountTestcases++; cnt = hd.Keys.Count; if ( cnt != 0) { iCountErrors++; Console.WriteLine("Err_0003c, Keys.Count is {0} instead of {1} after Clear()", cnt, 0); } iCountTestcases++; cnt = hd.Values.Count; if ( cnt != 0) { iCountErrors++; Console.WriteLine("Err_0002d, Values.Count is {0} instead of {1} after Clear()", cnt, 0); } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_general! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "Pass. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("Fail! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; HybridDictionary hd; HybridDictionary hd1; object root; object root1; string [] values = { "", " ", "a", "aa", "text", " spaces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; string [] keys = { "zero", "one", " ", "", "aa", "1", System.DateTime.Today.ToString(), "$%^#", Int32.MaxValue.ToString(), " spaces", "2222222222222222222222222" }; try { Console.WriteLine("--- create dictionary ---"); strLoc = "Loc_001oo"; int len = values.Length; iCountTestcases++; hd = new HybridDictionary(); hd1 = new HybridDictionary(); Console.WriteLine(" toString: " + hd.SyncRoot.ToString()); Console.WriteLine("1. SyncRoot for empty dictionary"); Console.WriteLine(" - roots of two different dictionaries"); iCountTestcases++; root = hd.SyncRoot; root1 = hd1.SyncRoot; if ( root.Equals(root1) ) { iCountErrors++; Console.WriteLine("Err_0001a, roots of two different dictionaries are equal"); } Console.WriteLine(" - roots of the same dictionary"); iCountTestcases++; root1 = hd.SyncRoot; if ( !root.Equals(root1) ) { iCountErrors++; Console.WriteLine("Err_0001b, roots for one dictionary are not equal"); } Console.WriteLine("2. SyncRoot for filled dictionary"); iCountTestcases++; for (int i = 0; i < len; i++) { hd.Add(keys[i], values[i]); } for (int i = 0; i < len; i++) { hd1.Add(keys[i], values[i]); } root = hd.SyncRoot; root1 = hd1.SyncRoot; Console.WriteLine(" - roots of two different dictionaries"); if ( root.Equals(root1) ) { iCountErrors++; Console.WriteLine("Err_0002a, roots of two different dictionaries are equal"); } Console.WriteLine(" - roots of the same dictionary"); iCountTestcases++; root1 = hd.SyncRoot; if ( !root.Equals(root1) ) { iCountErrors++; Console.WriteLine("Err_0002b, roots for one dictionary are not equal"); } Console.WriteLine("3. SyncRoot vs HybridDictionary"); iCountTestcases++; root = hd.SyncRoot; string str = root.ToString(); Console.WriteLine("SyncRoot.ToString(): " + str); if ( str.IndexOf("HybridDictionary", 0) < 0 ) { iCountErrors++; Console.WriteLine("Err_0003, root.ToString() doesn't contain \"HybridDictionary\""); } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_general! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "Pass. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("Fail! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; IntlStrings intl; String strLoc = "Loc_000oo"; HybridDictionary hd; const int BIG_LENGTH = 100; string [] valuesShort = { "", " ", "$%^#", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; string [] keysShort = { Int32.MaxValue.ToString(), " ", System.DateTime.Today.ToString(), "", "$%^#" }; string [] valuesLong = new string[BIG_LENGTH]; string [] keysLong = new string[BIG_LENGTH]; int cnt = 0; try { intl = new IntlStrings(); for (int i = 0; i < BIG_LENGTH; i++) { valuesLong[i] = "Item" + i; keysLong[i] = "keY" + i; } Console.WriteLine("--- create dictionary ---"); strLoc = "Loc_001_oo"; iCountTestcases++; hd = new HybridDictionary(); cnt = hd.Count; if ( cnt != 0) { iCountErrors++; Console.WriteLine("Err_0001_, count is {0} instead of {1} after default ctor", hd.Count, 0); } Console.WriteLine("1. call Clear() on empty dictionary"); strLoc = "Loc_001oo"; iCountTestcases++; hd.Clear(); cnt = hd.Count; if ( cnt != 0) { iCountErrors++; Console.WriteLine("Err_0001a, count is {0} instead of {1} after Clear()", hd.Count, 0); } iCountTestcases++; cnt = hd.Keys.Count; if ( cnt != 0) { iCountErrors++; Console.WriteLine("Err_0001b, Keys.Count is {0} instead of {1} after Clear()", cnt, 0); } iCountTestcases++; cnt = hd.Values.Count; if ( cnt != 0) { iCountErrors++; Console.WriteLine("Err_0001c, Values.Count is {0} instead of {1} after Clear()", cnt, 0); } Console.WriteLine("2. add few simple strings and Clear()"); strLoc = "Loc_002oo"; iCountTestcases++; cnt = hd.Count; for (int i = 0; i < valuesShort.Length; i++) { hd.Add(keysShort[i], valuesShort[i]); } if (hd.Count != valuesShort.Length) { iCountErrors++; Console.WriteLine("Err_0002a, count is {0} instead of {1}", hd.Count, valuesShort.Length); } iCountTestcases++; hd.Clear(); cnt = hd.Count; if ( cnt != 0) { iCountErrors++; Console.WriteLine("Err_0002b, count is {0} instead of {1} after Clear()", hd.Count, 0); } iCountTestcases++; cnt = hd.Keys.Count; if ( cnt != 0) { iCountErrors++; Console.WriteLine("Err_0002c, Keys.Count is {0} instead of {1} after Clear()", cnt, 0); } iCountTestcases++; cnt = hd.Values.Count; if ( cnt != 0) { iCountErrors++; Console.WriteLine("Err_0002d, Values.Count is {0} instead of {1} after Clear()", cnt, 0); } Console.WriteLine("3. add intl strings and Clear()"); strLoc = "Loc_003oo"; int len = valuesShort.Length; string [] intlValues = new string [len * 2]; for (int i = 0; i < len * 2; i++) { string val = intl.GetString(MAX_LEN, true, true, true); while (Array.IndexOf(intlValues, val) != -1 ) val = intl.GetString(MAX_LEN, true, true, true); intlValues[i] = val; } cnt = hd.Count; iCountTestcases++; for (int i = 0; i < len; i++) { hd.Add(intlValues[i+len], intlValues[i]); } if (hd.Count != (cnt + len)) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", hd.Count, cnt + len); } iCountTestcases++; hd.Clear(); cnt = hd.Count; if ( cnt != 0) { iCountErrors++; Console.WriteLine("Err_0003b, count is {0} instead of {1} after Clear()", hd.Count, 0); } iCountTestcases++; cnt = hd.Keys.Count; if ( cnt != 0) { iCountErrors++; Console.WriteLine("Err_0003c, Keys.Count is {0} instead of {1} after Clear()", cnt, 0); } iCountTestcases++; cnt = hd.Values.Count; if ( cnt != 0) { iCountErrors++; Console.WriteLine("Err_0003d, Values.Count is {0} instead of {1} after Clear()", cnt, 0); } Console.WriteLine("4. add many simple strings and Clear()"); strLoc = "Loc_004oo"; iCountTestcases++; hd.Clear(); for (int i = 0; i < valuesLong.Length; i++) { hd.Add(keysLong[i], valuesLong[i]); } if (hd.Count != valuesLong.Length) { iCountErrors++; Console.WriteLine("Err_0004a, count is {0} instead of {1}", hd.Count, valuesLong.Length); } iCountTestcases++; hd.Clear(); cnt = hd.Count; if ( cnt != 0) { iCountErrors++; Console.WriteLine("Err_0004b, count is {0} instead of {1} after Clear()", hd.Count, 0); } iCountTestcases++; cnt = hd.Keys.Count; if ( cnt != 0) { iCountErrors++; Console.WriteLine("Err_0004c, Keys.Count is {0} instead of {1} after Clear()", cnt, 0); } iCountTestcases++; cnt = hd.Values.Count; if ( cnt != 0) { iCountErrors++; Console.WriteLine("Err_0004d, Values.Count is {0} instead of {1} after Clear()", cnt, 0); } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_general! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "Pass. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("Fail! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
protected internal void CopyState(int parentEditLevel) { CopyingState(); Type currentType = this.GetType(); HybridDictionary state = new HybridDictionary(); if (this.EditLevel + 1 > parentEditLevel) throw new UndoException(string.Format(Resources.EditLevelMismatchException, "CopyState")); do { var currentTypeName = currentType.FullName; // get the list of fields in this type List<DynamicMemberHandle> handlers = UndoableHandler.GetCachedFieldHandlers(currentType); foreach (var h in handlers) { var value = h.DynamicMemberGet(this); if (typeof(Csla.Core.IUndoableObject).IsAssignableFrom(h.MemberType)) { // make sure the variable has a value if (value == null) { // variable has no value - store that fact state.Add(GetFieldName(currentTypeName, h.MemberName), null); } else { // this is a child object, cascade the call ((Core.IUndoableObject)value).CopyState(this.EditLevel + 1, BindingEdit); } } else { // this is a normal field, simply trap the value state.Add(GetFieldName(currentTypeName, h.MemberName), value); } } currentType = currentType.BaseType; } while (currentType != typeof(UndoableBase)); // serialize the state and stack it using (MemoryStream buffer = new MemoryStream()) { ISerializationFormatter formatter = SerializationFormatterFactory.GetFormatter(); formatter.Serialize(buffer, state); _stateStack.Push(buffer.ToArray()); } CopyStateComplete(); }
public void Ctor_Int_Bool(int initialSize, bool caseInsensitive) { HybridDictionary hybridDictionary = new HybridDictionary(initialSize, caseInsensitive); VerifyCtor(hybridDictionary, caseInsensitive: caseInsensitive); }
static void Main(string[] args) { Console.WindowHeight = 60; var ci = new CultureInfo("en-NZ"); var mfi = new MeasurementFormatInfo(ci.NumberFormat); var dict = new HybridDictionary(); dict["FuelEfficiency"] = "km/L;0.0"; dict["Length"] = "in"; dict["MassFlow"] = "t/d;0.00000"; dict["Angle"] = ">+0d0'0.00\""; dict["Angle~brg"] = "<{>B} ({>+000d})"; dict["Angle~test"] = "<{~brg} {/3.1415926536;0.00}\u03C0 {!;0.0} {*} {%} {>x}"; mfi.SetPreferences(dict); var ang1 = Angle.Degrees(-25); string sAng1 = ang1.ToString("~test", mfi); Console.WriteLine("composite format: 25deg: {0}", sAng1); var ang2 = Angle.Degrees(333); string sAng2 = ang2.ToString("~brg", mfi); Console.WriteLine("composite format: 333deg: {0} {1:>X}", sAng2, ang2); for (int deg3 = 0; deg3 < 700; deg3 += 50) { Angle ang3 = Angle.Degrees(deg3); string sAng3 = ang3.ToString("<{!},{>0d},{>+0d},{>-000d00'00.0\"}", mfi); Console.WriteLine("normal, full and half: {0}", sAng3); } string x1 = string.Format(mfi, "\r\nUnitless: {0:*}" + // unitless SI value "\r\nKnown unit: {1:km/L}" + // use km/L unit "\r\nMultiplier: {2:*3.6;0,000.000}" + // unitless, multiply SI value "\r\nCanonical: {3:!;0.00}" + // show simple SI base units with dots between units "\r\nSI base: {4:^}" + // show simple SI base units without dots between, and using superscripts for 1..3 "\r\nAngle: {5:deg;0.0}" + // display unit different from the lookup key "\r\nCurrency: {6:@}" + // @ is the lookup character for the generic currency symbol "\r\nTemperature: {7:degF;0.0}" + // temperature scale conversion "\r\nFeet: {8:';30.0}" + // use of ' mark "\r\nPreferred: {9}" + // uses the preferences in MeasureFormatInfo "\r\nEasy unit: {10: m3}" + // converts 3 to superscript before lookup "\r\nSlash unit: {11:ps;0}" // 'per' ... , Length.Metre(10) //0 , FuelEfficiency.KmPerLitre(11.5) //1 , Speed.MetrePerSec(893483.0) //2 , Pressure.Pascal(1013.293840129348) //3 , Volume.CubicMetre(7.0012) //4 , Angle.Degrees(89.55) //5 , new Currency(1200) //6 , Temperature.Kelvin(233.15) //7 , Length.Metre(3) //8 , MassFlow.KgPerSec(2.3) // 9 , Volume.USGallon(100.0) // 10 , Frequency.Hertz(60) // 11 ); var m1 = new Measurement(0.1334, new MUnit(2, 3, -1, 0, 0, 1, 0)); string x2 = string.Format(mfi, "\r\nCanonical {0:!}" + "\r\nSuperscript {1:^}" + "\r\nUnitless {2:*}" + "\r\nMultiplier {3:*100}%" + "\r\nDivider {4:/2}" + "\r\nPreferred {5}" , m1, m1, m1, m1, m1, m1 ); Console.WriteLine(x1); Console.WriteLine(x2); Console.WriteLine(FuelEfficiency.USGallonPer100Mile(5.0).ToString(null, mfi)); string q; Console.WriteLine(Angle.Degrees(-123.457).ToString(">000E 00' 00.0\"", mfi)); Console.WriteLine(q = Angle.Degrees(-123.457).ToString(">#DN 00' 00.0\"", mfi)); Console.WriteLine(Angle.Degrees(3.457).ToString(">000.00000d", mfi)); Console.WriteLine(Angle.Degrees(-6.1234123).ToString(">0.00000d 0.00000' 0.00000\u2033", mfi)); Console.WriteLine("---"); var time = Time.Hours(2); var speed = Speed.Kph(20); var length = (Length)((Measurement)speed * time); Console.WriteLine(string.Format(mfi, "Length = {0:km}", length)); Console.WriteLine(Length.Metre(20).ToString("yd", mfi)); Console.WriteLine(string.Format(mfi, "-> {0}", Length.Metre(0.01))); Console.WriteLine("=> " + Length.Metre(0.01).ToString(null, mfi)); //string s = FuelEfficiency.KmPerLitre(14.5).ToString("gal/100mi", measureFormatInfo); string s = Angle.Degrees(45).ToString("%;0.0", mfi); Console.WriteLine(s); var a = Length.Metre(5e-9); var ss = string.Format(mfi, "{0:/1e-9;0}nm = {1:*1e9;0}nm", a, a); Console.WriteLine(ss); ss = string.Format(mfi, "{0:*;0}nm", new Measurement(a.InSI(SIPrefix.Nano))); Console.WriteLine(ss); var fe1 = FuelEfficiency.KmPerLitre(11).ToString("<{km/L;0.0} ({L/100km;0})", mfi); Console.WriteLine("FE: " + fe1); var sp1 = Speed.Kph(5.1).ToString("<{*86.4;0}km/24h", mfi); Console.WriteLine("Daily distance " + sp1); string z = "Length:12"; Length l1 = (Length)Measurement.Parse(z); Length l2 = Measurement.Parse<Length>(z); Console.WriteLine("{0}", l1); Console.WriteLine(l2); FuelEfficiency ff = FuelEfficiency.KmPerLitre(11); z = Measurement.PString(ff); Console.WriteLine(z); FuelEfficiency ff2 = Measurement.Parse<FuelEfficiency>(z); Console.WriteLine(string.Format(mfi, "FuelEfficiency, Preferred: {0}", ff2)); Console.WriteLine(ff2.ToString(null, mfi)); if ((Measurement)ff2 != ff) Console.WriteLine("not the same"); var m2 = new Measurement(17.7, new MUnit(-1, -1, -3, 0, 1, -1, 2)); Console.WriteLine(m2.ToString(null, mfi)); z = Measurement.PString(m2); Console.WriteLine(z); var m3 = Measurement.Parse(z); Console.WriteLine(m3); var forex = mfi.ExchangeRates; forex["USD"] = 1.0; forex["NZD"] = 1.3839; forex["EUR"] = 0.6870; forex["DKK"] = 5.1121; var c1 = new Currency(34.98); var cs1 = c1.ToString("<{>USD;0 @} {>NZD;c} {>EUR;\u20AC0.00} {>DKK } {>XYZ;0} {@} {$}", mfi); Console.WriteLine("Currency: " + cs1); Console.WriteLine(new Currency(12000).ToString(">NZD ;@0;@(0);nil", mfi)); var c2 = new Currency(36.00, "NZD", mfi); var cs2 = c2.ToString("<{>NZD;c} stored as {*}", mfi); Console.WriteLine("Conversion: "+ cs2); string[] af = { Measurement.Format("Angle:2", null), Measurement.Format("Angle:2", mfi), Measurement.Format("Angle:2 ~brg", mfi), Measurement.Format("Angle:2 ~test", mfi), Measurement.Format("Angle:2 !;0.0", mfi), Measurement.Format("Angle:2 <quadrant {>X} {>b}", mfi), Measurement.Format("Angle:2 deg", mfi), Measurement.Format("Currency:750 >NZD;c", mfi), Measurement.Format("M:123;1,1,1,-1,-2,-2,1 <{!} ({*;0} units)", mfi), }; Console.WriteLine("Measurement.Format()"); foreach (string afi in af) Console.WriteLine(" {0}", afi); Console.ReadKey(); }
/// <summary> /// Gets the bar width distribution and calculates narrow bar width over the specified /// range of the histogramResult. A histogramResult could have multiple ranges, separated /// by quiet zones. /// </summary> /// <param name="hist">histogramResult data</param> /// <param name="iStart">start coordinate to be considered</param> /// <param name="iEnd">end coordinate + 1</param> private static void GetBarWidthDistribution(ref histogramResult hist, int iStart, int iEnd) { HybridDictionary hdLightBars = new HybridDictionary (); HybridDictionary hdDarkBars = new HybridDictionary (); bool bDarkBar = (hist.histogram[iStart] <= hist.threshold); int iBarStart = 0; for (int i = iStart + 1; i < iEnd; i++) { bool bDark = (hist.histogram[i] <= hist.threshold); if (bDark != bDarkBar) { int iBarWidth = i - iBarStart; if (bDarkBar) { if (!hdDarkBars.Contains (iBarWidth)) hdDarkBars.Add (iBarWidth, 1); else hdDarkBars[iBarWidth] = (int) hdDarkBars[iBarWidth] + 1; } else { if (!hdLightBars.Contains (iBarWidth)) hdLightBars.Add (iBarWidth, 1); else hdLightBars[iBarWidth] = (int) hdLightBars[iBarWidth] + 1; } bDarkBar = bDark; iBarStart = i; } } // Now get the most common bar widths CalcNarrowBarWidth (hdLightBars, out hist.lightnarrowbarwidth, out hist.lightwiderbarwidth); CalcNarrowBarWidth (hdDarkBars, out hist.darknarrowbarwidth, out hist.darkwiderbarwidth); }
/// <summary> /// Remove dead entries from the data for the given source. Returns true if /// some entries were actually removed. /// </summary> protected override bool Purge(object source, object data, bool purgeAll) { bool foundDirt = false; if (!purgeAll) { HybridDictionary dict = (HybridDictionary)data; int ignoredKeys = 0; if (!BaseAppContextSwitches.EnableWeakEventMemoryImprovements) { // copy the keys into a separate array, so that later on // we can change the dictionary while iterating over the keys ICollection ic = dict.Keys; String[] keys = new String[ic.Count]; ic.CopyTo(keys, 0); for (int i = keys.Length - 1; i >= 0; --i) { if (keys[i] == AllListenersKey) { ++ignoredKeys; continue; // ignore the special entry for now } // for each key, remove dead entries in its list bool removeList = purgeAll || source == null; if (!removeList) { ListenerList list = (ListenerList)dict[keys[i]]; if (ListenerList.PrepareForWriting(ref list)) { dict[keys[i]] = list; } if (list.Purge()) { foundDirt = true; } removeList = (list.IsEmpty); } // if there are no more entries, remove the key if (removeList) { dict.Remove(keys[i]); } } #if WeakEventTelemetry LogAllocation(ic.GetType(), 1, 12); // dict.Keys - Hashtable+KeyCollection LogAllocation(typeof(String[]), 1, 12 + ic.Count * 4); // keys #endif } else { Debug.Assert(_toRemove.Count == 0, "to-remove list should be empty"); // enumerate the dictionary using IDE explicitly rather than // foreach, to avoid allocating temporary DictionaryEntry objects IDictionaryEnumerator ide = dict.GetEnumerator() as IDictionaryEnumerator; while (ide.MoveNext()) { String key = (String)ide.Key; if (key == AllListenersKey) { ++ignoredKeys; continue; // ignore the special entry for now } // for each key, remove dead entries in its list bool removeList = purgeAll || source == null; if (!removeList) { ListenerList list = (ListenerList)ide.Value; if (ListenerList.PrepareForWriting(ref list)) { dict[key] = list; } if (list.Purge()) { foundDirt = true; } removeList = (list.IsEmpty); } // if there are no more entries, remove the key if (removeList) { _toRemove.Add(key); } } // do the actual removal (outside the dictionary iteration) if (_toRemove.Count > 0) { foreach (String key in _toRemove) { dict.Remove(key); } _toRemove.Clear(); _toRemove.TrimExcess(); } #if WeakEventTelemetry Type enumeratorType = ide.GetType(); if (enumeratorType.Name.IndexOf("NodeEnumerator") >= 0) { LogAllocation(enumeratorType, 1, 24); // ListDictionary+NodeEnumerator } else { LogAllocation(enumeratorType, 1, 36); // Hashtable+HashtableEnumerator } #endif } if (dict.Count == ignoredKeys) { // if there are no more listeners at all, remove the entry from // the main table, and prepare to stop listening purgeAll = true; if (source != null) // source may have been GC'd { this.Remove(source); } } else if (foundDirt) { // if any entries were purged, invalidate the special entry dict.Remove(AllListenersKey); _proposedAllListenersList = null; } } if (purgeAll) { // stop listening. List cleanup is handled by Purge() if (source != null) // source may have been GC'd { StopListening(source); } foundDirt = true; } return(foundDirt); }
public void Test01() { IntlStrings intl; HybridDictionary hd; const int BIG_LENGTH = 100; // simple string values string[] valuesShort = { "", " ", "$%^#", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; // keys for simple string values string[] keysShort = { Int32.MaxValue.ToString(), " ", System.DateTime.Today.ToString(), "", "$%^#" }; string[] valuesLong = new string[BIG_LENGTH]; string[] keysLong = new string[BIG_LENGTH]; // string [] destination; Array destination; int cnt = 0; // Count // initialize IntStrings intl = new IntlStrings(); for (int i = 0; i < BIG_LENGTH; i++) { valuesLong[i] = "Item" + i; keysLong[i] = "keY" + i; } // [] HybridDictionary is constructed as expected //----------------------------------------------------------------- hd = new HybridDictionary(); // [] Copy empty dictionary into empty array // destination = Array.CreateInstance(typeof(Object), 0); Assert.Throws <ArgumentOutOfRangeException>(() => { hd.CopyTo(destination, -1); }); hd.CopyTo(destination, 0); // exception even when copying empty dictionary Assert.Throws <ArgumentException>(() => { hd.CopyTo(destination, 1); }); // [] Copy empty dictionary into filled array // destination = Array.CreateInstance(typeof(Object), valuesShort.Length); for (int i = 0; i < valuesShort.Length; i++) { destination.SetValue(valuesShort[i], i); } hd.CopyTo(destination, 0); if (destination.Length != valuesShort.Length) { Assert.False(true, string.Format("Error, altered array after copying empty dictionary")); } if (destination.Length == valuesShort.Length) { for (int i = 0; i < valuesShort.Length; i++) { if (String.Compare(destination.GetValue(i).ToString(), valuesShort[i]) != 0) { Assert.False(true, string.Format("Error, altered item {0} after copying empty dictionary", i)); } } } // [] few simple strings and CopyTo(Array, 0) // hd.Clear(); cnt = hd.Count; int len = valuesShort.Length; for (int i = 0; i < len; i++) { hd.Add(keysShort[i], valuesShort[i]); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, valuesShort.Length)); } destination = Array.CreateInstance(typeof(Object), len); hd.CopyTo(destination, 0); // // for (int i = 0; i < len; i++) { // verify that dictionary is copied correctly // if (String.Compare(hd[keysShort[i]].ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString()) != 0) { Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value.ToString(), hd[keysShort[i]])); } if (String.Compare(keysShort[i], ((DictionaryEntry)destination.GetValue(i)).Key.ToString()) != 0) { Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key.ToString(), keysShort[i])); } } // [] few simple strings and CopyTo(Array, middle_index) // hd.Clear(); hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysShort[i], valuesShort[i]); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, valuesShort.Length)); } destination = Array.CreateInstance(typeof(Object), len * 2); hd.CopyTo(destination, len); // // for (int i = 0; i < len; i++) { // verify that dictionary is copied correctly // if (String.Compare(hd[keysShort[i]].ToString(), ((DictionaryEntry)destination.GetValue(i + len)).Value.ToString()) != 0) { Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len)).Value, hd[keysShort[i]])); } // verify keysShort if (String.Compare(keysShort[i], ((DictionaryEntry)destination.GetValue(i + len)).Key.ToString()) != 0) { Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len)).Key, keysShort[i])); } } // [] many simple strings and CopyTo(Array, 0) // hd.Clear(); cnt = hd.Count; len = valuesLong.Length; for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } destination = Array.CreateInstance(typeof(Object), len); hd.CopyTo(destination, 0); // // IDictionaryEnumerator en = hd.GetEnumerator(); en.MoveNext(); // items are copied in the same order they are enumerated for (int i = 0; i < len; i++) { // verify that dictionary is copied correctly // Object k = en.Key; if (String.Compare(hd[k].ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString()) != 0) { Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value.ToString(), hd[k])); } if (String.Compare(k.ToString(), ((DictionaryEntry)destination.GetValue(i)).Key.ToString()) != 0) { Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key.ToString(), k.ToString())); } en.MoveNext(); } // [] many simple strings and CopyTo(Array, middle_index) // hd.Clear(); hd.Clear(); len = valuesLong.Length; for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } if (hd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } destination = Array.CreateInstance(typeof(Object), len * 2); hd.CopyTo(destination, len); // // en = hd.GetEnumerator(); en.MoveNext(); for (int i = 0; i < len; i++) { // verify that dictionary is copied correctly // Object k = en.Key; if (String.Compare(hd[k].ToString(), ((DictionaryEntry)destination.GetValue(i + len)).Value.ToString()) != 0) { Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len)).Value, hd[k])); } // verify keysShort if (String.Compare(k.ToString(), ((DictionaryEntry)destination.GetValue(i + len)).Key.ToString()) != 0) { Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len)).Key, k)); } en.MoveNext(); } // // [] many Intl strings and CopyTo(Array, 0) // string[] intlValues = new string[len * 2]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { string val = intl.GetRandomString(MAX_LEN); while (Array.IndexOf(intlValues, val) != -1) { val = intl.GetRandomString(MAX_LEN); } intlValues[i] = val; } Boolean caseInsensitive = false; for (int i = 0; i < len * 2; i++) { if (intlValues[i].Length != 0 && intlValues[i].ToLower() == intlValues[i].ToUpper()) { caseInsensitive = true; } } hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(intlValues[i + len], intlValues[i]); } if (hd.Count != (len)) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len)); } destination = Array.CreateInstance(typeof(Object), len); hd.CopyTo(destination, 0); // // en = hd.GetEnumerator(); en.MoveNext(); for (int i = 0; i < len; i++) { // verify that dictionary is copied correctly // Object k = en.Key; if (String.Compare(hd[k].ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString()) != 0) { Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value, hd[k])); } // verify keysShort if (String.Compare(k.ToString(), ((DictionaryEntry)destination.GetValue(i)).Key.ToString()) != 0) { Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key, k)); } en.MoveNext(); } // // [] many Intl strings and CopyTo(Array, middle_index) // destination = Array.CreateInstance(typeof(Object), len * 2); hd.CopyTo(destination, len); // // order of items is the same as they were in dictionary // en = hd.GetEnumerator(); en.MoveNext(); for (int i = 0; i < len; i++) { // verify that dictionary is copied correctly // Object k = en.Key; if (String.Compare(hd[k].ToString(), ((DictionaryEntry)destination.GetValue(i + len)).Value.ToString()) != 0) { Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len)).Value, hd[k])); } // verify keysShort if (String.Compare(k.ToString(), ((DictionaryEntry)destination.GetValue(i + len)).Key.ToString()) != 0) { Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len)).Key, k)); } en.MoveNext(); } // [] few Intl strings and CopyTo(Array, 0) // int len1 = valuesShort.Length; hd.Clear(); for (int i = 0; i < len1; i++) { hd.Add(intlValues[i + len1], intlValues[i]); } if (hd.Count != (len1)) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len1)); } destination = Array.CreateInstance(typeof(Object), len1); hd.CopyTo(destination, 0); // // en = hd.GetEnumerator(); en.MoveNext(); for (int i = 0; i < len1; i++) { // verify that dictionary is copied correctly // Object k = en.Key; if (String.Compare(hd[k].ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString()) != 0) { Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value, hd[k])); } // verify keysShort if (String.Compare(k.ToString(), ((DictionaryEntry)destination.GetValue(i)).Key.ToString()) != 0) { Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key, k)); } en.MoveNext(); } // // [] few Intl strings and CopyTo(Array, middle_index) // destination = Array.CreateInstance(typeof(Object), len1 * 2); hd.CopyTo(destination, len1); // // order of items is the same as they were in dictionary // en = hd.GetEnumerator(); en.MoveNext(); for (int i = 0; i < len1; i++) { // verify that dictionary is copied correctly // Object k = en.Key; if (String.Compare(hd[k].ToString(), ((DictionaryEntry)destination.GetValue(i + len1)).Value.ToString()) != 0) { Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len1)).Value, hd[k])); } // verify keysShort if (String.Compare(k.ToString(), ((DictionaryEntry)destination.GetValue(i + len1)).Key.ToString()) != 0) { Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len1)).Key, k)); } en.MoveNext(); } // // [] Case sensitivity // string[] intlValuesUpper = new string[len * 2]; string[] intlValuesLower = new string[len * 2]; // fill array with unique upper-case strings // for (int i = 0; i < len * 2; i++) { string val = intlValues[i].ToUpper(); while (Array.IndexOf(intlValuesUpper, val) != -1) { val = intl.GetRandomString(MAX_LEN).ToUpper(); } intlValuesUpper[i] = val; } caseInsensitive = false; for (int i = 0; i < len * 2; i++) { intlValuesLower[i] = intlValuesUpper[i].ToLower(); if (intlValuesLower[i].Length != 0 && intlValuesLower[i] == intlValuesUpper[i]) { caseInsensitive = true; } } hd.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { hd.Add(intlValuesUpper[i + len], intlValuesUpper[i]); // adding uppercase strings } destination = Array.CreateInstance(typeof(Object), len); hd.CopyTo(destination, 0); // // en = hd.GetEnumerator(); en.MoveNext(); for (int i = 0; i < len; i++) { // verify that dictionary is copied correctly // Object k = en.Key; if (String.Compare(hd[k].ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString()) != 0) { Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value, hd[k])); } if (!caseInsensitive && Array.IndexOf(intlValuesLower, ((DictionaryEntry)destination.GetValue(i)).Value.ToString()) > -1) { Assert.False(true, string.Format("Error, copied lowercase string")); } // verify keysShort if (String.Compare(k.ToString(), ((DictionaryEntry)destination.GetValue(i)).Key.ToString()) != 0) { Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key, k)); } if (!caseInsensitive && Array.IndexOf(intlValuesLower, ((DictionaryEntry)destination.GetValue(i)).Key.ToString()) > -1) { Assert.False(true, string.Format("Error, copied lowercase key")); } en.MoveNext(); } // ---------------------------------------------------------------- // [] Parameter validation for short HybridDictionary (list) // ---------------------------------------------------------------- hd = new HybridDictionary(); for (int i = 0; i < len1; i++) { hd.Add(keysShort[i], valuesShort[i]); } // // CopyTo(null, int) // destination = null; Assert.Throws <ArgumentNullException>(() => { hd.CopyTo(destination, 0); }); // // CopyTo(Array, -1) // destination = Array.CreateInstance(typeof(Object), 2); Assert.Throws <ArgumentOutOfRangeException>(() => { hd.CopyTo(destination, -1); }); // // CopyTo(Array, upperBound+1) // cnt = hd.Count; destination = Array.CreateInstance(typeof(Object), cnt); Assert.Throws <ArgumentException>(() => { hd.CopyTo(destination, cnt); }); // // CopyTo(Array, upperBound+2) // Assert.Throws <ArgumentException>(() => { hd.CopyTo(destination, cnt + 1); }); // // CopyTo(Array, not_enough_space) // Assert.Throws <ArgumentException>(() => { hd.CopyTo(destination, cnt / 2); }); // // CopyTo(multidim_Array, 0) // Array dest = new String[cnt, cnt]; Assert.Throws <ArgumentException>(() => { hd.CopyTo(dest, 0); }); // // CopyTo(wrong_type, 0) // dest = Array.CreateInstance(typeof(ArrayList), cnt); Assert.Throws <System.InvalidCastException>(() => { hd.CopyTo(dest, 0); }); // // CopyTo(Array, upperBound+1) - copy empty dictionary - no exception // hd.Clear(); destination = Array.CreateInstance(typeof(Object), len); hd.CopyTo(destination, len); // ---------------------------------------------------------------- // [] Parameter validation for long HybridDictionary (hashtable) // ---------------------------------------------------------------- hd = new HybridDictionary(); len = valuesLong.Length; for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } // // CopyTo(null, int) // destination = null; Assert.Throws <ArgumentNullException>(() => { hd.CopyTo(destination, 0); }); // // CopyTo(Array, -1) // destination = Array.CreateInstance(typeof(Object), 2); Assert.Throws <ArgumentOutOfRangeException>(() => { hd.CopyTo(destination, -1); }); // // CopyTo(Array, upperBound+1) // cnt = hd.Count; destination = Array.CreateInstance(typeof(Object), cnt); Assert.Throws <ArgumentException>(() => { hd.CopyTo(destination, cnt); }); // // CopyTo(Array, upperBound+2) // Assert.Throws <ArgumentException>(() => { hd.CopyTo(destination, cnt + 1); }); // // CopyTo(Array, not_enough_space) // Assert.Throws <ArgumentException>(() => { hd.CopyTo(destination, cnt / 2); }); // // CopyTo(multidim_Array, 0) // dest = Array.CreateInstance(typeof(string), cnt, cnt); Assert.Throws <ArgumentException>(() => { hd.CopyTo(dest, 0); }); // // CopyTo(wrong_type, 0) // dest = Array.CreateInstance(typeof(ArrayList), cnt); Assert.Throws <System.InvalidCastException>(() => { hd.CopyTo(dest, 0); }); // // [] CopyTo() for few not_overriding_Equals objects // hd.Clear(); int num = 2; Hashtable[] lbl = new Hashtable[num]; ArrayList[] b = new ArrayList[num]; for (int i = 0; i < num; i++) { lbl[i] = new Hashtable(); b[i] = new ArrayList(); hd.Add(lbl[i], b[i]); } destination = Array.CreateInstance(typeof(Object), num); hd.CopyTo(destination, 0); // // en = hd.GetEnumerator(); en.MoveNext(); for (int i = 0; i < num; i++) { // verify that dictionary is copied correctly // Object k = en.Key; if (!hd[k].Equals(((DictionaryEntry)destination.GetValue(i)).Value)) { Assert.False(true, string.Format("Error, failed to copy {0}th entry", i)); } // verify keysShort if (!k.Equals(((DictionaryEntry)destination.GetValue(i)).Key)) { Assert.False(true, string.Format("Error, failed to copy {0} entry", i)); } en.MoveNext(); } // [] CopyTo() for many not_overriding_Equals objects // hd.Clear(); num = 40; lbl = new Hashtable[num]; b = new ArrayList[num]; for (int i = 0; i < num; i++) { lbl[i] = new Hashtable(); b[i] = new ArrayList(); hd.Add(lbl[i], b[i]); } destination = Array.CreateInstance(typeof(Object), num); hd.CopyTo(destination, 0); // // en = hd.GetEnumerator(); en.MoveNext(); for (int i = 0; i < num; i++) { // verify that dictionary is copied correctly // Object k = en.Key; if (!hd[k].Equals(((DictionaryEntry)destination.GetValue(i)).Value)) { Assert.False(true, string.Format("Error, failed to copy {0}th entry", i)); } // verify keysShort if (!k.Equals(((DictionaryEntry)destination.GetValue(i)).Key)) { Assert.False(true, string.Format("Error, failed to copy {0} entry", i)); } en.MoveNext(); } // // [] CopyTo() - for short case-insensitive HybridDictionary // hd = new HybridDictionary(true); len = 3; for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } destination = Array.CreateInstance(typeof(Object), len); hd.CopyTo(destination, 0); // // en = hd.GetEnumerator(); en.MoveNext(); for (int i = 0; i < len; i++) { // verify that dictionary is copied correctly // Object k = en.Key; if (String.Compare(hd[k].ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString()) < 0) { Assert.False(true, string.Format("Error, failed to copy {0}th entry when case-insensitive", i)); } // verify keysShort if (String.Compare(k.ToString(), ((DictionaryEntry)destination.GetValue(i)).Key.ToString()) < 0) { Assert.False(true, string.Format("Error, failed to copy {0} entry when case-insensitive", i)); } en.MoveNext(); } // [] CopyTo() - for long case-insensitive HybridDictionary // hd = new HybridDictionary(true); len = valuesLong.Length; for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } destination = Array.CreateInstance(typeof(Object), len); hd.CopyTo(destination, 0); // // en = hd.GetEnumerator(); en.MoveNext(); for (int i = 0; i < len; i++) { // verify that dictionary is copied correctly // Object k = en.Key; if (String.Compare(hd[k].ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString()) < 0) { Assert.False(true, string.Format("Error, failed to copy {0}th entry when case-insensitive", i)); } // verify keysShort if (String.Compare(k.ToString(), ((DictionaryEntry)destination.GetValue(i)).Key.ToString()) < 0) { Assert.False(true, string.Format("Error, failed to copy {0} entry when case-insensitive", i)); } en.MoveNext(); } }
// event handler for PropertyChanged event private void OnPropertyChanged(object sender, PropertyChangedEventArgs args) { ListenerList list; string propertyName = args.PropertyName; // get the list of listeners using (ReadLock) { // look up the list of listeners HybridDictionary dict = (HybridDictionary)this[sender]; if (dict == null) { // this can happen when the last listener stops listening, but the // source raises the event on another thread after the dictionary // has been removed list = ListenerList.Empty; } else if (!String.IsNullOrEmpty(propertyName)) { // source has changed a particular property. Notify targets // who are listening either for this property or for all properties. ListenerList <PropertyChangedEventArgs> listeners = (ListenerList <PropertyChangedEventArgs>)dict[propertyName]; ListenerList <PropertyChangedEventArgs> genericListeners = (ListenerList <PropertyChangedEventArgs>)dict[String.Empty]; if (genericListeners == null) { if (listeners != null) { list = listeners; // only specific listeners } else { list = ListenerList.Empty; // no listeners at all } } else { if (listeners != null) { // there are both specific and generic listeners - // combine the two lists. list = new ListenerList <PropertyChangedEventArgs>(listeners.Count + genericListeners.Count); for (int i = 0, n = listeners.Count; i < n; ++i) { list.Add(listeners.GetListener(i)); } for (int i = 0, n = genericListeners.Count; i < n; ++i) { list.Add(genericListeners.GetListener(i)); } } else { list = genericListeners; // only generic listeners } } } else { // source has changed all properties. Notify all targets. // Use previously calculated combined list, if available. list = (ListenerList)dict[AllListenersKey]; if (list == null) { // make one pass to compute the size of the combined list. // This avoids expensive reallocations. int size = 0; foreach (DictionaryEntry de in dict) { Debug.Assert((String)de.Key != AllListenersKey, "special key should not appear"); size += ((ListenerList)de.Value).Count; } // create the combined list list = new ListenerList <PropertyChangedEventArgs>(size); // fill in the combined list foreach (DictionaryEntry de in dict) { ListenerList listeners = ((ListenerList)de.Value); for (int i = 0, n = listeners.Count; i < n; ++i) { list.Add(listeners.GetListener(i)); } } // save the result for future use (see below) _proposedAllListenersList = list; } } // mark the list "in use", even outside the read lock, // so that any writers will know not to modify it (they'll // modify a clone intead). list.BeginUse(); } // deliver the event, being sure to undo the effect of BeginUse(). try { DeliverEventToList(sender, args, list); } finally { list.EndUse(); } // if we calculated an AllListeners list, we should now try to store // it in the dictionary so it can be used in the future. This must be // done under a WriteLock - which is why we didn't do it immediately. if (_proposedAllListenersList == list) { using (WriteLock) { // test again, in case another thread changed _proposedAllListersList. if (_proposedAllListenersList == list) { HybridDictionary dict = (HybridDictionary)this[sender]; if (dict != null) { dict[AllListenersKey] = list; } _proposedAllListenersList = null; } // Another thread could have changed _proposedAllListersList // since we set it (earlier in this method), either // because it calculated a new one while handling a PropertyChanged(""), // or because it added/removed/purged a listener. // In that case, we will simply abandon our proposed list and we'll // have to compute it again the next time. But that only happens // if there's thread contention. It's not worth doing something // more complicated just for that case. } } }
private bool AzManTestCheckAccess() { WindowsIdentity identity = this.Request.LogonUserIdentity; string applicationName = "Application Test"; string[] operations = new string[] { this.txtOperation.Text }; HybridDictionary businessRuleParameters = new HybridDictionary(); AzAuthorizationStoreClass store = new AzAuthorizationStoreClass(); store.Initialize(0, AzManStorePath, null); IAzApplication azApp = store.OpenApplication(applicationName, null); IAzClientContext clientCtx = azApp.InitializeClientContextFromToken((UInt64)identity.Token, null); // costruisce il vettore dei valori e dei delle regole di business Object[] names = new Object[0]; Object[] values = new Object[0]; Object[] operationIds = new Object[operations.Length]; for (Int32 index = 0; index < operations.Length; index++) { operationIds[index] = azApp.OpenOperation(operations[index], null).OperationID; } Object[] internalScopes = new Object[1]; Object[] result = (Object[])clientCtx.AccessCheck("AuditString", internalScopes, operationIds, names, values, null, null, null); foreach (Int32 accessAllowed in result) { if (accessAllowed != 0) { return false; } } return true; }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; IntlStrings intl; String strLoc = "Loc_000oo"; HybridDictionary hd; const int BIG_LENGTH = 100; string [] valuesShort = { "", " ", "$%^#", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; string [] keysShort = { Int32.MaxValue.ToString(), " ", System.DateTime.Today.ToString(), "", "$%^#" }; string [] valuesLong = new string[BIG_LENGTH]; string [] keysLong = new string[BIG_LENGTH]; int cnt = 0; try { intl = new IntlStrings(); for (int i = 0; i < BIG_LENGTH; i++) { valuesLong[i] = "Item" + i; keysLong[i] = "keY" + i; } Console.WriteLine("--- create dictionary ---"); strLoc = "Loc_001oo"; iCountTestcases++; hd = new HybridDictionary(); Console.WriteLine("1. Contains() on empty dictionary"); iCountTestcases++; Console.WriteLine(" - Contains(null)"); try { hd.Contains(null); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0001b, unexpected exception: {0}", e.ToString()); } Console.WriteLine(" - Contains(some_object)"); if ( hd.Contains("some_string") ) { iCountErrors++; Console.WriteLine("Err_0001c, empty dictionary contains some_object"); } Console.WriteLine("2. add few simple strings and check Contains()"); strLoc = "Loc_002oo"; iCountTestcases++; cnt = hd.Count; int len = valuesShort.Length; for (int i = 0; i < len; i++) { hd.Add(keysShort[i], valuesShort[i]); } if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0002a, count is {0} instead of {1}", hd.Count, valuesShort.Length); } for (int i = 0; i < len; i++) { iCountTestcases++; if ( ! hd.Contains(keysShort[i]) ) { iCountErrors++; Console.WriteLine("Err_0002_{0}b, doesn't contain \"{1}\"", i, keysShort[i]); } } Console.WriteLine(" .. increase number of elements"); cnt = hd.Count; len = valuesLong.Length; for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } if (hd.Count != len+cnt) { iCountErrors++; Console.WriteLine("Err_0002c, count is {0} instead of {1}", hd.Count, len+cnt); } for (int i = 0; i < len; i++) { iCountTestcases++; if ( ! hd.Contains(keysLong[i]) ) { iCountErrors++; Console.WriteLine("Err_0002_{0}d, doesn't contain \"{1}\"", i, keysLong[i]); } } for (int i = 0; i < valuesShort.Length; i++) { iCountTestcases++; if ( ! hd.Contains(keysShort[i]) ) { iCountErrors++; Console.WriteLine("Err_0002_{0}e, doesn't contain \"{1}\"", i, keysShort[i]); } } Console.WriteLine("3. add intl strings check Contains()"); strLoc = "Loc_003oo"; iCountTestcases++; string [] intlValues = new string [len * 2]; for (int i = 0; i < len*2; i++) { string val = intl.GetString(MAX_LEN, true, true, true); while (Array.IndexOf(intlValues, val) != -1 ) val = intl.GetString(MAX_LEN, true, true, true); intlValues[i] = val; } iCountTestcases++; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(intlValues[i+len], intlValues[i]); } if ( hd.Count != (len) ) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", hd.Count, len); } for (int i = 0; i < len; i++) { iCountTestcases++; if ( ! hd.Contains(intlValues[i+len]) ) { iCountErrors++; Console.WriteLine("Err_0003_{0}b, doesn't contain \"{1}\"", i, intlValues[i+len]); } } Console.WriteLine("4. case sensitivity"); strLoc = "Loc_004oo"; hd.Clear(); len = valuesLong.Length; for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } for (int i = 0; i < len; i++) { iCountTestcases++; if ( ! hd.Contains(keysLong[i]) ) { iCountErrors++; Console.WriteLine("Err_0004_{0}a, doesn't contain added uppercase \"{1}\"", i, keysLong[i]); } iCountTestcases++; if ( hd.Contains(keysLong[i].ToUpper()) ) { iCountErrors++; Console.WriteLine("Err_0004_{0}a, contains uppercase \"{1}\" - should not", i, keysLong[i].ToUpper()); } } Console.WriteLine("5. similar_but_different_in_casing keys and Contains()"); strLoc = "Loc_005oo"; iCountTestcases++; hd.Clear(); string [] ks = {"Key", "kEy", "keY"}; len = ks.Length; for (int i = 0; i < len; i++) { hd.Add(ks[i], "Value"+i); } if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0005a, count is {0} instead of {1}", hd.Count, len); } iCountTestcases++; if ( hd.Contains("Value0") ) { iCountErrors++; Console.WriteLine("Err_0005b, returned true when should not"); } for (int i = 0; i < len; i++) { iCountTestcases++; if ( !hd.Contains(ks[i]) ) { iCountErrors++; Console.WriteLine("Err_0005c_{0}, returned false when true expected", i); } } Console.WriteLine(" .. increase number of elements"); cnt = hd.Count; len = valuesLong.Length; for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } if (hd.Count != len+cnt) { iCountErrors++; Console.WriteLine("Err_0005d, count is {0} instead of {1}", hd.Count, len+cnt); } for (int i = 0; i < len; i++) { iCountTestcases++; if ( ! hd.Contains(keysLong[i]) ) { iCountErrors++; Console.WriteLine("Err_0005_{0}e, doesn't contain \"{1}\"", i, keysLong[i]); } } for (int i = 0; i < ks.Length; i++) { iCountTestcases++; if ( ! hd.Contains(ks[i]) ) { iCountErrors++; Console.WriteLine("Err_0005_{0}f, doesn't contain \"{1}\"", i, ks[i]); } } Console.WriteLine("6. Contains(null) for filled dictionary"); strLoc = "Loc_006oo"; iCountTestcases++; len = valuesShort.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysShort[i], valuesShort[i]); } try { hd.Contains(null); iCountErrors++; Console.WriteLine("Err_0006a, no exception"); } catch (ArgumentNullException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0006b, unexpected exception: {0}", e.ToString()); } Console.WriteLine("7. Contains() for case-insensitive comparer dictionary"); hd = new HybridDictionary(true); strLoc = "Loc_007oo"; iCountTestcases++; hd.Clear(); len = ks.Length; hd.Add(ks[0], "Value0"); for (int i = 1; i < len; i++) { try { hd.Add(ks[i], "Value"+i); iCountErrors++; Console.WriteLine("Err_0007a_{0}, no exception", i); } catch (ArgumentException e) { Console.WriteLine("_{0}, Expected exception: {1}", i, e.Message); } catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_0007b_{0}, unexpected exception: {1}", i, ex.ToString()); } } if (hd.Count != 1) { iCountErrors++; Console.WriteLine("Err_0007c, count is {0} instead of {1}", hd.Count, 1); } iCountTestcases++; if ( hd.Contains("Value0") ) { iCountErrors++; Console.WriteLine("Err_0007d, returned true when should not"); } for (int i = 0; i < len; i++) { iCountTestcases++; if ( !hd.Contains(ks[i]) ) { iCountErrors++; Console.WriteLine("Err_0007e_{0}, returned false when true expected", i); } } iCountTestcases++; if ( !hd.Contains("KEY") ) { iCountErrors++; Console.WriteLine("Err_0007f, returned false non-existing-cased key"); } Console.WriteLine("9. Contains() and few SpecialStructs_not_overriding_Equals"); hd = new HybridDictionary(); strLoc = "Loc_009oo"; iCountTestcases++; Co8686_SpecialStruct s = new Co8686_SpecialStruct(); s.Num = 1; s.Wrd = "one"; Co8686_SpecialStruct s1 = new Co8686_SpecialStruct(); s.Num = 1; s.Wrd = "one"; hd.Add(s, "first"); hd.Add(s1, "second"); if (hd.Count != 2) { iCountErrors++; Console.WriteLine("Err_0009a, count is {0} instead of {1}", hd.Count, 2); } iCountTestcases++; if ( !hd.Contains(s) ) { iCountErrors++; Console.WriteLine("Err_0009b, returned false when true expected"); } iCountTestcases++; if ( !hd.Contains(s1) ) { iCountErrors++; Console.WriteLine("Err_0009c, returned false when true expected"); } Console.WriteLine("10. Contains() and many SpecialStructs_not_overriding_Equals"); int num = 40; hd = new HybridDictionary(); strLoc = "Loc_010oo"; iCountTestcases++; Co8686_SpecialStruct [] ss = new Co8686_SpecialStruct[num]; for (int i = 0; i < num; i++) { ss[i] = new Co8686_SpecialStruct(); ss[i].Num = i; ss[i].Wrd = "value"+i; hd.Add(ss[i], "item"+i); } if (hd.Count != num) { iCountErrors++; Console.WriteLine("Err_0010a, count is {0} instead of {1}", hd.Count, num); } for (int i = 0; i < num; i++) { iCountTestcases++; if ( !hd.Contains(ss[i]) ) { iCountErrors++; Console.WriteLine("Err_0010b_{0}, returned false when true expected", i); } } iCountTestcases++; s = new Co8686_SpecialStruct(); s.Num = 1; s.Wrd = "value1"; if ( hd.Contains(s) ) { iCountErrors++; Console.WriteLine("Err_0010c, returned true when false expected"); } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_general! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "Pass. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("Fail! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
static void LegacyDictionaries() { // Hashtable (dictionary with unique keys) Hashtable hashtable = new Hashtable(); hashtable.Add("Key1", "Hashtable 1"); hashtable.Add("Key2", "Hashtable 2"); foreach (DictionaryEntry item in hashtable) { Console.WriteLine("{0}: {1}", item.Key, item.Value); } // SortedList (sorted dictionary with unique keys) SortedList sortedList = new SortedList(); sortedList.Add("Key2", "SortedList 2"); sortedList.Add("Key1", "SortedList 1"); foreach (DictionaryEntry item in sortedList) { Console.WriteLine("{0}: {1}", item.Key, item.Value); } // ListDictionary (dictionary with unique keys - optimized for a maximum of 10 items) ListDictionary listDictionary = new ListDictionary(); listDictionary.Add("Key1", "ListDictionary 1"); listDictionary.Add("Key2", "ListDictionary 2"); foreach (DictionaryEntry item in listDictionary) { Console.WriteLine("{0}: {1}", item.Key, item.Value); } // HybridDictionary (dictionary with unique keys - starts as a ListDictionary, // transforms into a Hashtable upon the eleventh entry) HybridDictionary hybridDictionary = new HybridDictionary(); hybridDictionary.Add("Key1", "HybridDictionary 1"); hybridDictionary.Add("Key2", "HybridDictionary 2"); foreach (DictionaryEntry item in hybridDictionary) { Console.WriteLine("{0}: {1}", item.Key, item.Value); } // NameValueCollection (dictionary with support for multiple keys) NameValueCollection nameValueCollection = new NameValueCollection(); nameValueCollection.Add("Key1", "NameValueCollection 1"); nameValueCollection.Add("Key2", "NameValueCollection 2"); nameValueCollection.Add("Key2", "NameValueCollection 3"); foreach (string key in nameValueCollection) { Console.WriteLine("{0}:", key); foreach (object item in nameValueCollection.GetValues(key)) { Console.WriteLine("\t{0}", item); } } }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; HybridDictionary hd; int cnt; const int BIG_LENGTH = 100; string [] valuesShort = { "", " ", "$%^#", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; string [] keysShort = { Int32.MaxValue.ToString(), " ", System.DateTime.Today.ToString(), "", "$%^#" }; string [] valuesLong = new string[BIG_LENGTH]; string [] keysLong = new string[BIG_LENGTH]; try { for (int i = 0; i < BIG_LENGTH; i++) { valuesLong[i] = "Item" + i; keysLong[i] = "keY" + i; } Console.WriteLine("--- create dictionary ---"); strLoc = "Loc_001oo"; iCountTestcases++; hd = new HybridDictionary(); Console.WriteLine("1. IsReadOnly on empty dictionary"); iCountTestcases++; if (hd.IsReadOnly) { iCountErrors++; Console.WriteLine("Err_0001, returned true for empty dictionary"); } Console.WriteLine("2. IsReadOnly for short filled dictionary"); strLoc = "Loc_002oo"; iCountTestcases++; hd.Clear(); cnt = valuesShort.Length; for (int i = 0; i < cnt; i++) { hd.Add(keysShort[i], valuesShort[i]); } if (hd.Count != cnt) { iCountErrors++; Console.WriteLine("Err_0002a, count is {0} instead of {1}", hd.Count, cnt); } iCountTestcases++; if (hd.IsReadOnly) { iCountErrors++; Console.WriteLine("Err_0002b, returned true for short filled dictionary"); } Console.WriteLine("3. IsReadOnly for long filled dictionary"); strLoc = "Loc_003oo"; iCountTestcases++; hd.Clear(); cnt = valuesLong.Length; for (int i = 0; i < cnt; i++) { hd.Add(keysLong[i], valuesLong[i]); } if (hd.Count != cnt) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", hd.Count, cnt); } iCountTestcases++; if (hd.IsReadOnly) { iCountErrors++; Console.WriteLine("Err_0003b, returned true for long filled dictionary"); } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_general! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "Pass. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("Fail! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
static HybridDictionary parse_info_xml(string filepath, ref Decryptor decryptor, HybridDictionary decrypt_material_dict) { // Create the XmlDocument. XmlDocument info_dom = new XmlDocument(); info_dom.Load(filepath); if (info_dom.GetElementsByTagName("info.xml").Count != 1) { Console.WriteLine("First tag should be 'info.xml', not '{0}'", info_dom.FirstChild.Name); decryptor = null; return(null); } string parent = Directory.GetParent(filepath).FullName; XmlDocument doc; XmlNodeList elemList = info_dom.GetElementsByTagName("row"); foreach (XmlNode entry in elemList) { string title = entry.Attributes["table"].Value; switch (title) { case "BackupFilesTypeInfo": doc = new XmlDocument(); doc.LoadXml(entry.OuterXml); parse_backup_files_type_info(ref decryptor, doc); break; case "HeaderInfo": case "BackupFilePhoneInfo": case "BackupFileVersionInfo": ignore_entry(entry); break; case "BackupFileModuleInfo": case "BackupFileModuleInfo_Contact": case "BackupFileModuleInfo_Media": case "BackupFileModuleInfo_SystemData": doc = new XmlDocument(); doc.LoadXml(entry.OuterXml); DecryptMaterial dec_material = parse_backup_file_module_info(doc); if (dec_material != null) { string dkey = Path.Combine(parent, dec_material.name); decrypt_material_dict[dkey] = dec_material; } break; default: Console.WriteLine("Unknown entry in 'info.xml': {0}", title); break; } } return(decrypt_material_dict); }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; HybridDictionary hd; const int BIG_LENGTH = 100; string [] valuesLong = new string[BIG_LENGTH]; string [] keysLong = new string[BIG_LENGTH]; int len; try { for (int i = 0; i < BIG_LENGTH; i++) { valuesLong[i] = "Item" + i; keysLong[i] = "keY" + i; } Console.WriteLine("--- create dictionary ---"); Console.WriteLine(""); strLoc = "Loc_001oo-0"; iCountTestcases++; Console.WriteLine(" A. ctor(0)"); hd = new HybridDictionary(0); Console.WriteLine("1. compare to null"); iCountTestcases++; if (hd == null) { iCountErrors++; Console.WriteLine("Err_0001, dictionary is null after default ctor"); } Console.WriteLine("2. check Count"); iCountTestcases++; if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0002, Count = {0} after default ctor", hd.Count); } Console.WriteLine("3. check Item(some_key)"); iCountTestcases++; if (hd["key"] != null) { iCountErrors++; Console.WriteLine("Err_0003, Item(some_key) returned non-null after default ctor"); } Console.WriteLine("4. check ToString()"); iCountTestcases++; string temp = hd.ToString(); Console.WriteLine(" ToString(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0004, ToString() doesn't contain \"HybridDictionary\""); } Console.WriteLine("5. check returned Type"); iCountTestcases++; temp = hd.GetType().ToString().Trim(); Console.WriteLine(" GetType(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0005: returned type doesn't contain \"HybridDictionary\""); } Console.WriteLine("6. compare returned Type of two dictionary"); iCountTestcases++; string temp1 = (new HybridDictionary()).GetType().ToString().Trim(); if (String.Compare(temp, temp1) != 0) { iCountErrors++; Console.WriteLine("Err_0006: returned types of two collections differ"); } Console.WriteLine("7. check Keys collection"); iCountTestcases++; System.Collections.ICollection keys = hd.Keys; if ( keys.Count != 0) { iCountErrors++; Console.WriteLine("Err_0007: Keys contains {0} keys after default ctor", keys.Count); } Console.WriteLine("8. check Values collection"); iCountTestcases++; System.Collections.ICollection values = hd.Values; if ( values.Count != 0) { iCountErrors++; Console.WriteLine("Err_0008: Values contains {0} items after default ctor", values.Count); } Console.WriteLine("9. Add(name, value)"); iCountTestcases++; hd.Add("Name", "Value"); if (hd.Count != 1) { iCountErrors++; Console.WriteLine("Err_0009a: Count returned {0} instead of 1", hd.Count); } if (String.Compare(hd["Name"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0009b: Item() returned unexpected value"); } if (hd["NAME"] != null) { iCountErrors++; Console.WriteLine("Err_0009c: Item() returned non-null value for uppercase key"); } Console.WriteLine("10. Clear() short dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_00010a: Count returned {0} instead of 0 after Clear()", hd.Count); } if (hd["Name"] != null) { iCountErrors++; Console.WriteLine("Err_00010b: Item() returned non-null value after Clear()"); } Console.WriteLine("11. multiple Add(name, value)"); iCountTestcases++; len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } iCountTestcases++; if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0011a: Count returned {0} instead of {1}", hd.Count, len); } for (int i = 0; i < len; i++) { iCountTestcases++; if (String.Compare(hd[keysLong[i]].ToString(), valuesLong[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_0011b_{0}: Item() returned unexpected value", i); } if (hd[keysLong[i].ToUpper()] != null) { iCountErrors++; Console.WriteLine("Err_0011c_{0}: Item() returned non-null for uppercase key", i); } } Console.WriteLine("12. Clear() long dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_00012: Count returned {0} instead of 0 after Clear()", hd.Count); } Console.WriteLine(""); strLoc = "Loc_001ooB-10"; iCountTestcases++; Console.WriteLine(" B. ctor(10)"); hd = new HybridDictionary(10); Console.WriteLine("1. compare to null"); iCountTestcases++; if (hd == null) { iCountErrors++; Console.WriteLine("Err_0001, dictionary is null after default ctor"); } Console.WriteLine("2. check Count"); iCountTestcases++; if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0002, Count = {0} after default ctor", hd.Count); } Console.WriteLine("3. check Item(some_key)"); iCountTestcases++; if (hd["key"] != null) { iCountErrors++; Console.WriteLine("Err_0003, Item(some_key) returned non-null after default ctor"); } Console.WriteLine("4. check ToString()"); iCountTestcases++; temp = hd.ToString(); Console.WriteLine(" ToString(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0004, ToString() doesn't contain \"HybridDictionary\""); } Console.WriteLine("5. check returned Type"); iCountTestcases++; temp = hd.GetType().ToString().Trim(); Console.WriteLine(" GetType(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0005: returned type doesn't contain \"HybridDictionary\""); } Console.WriteLine("6. compare returned Type of two dictionary"); iCountTestcases++; temp1 = (new HybridDictionary()).GetType().ToString().Trim(); if (String.Compare(temp, temp1) != 0) { iCountErrors++; Console.WriteLine("Err_0006: returned types of two collections differ"); } Console.WriteLine("7. check Keys collection"); iCountTestcases++; keys = hd.Keys; if ( keys.Count != 0) { iCountErrors++; Console.WriteLine("Err_0007: Keys contains {0} keys after default ctor", keys.Count); } Console.WriteLine("8. check Values collection"); iCountTestcases++; values = hd.Values; if ( values.Count != 0) { iCountErrors++; Console.WriteLine("Err_0008: Values contains {0} items after default ctor", values.Count); } Console.WriteLine("9. Add(name, value)"); iCountTestcases++; hd.Add("Name", "Value"); if (hd.Count != 1) { iCountErrors++; Console.WriteLine("Err_0009a: Count returned {0} instead of 1", hd.Count); } if (String.Compare(hd["Name"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0009b: Item() returned unexpected value"); } if (hd["NAME"] != null) { iCountErrors++; Console.WriteLine("Err_0009c: Item() returned non-null value for uppercase key"); } Console.WriteLine("10. Clear() short dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_00010a: Count returned {0} instead of 0 after Clear()", hd.Count); } if (hd["Name"] != null) { iCountErrors++; Console.WriteLine("Err_00010b: Item() returned non-null value after Clear()"); } Console.WriteLine("11. multiple Add(name, value)"); iCountTestcases++; len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } iCountTestcases++; if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0011a: Count returned {0} instead of {1}", hd.Count, len); } for (int i = 0; i < len; i++) { iCountTestcases++; if (String.Compare(hd[keysLong[i]].ToString(), valuesLong[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_0011b_{0}: Item() returned unexpected value", i); } if (hd[keysLong[i].ToUpper()] != null) { iCountErrors++; Console.WriteLine("Err_0011c_{0}: Item() returned non-null for uppercase key", i); } } Console.WriteLine("12. Clear() long dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_00012: Count returned {0} instead of 0 after Clear()", hd.Count); } Console.WriteLine(""); strLoc = "Loc_001ooC-100"; iCountTestcases++; Console.WriteLine(" C. ctor(100)"); hd = new HybridDictionary(100); Console.WriteLine("1. compare to null"); iCountTestcases++; if (hd == null) { iCountErrors++; Console.WriteLine("Err_0001, dictionary is null after default ctor"); } Console.WriteLine("2. check Count"); iCountTestcases++; if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_0002, Count = {0} after default ctor", hd.Count); } Console.WriteLine("3. check Item(some_key)"); iCountTestcases++; if (hd["key"] != null) { iCountErrors++; Console.WriteLine("Err_0003, Item(some_key) returned non-null after default ctor"); } Console.WriteLine("4. check ToString()"); iCountTestcases++; temp = hd.ToString(); Console.WriteLine(" ToString(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0004, ToString() doesn't contain \"HybridDictionary\""); } Console.WriteLine("5. check returned Type"); iCountTestcases++; temp = hd.GetType().ToString().Trim(); Console.WriteLine(" GetType(): " + temp); if (temp.IndexOf("HybridDictionary") == -1) { iCountErrors++; Console.WriteLine("Err_0005: returned type doesn't contain \"HybridDictionary\""); } Console.WriteLine("6. compare returned Type of two dictionary"); iCountTestcases++; temp1 = (new HybridDictionary()).GetType().ToString().Trim(); if (String.Compare(temp, temp1) != 0) { iCountErrors++; Console.WriteLine("Err_0006: returned types of two collections differ"); } Console.WriteLine("7. check Keys collection"); iCountTestcases++; keys = hd.Keys; if ( keys.Count != 0) { iCountErrors++; Console.WriteLine("Err_0007: Keys contains {0} keys after default ctor", keys.Count); } Console.WriteLine("8. check Values collection"); iCountTestcases++; values = hd.Values; if ( values.Count != 0) { iCountErrors++; Console.WriteLine("Err_0008: Values contains {0} items after default ctor", values.Count); } Console.WriteLine("9. Add(name, value)"); iCountTestcases++; hd.Add("Name", "Value"); if (hd.Count != 1) { iCountErrors++; Console.WriteLine("Err_0009a: Count returned {0} instead of 1", hd.Count); } if (String.Compare(hd["Name"].ToString(), "Value", false) != 0) { iCountErrors++; Console.WriteLine("Err_0009b: Item() returned unexpected value"); } if (hd["NAME"] != null) { iCountErrors++; Console.WriteLine("Err_0009c: Item() returned non-null value for uppercase key"); } Console.WriteLine("10. Clear() short dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_00010a: Count returned {0} instead of 0 after Clear()", hd.Count); } if (hd["Name"] != null) { iCountErrors++; Console.WriteLine("Err_00010b: Item() returned non-null value after Clear()"); } Console.WriteLine("11. multiple Add(name, value)"); iCountTestcases++; len = valuesLong.Length; hd.Clear(); for (int i = 0; i < len; i++) { hd.Add(keysLong[i], valuesLong[i]); } iCountTestcases++; if (hd.Count != len) { iCountErrors++; Console.WriteLine("Err_0011a: Count returned {0} instead of {1}", hd.Count, len); } for (int i = 0; i < len; i++) { iCountTestcases++; if (String.Compare(hd[keysLong[i]].ToString(), valuesLong[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_0011b_{0}: Item() returned unexpected value", i); } if (hd[keysLong[i].ToUpper()] != null) { iCountErrors++; Console.WriteLine("Err_0011c_{0}: Item() returned non-null for uppercase key", i); } } Console.WriteLine("12. Clear() long dictionary"); iCountTestcases++; hd.Clear(); if (hd.Count != 0) { iCountErrors++; Console.WriteLine("Err_00012: Count returned {0} instead of 0 after Clear()", hd.Count); } Console.WriteLine(""); Console.WriteLine("15. ctor(-1) - no exception"); try { hd = new HybridDictionary(-1); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_00015a: unexpected exception: {0}", e.ToString()); } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_general! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "Pass. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("Fail! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
private static void CalcNarrowBarWidth(HybridDictionary hdBarWidths, out float fNarrowBarWidth, out float fWiderBarWidth) { fNarrowBarWidth = 1.0f; fWiderBarWidth = 2.0f; if (hdBarWidths.Count > 1) // we expect at least two different bar widths in supported barcodes { int[] aiWidths = new int[hdBarWidths.Count]; int[] aiCounts = new int[hdBarWidths.Count]; int i = 0; foreach (int iKey in hdBarWidths.Keys) { aiWidths[i] = iKey; aiCounts[i] = (int) hdBarWidths[iKey]; i++; } Array.Sort (aiWidths, aiCounts); // walk from lowest to highest width. The narrowest bar should occur at least 4 times fNarrowBarWidth = aiWidths[0]; fWiderBarWidth = WIDEFACTOR * fNarrowBarWidth; for (i = 0; i < aiCounts.Length; i++) { if (aiCounts[i] >= MINNARROWBARCOUNT) { fNarrowBarWidth = aiWidths[i]; if (fNarrowBarWidth < 3) fWiderBarWidth = WIDEFACTOR * fNarrowBarWidth; else { // if the width is not singular, look for the most common width in the neighbourhood float fCount; FindPeakWidth (i, ref aiWidths, ref aiCounts, out fNarrowBarWidth, out fCount); fWiderBarWidth = WIDEFACTOR * fNarrowBarWidth; if (fNarrowBarWidth >= 6) { // ... and for the next wider common bar width if the barcode is fairly large float fMaxCount = 0.0f; for (int j = i + 1; j < aiCounts.Length; j++) { float fNextWidth, fNextCount; FindPeakWidth (j, ref aiWidths, ref aiCounts, out fNextWidth, out fNextCount); if (fNextWidth / fNarrowBarWidth > 1.5) { if (fNextCount > fMaxCount) { fWiderBarWidth = fNextWidth; fMaxCount = fNextCount; } else break; } } } } break; } } } }