Int16ConverterTests.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. //
  2. // System.ComponentModel.Int16Converter test cases
  3. //
  4. // Authors:
  5. // Gert Driesen ([email protected])
  6. //
  7. // (c) 2005 Novell, Inc. (http://www.ximian.com)
  8. //
  9. using System;
  10. using System.ComponentModel;
  11. using System.ComponentModel.Design.Serialization;
  12. using System.Globalization;
  13. using NUnit.Framework;
  14. namespace MonoTests.System.ComponentModel
  15. {
  16. [TestFixture]
  17. public class Int16ConverterTests
  18. {
  19. private Int16Converter converter;
  20. [SetUp]
  21. public void SetUp ()
  22. {
  23. converter = new Int16Converter ();
  24. }
  25. [Test]
  26. public void CanConvertFrom ()
  27. {
  28. Assert.IsTrue (converter.CanConvertFrom (typeof (string)), "#1");
  29. Assert.IsFalse (converter.CanConvertFrom (typeof (short)), "#2");
  30. Assert.IsFalse (converter.CanConvertFrom (typeof (object)), "#3");
  31. Assert.IsTrue (converter.CanConvertFrom (typeof (InstanceDescriptor)), "#4");
  32. }
  33. [Test]
  34. public void CanConvertTo ()
  35. {
  36. Assert.IsTrue (converter.CanConvertTo (typeof (string)), "#1");
  37. Assert.IsFalse (converter.CanConvertTo (typeof (object)), "#2");
  38. }
  39. [Test]
  40. public void ConvertFrom_MinValue ()
  41. {
  42. Assert.AreEqual (short.MinValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "#8000"), "#1");
  43. Assert.AreEqual (short.MinValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "#0x8000"), "#2");
  44. Assert.AreEqual (short.MinValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "#0X8000"), "#3");
  45. Assert.AreEqual (short.MinValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "0x8000"), "#4");
  46. Assert.AreEqual (short.MinValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "0X8000"), "#5");
  47. }
  48. [Test]
  49. public void ConvertFrom_MaxValue ()
  50. {
  51. Assert.AreEqual (short.MaxValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "#7fff"), "#1");
  52. Assert.AreEqual (short.MaxValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "#7FFF"), "#2");
  53. Assert.AreEqual (short.MaxValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "#0x7fff"), "#3");
  54. Assert.AreEqual (short.MaxValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "#0X7FFF"), "#4");
  55. Assert.AreEqual (short.MaxValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "0x7fff"), "#5");
  56. Assert.AreEqual (short.MaxValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "0X7FFF"), "#6");
  57. }
  58. [Test]
  59. public void ConvertToString ()
  60. {
  61. CultureInfo culture = new MyCultureInfo ();
  62. NumberFormatInfo numberFormatInfo = (NumberFormatInfo) culture.GetFormat (typeof (NumberFormatInfo));
  63. Assert.AreEqual (numberFormatInfo.NegativeSign + "5", converter.ConvertToString (null, culture, (short) -5), "#1");
  64. Assert.AreEqual (culture.NumberFormat.NegativeSign + "5", converter.ConvertToString (null, culture, (int) -5), "#2");
  65. }
  66. [Test]
  67. public void ConvertFromString ()
  68. {
  69. CultureInfo culture = new MyCultureInfo ();
  70. NumberFormatInfo numberFormatInfo = (NumberFormatInfo) culture.GetFormat (typeof (NumberFormatInfo));
  71. Assert.AreEqual (-5, converter.ConvertFrom (null, culture, numberFormatInfo.NegativeSign + "5"));
  72. }
  73. [Test]
  74. [ExpectedException (typeof (NotSupportedException))]
  75. public void ConvertFrom_Object ()
  76. {
  77. converter.ConvertFrom (new object ());
  78. }
  79. [Test]
  80. [ExpectedException (typeof (NotSupportedException))]
  81. public void ConvertFrom_Int16 ()
  82. {
  83. converter.ConvertFrom ((short) 10);
  84. }
  85. [Test]
  86. [ExpectedException (typeof (NotSupportedException))]
  87. public void ConvertFrom_Int32 ()
  88. {
  89. converter.ConvertFrom (10);
  90. }
  91. [Test]
  92. public void ConvertTo_MinValue ()
  93. {
  94. Assert.AreEqual (short.MinValue.ToString (CultureInfo.InvariantCulture),
  95. converter.ConvertTo (null, CultureInfo.InvariantCulture, short.MinValue,
  96. typeof (string)), "#1");
  97. Assert.AreEqual (short.MinValue.ToString (CultureInfo.CurrentCulture),
  98. converter.ConvertTo (null, CultureInfo.CurrentCulture, short.MinValue,
  99. typeof (string)), "#2");
  100. Assert.AreEqual (short.MinValue.ToString (CultureInfo.CurrentCulture),
  101. converter.ConvertTo (short.MinValue, typeof (string)), "#3");
  102. }
  103. [Test]
  104. public void ConvertTo_MaxValue ()
  105. {
  106. Assert.AreEqual (short.MaxValue.ToString (CultureInfo.InvariantCulture),
  107. converter.ConvertTo (null, CultureInfo.InvariantCulture, short.MaxValue,
  108. typeof (string)), "#1");
  109. Assert.AreEqual (short.MaxValue.ToString (CultureInfo.CurrentCulture),
  110. converter.ConvertTo (null, CultureInfo.CurrentCulture, short.MaxValue,
  111. typeof (string)), "#2");
  112. Assert.AreEqual (short.MaxValue.ToString (CultureInfo.CurrentCulture),
  113. converter.ConvertTo (short.MaxValue, typeof (string)), "#3");
  114. }
  115. [Test]
  116. public void ConvertToString_MinValue ()
  117. {
  118. Assert.AreEqual (short.MinValue.ToString (CultureInfo.InvariantCulture),
  119. converter.ConvertToString (null, CultureInfo.InvariantCulture,
  120. short.MinValue), "#1");
  121. Assert.AreEqual (short.MinValue.ToString (CultureInfo.CurrentCulture),
  122. converter.ConvertToString (null, short.MinValue), "#2");
  123. Assert.AreEqual (short.MinValue.ToString (CultureInfo.CurrentCulture),
  124. converter.ConvertToString (null, CultureInfo.CurrentCulture,
  125. short.MinValue), "#3");
  126. Assert.AreEqual (short.MinValue.ToString (CultureInfo.CurrentCulture),
  127. converter.ConvertToString (short.MinValue), "#4");
  128. }
  129. [Test]
  130. public void ConvertToString_MaxValue ()
  131. {
  132. Assert.AreEqual (short.MaxValue.ToString (CultureInfo.InvariantCulture),
  133. converter.ConvertToString (null, CultureInfo.InvariantCulture,
  134. short.MaxValue), "#1");
  135. Assert.AreEqual (short.MaxValue.ToString (CultureInfo.CurrentCulture),
  136. converter.ConvertToString (null, short.MaxValue), "#2");
  137. Assert.AreEqual (short.MaxValue.ToString (CultureInfo.CurrentCulture),
  138. converter.ConvertToString (null, CultureInfo.CurrentCulture,
  139. short.MaxValue), "#3");
  140. Assert.AreEqual (short.MaxValue.ToString (CultureInfo.CurrentCulture),
  141. converter.ConvertToString (short.MaxValue), "#4");
  142. }
  143. [Test]
  144. public void ConvertFrom_InvalidValue ()
  145. {
  146. try {
  147. converter.ConvertFrom ("*1");
  148. Assert.Fail ("#1");
  149. } catch (AssertionException) {
  150. throw;
  151. } catch (Exception ex) {
  152. Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
  153. Assert.IsNotNull (ex.InnerException, "#3");
  154. Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
  155. }
  156. }
  157. [Test]
  158. public void ConvertFrom_InvalidValue_Invariant ()
  159. {
  160. try {
  161. converter.ConvertFrom (null, CultureInfo.InvariantCulture, "*1");
  162. Assert.Fail ("#1");
  163. } catch (AssertionException) {
  164. throw;
  165. } catch (Exception ex) {
  166. Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
  167. Assert.IsNotNull (ex.InnerException, "#3");
  168. Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
  169. }
  170. }
  171. [Test]
  172. public void ConvertFrom_Base10_MinOverflow ()
  173. {
  174. string minOverflow = ((int) (short.MinValue - 1)).ToString (
  175. CultureInfo.CurrentCulture);
  176. try {
  177. converter.ConvertFrom (minOverflow);
  178. Assert.Fail ("#1");
  179. } catch (AssertionException) {
  180. throw;
  181. } catch (Exception ex) {
  182. Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
  183. Assert.IsNotNull (ex.InnerException, "#3");
  184. Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#3");
  185. }
  186. }
  187. [Test]
  188. public void ConvertFrom_Base10_MinOverflow_Invariant ()
  189. {
  190. string minOverflow = ((int) (short.MinValue - 1)).ToString (
  191. CultureInfo.InvariantCulture);
  192. try {
  193. converter.ConvertFrom (null, CultureInfo.InvariantCulture,
  194. minOverflow);
  195. Assert.Fail ("#1");
  196. } catch (AssertionException) {
  197. throw;
  198. } catch (Exception ex) {
  199. Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
  200. Assert.IsNotNull (ex.InnerException, "#3");
  201. Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#3");
  202. }
  203. }
  204. [Test]
  205. public void ConvertFrom_Base10_MaxOverflow ()
  206. {
  207. string maxOverflow = ((int) (short.MaxValue + 1)).ToString (
  208. CultureInfo.CurrentCulture);
  209. try {
  210. converter.ConvertFrom (maxOverflow);
  211. Assert.Fail ("#1");
  212. } catch (AssertionException) {
  213. throw;
  214. } catch (Exception ex) {
  215. Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
  216. Assert.IsNotNull (ex.InnerException, "#3");
  217. Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#3");
  218. }
  219. }
  220. [Test]
  221. public void ConvertFrom_Base10_MaxOverflow_Invariant ()
  222. {
  223. string maxOverflow = ((int) (short.MaxValue + 1)).ToString (
  224. CultureInfo.InvariantCulture);
  225. try {
  226. converter.ConvertFrom (null, CultureInfo.InvariantCulture,
  227. maxOverflow);
  228. Assert.Fail ("#1");
  229. } catch (AssertionException) {
  230. throw;
  231. } catch (Exception ex) {
  232. Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
  233. Assert.IsNotNull (ex.InnerException, "#3");
  234. Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#3");
  235. }
  236. }
  237. [Test]
  238. public void ConvertFrom_Base16_MinOverflow ()
  239. {
  240. string minOverflow = ((int) (short.MinValue - 1)).ToString ("x",
  241. CultureInfo.CurrentCulture);
  242. try {
  243. converter.ConvertFrom ("#" + minOverflow);
  244. Assert.Fail ("#1");
  245. } catch (AssertionException) {
  246. throw;
  247. } catch (Exception ex) {
  248. Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
  249. Assert.IsNotNull (ex.InnerException, "#3");
  250. Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#3");
  251. }
  252. }
  253. [Test]
  254. public void ConvertFrom_Base16_MinOverflow_Invariant ()
  255. {
  256. string minOverflow = ((int) (short.MinValue - 1)).ToString ("x",
  257. CultureInfo.InvariantCulture);
  258. try {
  259. converter.ConvertFrom (null, CultureInfo.InvariantCulture,
  260. "#" + minOverflow);
  261. Assert.Fail ("#1");
  262. } catch (AssertionException) {
  263. throw;
  264. } catch (Exception ex) {
  265. Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
  266. Assert.IsNotNull (ex.InnerException, "#3");
  267. Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#4");
  268. }
  269. }
  270. [Test]
  271. public void ConvertFrom_Base16_MaxOverflow ()
  272. {
  273. string maxOverflow = ((int) (short.MaxValue + 1)).ToString ("x",
  274. CultureInfo.CurrentCulture);
  275. Assert.AreEqual (-32768, converter.ConvertFrom (null, CultureInfo.CurrentCulture,
  276. "#" + maxOverflow), "#1");
  277. maxOverflow = ((int) (ushort.MaxValue)).ToString ("x",
  278. CultureInfo.CurrentCulture);
  279. Assert.AreEqual (-1, converter.ConvertFrom (null, CultureInfo.CurrentCulture,
  280. "#" + maxOverflow), "#2");
  281. maxOverflow = (ushort.MaxValue + 1).ToString ("x",
  282. CultureInfo.CurrentCulture);
  283. try {
  284. converter.ConvertFrom (null, CultureInfo.CurrentCulture,
  285. "#" + maxOverflow);
  286. Assert.Fail ("#3");
  287. } catch (AssertionException) {
  288. throw;
  289. } catch (Exception ex) {
  290. Assert.AreEqual (typeof (Exception), ex.GetType (), "#4");
  291. Assert.IsNotNull (ex.InnerException, "#5");
  292. Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#6");
  293. }
  294. }
  295. [Test]
  296. public void ConvertFrom_Base16_MaxOverflow_Invariant ()
  297. {
  298. string maxOverflow = ((int) (short.MaxValue + 1)).ToString ("x",
  299. CultureInfo.InvariantCulture);
  300. Assert.AreEqual (-32768, converter.ConvertFrom (null, CultureInfo.InvariantCulture,
  301. "#" + maxOverflow), "#1");
  302. maxOverflow = ((int) (ushort.MaxValue)).ToString ("x",
  303. CultureInfo.InvariantCulture);
  304. Assert.AreEqual (-1, converter.ConvertFrom (null, CultureInfo.InvariantCulture,
  305. "#" + maxOverflow), "#2");
  306. maxOverflow = (ushort.MaxValue + 1).ToString ("x",
  307. CultureInfo.InvariantCulture);
  308. try {
  309. converter.ConvertFrom (null, CultureInfo.InvariantCulture,
  310. "#" + maxOverflow);
  311. Assert.Fail ("#3");
  312. } catch (AssertionException) {
  313. throw;
  314. } catch (Exception ex) {
  315. Assert.AreEqual (typeof (Exception), ex.GetType (), "#4");
  316. Assert.IsNotNull (ex.InnerException, "#5");
  317. Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#6");
  318. }
  319. }
  320. [Test]
  321. public void ConvertFromString_InvalidValue ()
  322. {
  323. try {
  324. converter.ConvertFromString ("*1");
  325. Assert.Fail ("#1");
  326. } catch (AssertionException) {
  327. throw;
  328. } catch (Exception ex) {
  329. Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
  330. Assert.IsNotNull (ex.InnerException, "#3");
  331. Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
  332. }
  333. }
  334. [Test]
  335. public void ConvertFromString_InvalidValue_Invariant ()
  336. {
  337. try {
  338. converter.ConvertFromString (null, CultureInfo.InvariantCulture, "*1");
  339. Assert.Fail ("#1");
  340. } catch (AssertionException) {
  341. throw;
  342. } catch (Exception ex) {
  343. Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
  344. Assert.IsNotNull (ex.InnerException, "#3");
  345. Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
  346. }
  347. }
  348. [Test]
  349. public void ConvertFromString_Base10_MinOverflow ()
  350. {
  351. string minOverflow = ((int) (short.MinValue - 1)).ToString (
  352. CultureInfo.CurrentCulture);
  353. try {
  354. converter.ConvertFromString (minOverflow);
  355. Assert.Fail ("#1");
  356. } catch (AssertionException) {
  357. throw;
  358. } catch (Exception ex) {
  359. Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
  360. Assert.IsNotNull (ex.InnerException, "#3");
  361. Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#3");
  362. }
  363. }
  364. [Test]
  365. public void ConvertFromString_Base10_MinOverflow_Invariant ()
  366. {
  367. string minOverflow = ((int) (short.MinValue - 1)).ToString (
  368. CultureInfo.InvariantCulture);
  369. try {
  370. converter.ConvertFromString (null, CultureInfo.InvariantCulture,
  371. minOverflow);
  372. Assert.Fail ("#1");
  373. } catch (AssertionException) {
  374. throw;
  375. } catch (Exception ex) {
  376. Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
  377. Assert.IsNotNull (ex.InnerException, "#3");
  378. Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#3");
  379. }
  380. }
  381. [Test]
  382. public void ConvertFromString_Base10_MaxOverflow ()
  383. {
  384. string maxOverflow = ((int) (short.MaxValue + 1)).ToString (
  385. CultureInfo.CurrentCulture);
  386. try {
  387. converter.ConvertFromString (maxOverflow);
  388. Assert.Fail ("#1");
  389. } catch (AssertionException) {
  390. throw;
  391. } catch (Exception ex) {
  392. Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
  393. Assert.IsNotNull (ex.InnerException, "#3");
  394. Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#3");
  395. }
  396. }
  397. [Test]
  398. public void ConvertFromString_Base10_MaxOverflow_Invariant ()
  399. {
  400. string maxOverflow = ((int) (short.MaxValue + 1)).ToString (
  401. CultureInfo.InvariantCulture);
  402. try {
  403. converter.ConvertFromString (null, CultureInfo.InvariantCulture,
  404. maxOverflow);
  405. Assert.Fail ("#1");
  406. } catch (AssertionException) {
  407. throw;
  408. } catch (Exception ex) {
  409. Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
  410. Assert.IsNotNull (ex.InnerException, "#3");
  411. Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#3");
  412. }
  413. }
  414. [Test]
  415. public void ConvertFromString_Base16_MinOverflow ()
  416. {
  417. string minOverflow = ((int) (short.MinValue - 1)).ToString ("x",
  418. CultureInfo.CurrentCulture);
  419. try {
  420. converter.ConvertFromString ("#" + minOverflow);
  421. Assert.Fail ("#1");
  422. } catch (AssertionException) {
  423. throw;
  424. } catch (Exception ex) {
  425. Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
  426. Assert.IsNotNull (ex.InnerException, "#3");
  427. Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#3");
  428. }
  429. }
  430. [Test]
  431. public void ConvertFromString_Base16_MinOverflow_Invariant ()
  432. {
  433. string minOverflow = ((int) (short.MinValue - 1)).ToString ("x",
  434. CultureInfo.InvariantCulture);
  435. try {
  436. converter.ConvertFromString (null, CultureInfo.InvariantCulture,
  437. "#" + minOverflow);
  438. Assert.Fail ("#1");
  439. } catch (AssertionException) {
  440. throw;
  441. } catch (Exception ex) {
  442. Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
  443. Assert.IsNotNull (ex.InnerException, "#3");
  444. Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#3");
  445. }
  446. }
  447. [Test]
  448. public void ConvertFromString_Base16_MaxOverflow ()
  449. {
  450. string maxOverflow = ((int) (short.MaxValue + 1)).ToString ("x",
  451. CultureInfo.CurrentCulture);
  452. Assert.AreEqual (-32768, converter.ConvertFromString ("#" + maxOverflow), "#1");
  453. maxOverflow = (ushort.MaxValue).ToString ("x",
  454. CultureInfo.CurrentCulture);
  455. Assert.AreEqual (-1, converter.ConvertFromString ("#" + maxOverflow), "#2");
  456. maxOverflow = (ushort.MaxValue + 1).ToString ("x",
  457. CultureInfo.CurrentCulture);
  458. try {
  459. converter.ConvertFromString ("#" + maxOverflow);
  460. Assert.Fail ("#3");
  461. } catch (AssertionException) {
  462. throw;
  463. } catch (Exception ex) {
  464. Assert.AreEqual (typeof (Exception), ex.GetType (), "#4");
  465. Assert.IsNotNull (ex.InnerException, "#5");
  466. Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#6");
  467. }
  468. }
  469. [Test]
  470. public void ConvertFromString_Base16_MaxOverflow_Invariant ()
  471. {
  472. string maxOverflow = ((int) (short.MaxValue + 1)).ToString ("x",
  473. CultureInfo.CurrentCulture);
  474. Assert.AreEqual (-32768, converter.ConvertFromString ("#" + maxOverflow), "#1");
  475. maxOverflow = (ushort.MaxValue + 1).ToString ("x",
  476. CultureInfo.CurrentCulture);
  477. try {
  478. converter.ConvertFromString (null, CultureInfo.InvariantCulture,
  479. "#" + maxOverflow);
  480. Assert.Fail ("#2");
  481. } catch (AssertionException) {
  482. throw;
  483. } catch (Exception ex) {
  484. Assert.AreEqual (typeof (Exception), ex.GetType (), "#3");
  485. Assert.IsNotNull (ex.InnerException, "#4");
  486. Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#5");
  487. }
  488. }
  489. [Serializable]
  490. private sealed class MyCultureInfo : CultureInfo
  491. {
  492. internal MyCultureInfo ()
  493. : base ("en-US")
  494. {
  495. }
  496. public override object GetFormat (Type formatType)
  497. {
  498. if (formatType == typeof (NumberFormatInfo)) {
  499. NumberFormatInfo nfi = (NumberFormatInfo) ((NumberFormatInfo) base.GetFormat (formatType)).Clone ();
  500. nfi.NegativeSign = "myNegativeSign";
  501. return NumberFormatInfo.ReadOnly (nfi);
  502. } else {
  503. return base.GetFormat (formatType);
  504. }
  505. }
  506. #if NET_2_0
  507. // adding this override in 1.x shows different result in .NET (it is ignored).
  508. // Some compatibility kids might want to fix this issue.
  509. public override NumberFormatInfo NumberFormat {
  510. get {
  511. NumberFormatInfo nfi = (NumberFormatInfo) base.NumberFormat.Clone ();
  512. nfi.NegativeSign = "myNegativeSign";
  513. return nfi;
  514. }
  515. set { throw new NotSupportedException (); }
  516. }
  517. #endif
  518. }
  519. }
  520. }