public void TestWrite2()
{
try {
var fr = new RandomGenerator();
EFloat ef = null;
{
CBORObject cborTemp1 = CBORObject.FromObject(ef);
CBORObject cborTemp2 = CBORObject.FromObject((object)ef);
TestCommon.CompareTestEqualAndConsistent(cborTemp1, cborTemp2);
try {
CBORObject.Write(ef, null);
Assert.Fail("Should have failed");
} catch (ArgumentNullException) {
new Object();
} catch (Exception ex) {
Assert.Fail(ex.ToString());
throw new InvalidOperationException(String.Empty, ex);
}
AssertWriteThrow(cborTemp1);
using (var ms = new MemoryStream()) {
CBORObject.Write(ef, ms);
CBORObject.Write(cborTemp1, ms);
cborTemp1.WriteTo(ms);
AssertReadThree(ms.ToArray(), CBORObject.FromObject((object)null));
}
TestWriteObj((object)ef, null);
}
ef = EFloat.FromString("20");
{
CBORObject cborTemp1 = CBORObject.FromObject(ef);
CBORObject cborTemp2 = CBORObject.FromObject((object)ef);
TestCommon.CompareTestEqualAndConsistent(cborTemp1, cborTemp2);
try {
CBORObject.Write(ef, null);
Assert.Fail("Should have failed");
} catch (ArgumentNullException) {
new Object();
} catch (Exception ex) {
Assert.Fail(ex.ToString());
throw new InvalidOperationException(String.Empty, ex);
}
AssertWriteThrow(cborTemp1);
using (var ms = new MemoryStream()) {
CBORObject.Write(ef, ms);
CBORObject.Write(cborTemp1, ms);
cborTemp1.WriteTo(ms);
AssertReadThree(ms.ToArray(), CBORObject.FromObject(ef));
}
TestWriteObj((object)ef, ef);
}
ERational er = null;
{
CBORObject cborTemp1 = CBORObject.FromObject(er);
CBORObject cborTemp2 = CBORObject.FromObject((object)er);
TestCommon.CompareTestEqualAndConsistent(cborTemp1, cborTemp2);
try {
CBORObject.Write(er, null);
Assert.Fail("Should have failed");
} catch (ArgumentNullException) {
new Object();
} catch (Exception ex) {
Assert.Fail(ex.ToString());
throw new InvalidOperationException(String.Empty, ex);
}
AssertWriteThrow(cborTemp1);
using (var ms = new MemoryStream()) {
CBORObject.Write(er, ms);
CBORObject.Write(cborTemp1, ms);
cborTemp1.WriteTo(ms);
AssertReadThree(ms.ToArray(), CBORObject.FromObject((object)null));
}
TestWriteObj((object)er, null);
}
do {
er = RandomObjects.RandomERational(fr);
} while (er.IsNegative && er.IsZero);
{
CBORObject cborTemp1 = CBORObject.FromObject(er);
CBORObject cborTemp2 = CBORObject.FromObject((object)er);
TestCommon.CompareTestEqualAndConsistent(cborTemp1, cborTemp2);
try {
CBORObject.Write(er, null);
Assert.Fail("Should have failed");
} catch (ArgumentNullException) {
new Object();
} catch (Exception ex) {
Assert.Fail(ex.ToString());
throw new InvalidOperationException(String.Empty, ex);
}
AssertWriteThrow(cborTemp1);
using (var ms = new MemoryStream()) {
CBORObject.Write(er, ms);
CBORObject.Write(cborTemp1, ms);
cborTemp1.WriteTo(ms);
if (cborTemp1.IsNegative && cborTemp1.IsZero) {
AssertReadThree(ms.ToArray());
} else {
AssertReadThree(ms.ToArray(), CBORObject.FromObject(er));
}
}
TestWriteObj((object)er, er);
}
EDecimal ed = null;
{
CBORObject cborTemp1 = CBORObject.FromObject(ed);
CBORObject cborTemp2 = CBORObject.FromObject((object)ed);
TestCommon.CompareTestEqualAndConsistent(cborTemp1, cborTemp2);
try {
CBORObject.Write(ed, null);
Assert.Fail("Should have failed");
} catch (ArgumentNullException) {
new Object();
} catch (Exception ex) {
Assert.Fail(ex.ToString());
throw new InvalidOperationException(String.Empty, ex);
}
AssertWriteThrow(cborTemp1);
using (var ms = new MemoryStream()) {
CBORObject.Write(ed, ms);
CBORObject.Write(cborTemp1, ms);
cborTemp1.WriteTo(ms);
AssertReadThree(ms.ToArray(), CBORObject.FromObject((object)null));
}
TestWriteObj((object)ed, null);
}
EInteger bigint = null;
{
CBORObject cborTemp1 = CBORObject.FromObject(bigint);
CBORObject cborTemp2 = CBORObject.FromObject((object)bigint);
TestCommon.CompareTestEqualAndConsistent(cborTemp1, cborTemp2);
try {
CBORObject.Write(bigint, null);
Assert.Fail("Should have failed");
} catch (ArgumentNullException) {
new Object();
} catch (Exception ex) {
Assert.Fail(ex.ToString());
throw new InvalidOperationException(String.Empty, ex);
}
AssertWriteThrow(cborTemp1);
using (var ms = new MemoryStream()) {
CBORObject.Write(bigint, ms);
CBORObject.Write(cborTemp1, ms);
cborTemp1.WriteTo(ms);
AssertReadThree(ms.ToArray(), CBORObject.FromObject((object)null));
}
TestWriteObj((object)bigint, null);
}
} catch (IOException ex) {
Assert.Fail(ex.ToString());
throw new InvalidOperationException(ex.ToString(), ex);
}
}