Permalink
Browse files

- Updated, to allow only to/from tests

- Added DataGridPreferredColumnWidthTypeConverter

svn path=/trunk/winforms/; revision=44943
  • Loading branch information...
1 parent 5ff649b commit 3986b13e689edbb9a4799ca8b17297a9b116d8ab Peter Dennis Bartok committed May 24, 2005
Showing with 70 additions and 25 deletions.
  1. +70 −25 converters/converters.cs
View
95 converters/converters.cs
@@ -72,53 +72,80 @@ class MainWindow : System.Windows.Forms.Form {
}
}
+
public void CheckConversion(object check, object expect, TypeConverter conv, Type type) {
- CheckConversion(check, expect, conv, type, CultureInfo.InvariantCulture);
- CheckConversion(check, expect, conv, type, CultureInfo.CreateSpecificCulture("de-de"));
+ CheckConversion(check, expect, conv, type, true, true, CultureInfo.InvariantCulture);
+ CheckConversion(check, expect, conv, type, true, true, CultureInfo.CreateSpecificCulture("de-de"));
}
+
+ public void CheckConversion(object check, object expect, TypeConverter conv, Type type, bool test_from, bool test_to) {
+ CheckConversion(check, expect, conv, type, test_from, test_to, CultureInfo.InvariantCulture);
+ CheckConversion(check, expect, conv, type, test_from, test_to, CultureInfo.CreateSpecificCulture("de-de"));
+ }
public void CheckConversion(object check, object expect, TypeConverter conv, Type type, CultureInfo culture) {
+ CheckConversion(check, expect, conv, type, true, true, culture);
+ }
+
+ 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");
}
- obj = conv.ConvertTo(null, culture, check, type);
+ 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;
+ }
- if (obj == null) {
- if (expect != null) {
+ // Intermediate verification
+ if (expect != null && !obj.Equals(expect)) {
failed++;
- Console.WriteLine("{0}: ConvertTo failed, type {1}, expected {2}, got null", conv.ToString(), type.ToString(), expect.ToString());
+ if (verbose > 0) {
+ Console.WriteLine("{0}: ConvertTo failed, type {1}, expected {2}, got {3}", conv.ToString(), type.ToString(), expect.ToString(), obj.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 (debug > 1) {
- Console.WriteLine("{0}: CheckConversion, ConvertTo result: '{1}')", conv.ToString(), obj);
- }
- result = conv.ConvertFrom(null, culture, obj);
+ if (test_from) {
+ result = conv.ConvertFrom(null, culture, obj);
- // Roundtrip check
- if (!check.Equals(result)) {
- failed++;
- if (verbose > 0) {
- Console.WriteLine("{0}: ConvertTo/ConvertFrom roundtrip failed, type {1}", conv.ToString(), type.ToString());
+ 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);
+ if (debug > 1) {
+ Console.WriteLine("{0}: CheckConversion, ConvertFrom result: '{1}')", conv.ToString(), result);
+ }
}
}
@@ -255,13 +282,31 @@ class MainWindow : System.Windows.Forms.Form {
CheckConversion(sel, "01.02.1969; 27.05.1977", conv, typeof(string), CultureInfo.CreateSpecificCulture("de-de"));
}
+ public void TestDataGridPreferredColumnWidthTypeConverter() {
+ DataGridPreferredColumnWidthTypeConverter conv;
+ int val;
+
+ conv = new DataGridPreferredColumnWidthTypeConverter();
+
+ CheckConvert(2, 1, conv, typeof(int));
+
+ CheckConversion(-1, "AutoColumnResize (-1)", conv, typeof(string));
+ CheckConversion(0, "0", conv, typeof(string));
+ CheckConversion(1, "1", conv, typeof(string));
+
+ CheckConversion("AutoColumnResize (-1)", -1, conv, typeof(int), true, false);
+ CheckConversion("0", 0, conv, typeof(int), true, false);
+ CheckConversion("1", 1, conv, typeof(int), true, false);
+ }
+
public MainWindow() {
ClientSize = new System.Drawing.Size (520, 520);
Text = "SWF Converters Test App";
TestKeysConverter();
TestOpacityConverter();
TestSelectionRangeConverter();
+ TestDataGridPreferredColumnWidthTypeConverter();
if (visual) {
if (failed != failed_expected) {

0 comments on commit 3986b13

Please sign in to comment.