1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2006 Novell, Inc.
25 using System.ComponentModel;
26 using System.Globalization;
27 using System.Windows.Forms;
28 using System.Windows.Forms.Layout;
30 using NUnit.Framework;
31 using System.Collections.Generic;
33 namespace MonoTests.System.Windows.Forms.Layout {
36 public class TableLayoutSettingsTypeConverterTest : TestHelper {
39 public void CanConvertFrom ()
41 TableLayoutSettingsTypeConverter c = new TableLayoutSettingsTypeConverter ();
43 Assert.IsTrue (c.CanConvertFrom (null, typeof (string)), "1");
44 Assert.IsFalse (c.CanConvertFrom (null, typeof (int)), "2");
45 Assert.IsFalse (c.CanConvertFrom (null, typeof (float)), "3");
46 Assert.IsFalse (c.CanConvertFrom (null, typeof (object)), "4");
50 public void CanConvertTo ()
52 TableLayoutSettingsTypeConverter c = new TableLayoutSettingsTypeConverter ();
54 Assert.IsTrue (c.CanConvertTo (null, typeof (string)), "1");
55 Assert.IsFalse (c.CanConvertTo (null, typeof (int)), "2");
56 Assert.IsFalse (c.CanConvertTo (null, typeof (float)), "3");
57 Assert.IsFalse (c.CanConvertTo (null, typeof (object)), "4");
61 public void Roundtrip ()
63 TableLayoutSettingsTypeConverter c = new TableLayoutSettingsTypeConverter ();
66 string sv = @"<?xml version=""1.0"" encoding=""utf-16""?><TableLayoutSettings>"
68 + @"<Control Name=""userNameLabel"" Row=""0"" RowSpan=""1"" Column=""0"" ColumnSpan=""1"" />"
69 + @"<Control Name=""savePassword"" Row=""2"" RowSpan=""1"" Column=""1"" ColumnSpan=""1"" />"
70 + @"<Control Name=""userName"" Row=""0"" RowSpan=""1"" Column=""1"" ColumnSpan=""1"" />"
71 + @"<Control Name=""password"" Row=""1"" RowSpan=""1"" Column=""1"" ColumnSpan=""1"" />"
72 + @"<Control Name=""passwordLabel"" Row=""1"" RowSpan=""1"" Column=""0"" ColumnSpan=""1"" />"
73 + @"</Controls><Columns Styles=""AutoSize,0,Percent,100"" />"
74 + @"<Rows Styles=""AutoSize,0,AutoSize,0,AutoSize,0"" />"
75 + @"</TableLayoutSettings>";
77 result = c.ConvertFrom (null, null, sv);
79 Assert.AreEqual (typeof (TableLayoutSettings), result.GetType(), "1");
81 TableLayoutSettings ts = (TableLayoutSettings)result;
83 Assert.AreEqual (2, ts.ColumnStyles.Count, "2");
84 Assert.AreEqual (SizeType.AutoSize, ts.ColumnStyles[0].SizeType, "3");
85 Assert.AreEqual (0.0f, ts.ColumnStyles[0].Width, "4");
86 Assert.AreEqual (SizeType.Percent, ts.ColumnStyles[1].SizeType, "5");
87 Assert.AreEqual (100.0f, ts.ColumnStyles[1].Width, "6");
89 Assert.AreEqual (3, ts.RowStyles.Count, "7");
91 Assert.AreEqual (SizeType.AutoSize, ts.RowStyles[0].SizeType, "8");
92 Assert.AreEqual (0.0f, ts.RowStyles[0].Height, "9");
93 Assert.AreEqual (SizeType.AutoSize, ts.RowStyles[1].SizeType, "10");
94 Assert.AreEqual (0.0f, ts.RowStyles[1].Height, "11");
95 Assert.AreEqual (SizeType.AutoSize, ts.RowStyles[2].SizeType, "12");
96 Assert.AreEqual (0.0f, ts.RowStyles[2].Height, "13");
98 string rv = (string)c.ConvertTo (null, null, ts, typeof (string));
100 // We do not guarantee the order of <Controls>, but the length should be the same
101 Assert.AreEqual (sv.Length, rv.Length, "roundtrip");
104 //--------------------------------------------------------------
105 private static TableLayoutSettings CreateSettingsEmpty()
107 return new TableLayoutPanel().LayoutSettings;
109 const String XmlSettingsEmpty
110 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"
111 + "<TableLayoutSettings>"
113 + "<Columns Styles=\"\" /><Rows Styles=\"\" />"
114 + "</TableLayoutSettings>";
116 private static TableLayoutSettings CreateSettingsB()
118 TableLayoutPanel tlp = new TableLayoutPanel();
119 tlp.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
120 tlp.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 40F));
121 tlp.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 10F));
122 tlp.RowStyles.Add(new RowStyle(SizeType.Percent, 40F));
123 tlp.RowStyles.Add(new RowStyle(SizeType.Percent, 35F));
124 return tlp.LayoutSettings;
126 const String XmlSettingsB
127 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"
128 + "<TableLayoutSettings>"
130 + "<Columns Styles=\"Percent,50,Percent,40,Absolute,10\" />"
131 + "<Rows Styles=\"Percent,40,Percent,35\" />"
132 + "</TableLayoutSettings>";
134 private static TableLayoutSettings CreateSettingsC()
136 TableLayoutPanel tlp = new TableLayoutPanel();
137 tlp.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
138 tlp.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 400));
139 tlp.RowStyles.Add(new RowStyle(SizeType.Percent, 40F));
140 tlp.RowStyles.Add(new RowStyle(SizeType.AutoSize, 35F));
141 tlp.RowStyles.Add(new RowStyle(SizeType.AutoSize));
142 return tlp.LayoutSettings;
144 const String XmlSettingsC
145 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"
146 + "<TableLayoutSettings>"
148 + "<Columns Styles=\"AutoSize,0,Absolute,400\" />"
149 + "<Rows Styles=\"Percent,40,AutoSize,35,AutoSize,0\" />"
150 + "</TableLayoutSettings>";
152 private static TableLayoutSettings CreateSettingsD()
154 TableLayoutPanel tlp = new TableLayoutPanel();
155 tlp.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100));
156 tlp.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
157 return tlp.LayoutSettings;
159 const String XmlSettingsD
160 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"
161 + "<TableLayoutSettings>"
163 + "<Columns Styles=\"Percent,100\" />"
164 + "<Rows Styles=\"Percent,100\" />"
165 + "</TableLayoutSettings>";
167 private static TableLayoutSettings CreateSettingsEDecimalOneItem()
169 TableLayoutPanel tlp = new TableLayoutPanel();
170 tlp.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 98.9F));
171 tlp.RowStyles.Add(new RowStyle(SizeType.Percent, 99.9F));
172 return tlp.LayoutSettings;
174 const String XmlSettingsEDecimalOneItem
175 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"
176 + "<TableLayoutSettings>"
178 + "<Columns Styles=\"Percent,98.9\" />"
179 + "<Rows Styles=\"Percent,99.9\" />"
180 + "</TableLayoutSettings>";
181 // See https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=156278&wa=wsignin1.0
182 // and e.g. http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.dotnet.internationalization&tid=f11516e2-33da-4047-8e2f-205df4ab09e5&cat=en_US_3fcb35c8-ccb3-4554-bd55-8038c0ecc923&lang=en&cr=US&sloc=&p=1
183 // Uses comma as separator, but uses current cultures number formatting thus 99,9%
184 const String XmlSettingsEDecimalOneItemCommaDecimalPoint
185 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"
186 + "<TableLayoutSettings>"
188 + "<Columns Styles=\"Percent,98,9\" />"
189 + "<Rows Styles=\"Percent,99,9\" />"
190 + "</TableLayoutSettings>";
191 const String XmlSettingsEDecimalOneItemCommaDecimalPoint_RowDataFirst
192 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"
193 + "<TableLayoutSettings>"
195 + "<Rows Styles=\"Percent,99,9\" />"
196 + "<Columns Styles=\"Percent,98,9\" />"
197 + "</TableLayoutSettings>";
199 private static TableLayoutSettings CreateSettingsF()
201 TableLayoutPanel tlp = new TableLayoutPanel();
202 tlp.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
203 tlp.RowStyles.Add(new RowStyle(SizeType.AutoSize));
204 return tlp.LayoutSettings;
206 const String XmlSettingsF
207 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"
208 + "<TableLayoutSettings>"
210 + "<Columns Styles=\"AutoSize,0\" />"
211 + "<Rows Styles=\"AutoSize,0\" />"
212 + "</TableLayoutSettings>";
213 const String XmlSettingsF_EmptyNumericElement
214 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"
215 + "<TableLayoutSettings>"
217 + "<Columns Styles=\"AutoSize,\" />"
218 + "<Rows Styles=\"AutoSize,\" />"
219 + "</TableLayoutSettings>";
220 const String XmlSettingsF_NoNumericElement
221 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"
222 + "<TableLayoutSettings>"
224 + "<Columns Styles=\"AutoSize\" />"
225 + "<Rows Styles=\"AutoSize\" />"
226 + "</TableLayoutSettings>";
228 private static TableLayoutSettings CreateSettingsGDecimalTwoItems()
230 TableLayoutPanel tlp = new TableLayoutPanel();
231 tlp.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 12.3456F));
232 tlp.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33.3333F));
233 tlp.RowStyles.Add(new RowStyle(SizeType.Percent, 98.7654F));
234 tlp.RowStyles.Add(new RowStyle(SizeType.Percent, 33.3333F));
235 return tlp.LayoutSettings;
237 const String XmlSettingsGDecimalTwoItems
238 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"
239 + "<TableLayoutSettings>"
241 + "<Columns Styles=\"Percent,12.3456,Percent,33.3333\" />"
242 + "<Rows Styles=\"Percent,98.7654,Percent,33.3333\" />"
243 + "</TableLayoutSettings>";
244 // See https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=156278&wa=wsignin1.0
245 // and e.g. http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.dotnet.internationalization&tid=f11516e2-33da-4047-8e2f-205df4ab09e5&cat=en_US_3fcb35c8-ccb3-4554-bd55-8038c0ecc923&lang=en&cr=US&sloc=&p=1
246 // Uses comma as separator, but uses current cultures number formatting thus 99,9%
247 // !!!! e.g. <Columns Styles="Percent,99,9" />
248 const String XmlSettingsGDecimalTwoItems_CommaDecimalPoint
249 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"
250 + "<TableLayoutSettings>"
252 + "<Columns Styles=\"Percent,12,3456,Percent,33,3333\" />"
253 + "<Rows Styles=\"Percent,98,7654,Percent,33,3333\" />"
254 + "</TableLayoutSettings>";
255 const String XmlSettingsGDecimalTwoItems_CommaDecimalPoint_RowDataFirst
256 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"
257 + "<TableLayoutSettings>"
259 + "<Rows Styles=\"Percent,98,7654,Percent,33,3333\" />"
260 + "<Columns Styles=\"Percent,12,3456,Percent,33,3333\" />"
261 + "</TableLayoutSettings>";
263 //--------------------------------------------------------------
265 public void ConvertTo()
267 TableLayoutSettingsTypeConverter c = new TableLayoutSettingsTypeConverter();
269 TableLayoutSettings tls;
272 tls = CreateSettingsEmpty();
273 result = c.ConvertToInvariantString(tls);
274 Assert.AreEqual(XmlSettingsEmpty, result, "#1-empty");
276 tls = CreateSettingsB();
277 result = c.ConvertToInvariantString(tls);
278 Assert.AreEqual(XmlSettingsB, result, "#B");
280 tls = CreateSettingsC();
281 result = c.ConvertToInvariantString(tls);
282 Assert.AreEqual(XmlSettingsC, result, "#C");
284 tls = CreateSettingsD();
285 result = c.ConvertToInvariantString(tls);
286 Assert.AreEqual(XmlSettingsD, result, "#D");
288 tls = CreateSettingsEDecimalOneItem();
289 result = c.ConvertToInvariantString(tls);
290 Assert.AreEqual(XmlSettingsEDecimalOneItem, result, "#DDecimal");
292 tls = CreateSettingsF();
293 result = c.ConvertToInvariantString(tls);
294 Assert.AreEqual(XmlSettingsF, result, "#E");
298 public void ConvertTo_CurrentCultureHasDot_IsInvariantCulture()
300 CultureInfo culture = CultureInfo.InvariantCulture;
301 ConvertTo_WithCurrentCulture(culture, XmlSettingsEDecimalOneItem);
305 public void ConvertTo_CurrentCultureHasDot()
307 CultureInfo culture = CultureInfo.GetCultureInfo("en-US");
308 ConvertTo_WithCurrentCulture(culture, XmlSettingsEDecimalOneItem);
312 public void ConvertTo_CurrentCultureHasComma()
314 if (!IsMonoRuntime) {
315 Assert.Ignore("Remember MSFT still uses the current culture decimal mark!");
318 // Changed to always use dot-decimal-point float format
320 // This test is a test of current behaviour, and NOT *desired* behaviour.
321 // It would likely be preferable for the float values (and everything)
322 // to be written using InvariantCulture, e.g. style.Width.ToString (CultureInfo.InvariantCulture)
324 // The bug in MSFT's output mentioned above causes 99.9% to be written
325 // culture sensitively as "99,9".
326 // The bug depends on the *current* culture and NOT the culture passed-in
329 // de-DE or fr-FR would work here too!
330 CultureInfo culture = CultureInfo.GetCultureInfo("ca-ES");
331 ConvertTo_WithCurrentCulture(culture, XmlSettingsEDecimalOneItem);
332 // was: XmlSettingsEDecimalOneItemCommaDecimalPoint
334 // Just check that this culture normal produces "99,9"
335 Assert.AreEqual("99,9", String.Format(culture, "{0}", 99.9d), "ToString d");
336 Assert.AreEqual("99,9", String.Format(culture, "{0}", 99.9f), "ToString f");
337 Assert.AreEqual("99,9", String.Format(culture, "{0}", 99.9m), "ToString m");
340 private static void ConvertTo_WithCurrentCulture(CultureInfo culture, String expectedXml)
342 TableLayoutSettingsTypeConverter c = new TableLayoutSettingsTypeConverter();
346 TableLayoutSettings tls = CreateSettingsEDecimalOneItem();
347 CultureInfo previous = global::System.Threading.Thread.CurrentThread.CurrentCulture;
348 global::System.Threading.Thread.CurrentThread.CurrentCulture = culture;
350 result = c.ConvertToString(null, culture, tls);
351 Assert.AreEqual(expectedXml, result, "Culture passed");
353 result = c.ConvertToString(null, null, tls);
354 Assert.AreEqual(expectedXml, result, "No culture passed");
356 result = c.ConvertToInvariantString(tls);
357 Assert.AreEqual(expectedXml, result, "Invariant");
359 global::System.Threading.Thread.CurrentThread.CurrentCulture = previous;
363 //--------------------------------------------------------------
364 void Assert_IsInstanceOfType(Type expected, Object value, String message)
366 if (expected == null)
367 throw new ArgumentNullException("expected");
368 //Assert.AreEqual(expected, value == null ? null : value.GetType(), message);
369 if (!expected.IsInstanceOfType(value))
370 throw new Exception("Booooo: " + message + Environment.NewLine
371 + "expected: '" + expected + "'" + Environment.NewLine
372 + "actual: '" + (value == null ? "(null)" : value.GetType().ToString()) + "'");
376 public void ConvertFrom_NOT()
378 TableLayoutSettingsTypeConverter c = new TableLayoutSettingsTypeConverter();
382 Assert.Fail("should have thrown -- " + "#1");
383 } catch (Exception ex) {
384 Assert_IsInstanceOfType(typeof(NotSupportedException), ex, "ExType -- " + "#1");
388 Assert.Fail("should have thrown -- " + "#2");
389 } catch (Exception ex) {
390 Assert_IsInstanceOfType(typeof(NotSupportedException), ex, "ExType -- " + "#2");
393 c.ConvertFrom(String.Empty);
394 Assert.Fail("should have thrown -- " + "#3");
395 } catch (Exception ex) {
396 Assert_IsInstanceOfType(typeof(global::System.Xml.XmlException), ex, "ExType -- " + "#3");
401 public void ConvertFrom_notCheckResults()
403 TableLayoutSettingsTypeConverter c = new TableLayoutSettingsTypeConverter();
405 c.ConvertFromInvariantString(XmlSettingsB);
406 c.ConvertFromInvariantString(XmlSettingsC);
407 c.ConvertFromInvariantString(XmlSettingsD);
408 c.ConvertFromInvariantString(XmlSettingsEDecimalOneItem);
409 c.ConvertFromInvariantString(XmlSettingsF);
413 public void ConvertFrom_notCheckResults_Empty()
415 TableLayoutSettingsTypeConverter c = new TableLayoutSettingsTypeConverter();
417 c.ConvertFromInvariantString(XmlSettingsEmpty);
418 // Mono fails (reports problem with value in Enum.Parse).
419 // This is valid content (as output both platforms) so it should work.
423 public void ConvertFrom_notCheckResults_Bad_EmptyNumericElement()
425 TableLayoutSettingsTypeConverter c = new TableLayoutSettingsTypeConverter();
428 // It's manually broken content, so it's ok to fail...
429 c.ConvertFromInvariantString(XmlSettingsF_EmptyNumericElement);
430 } catch (IndexOutOfRangeException) {
431 // MSFT fails here. Mono doesn't
436 public void ConvertFrom_notCheckResults_Bad_NoNumericElement()
438 TableLayoutSettingsTypeConverter c = new TableLayoutSettingsTypeConverter();
441 // It's manually broken content, so it's ok to fail...
442 c.ConvertFromInvariantString(XmlSettingsF_NoNumericElement);
443 } catch (IndexOutOfRangeException) {
449 public void ConvertFrom_notCheckResults_CommaDecimalPoint()
451 // The bug in MSFT's output mentioned above causes 99.9% to be written
452 // culture sensitively as "99,9".
453 // Test whether ConvertFrom crashes on reading such bad content.
455 TableLayoutSettingsTypeConverter c = new TableLayoutSettingsTypeConverter();
457 c.ConvertFromInvariantString(XmlSettingsEDecimalOneItemCommaDecimalPoint);
461 public void ConvertFrom_notCheckResults_CommaDecimalPoint_RowDataFirst()
463 // The bug in MSFT's output mentioned above causes 99.9% to be written
464 // culture sensitively as "99,9".
465 // Test whether ConvertFrom crashes on reading such bad content.
467 TableLayoutSettingsTypeConverter c = new TableLayoutSettingsTypeConverter();
469 c.ConvertFromInvariantString(XmlSettingsEDecimalOneItemCommaDecimalPoint_RowDataFirst);
476 public TableLayoutSettings Settings;
477 public String XmlContent;
478 public Directions Directions;
480 public TestRow(TableLayoutSettings settings, String xmlContent, String name, Directions directions)
483 this.Settings = settings;
484 this.XmlContent = xmlContent;
485 this.Directions = directions;
497 IList<TestRow> tests;
499 public TableLayoutSettingsTypeConverterTest()
501 BuildLoopTestCaseList();
504 private void BuildLoopTestCaseList()
506 tests = new List<TestRow>();
508 // **very** basic test of equality checking methods...
509 //-tests.Add(new TestRow(CreateSettingsC(), XmlSettingsB, "XmlSettingsB vs C!!!!", Directions.From));
512 tests.Add(new TestRow(CreateSettingsB(), XmlSettingsB, "XmlSettingsB", Directions.Both));
514 tests.Add(new TestRow(CreateSettingsC(), XmlSettingsC, "XmlSettingsC", Directions.Both));
516 tests.Add(new TestRow(CreateSettingsD(), XmlSettingsD, "XmlSettingsD", Directions.Both));
518 tests.Add(new TestRow(CreateSettingsEDecimalOneItem(), XmlSettingsEDecimalOneItem,
519 "XmlSettingsEDecimalOneItem",
521 tests.Add(new TestRow(CreateSettingsEDecimalOneItem(), XmlSettingsEDecimalOneItemCommaDecimalPoint,
522 "XmlSettingsEDecimalOneItem_CommaDecimalPoint",
523 Directions.From)); // 'To' case is the one above.
524 tests.Add(new TestRow(CreateSettingsEDecimalOneItem(), XmlSettingsEDecimalOneItemCommaDecimalPoint_RowDataFirst,
525 "XmlSettingsEDecimalOneItem_CommaDecimalPoint_RowDataFirst",
526 Directions.From)); // 'To' case is the one above.
528 tests.Add(new TestRow(CreateSettingsF(), XmlSettingsF, "XmlSettingsF", Directions.Both));
529 tests.Add(new TestRow(CreateSettingsF(), XmlSettingsF_EmptyNumericElement,
530 "XmlSettingsF_EmptyNumericElement",
531 Directions.None)); // Fails on both platforms, see individual test methods.
532 tests.Add(new TestRow(CreateSettingsF(), XmlSettingsF_NoNumericElement,
533 "XmlSettingsF_NoNumericElement",
534 Directions.None)); // Fails on both platforms, see individual test methods.
536 tests.Add(new TestRow(CreateSettingsGDecimalTwoItems(), XmlSettingsGDecimalTwoItems,
537 "XmlSettingsGDecimalTwoItems",
539 tests.Add(new TestRow(CreateSettingsGDecimalTwoItems(), XmlSettingsGDecimalTwoItems_CommaDecimalPoint,
540 "XmlSettingsGDecimalTwoItems_CommaDecimalPoint",
541 Directions.From)); // 'To' case is the one above.
542 tests.Add(new TestRow(CreateSettingsGDecimalTwoItems(), XmlSettingsGDecimalTwoItems_CommaDecimalPoint_RowDataFirst,
543 "XmlSettingsGDecimalTwoItems_CommaDecimalPoint_RowDataFirst",
544 Directions.From)); // 'To' case is the one above.
546 tests.Add(new TestRow(CreateSettingsEmpty(), XmlSettingsEmpty,
547 "XmlSettingsEmpty", Directions.Both));
552 public void ConvertTo_Loop_InvariantCulture()
554 ConvertTo_Loop(CultureInfo.InvariantCulture);
558 public void ConvertTo_Loop_CultureWithComma()
560 ConvertTo_Loop(CultureInfo.GetCultureInfo("de-DE"));
564 public void ConvertTo_Loop_CurrentCultureWithComma_CultureWithComma()
566 if (!IsMonoRuntime) {
567 Assert.Ignore("Remember MSFT still uses the current culture decimal mark!");
570 CultureInfo previous = global::System.Threading.Thread.CurrentThread.CurrentCulture;
571 global::System.Threading.Thread.CurrentThread.CurrentCulture
572 = CultureInfo.GetCultureInfo("de-DE");
574 ConvertTo_Loop(CultureInfo.GetCultureInfo("de-DE"));
576 global::System.Threading.Thread.CurrentThread.CurrentCulture = previous;
580 private bool IsMonoRuntime
582 get { return Type.GetType("Mono.Runtime") != null; }
586 // Ohh for a more recent version on NUnit, (/and addin) to do row test cases!
587 private void ConvertTo_Loop(CultureInfo culturePassedToConvertTo)
589 TableLayoutSettingsTypeConverter c = new TableLayoutSettingsTypeConverter();
592 foreach (TestRow row in tests) {
593 if ((row.Directions & Directions.To) == 0) {
594 //Console.WriteLine("ConvertTo_Loop skipping: " + row.Name);
598 String title = String.Format("#{0}, {1}", i, row.Name);
600 String result = (String)c.ConvertTo(null, culturePassedToConvertTo, row.Settings, typeof(String));
601 Assert.AreEqual(row.XmlContent, result, row.Name);
605 Console.WriteLine("ConvertTo_Loop row that failed ** : " + title);
613 public void ConvertFrom_Loop_InvariantCulture()
615 ConvertFrom_Loop(CultureInfo.InvariantCulture);
619 public void ConvertFrom_Loop_CultureWithComma()
621 ConvertFrom_Loop(CultureInfo.GetCultureInfo("de-DE"));
624 public void ConvertFrom_Loop_CurrentCultureWithComma_CultureWithComma()
626 CultureInfo previous = global::System.Threading.Thread.CurrentThread.CurrentCulture;
627 global::System.Threading.Thread.CurrentThread.CurrentCulture
628 = CultureInfo.GetCultureInfo("de-DE");
630 ConvertFrom_Loop(CultureInfo.GetCultureInfo("de-DE"));
632 global::System.Threading.Thread.CurrentThread.CurrentCulture = previous;
636 public void ConvertFrom_Loop_CurrentCultureWithComma_InvariantCulture()
638 CultureInfo previous = global::System.Threading.Thread.CurrentThread.CurrentCulture;
639 global::System.Threading.Thread.CurrentThread.CurrentCulture
640 = CultureInfo.GetCultureInfo("de-DE");
642 ConvertFrom_Loop(CultureInfo.InvariantCulture);
644 global::System.Threading.Thread.CurrentThread.CurrentCulture = previous;
648 // Ohh for a more recent version on NUnit, (/and addin) to do row test cases!
649 private void ConvertFrom_Loop(CultureInfo culturePassedToConvertFrom)
651 TableLayoutSettingsTypeConverter c = new TableLayoutSettingsTypeConverter();
654 foreach (TestRow row in tests) {
655 if ((row.Directions & Directions.From) == 0) {
656 //Console.WriteLine("ConvertFrom_Loop skipping: " + row.Name);
660 String title = String.Format("#{0}, {1}", i, row.Name);
662 TableLayoutSettings result = (TableLayoutSettings)
663 c.ConvertFrom(null, culturePassedToConvertFrom, row.XmlContent);
664 Assert_AreEqual(row.Settings, result, row.Name);
668 Console.WriteLine("ConvertFrom_Loop row that failed ** : " + title);
675 static void Assert_AreEqual(TableLayoutSettings expected, TableLayoutSettings actual, String message)
677 Assert_AreEqual(expected.ColumnStyles, actual.ColumnStyles, "ColumnStyles -- " + message);
678 Assert_AreEqual(expected.RowStyles, actual.RowStyles, "RowStyles -- " + message);
681 static void Assert_AreEqual(TableLayoutColumnStyleCollection expected, TableLayoutColumnStyleCollection actual, String message)
683 for (int i = 0; i < Math.Min(expected.Count, actual.Count); ++i) {
684 ColumnStyle expectedCur = expected[i];
685 ColumnStyle actualCur = actual[i];
686 Assert_AreEqual(expectedCur, actualCur, "TableLayoutColumnStyleCollection[" + i + "] -- " + message);
688 // Check this *after*, so that if the initial values in the lists don't match
689 // that's reported instead -- it makes it more obvious what is being mis-parsed.
690 Assert.AreEqual(expected.Count, actual.Count, "TableLayoutColumnStyleCollection.Count -- " + message);
692 static void Assert_AreEqual(TableLayoutRowStyleCollection expected, TableLayoutRowStyleCollection actual, String message)
694 for (int i = 0; i < Math.Min(expected.Count, actual.Count); ++i) {
695 RowStyle expectedCur = expected[i];
696 RowStyle actualCur = actual[i];
697 Assert_AreEqual(expectedCur, actualCur, "TableLayoutRowStyleCollection[" + i + "] -- " + message);
699 // Check this *after*, so that if the initial values in the lists don't match
700 // that's reported instead -- it makes it more obvious what is being mis-parsed.
701 Assert.AreEqual(expected.Count, actual.Count, "TableLayoutRowStyleCollection.Count -- " + message);
704 static void Assert_AreEqual(ColumnStyle expected, ColumnStyle actual, String message)
706 Assert.AreEqual(expected.SizeType, actual.SizeType, "ColumnStyle.SizeType -- " + message);
707 Assert.AreEqual(expected.Width, actual.Width, "ColumnStyle.Width -- " + message);
709 static void Assert_AreEqual(RowStyle expected, RowStyle actual, String message)
711 Assert.AreEqual(expected.SizeType, actual.SizeType, "RowStyle.SizeType -- " + message);
712 Assert.AreEqual(expected.Height, actual.Height, "RowStyle.Height -- " + message);