|
1 | 1 | usingSystem;
|
2 | 2 | usingSystem.Collections.Generic;
|
3 | 3 | usingNUnit.Framework;
|
| 4 | + |
4 | 5 | usingPython.Runtime;
|
5 | 6 |
|
| 7 | +usingPyRuntime=Python.Runtime.Runtime; |
| 8 | + |
6 | 9 | namespacePython.EmbeddingTest
|
7 | 10 | {
|
8 | 11 | publicclassTestConverter
|
9 | 12 | {
|
| 13 | +staticreadonlyType[]_numTypes=newType[] |
| 14 | +{ |
| 15 | +typeof(short), |
| 16 | +typeof(ushort), |
| 17 | +typeof(int), |
| 18 | +typeof(uint), |
| 19 | +typeof(long), |
| 20 | +typeof(ulong) |
| 21 | +}; |
| 22 | + |
10 | 23 | [OneTimeSetUp]
|
11 | 24 | publicvoidSetUp()
|
12 | 25 | {
|
@@ -47,6 +60,55 @@ public void TestConvertDoubleToManaged(
|
47 | 60 | Assert.IsTrue(((double)convertedValue).Equals(testValue));
|
48 | 61 | }
|
49 | 62 |
|
| 63 | +[Test] |
| 64 | +publicvoidCovertTypeError() |
| 65 | +{ |
| 66 | +using(vars=newPyString("abc")) |
| 67 | +{ |
| 68 | +foreach(vartypein_numTypes) |
| 69 | +{ |
| 70 | +objectvalue; |
| 71 | +try |
| 72 | +{ |
| 73 | +boolres=Converter.ToManaged(s.Handle,type,outvalue,true); |
| 74 | +Assert.IsFalse(res); |
| 75 | +varbo=Exceptions.ExceptionMatches(Exceptions.TypeError); |
| 76 | +Assert.IsTrue(Exceptions.ExceptionMatches(Exceptions.TypeError) |
| 77 | +||Exceptions.ExceptionMatches(Exceptions.ValueError)); |
| 78 | +} |
| 79 | +finally |
| 80 | +{ |
| 81 | +Exceptions.Clear(); |
| 82 | +} |
| 83 | +} |
| 84 | +} |
| 85 | +} |
| 86 | + |
| 87 | +[Test] |
| 88 | +publicvoidConvertOverflow() |
| 89 | +{ |
| 90 | +using(varnum=newPyLong(ulong.MaxValue)) |
| 91 | +{ |
| 92 | +IntPtrlargeNum=PyRuntime.PyNumber_Add(num.Handle,num.Handle); |
| 93 | +try |
| 94 | +{ |
| 95 | +objectvalue; |
| 96 | +foreach(vartypein_numTypes) |
| 97 | +{ |
| 98 | +boolres=Converter.ToManaged(largeNum,type,outvalue,true); |
| 99 | +Assert.IsFalse(res); |
| 100 | +Assert.IsTrue(Exceptions.ExceptionMatches(Exceptions.OverflowError)); |
| 101 | +Exceptions.Clear(); |
| 102 | +} |
| 103 | +} |
| 104 | +finally |
| 105 | +{ |
| 106 | +Exceptions.Clear(); |
| 107 | +PyRuntime.XDecref(largeNum); |
| 108 | +} |
| 109 | +} |
| 110 | +} |
| 111 | + |
50 | 112 | [Test]
|
51 | 113 | publicvoidRawListProxy()
|
52 | 114 | {
|
|