Exemplo n.º 1
0
		public void CheckConvert(int expect_from, int expect_to, TypeConverter conv, Type type) {
			int from_count	 = 0;
			int to_count	 = 0;

			foreach (Type t in typeof(int).Assembly.GetTypes ()) {
				if (conv.CanConvertFrom(null, t)) {
					from_count++;
					if (debug > 0) {
						Console.WriteLine("{0}: Conversion from {1} supported", conv.ToString(), t.ToString());
					}
				}

				if (conv.CanConvertTo(null, t)) {
					to_count++;
					if (debug > 0) {
						Console.WriteLine("{0}: Conversion to {1} supported", conv.ToString(), t.ToString());
					}
				}
			}

#if not
			foreach (Type t in type.Assembly.GetTypes ()) {
				if (conv.CanConvertFrom(null, t)) {
					from_count++;
					if (debug > 0) {
						Console.WriteLine("{0}: Conversion from {1} supported", conv.ToString(), t.ToString());
					}
				}

				if (conv.CanConvertTo(null, t)) {
					to_count++;
					if (debug > 0) {
						Console.WriteLine("{0}: Conversion to {1} supported", conv.ToString(), t.ToString());
					}
				}
			}
#endif

			if (from_count != expect_from) {
				if (verbose > 0) {
					Console.WriteLine("{0}: ConvertFrom expected {1}, returned {2}", conv.ToString(), expect_from, from_count);
				}
				failed++;
			}

			if (to_count != expect_to) {
				if (verbose > 0) {
					Console.WriteLine("{0}: ConvertTo expected {1}, returned {2}", conv.ToString(), expect_to, to_count);
				}
				failed++;
			}

		}
Exemplo n.º 2
0
		public void CheckConversion(object check, object expect, TypeConverter conv, Type type, bool test_from, bool test_to, CultureInfo culture) {
			object obj;
			object result;

			obj = check;

			if (debug > 0) {
				Console.WriteLine("{0}: CheckConversion, checking {1}({2}) <-> {3}({4})", conv.ToString(), check.GetType().ToString(), check.ToString(), type.ToString(), expect != null ? expect.ToString() : "null");
			}

			if (test_to) {
				obj = conv.ConvertTo(null, culture, check, type);

				if (obj == null) {
					if (expect != null) {
						failed++;
						Console.WriteLine("{0}: ConvertTo failed, type {1}, expected {2}, got null", conv.ToString(), type.ToString(), expect.ToString());
					}
					return;
				}

				// Intermediate verification
				if (expect != null && !obj.Equals(expect)) {
					failed++;
					if (verbose > 0) {
						Console.WriteLine("{0}: ConvertTo failed, type {1}, expected {2}, got {3}", conv.ToString(), type.ToString(), expect.ToString(), obj.ToString());
					}
				}

				if (debug > 1) {
					Console.WriteLine("{0}: CheckConversion, ConvertTo result: '{1}')", conv.ToString(), obj);
				}
			}


			if (test_from) {
				result = conv.ConvertFrom(null, culture, obj);

				if (test_to) {
					// Roundtrip check
					if (!check.Equals(result)) {
						failed++;
						if (verbose > 0) {
							Console.WriteLine("{0}: ConvertTo/ConvertFrom roundtrip failed, type {1}", conv.ToString(), type.ToString());
						}
					}

				} else {
					if (!expect.Equals(result)) {
						failed++;
						if (verbose > 0) {
							Console.WriteLine("{0}: ConvertFrom failed, type {1}", conv.ToString(), type.ToString());
						}
					}
				}

				if (debug > 1) {
					Console.WriteLine("{0}: CheckConversion, ConvertFrom result: '{1}')", conv.ToString(), result);
				}
			}
		}
Exemplo n.º 3
0
		public void CheckStandardValuesSupported(bool expect, TypeConverter conv) {
			bool result;

			result = conv.GetStandardValuesSupported(null);

			if (result != expect) {
				failed++;
				if (verbose > 0) {
					Console.WriteLine("{0}: GetStandardValuesSupported expected {1}, returned {2}", conv.ToString(), expect, result);
				}
			}
		}
Exemplo n.º 4
0
		public void CheckStandardValues(object[] expected, TypeConverter conv) {
			TypeConverter.StandardValuesCollection	values;

			values = conv.GetStandardValues(null);

			if (values == null && expected != null) {
				failed++;
				if (verbose > 0) {
					Console.WriteLine("{0}: GetStandardValues expected {0} values, got null", conv.ToString(), expected.Length);
				}
				return;
			}

			if (values != null && expected == null) {
				failed++;
				if (verbose > 0) {
					Console.WriteLine("{0}: GetStandardValues expected no values, got {1} values", conv.ToString(), values.Count);
				}
				return;
			}

			if (values != null) {
				if (values.Count != expected.Length) {
					if (verbose > 0) {
						Console.WriteLine("{0} GetStandardValues expected {1} values, returned {2}", conv.ToString(), expected.Length, values.Count);
					}
					failed++;
				}

				if (debug > 0) {
					Console.WriteLine("{0} Got {1} standard values", conv.ToString(), values.Count);
				}

				for (int i = 0; i < Math.Min(values.Count, expected.Length); i++) {
					if (debug > 0) {
						Console.WriteLine("{0}: Index {1:2} expecting:{2}, returned {3}", conv.ToString(), i, expected[i], values[i]);
					}

					if (!expected[i].Equals(values[i].ToString())) {
						if (verbose > 0) {
							Console.WriteLine("{0}: GetStandardValues Index {1} values don't match ({2} != {3})", conv.ToString(), i, expected[i], values[i]);
						}
						failed++;

					}
				}
			}
		}