コード例 #1
0
 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";
     StringDictionary sd; 
     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"
     };
     Array destination;
     int cnt = 0;            
     try
     {
         intl = new IntlStrings(); 
         Console.WriteLine("--- create dictionary ---");
         strLoc = "Loc_001oo"; 
         iCountTestcases++;
         sd = new StringDictionary();
         Console.WriteLine("1. Copy empty dictionary into empty array");
         iCountTestcases++;
         destination = Array.CreateInstance(typeof(Object), sd.Count);
         Console.WriteLine("     - CopyTo(arr, -1)");
         try 
         {
             sd.CopyTo(destination, -1);
             iCountErrors++;
             Console.WriteLine("Err_0001a, no exception");
         }
         catch (ArgumentOutOfRangeException ex) 
         {
             Console.WriteLine("  Expected exception: {0}", ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_001b, unexpected exception: {0}", e.ToString());
         }
         iCountTestcases++;
         Console.WriteLine("     - CopyTo(arr, 0)");
         try 
         {
             sd.CopyTo(destination, 0);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_001c, unexpected exception: {0}", e.ToString());
         }
         iCountTestcases++;
         Console.WriteLine("     - CopyTo(arr, 1)");
         try 
         {
             sd.CopyTo(destination, 1);
             iCountErrors++;
             Console.WriteLine("Err_0001d, no exception");
         }
         catch (ArgumentException ex) 
         {
             Console.WriteLine("  Expected exception: {0}", ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_001e, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("2. Copy empty dictionary into non-empty array");
         iCountTestcases++;
         destination = Array.CreateInstance(typeof(Object), values.Length);
         for (int i = 0; i < values.Length; i++) 
         {
             destination.SetValue(values[i], i);
         }
         sd.CopyTo(destination, 0);
         if( destination.Length != values.Length) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002a, altered array after copying empty collection");
         } 
         if (destination.Length == values.Length) 
         {
             for (int i = 0; i < values.Length; i++) 
             {
                 iCountTestcases++;
                 if (String.Compare(destination.GetValue(i).ToString(), values[i], false) != 0) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_0002_{0}b, altered item {0} after copying empty collection", i);
                 }
             } 
         }
         Console.WriteLine("3. add simple strings and CopyTo(Array, 0)");
         strLoc = "Loc_003oo"; 
         iCountTestcases++;
         cnt = sd.Count;
         int len = values.Length;
         for (int i = 0; i < len; i++) 
         {
             sd.Add(keys[i], values[i]);
         }
         if (sd.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003a, count is {0} instead of {1}", sd.Count, values.Length);
         } 
         destination = Array.CreateInstance(typeof(Object), len);
         sd.CopyTo(destination, 0);
         IEnumerator en = sd.GetEnumerator();
         for (int i = 0; i < len; i++) 
         {
             en.MoveNext();
             DictionaryEntry curr = (DictionaryEntry)en.Current;
             iCountTestcases++;
             if ( String.Compare(curr.Value.ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString(), false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0003_{0}b, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value, curr.Value);
             }  
             iCountTestcases++;
             if ( String.Compare(curr.Key.ToString(), ((DictionaryEntry)destination.GetValue(i)).Key.ToString(), false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0003_{0}c, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key, curr.Key);
             }  
         }
         Console.WriteLine("4. add simple strings and CopyTo(Array, {0})", values.Length);
         sd.Clear();
         strLoc = "Loc_004oo"; 
         iCountTestcases++;
         for (int i = 0; i < len; i++) 
         {
             sd.Add(keys[i], values[i]);
         }
         if (sd.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0004a, count is {0} instead of {1}", sd.Count, values.Length);
         } 
         destination = Array.CreateInstance(typeof(Object), len*2);
         sd.CopyTo(destination, len);
         en = sd.GetEnumerator();
         for (int i = 0; i < len; i++) 
         {
             en.MoveNext();
             DictionaryEntry curr = (DictionaryEntry)en.Current;
             iCountTestcases++;
             if ( String.Compare(curr.Value.ToString(), ((DictionaryEntry)destination.GetValue(i+len)).Value.ToString(), false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0003_{0}b, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i+len)).Value, curr.Value);
             }  
             iCountTestcases++;
             if ( String.Compare(curr.Key.ToString(), ((DictionaryEntry)destination.GetValue(i+len)).Key.ToString(), false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0003_{0}c, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i+len)).Key, curr.Key);
             }  
         }
         Console.WriteLine("5. add intl strings and CopyTo(Array, 0)");
         strLoc = "Loc_005oo"; 
         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;
         } 
         Boolean caseInsensitive = false;
         for (int i = 0; i < len * 2; i++) 
         {
             if(intlValues[i].Length!=0 && intlValues[i].ToLower()==intlValues[i].ToUpper())
                 caseInsensitive = true;
         }            
         iCountTestcases++;
         sd.Clear();
         for (int i = 0; i < len; i++) 
         {
             sd.Add(intlValues[i+len], intlValues[i]);
         } 
         if ( sd.Count != (len) ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0005a, count is {0} instead of {1}", sd.Count, len);
         } 
         destination = Array.CreateInstance(typeof(Object), len);
         sd.CopyTo(destination, 0);
         en = sd.GetEnumerator();
         for (int i = 0; i < len; i++) 
         {
             en.MoveNext();
             DictionaryEntry curr = (DictionaryEntry)en.Current;
             iCountTestcases++;
             if ( String.Compare(curr.Value.ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString(), false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0003_{0}b, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value, curr.Value);
             }  
             iCountTestcases++;
             if ( String.Compare(curr.Key.ToString(), ((DictionaryEntry)destination.GetValue(i)).Key.ToString(), false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0003_{0}c, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key, curr.Key);
             }  
         }
         Console.WriteLine("6. add intl strings and CopyTo(Array, {0})", len);
         strLoc = "Loc_006oo"; 
         destination = Array.CreateInstance(typeof(Object), len*2);
         sd.CopyTo(destination, len);
         en = sd.GetEnumerator();
         for (int i = 0; i < len; i++) 
         {
             en.MoveNext();
             DictionaryEntry curr = (DictionaryEntry)en.Current;
             iCountTestcases++;
             if ( String.Compare(curr.Value.ToString(), ((DictionaryEntry)destination.GetValue(i+len)).Value.ToString(), false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0006_{0}a, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i+len)).Value, curr.Value);
             }  
             iCountTestcases++;
             if ( String.Compare(curr.Key.ToString(), ((DictionaryEntry)destination.GetValue(i+len)).Key.ToString(), false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0006_{0}b, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i+len)).Key, curr.Key);
             }  
         }
         Console.WriteLine("7. case sensitivity");
         strLoc = "Loc_007oo"; 
         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();
         } 
         sd.Clear();
         for (int i = 0; i < len; i++) 
         {
             sd.Add(intlValues[i+len], intlValues[i]);     
         }
         destination = Array.CreateInstance(typeof(Object), len);
         sd.CopyTo(destination, 0);
         en = sd.GetEnumerator();
         for (int i = 0; i < len; i++) 
         {
             en.MoveNext();
             DictionaryEntry curr = (DictionaryEntry)en.Current;
             iCountTestcases++;
             if ( String.Compare(curr.Value.ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString(), false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0006_{0}a, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value, curr.Value);
             }
             iCountTestcases++;
             if ( !caseInsensitive && (Array.IndexOf(intlValuesLower, ((DictionaryEntry)destination.GetValue(i)).Value.ToString()) != -1 )) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0006_{0}b, copied lowercase string");
             }  
             iCountTestcases++;
             if ( String.Compare(curr.Key.ToString(), ((DictionaryEntry)destination.GetValue(i)).Key.ToString(), false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0006_{0}c, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key, curr.Key);
             } 
             iCountTestcases++;
             if ( Array.IndexOf(intlValuesLower, ((DictionaryEntry)destination.GetValue(i)).Key.ToString()) == -1 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0006_{0}d, copied uppercase key");
             }  
         }
         Console.WriteLine("8. CopyTo(null, int)");
         strLoc = "Loc_008oo"; 
         iCountTestcases++;
         destination = null;
         try 
         {
             sd.CopyTo(destination, 0);
             iCountErrors++;
             Console.WriteLine("Err_0008a: no exception ");
         }
         catch (ArgumentNullException ex) 
         {
             Console.WriteLine("  Expected exception: {0}", ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0008b, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("9. CopyTo(Array, -1)");
         strLoc = "Loc_009oo"; 
         iCountTestcases++;
         cnt = sd.Count;
         destination = Array.CreateInstance(typeof(Object), cnt);
         try 
         {
             sd.CopyTo(destination, -1);
             iCountErrors++;
             Console.WriteLine("Err_0009b: no exception ");
         }
         catch (ArgumentOutOfRangeException ex) 
         {
             Console.WriteLine("  Expected exception: {0}", ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0009c, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("10. CopyTo(Array, upperBound+1)");
         strLoc = "Loc_0010oo"; 
         iCountTestcases++;
         if (sd.Count < 1) 
         {
             for (int i = 0; i < len; i++) 
             {
                 sd.Add(keys[i], values[i]);
             }
         }
         destination = Array.CreateInstance(typeof(Object), len);
         try 
         {
             sd.CopyTo(destination, len);
             iCountErrors++;
             Console.WriteLine("Err_0010b: no exception ");
         }
         catch (ArgumentException ex) 
         {
             Console.WriteLine("  Expected exception: {0}", ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0010c, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("11. CopyTo(Array, upperBound+2)");
         strLoc = "Loc_010oo"; 
         iCountTestcases++;
         try 
         {
             sd.CopyTo(destination, len+1);
             iCountErrors++;
             Console.WriteLine("Err_0011b: no exception ");
         }
         catch (ArgumentException ex) 
         {
             Console.WriteLine("  Expected exception: {0}", ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0011c, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("12. CopyTo(Array, not_enough_space)");
         strLoc = "Loc_012oo"; 
         iCountTestcases++;
         try 
         {
             sd.CopyTo(destination, len / 2);
             iCountErrors++;
             Console.WriteLine("Err_0012a: no exception ");
         }
         catch (ArgumentException ex) 
         {
             Console.WriteLine("  Expected exception: {0}", ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0012b, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("13. CopyTo(multidim_Array, 0)");
         strLoc = "Loc_013oo"; 
         iCountTestcases++;
         destination = Array.CreateInstance(typeof(Object), len, len);
         try 
         {
             sd.CopyTo(destination, 0);
             iCountErrors++;
             Console.WriteLine("Err_0013a: no exception ");
         }
         catch (ArgumentException ex) 
         {
             Console.WriteLine("  Expected exception: {0}", ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0013b, 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;
     }
 }
コード例 #2
0
        public void TestEnvironmentVariablesPropertyUnix()
        {
            ProcessStartInfo psi = new ProcessStartInfo();

            // Creating a detached ProcessStartInfo will pre-populate the environment
            // with current environmental variables.

            StringDictionary environmentVariables = psi.EnvironmentVariables;

            Assert.NotEqual(0, environmentVariables.Count);

            int CountItems = environmentVariables.Count;

            environmentVariables.Add("NewKey", "NewValue");
            environmentVariables.Add("NewKey2", "NewValue2");

            Assert.Equal(CountItems + 2, environmentVariables.Count);
            environmentVariables.Remove("NewKey");
            Assert.Equal(CountItems + 1, environmentVariables.Count);

            //Exception not thrown with invalid key
            Assert.Throws <ArgumentException>(() => { environmentVariables.Add("NewKey2", "NewValue2"); });
            Assert.False(environmentVariables.ContainsKey("NewKey"));

            environmentVariables.Add("newkey2", "newvalue2");
            Assert.True(environmentVariables.ContainsKey("newkey2"));
            Assert.Equal("newvalue2", environmentVariables["newkey2"]);
            Assert.Equal("NewValue2", environmentVariables["NewKey2"]);

            environmentVariables.Clear();

            Assert.Equal(0, environmentVariables.Count);

            environmentVariables.Add("NewKey", "newvalue");
            environmentVariables.Add("newkey2", "NewValue2");
            Assert.False(environmentVariables.ContainsKey("newkey"));
            Assert.False(environmentVariables.ContainsValue("NewValue"));

            string result = null;
            int    index  = 0;

            foreach (string e1 in environmentVariables.Values)
            {
                index++;
                result += e1;
            }
            Assert.Equal(2, index);
            Assert.Equal("newvalueNewValue2", result);

            result = null;
            index  = 0;
            foreach (string e1 in environmentVariables.Keys)
            {
                index++;
                result += e1;
            }
            Assert.Equal("NewKeynewkey2", result);
            Assert.Equal(2, index);

            result = null;
            index  = 0;
            foreach (KeyValuePair <string, string> e1 in environmentVariables)
            {
                index++;
                result += e1.Key;
            }
            Assert.Equal("NewKeynewkey2", result);
            Assert.Equal(2, index);

            //Key not found
            Assert.Throws <KeyNotFoundException>(() =>
            {
                string stringout = environmentVariables["NewKey99"];
            });

            //Exception not thrown with invalid key
            Assert.Throws <ArgumentNullException>(() =>
            {
                string stringout = environmentVariables[null];
            });

            //Exception not thrown with invalid key
            Assert.Throws <ArgumentNullException>(() => environmentVariables.Add(null, "NewValue2"));

            //Invalid Key to add
            Assert.Throws <ArgumentException>(() => environmentVariables.Add("newkey2", "NewValue2"));

            //Use KeyValuePair Enumerator
            var x = environmentVariables.GetEnumerator() as IEnumerator <KeyValuePair <string, string> >;

            x.MoveNext();
            var y1 = x.Current;

            Assert.Equal("NewKey newvalue", y1.Key + " " + y1.Value);
            x.MoveNext();
            y1 = x.Current;
            Assert.Equal("newkey2 NewValue2", y1.Key + " " + y1.Value);

            environmentVariables.Add("newkey3", "newvalue3");

            KeyValuePair <string, string>[] kvpa = new KeyValuePair <string, string> [10];
            environmentVariables.CopyTo(kvpa, 0);
            Assert.Equal("NewKey", kvpa[0].Key);
            Assert.Equal("newkey3", kvpa[2].Key);
            Assert.Equal("newvalue3", kvpa[2].Value);

            string[] kvp = new string[10];
            Assert.Throws <ArgumentException>(() => { environmentVariables.CopyTo(kvp, 6); });
            environmentVariables.CopyTo(kvpa, 6);
            Assert.Equal("NewKey", kvpa[6].Key);
            Assert.Equal("newvalue", kvpa[6].Value);

            Assert.Throws <ArgumentOutOfRangeException>(() => { environmentVariables.CopyTo(kvpa, -1); });

            Assert.Throws <ArgumentException>(() => { environmentVariables.CopyTo(kvpa, 9); });

            Assert.Throws <ArgumentNullException>(() =>
            {
                KeyValuePair <string, string>[] kvpanull = null;
                environmentVariables.CopyTo(kvpanull, 0);
            });
        }
コード例 #3
0
    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";
        StringDictionary sd;

        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"
        };
        Array destination;
        int   cnt = 0;

        try
        {
            intl = new IntlStrings();
            Console.WriteLine("--- create dictionary ---");
            strLoc = "Loc_001oo";
            iCountTestcases++;
            sd = new StringDictionary();
            Console.WriteLine("1. Copy empty dictionary into empty array");
            iCountTestcases++;
            destination = Array.CreateInstance(typeof(Object), sd.Count);
            Console.WriteLine("     - CopyTo(arr, -1)");
            try
            {
                sd.CopyTo(destination, -1);
                iCountErrors++;
                Console.WriteLine("Err_0001a, no exception");
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Console.WriteLine("  Expected exception: {0}", ex.Message);
            }
            catch (Exception e)
            {
                iCountErrors++;
                Console.WriteLine("Err_001b, unexpected exception: {0}", e.ToString());
            }
            iCountTestcases++;
            Console.WriteLine("     - CopyTo(arr, 0)");
            try
            {
                sd.CopyTo(destination, 0);
            }
            catch (Exception e)
            {
                iCountErrors++;
                Console.WriteLine("Err_001c, unexpected exception: {0}", e.ToString());
            }
            iCountTestcases++;
            Console.WriteLine("     - CopyTo(arr, 1)");
            try
            {
                sd.CopyTo(destination, 1);
                iCountErrors++;
                Console.WriteLine("Err_0001d, no exception");
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine("  Expected exception: {0}", ex.Message);
            }
            catch (Exception e)
            {
                iCountErrors++;
                Console.WriteLine("Err_001e, unexpected exception: {0}", e.ToString());
            }
            Console.WriteLine("2. Copy empty dictionary into non-empty array");
            iCountTestcases++;
            destination = Array.CreateInstance(typeof(Object), values.Length);
            for (int i = 0; i < values.Length; i++)
            {
                destination.SetValue(values[i], i);
            }
            sd.CopyTo(destination, 0);
            if (destination.Length != values.Length)
            {
                iCountErrors++;
                Console.WriteLine("Err_0002a, altered array after copying empty collection");
            }
            if (destination.Length == values.Length)
            {
                for (int i = 0; i < values.Length; i++)
                {
                    iCountTestcases++;
                    if (String.Compare(destination.GetValue(i).ToString(), values[i], false) != 0)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_0002_{0}b, altered item {0} after copying empty collection", i);
                    }
                }
            }
            Console.WriteLine("3. add simple strings and CopyTo(Array, 0)");
            strLoc = "Loc_003oo";
            iCountTestcases++;
            cnt = sd.Count;
            int len = values.Length;
            for (int i = 0; i < len; i++)
            {
                sd.Add(keys[i], values[i]);
            }
            if (sd.Count != len)
            {
                iCountErrors++;
                Console.WriteLine("Err_0003a, count is {0} instead of {1}", sd.Count, values.Length);
            }
            destination = Array.CreateInstance(typeof(Object), len);
            sd.CopyTo(destination, 0);
            IEnumerator en = sd.GetEnumerator();
            for (int i = 0; i < len; i++)
            {
                en.MoveNext();
                DictionaryEntry curr = (DictionaryEntry)en.Current;
                iCountTestcases++;
                if (String.Compare(curr.Value.ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString(), false) != 0)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_0003_{0}b, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value, curr.Value);
                }
                iCountTestcases++;
                if (String.Compare(curr.Key.ToString(), ((DictionaryEntry)destination.GetValue(i)).Key.ToString(), false) != 0)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_0003_{0}c, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key, curr.Key);
                }
            }
            Console.WriteLine("4. add simple strings and CopyTo(Array, {0})", values.Length);
            sd.Clear();
            strLoc = "Loc_004oo";
            iCountTestcases++;
            for (int i = 0; i < len; i++)
            {
                sd.Add(keys[i], values[i]);
            }
            if (sd.Count != len)
            {
                iCountErrors++;
                Console.WriteLine("Err_0004a, count is {0} instead of {1}", sd.Count, values.Length);
            }
            destination = Array.CreateInstance(typeof(Object), len * 2);
            sd.CopyTo(destination, len);
            en = sd.GetEnumerator();
            for (int i = 0; i < len; i++)
            {
                en.MoveNext();
                DictionaryEntry curr = (DictionaryEntry)en.Current;
                iCountTestcases++;
                if (String.Compare(curr.Value.ToString(), ((DictionaryEntry)destination.GetValue(i + len)).Value.ToString(), false) != 0)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_0003_{0}b, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len)).Value, curr.Value);
                }
                iCountTestcases++;
                if (String.Compare(curr.Key.ToString(), ((DictionaryEntry)destination.GetValue(i + len)).Key.ToString(), false) != 0)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_0003_{0}c, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len)).Key, curr.Key);
                }
            }
            Console.WriteLine("5. add intl strings and CopyTo(Array, 0)");
            strLoc = "Loc_005oo";
            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;
            }
            Boolean caseInsensitive = false;
            for (int i = 0; i < len * 2; i++)
            {
                if (intlValues[i].Length != 0 && intlValues[i].ToLower() == intlValues[i].ToUpper())
                {
                    caseInsensitive = true;
                }
            }
            iCountTestcases++;
            sd.Clear();
            for (int i = 0; i < len; i++)
            {
                sd.Add(intlValues[i + len], intlValues[i]);
            }
            if (sd.Count != (len))
            {
                iCountErrors++;
                Console.WriteLine("Err_0005a, count is {0} instead of {1}", sd.Count, len);
            }
            destination = Array.CreateInstance(typeof(Object), len);
            sd.CopyTo(destination, 0);
            en = sd.GetEnumerator();
            for (int i = 0; i < len; i++)
            {
                en.MoveNext();
                DictionaryEntry curr = (DictionaryEntry)en.Current;
                iCountTestcases++;
                if (String.Compare(curr.Value.ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString(), false) != 0)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_0003_{0}b, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value, curr.Value);
                }
                iCountTestcases++;
                if (String.Compare(curr.Key.ToString(), ((DictionaryEntry)destination.GetValue(i)).Key.ToString(), false) != 0)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_0003_{0}c, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key, curr.Key);
                }
            }
            Console.WriteLine("6. add intl strings and CopyTo(Array, {0})", len);
            strLoc      = "Loc_006oo";
            destination = Array.CreateInstance(typeof(Object), len * 2);
            sd.CopyTo(destination, len);
            en = sd.GetEnumerator();
            for (int i = 0; i < len; i++)
            {
                en.MoveNext();
                DictionaryEntry curr = (DictionaryEntry)en.Current;
                iCountTestcases++;
                if (String.Compare(curr.Value.ToString(), ((DictionaryEntry)destination.GetValue(i + len)).Value.ToString(), false) != 0)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_0006_{0}a, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len)).Value, curr.Value);
                }
                iCountTestcases++;
                if (String.Compare(curr.Key.ToString(), ((DictionaryEntry)destination.GetValue(i + len)).Key.ToString(), false) != 0)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_0006_{0}b, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len)).Key, curr.Key);
                }
            }
            Console.WriteLine("7. case sensitivity");
            strLoc = "Loc_007oo";
            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();
            }
            sd.Clear();
            for (int i = 0; i < len; i++)
            {
                sd.Add(intlValues[i + len], intlValues[i]);
            }
            destination = Array.CreateInstance(typeof(Object), len);
            sd.CopyTo(destination, 0);
            en = sd.GetEnumerator();
            for (int i = 0; i < len; i++)
            {
                en.MoveNext();
                DictionaryEntry curr = (DictionaryEntry)en.Current;
                iCountTestcases++;
                if (String.Compare(curr.Value.ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString(), false) != 0)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_0006_{0}a, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value, curr.Value);
                }
                iCountTestcases++;
                if (!caseInsensitive && (Array.IndexOf(intlValuesLower, ((DictionaryEntry)destination.GetValue(i)).Value.ToString()) != -1))
                {
                    iCountErrors++;
                    Console.WriteLine("Err_0006_{0}b, copied lowercase string");
                }
                iCountTestcases++;
                if (String.Compare(curr.Key.ToString(), ((DictionaryEntry)destination.GetValue(i)).Key.ToString(), false) != 0)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_0006_{0}c, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key, curr.Key);
                }
                iCountTestcases++;
                if (Array.IndexOf(intlValuesLower, ((DictionaryEntry)destination.GetValue(i)).Key.ToString()) == -1)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_0006_{0}d, copied uppercase key");
                }
            }
            Console.WriteLine("8. CopyTo(null, int)");
            strLoc = "Loc_008oo";
            iCountTestcases++;
            destination = null;
            try
            {
                sd.CopyTo(destination, 0);
                iCountErrors++;
                Console.WriteLine("Err_0008a: no exception ");
            }
            catch (ArgumentNullException ex)
            {
                Console.WriteLine("  Expected exception: {0}", ex.Message);
            }
            catch (Exception e)
            {
                iCountErrors++;
                Console.WriteLine("Err_0008b, unexpected exception: {0}", e.ToString());
            }
            Console.WriteLine("9. CopyTo(Array, -1)");
            strLoc = "Loc_009oo";
            iCountTestcases++;
            cnt         = sd.Count;
            destination = Array.CreateInstance(typeof(Object), cnt);
            try
            {
                sd.CopyTo(destination, -1);
                iCountErrors++;
                Console.WriteLine("Err_0009b: no exception ");
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Console.WriteLine("  Expected exception: {0}", ex.Message);
            }
            catch (Exception e)
            {
                iCountErrors++;
                Console.WriteLine("Err_0009c, unexpected exception: {0}", e.ToString());
            }
            Console.WriteLine("10. CopyTo(Array, upperBound+1)");
            strLoc = "Loc_0010oo";
            iCountTestcases++;
            if (sd.Count < 1)
            {
                for (int i = 0; i < len; i++)
                {
                    sd.Add(keys[i], values[i]);
                }
            }
            destination = Array.CreateInstance(typeof(Object), len);
            try
            {
                sd.CopyTo(destination, len);
                iCountErrors++;
                Console.WriteLine("Err_0010b: no exception ");
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine("  Expected exception: {0}", ex.Message);
            }
            catch (Exception e)
            {
                iCountErrors++;
                Console.WriteLine("Err_0010c, unexpected exception: {0}", e.ToString());
            }
            Console.WriteLine("11. CopyTo(Array, upperBound+2)");
            strLoc = "Loc_010oo";
            iCountTestcases++;
            try
            {
                sd.CopyTo(destination, len + 1);
                iCountErrors++;
                Console.WriteLine("Err_0011b: no exception ");
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine("  Expected exception: {0}", ex.Message);
            }
            catch (Exception e)
            {
                iCountErrors++;
                Console.WriteLine("Err_0011c, unexpected exception: {0}", e.ToString());
            }
            Console.WriteLine("12. CopyTo(Array, not_enough_space)");
            strLoc = "Loc_012oo";
            iCountTestcases++;
            try
            {
                sd.CopyTo(destination, len / 2);
                iCountErrors++;
                Console.WriteLine("Err_0012a: no exception ");
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine("  Expected exception: {0}", ex.Message);
            }
            catch (Exception e)
            {
                iCountErrors++;
                Console.WriteLine("Err_0012b, unexpected exception: {0}", e.ToString());
            }
            Console.WriteLine("13. CopyTo(multidim_Array, 0)");
            strLoc = "Loc_013oo";
            iCountTestcases++;
            destination = Array.CreateInstance(typeof(Object), len, len);
            try
            {
                sd.CopyTo(destination, 0);
                iCountErrors++;
                Console.WriteLine("Err_0013a: no exception ");
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine("  Expected exception: {0}", ex.Message);
            }
            catch (Exception e)
            {
                iCountErrors++;
                Console.WriteLine("Err_0013b, 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);
        }
    }
コード例 #4
0
    // pseudo SAX reader
    public static void xmlparse(string fname)
    {
        XmlReader reader = new XmlTextReader(fname);
        string line;

        urls    =       new ArrayList();
        int cnt  = 0;
        // http://msdn.microsoft.com/en-us/library/1z92b1d4.aspx
        // http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.readsubtree.aspx
        while (reader.Read()) {
        if (reader.MoveToContent() == XmlNodeType.Element &&
            reader.Name == "formvals") {

            XmlReader inner = reader.ReadSubtree();
            StringDictionary myCol = new StringDictionary();
            while (inner.Read()) {

                if (inner.MoveToContent() == XmlNodeType.Element &&
                    inner.Name == "input") {

                    inner.MoveToFirstAttribute();
        // to avoid dependency on the attribute order, key them by the attribute name
        // amended with the unique count of the current input element.
                    myCol.Add(String.Format("{0}-{1}", inner.Name, cnt.ToString()), inner.Value);
                    inner.MoveToNextAttribute();
                    myCol.Add(String.Format("{0}-{1}", inner.Name, cnt.ToString()), inner.Value);
                    cnt++;
                }

                DictionaryEntry[] myArr = new DictionaryEntry[myCol.Count];
                myCol.CopyTo(myArr, 0);

                for (int i = 0; i < myArr.Length; i++) {

                    try{

                        string inputNameRegExp = @"name\-(?<input>\d+)";
                        MatchCollection myMatchCollection =
                            Regex.Matches(myArr[i].Key.ToString(), inputNameRegExp );

                        foreach (Match myMatch in myMatchCollection) {

                            string pos =  myMatch.Groups["input"].Value.ToString();
                            // do not use StringDictionary for final formvals or you have your keyc converted to lower case.
                            formvals.Add(myCol[String.Format("name-{0}", pos)], myCol[String.Format("value-{0}", pos)]);

                        }
                    } catch (Exception e) {
                        Console.WriteLine(e.ToString());
                    }

                }
                myCol.Clear();
            }
            foreach ( KeyValuePair<string, string> kvp in formvals )
                Console.WriteLine("formvals[ {0} ] = {1}", kvp.Key, kvp.Value);

            inner.Close();

        }
        if (reader.MoveToContent() == XmlNodeType.Element &&   reader.Name == "url") {
            line    =       reader.ReadString();
            urls.Add(line);
            Console.WriteLine(line);
        }
        }
    }
コード例 #5
0
// pseudo SAX reader
    public static void xmlparse(string fname)
    {
        XmlReader reader = new XmlTextReader(fname);
        string    line;

        urls = new ArrayList();
        int cnt = 0;

        // http://msdn.microsoft.com/en-us/library/1z92b1d4.aspx
        // http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.readsubtree.aspx
        while (reader.Read())
        {
            if (reader.MoveToContent() == XmlNodeType.Element &&
                reader.Name == "formvals")
            {
                XmlReader        inner = reader.ReadSubtree();
                StringDictionary myCol = new StringDictionary();
                while (inner.Read())
                {
                    if (inner.MoveToContent() == XmlNodeType.Element &&
                        inner.Name == "input")
                    {
                        inner.MoveToFirstAttribute();
// to avoid dependency on the attribute order, key them by the attribute name
// amended with the unique count of the current input element.
                        myCol.Add(String.Format("{0}-{1}", inner.Name, cnt.ToString()), inner.Value);
                        inner.MoveToNextAttribute();
                        myCol.Add(String.Format("{0}-{1}", inner.Name, cnt.ToString()), inner.Value);
                        cnt++;
                    }

                    DictionaryEntry[] myArr = new DictionaryEntry[myCol.Count];
                    myCol.CopyTo(myArr, 0);

                    for (int i = 0; i < myArr.Length; i++)
                    {
                        try{
                            string          inputNameRegExp   = @"name\-(?<input>\d+)";
                            MatchCollection myMatchCollection =
                                Regex.Matches(myArr[i].Key.ToString(), inputNameRegExp);

                            foreach (Match myMatch in myMatchCollection)
                            {
                                string pos = myMatch.Groups["input"].Value.ToString();
                                // do not use StringDictionary for final formvals or you have your keyc converted to lower case.
                                formvals.Add(myCol[String.Format("name-{0}", pos)], myCol[String.Format("value-{0}", pos)]);
                            }
                        } catch (Exception e) {
                            Console.WriteLine(e.ToString());
                        }
                    }
                    myCol.Clear();
                }
                foreach (KeyValuePair <string, string> kvp in formvals)
                {
                    Console.WriteLine("formvals[ {0} ] = {1}", kvp.Key, kvp.Value);
                }


                inner.Close();
            }
            if (reader.MoveToContent() == XmlNodeType.Element && reader.Name == "url")
            {
                line = reader.ReadString();
                urls.Add(line);
                Console.WriteLine(line);
            }
        }
    }
コード例 #6
0
        public void Test01()
        {
            IntlStrings      intl;
            StringDictionary sd;

            // simple string values
            string[] values =
            {
                "",
                " ",
                "a",
                "aa",
                "text",
                "     spaces",
                "1",
                "$%^#",
                "2222222222222222222222222",
                System.DateTime.Today.ToString(),
                Int32.MaxValue.ToString()
            };

            // keys for simple string values
            string[] keys =
            {
                "zero",
                "one",
                " ",
                "",
                "aa",
                "1",
                System.DateTime.Today.ToString(),
                "$%^#",
                Int32.MaxValue.ToString(),
                "     spaces",
                "2222222222222222222222222"
            };

            Array destination;
            int   cnt = 0;          // Count

            // initialize IntStrings
            intl = new IntlStrings();


            // [] StringDictionary is constructed as expected
            //-----------------------------------------------------------------

            sd = new StringDictionary();

            // [] Copy empty dictionary into empty array
            //
            destination = Array.CreateInstance(typeof(Object), sd.Count);
            Assert.Throws <ArgumentOutOfRangeException>(() => { sd.CopyTo(destination, -1); });
            sd.CopyTo(destination, 0);
            Assert.Throws <ArgumentException>(() => { sd.CopyTo(destination, 1); });

            // [] Copy empty dictionary into non-empty array
            //
            destination = Array.CreateInstance(typeof(Object), values.Length);
            for (int i = 0; i < values.Length; i++)
            {
                destination.SetValue(values[i], i);
            }
            sd.CopyTo(destination, 0);
            if (destination.Length != values.Length)
            {
                Assert.False(true, string.Format("Error, altered array after copying empty collection"));
            }
            if (destination.Length == values.Length)
            {
                for (int i = 0; i < values.Length; i++)
                {
                    if (String.Compare(destination.GetValue(i).ToString(), values[i]) != 0)
                    {
                        Assert.False(true, string.Format("Error, altered item {0} after copying empty collection", i));
                    }
                }
            }


            // [] add simple strings and CopyTo(Array, 0)
            //

            cnt = sd.Count;
            int len = values.Length;

            for (int i = 0; i < len; i++)
            {
                sd.Add(keys[i], values[i]);
            }
            if (sd.Count != len)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, values.Length));
            }

            destination = Array.CreateInstance(typeof(Object), len);
            sd.CopyTo(destination, 0);

            IEnumerator en = sd.GetEnumerator();

            //
            // order of items is the same as order of enumerator
            //
            for (int i = 0; i < len; i++)
            {
                en.MoveNext();
                // verify that collection is copied correctly
                //
                DictionaryEntry curr = (DictionaryEntry)en.Current;

                if (String.Compare(curr.Value.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, curr.Value));
                }

                if (String.Compare(curr.Key.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, curr.Key));
                }
            }

            //
            // [] add simple strings and CopyTo(Array, middle_index)


            sd.Clear();

            for (int i = 0; i < len; i++)
            {
                sd.Add(keys[i], values[i]);
            }
            if (sd.Count != len)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, values.Length));
            }

            destination = Array.CreateInstance(typeof(Object), len * 2);
            sd.CopyTo(destination, len);

            en = sd.GetEnumerator();
            //
            // order of items is the same as order of enumerator
            //
            for (int i = 0; i < len; i++)
            {
                en.MoveNext();
                // verify that collection is copied correctly
                //
                DictionaryEntry curr = (DictionaryEntry)en.Current;

                if (String.Compare(curr.Value.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, curr.Value));
                }

                if (String.Compare(curr.Key.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, curr.Key));
                }
            }

            //
            // Intl strings
            // [] add 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].ToLowerInvariant() == intlValues[i].ToUpperInvariant())
                {
                    caseInsensitive = true;
                }
            }

            sd.Clear();
            for (int i = 0; i < len; i++)
            {
                sd.Add(intlValues[i + len], intlValues[i]);
            }
            if (sd.Count != (len))
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, len));
            }

            destination = Array.CreateInstance(typeof(Object), len);
            sd.CopyTo(destination, 0);

            en = sd.GetEnumerator();
            //
            // order of items is the same as order of enumerator
            //
            for (int i = 0; i < len; i++)
            {
                en.MoveNext();
                // verify that collection is copied correctly
                //
                DictionaryEntry curr = (DictionaryEntry)en.Current;

                if (String.Compare(curr.Value.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, curr.Value));
                }

                if (String.Compare(curr.Key.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, curr.Key));
                }
            }

            //
            // Intl strings
            // [] add intl strings and CopyTo(Array, middle_index)
            //


            destination = Array.CreateInstance(typeof(Object), len * 2);
            sd.CopyTo(destination, len);

            en = sd.GetEnumerator();
            //
            // order of items is the same as order of enumerator
            //
            for (int i = 0; i < len; i++)
            {
                en.MoveNext();
                // verify that collection is copied correctly
                //
                DictionaryEntry curr = (DictionaryEntry)en.Current;

                if (String.Compare(curr.Value.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, curr.Value));
                }

                if (String.Compare(curr.Key.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, curr.Key));
                }
            }


            //
            // [] Case sensitivity
            //

            string[] intlValuesLower = new string[len * 2];

            // fill array with unique strings
            //
            for (int i = 0; i < len * 2; i++)
            {
                intlValues[i] = intlValues[i].ToUpperInvariant();
            }

            for (int i = 0; i < len * 2; i++)
            {
                intlValuesLower[i] = intlValues[i].ToLowerInvariant();
            }

            sd.Clear();
            //
            // will use first half of array as values and second half as keys
            //
            for (int i = 0; i < len; i++)
            {
                sd.Add(intlValues[i + len], intlValues[i]);     // adding uppercase strings
            }

            destination = Array.CreateInstance(typeof(Object), len);
            sd.CopyTo(destination, 0);

            en = sd.GetEnumerator();
            //
            // order of items is the same as order of enumerator
            //
            for (int i = 0; i < len; i++)
            {
                en.MoveNext();
                // verify that collection is copied correctly
                //
                DictionaryEntry curr = (DictionaryEntry)en.Current;

                if (String.Compare(curr.Value.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, curr.Value));
                }

                if (!caseInsensitive && (Array.IndexOf(intlValuesLower, ((DictionaryEntry)destination.GetValue(i)).Value.ToString()) != -1))
                {
                    Assert.False(true, string.Format("Error, copied lowercase string"));
                }

                if (String.Compare(curr.Key.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, curr.Key));
                }

                if (Array.IndexOf(intlValuesLower, ((DictionaryEntry)destination.GetValue(i)).Key.ToString()) == -1)
                {
                    Assert.False(true, string.Format("Error, copied uppercase key"));
                }
            }


            //
            //  [] CopyTo(null, int)
            //
            destination = null;
            Assert.Throws <ArgumentNullException>(() => { sd.CopyTo(destination, 0); });

            //
            //  [] CopyTo(string[], -1)
            //
            cnt = sd.Count;

            destination = Array.CreateInstance(typeof(Object), cnt);
            Assert.Throws <ArgumentOutOfRangeException>(() => { sd.CopyTo(destination, -1); });

            //
            // [] CopyTo(Array, upperBound+1)
            //
            if (sd.Count < 1)
            {
                for (int i = 0; i < len; i++)
                {
                    sd.Add(keys[i], values[i]);
                }
            }

            destination = Array.CreateInstance(typeof(Object), len);
            Assert.Throws <ArgumentException>(() => { sd.CopyTo(destination, len); });

            //
            // [] CopyTo(Array, upperBound+2)
            //
            Assert.Throws <ArgumentException>(() => { sd.CopyTo(destination, len + 1); });

            //
            // [] CopyTo(Array, not_enough_space)
            //
            Assert.Throws <ArgumentException>(() => { sd.CopyTo(destination, len / 2); });

            //
            // [] CopyTo(multidim_Array, 0)
            //

            destination = new object[len, len];
            Assert.Throws <ArgumentException>(() => { sd.CopyTo(destination, 0); });
        }
コード例 #7
0
        static void Main()
        {
            StringDictionary strdic = new StringDictionary();

            strdic.Add("one", "Circle");
            strdic.Add("two", "Square");
            strdic.Add("three", "Triangle");
            strdic.Add("four", "Rectangle");
            strdic.Add("five", "Paralellogram");



            Console.WriteLine("Printing the Key Vakue pair");
            foreach (DictionaryEntry item in strdic)
            {
                Console.WriteLine("{0} : {1}", item.Key, item.Value);
            }



            Console.WriteLine("Checking weather the key six is present in the String dictionary or not");
            bool ck = strdic.ContainsKey("six");

            Console.WriteLine("Contains or not:{0}", ck);



            Console.WriteLine("Checking weather the value Square exist in the String Dictionary or not");
            bool cv = strdic.ContainsValue("Square");

            Console.WriteLine("Value present or not:{0}", cv);



            DictionaryEntry[] str1 = new DictionaryEntry[strdic.Count];
            strdic.CopyTo(str1, 0);
            Console.WriteLine("Printing the Copied array");
            foreach (var ar in str1)
            {
                Console.WriteLine("{0}:{1}", ar.Key, ar.Value);
            }



            Console.WriteLine("Printing the elements of the String Dictionary using GetEnumerator method");
            IEnumerator     ie = strdic.GetEnumerator();
            DictionaryEntry de;

            while (ie.MoveNext())
            {
                de = (DictionaryEntry)ie.Current;
                Console.WriteLine("{0}:{1}", de.Key, de.Value);
            }
            strdic.Remove("five");

            Console.WriteLine("Printing the String Dictionary after removing the key-----");
            foreach (DictionaryEntry item1 in strdic)
            {
                Console.WriteLine("{0} : {1}", item1.Key, item1.Value);
            }

            Console.Read();
        }
        static void Main()
        {
            StringDictionary myDict = new StringDictionary();

            myDict.Add("One", "This");
            myDict.Add("Two", "is");
            myDict.Add("Three", "String");
            myDict.Add("Four", "Dictionary");
            myDict.Add("Five", "Demo");
            myDict.Add("Six", "using");
            myDict.Add("Seven", "System");
            myDict.Add("Eight", "Collections");
            myDict.Add("Nine", "Specialized");

            foreach (DictionaryEntry item in myDict)
            {
                Console.WriteLine("Keys : {0}  Values : {1}", item.Key, item.Value);
            }



            Console.WriteLine("--------------");
            Console.WriteLine("Elements after copy to in myArr :");
            DictionaryEntry[] myArr = new DictionaryEntry[myDict.Count];
            myDict.CopyTo(myArr, 0);
            foreach (DictionaryEntry de in myArr)
            {
                Console.WriteLine("Keys : {0}  Values : {1}", de.Key, de.Value);
            }

            Console.WriteLine("-------------------");
            Console.WriteLine("Checks for provided key and value :");

            if (myDict.ContainsKey("Six"))
            {
                Console.WriteLine("StringDictionary myDict contains the key");
            }
            else
            {
                Console.WriteLine("StringDictionary myDict does not contain the key");
            }

            if (myDict.ContainsValue("Demo"))
            {
                Console.WriteLine("StringDictionary myDict contains the value");
            }
            else
            {
                Console.WriteLine("StringDictionary myDict does not contain the vlaue");
            }


            Console.WriteLine("-----------------");
            myDict.Remove("Nine");
            Console.WriteLine("Elements after Remove in StringDictionary");
            Console.WriteLine("The number of key/value pairs are : " + myDict.Count);

            foreach (DictionaryEntry a in myDict)
            {
                Console.WriteLine("Keys : {0}  Values : {1}", a.Key, a.Value);
            }



            Console.WriteLine("------------------");
            Console.WriteLine("Values in StringDictionary :");
            foreach (string val in myDict.Values)
            {
                Console.WriteLine(val);
            }

            Console.WriteLine("Keys in StringDictionary :");
            foreach (string val in myDict.Keys)
            {
                Console.WriteLine(val);
            }
        }
コード例 #9
0
        public Form1()
        {
            InitializeComponent();
            //Formatting form
            this.originalFormHeight    = this.Height;
            tabs.SelectedIndexChanged += (x, y) => {
                if (tabs.SelectedTab.Name == "readbacksettingsTab")
                {
                    this.Height = this.originalFormHeight;
                }
                else
                {
                    DisplayPanel();
                }
            };
            //Entry Settings
            InputTypecomboBox.SelectedValueChanged += DisplayPanel;
            InputTypecomboBox.SelectedIndex         = Properties.Settings.Default.inputType;
            if (Properties.Settings.Default.enterDataDownwards)
            {
                directionComboBox.SelectedIndex = 0;
                trueForRows_falseForColumns     = true;
            }
            else
            {
                directionComboBox.SelectedIndex = 1;
                trueForRows_falseForColumns     = false;
            }
            UpdateLabels();
            directionComboBox.SelectedIndexChanged += (x, y) => { UpdateLabels(); richTextBox1.Text = ""; };

            intminValueSelector.Minimum = Int32.MinValue; intminValueSelector.Maximum = Int32.MaxValue - 1;
            intmaxValueSelector.Minimum = Int32.MinValue + 1; intmaxValueSelector.Maximum = Int32.MaxValue;
            intminValueSelector.Value   = Properties.Settings.Default.intminValue;
            intmaxValueSelector.Value   = Properties.Settings.Default.intmaxValue;

            decimalPlacesSelector.Value      = Properties.Settings.Default.doubleDecimalPlaces;
            fpMinValueSelector.DecimalPlaces = Properties.Settings.Default.doubleDecimalPlaces;
            fpMaxValueSelector.DecimalPlaces = Properties.Settings.Default.doubleDecimalPlaces;
            fpMinValueSelector.Minimum       = Decimal.MinValue; fpMinValueSelector.Maximum = Decimal.MaxValue - 1;
            fpMaxValueSelector.Minimum       = Decimal.MinValue + 1; fpMaxValueSelector.Maximum = Decimal.MaxValue;
            fpMinValueSelector.Value         = Properties.Settings.Default.doubleminValue;
            fpMaxValueSelector.Value         = Properties.Settings.Default.doubleMaxValue;
            roundDecimal.Checked             = Properties.Settings.Default.roundDecimals;

            decimalPlacesSelector.ValueChanged += (e, s) =>
            {
                fpMinValueSelector.DecimalPlaces = (int)decimalPlacesSelector.Value;
                fpMaxValueSelector.DecimalPlaces = (int)decimalPlacesSelector.Value;
            };

            fpMinValueSelector.ValueChanged += (e, s) =>
            {
                if (fpMinValueSelector.Value > fpMaxValueSelector.Value)
                {
                    fpMaxValueSelector.Value = fpMinValueSelector.Value + 1;
                }
            };
            intminValueSelector.ValueChanged += (e, s) =>
            {
                if (intminValueSelector.Value > intmaxValueSelector.Value)
                {
                    intmaxValueSelector.Value = intminValueSelector.Value + 1;
                }
            };

            addResultTextBox.TextChanged += (e, s) =>
            {
                if (resultsListBox.Items.Contains(addResultTextBox.Text) || addResultTextBox.Text.Trim().Length == 0)
                {
                    addResultBtn.Enabled = false;
                }
                else
                {
                    addResultBtn.Enabled = true;
                }
            };

            phrasesListBox.SelectedIndexChanged += (s, e) =>
            {
                if (resultsListBox.SelectedIndex < 0)
                {
                    removePhraseBtn.Enabled = false;
                }
                else
                {
                    removePhraseBtn.Enabled = true;
                }
            };

            phrasetextBox.TextChanged += (s, e) =>
            {
                if (resultsListBox.SelectedIndex >= 0 && phrasetextBox.Text.Trim().Length > 0)
                {
                    addPhraseButton.Enabled = true;
                }
                else
                {
                    addPhraseButton.Enabled = false;
                }
            };

            resultsListBox.SelectedIndexChanged += (e, s) =>
            {
                if (resultsListBox.SelectedIndex < 0)
                {
                    addPhraseButton.Enabled    = false;
                    updateResultButton.Enabled = false;
                    removeResultBtn.Enabled    = false;
                }
                else
                {
                    updateResultButton.Enabled = true;
                    removeResultBtn.Enabled    = true;
                }

                phrasesListBox.Items.Clear();
                addResultTextBox.Text = resultsListBox.Text;
                insertAsTextBox.Text  = resultsDictionary[resultsListBox.Text];

                DictionaryEntry[] phrasesDictionaryArray = new DictionaryEntry[phrasesDictionary.Count];
                phrasesDictionary.CopyTo(phrasesDictionaryArray, 0);
                //Array.Sort(phrasesDictionaryArray,
                //  delegate (DictionaryEntry x, DictionaryEntry y) { return x.Key.ToString().CompareTo(y.Key.ToString()); });
                foreach (DictionaryEntry phrase in phrasesDictionaryArray)
                {
                    if (phrase.Value.ToString().Equals(resultsListBox.Text))
                    {
                        phrasesListBox.Items.Add(phrase.Key.ToString());
                    }
                }
            };

            if (Properties.Settings.Default.customSet != null)
            {
                resultsDictionary = Properties.Settings.Default.customSet;

                DictionaryEntry[] resultsDictionaryArray = new DictionaryEntry[resultsDictionary.Count];
                resultsDictionary.CopyTo(resultsDictionaryArray, 0);
                //Populate lists;
                Array.Sort(resultsDictionaryArray,
                           delegate(DictionaryEntry x, DictionaryEntry y) { return(x.Key.ToString().CompareTo(y.Key.ToString())); });
                foreach (DictionaryEntry entry in resultsDictionaryArray)
                {
                    resultsListBox.Items.Add(entry.Key.ToString());
                }
            }
            else
            {
                resultsDictionary = new StringDictionary();
            }
            if (Properties.Settings.Default.customSetPhrases != null)
            {
                phrasesDictionary = Properties.Settings.Default.customSetPhrases;
            }
            else
            {
                phrasesDictionary = new StringDictionary();
            }
            //Read back settings
            readBackCheckBox.CheckedChanged += (es, ar) =>
            {
                if (readBackCheckBox.Checked)
                {
                    panel3.Enabled = true;
                }
            };

            readBackCheckBox.Checked = Properties.Settings.Default.readBackValues;

            readBackWhencomboBox.SelectedIndexChanged += (e, ar) =>
            {
                if (readBackWhencomboBox.SelectedIndex == 1 || comboBox1.SelectedIndex == 1)
                {
                    periodicReadnumericUpDown.Enabled = true;
                    periodicLabel.Enabled             = true;
                }
                else
                {
                    periodicReadnumericUpDown.Enabled = false;
                    periodicLabel.Enabled             = false;
                }
            };


            readBackWhencomboBox.SelectedIndex = Properties.Settings.Default.readBackWhenCode;
            readColRowcheckBox.CheckedChanged += (e, ar) =>
            {
                if (readColRowcheckBox.Checked)
                {
                    readRowColInfopanel.Enabled = true;
                }
                else
                {
                    readRowColInfopanel.Enabled = false;
                }
            };
            readColRowcheckBox.Checked         = Properties.Settings.Default.readRowColInfo;
            readColRowcheckBox.CheckedChanged += (sen, argz) =>
            {
                if (readColRowcheckBox.Checked && (richTextBox1.Text.Length == 0))
                {
                    applyReadChangesButton.Enabled = false;
                }
            };

            comboBox1.SelectedIndexChanged += (e, ar) =>
            {
                if (readBackWhencomboBox.SelectedIndex == 1 || comboBox1.SelectedIndex == 1)
                {
                    periodicReadnumericUpDown.Enabled = true;
                    periodicLabel.Enabled             = true;
                }
                else
                {
                    periodicReadnumericUpDown.Enabled = false;
                    periodicLabel.Enabled             = false;
                }
            };

            comboBox1.SelectedIndex = Properties.Settings.Default.readRowColWhenCode;

            /* if (Properties.Settings.Default.rowColInfoNumbers != null &&
             *   Properties.Settings.Default.rowColInfoNumbers.Length > 0)
             * {
             *   foreach (var i in Properties.Settings.Default.rowColInfoNumbers)
             *       listBox1.Items.Add(i);
             * }*/
            if (Properties.Settings.Default.rowColReadbackString != null && Properties.Settings.Default.rowColReadbackString.Length > 0)
            {
                richTextBox1.Text    = Properties.Settings.Default.rowColReadbackString;
                richTextBox1.Enabled = true;
                Regex           rx      = new Regex(@"<column \d+>|<row \d+>");
                MatchCollection matches = rx.Matches(Properties.Settings.Default.rowColReadbackString);
                foreach (Match match in matches)
                {
                    int colnumber;
                    Int32.TryParse(Regex.Match(match.Value, @"\d+").Value, out colnumber);
                    char[] trimchars = new char[] { '<', '>' };
                    _tags.Add(match.Value.Trim(trimchars));
                    textBox1.Text   += colnumber + ", ";
                    textBox1.Visible = true;
                    label17.Visible  = true;
                }
            }
            periodicReadnumericUpDown.Value = Properties.Settings.Default.periodicReadBackCount;


            this.richTextBox1.DragEnter   += new DragEventHandler(this.richTextBox1_DragEnter);
            this.richTextBox1.DragDrop    += new DragEventHandler(this.richTextBox1_DragDrop);
            richTextBox1.SelectionChanged += richTextBox1_SelectionChanged;
            richTextBox1.KeyDown          += richTextBox1_KeyDown;
            richTextBox1.KeyPress         += richTextBoxKeyPress;
            richTextBox1.TextChanged      += (sen, argz) =>
            {
                if (richTextBox1.Text.Length > 0)
                {
                    applyReadChangesButton.Enabled = true;
                }
            };
        }
コード例 #10
0
        static void Main(string[] args)
        {
            Console.WriteLine("********************************String Collection*******************************************");
            StringCollection s1 = new StringCollection();

            s1.Add("rosy");
            s1.Add("sweety");
            s1.Add("anjali");
            s1.Add("kavya");
            Console.WriteLine("Elements in string collection");
            foreach (var i in s1)
            {
                Console.WriteLine(i);
            }
            Console.WriteLine("count of string{0}", s1.Count);
            var a1 = new string[s1.Count];

            Console.WriteLine("copying the string list to array a1");

            s1.CopyTo(a1, 0);
            foreach (var i in a1)
            {
                Console.WriteLine(i);
            }
            Console.WriteLine("using Ienumerator");
            StringEnumerator ie = s1.GetEnumerator();

            while (ie.MoveNext())
            {
                Console.WriteLine(ie.Current);
            }
            Console.WriteLine("insterting a string");
            s1.Insert(2, "swagata");
            foreach (var i in s1)
            {
                Console.WriteLine(i);
            }

            Console.WriteLine("*******************************************String Dictionary***********************************************");
            StringDictionary s2 = new StringDictionary();

            s2.Add("one", "first");
            s2.Add("two", "second");
            s2.Add("three", "third");
            foreach (DictionaryEntry ide in s2)

            {
                Console.WriteLine("{0}={1}", ide.Key, ide.Value);
            }
            DictionaryEntry[] a2 = new
                                   DictionaryEntry[s2.Count];
            Console.WriteLine("copying the string list to array a1");
            s2.CopyTo(a2, 0);
            foreach (DictionaryEntry ide in a2)

            {
                Console.WriteLine("{0}={1}", ide.Key, ide.Value);
            }
            Console.WriteLine("using Ienumerator");
            StringEnumerator id = s1.GetEnumerator();
            DictionaryEntry  de;

            while (id.MoveNext())
            {
                //de = (DictionaryEntry)id.Current;

                Console.WriteLine("{0}:{1}", de.Key, de.Value);
            }
            Console.WriteLine("Removing two");
            s2.Remove("two");

            foreach (DictionaryEntry ide in s2)

            {
                Console.WriteLine("{0}={1}", ide.Key, ide.Value);
            }
        }