public void TestSatisfiableRange() { using (var ctx = new Context()) { IPAddress low = IPAddress.Parse("127.0.0.1"); IPAddress high = IPAddress.Parse("127.0.0.10"); var range = new AddressRange { Low = low, High = high }; string variableName = "address"; BitVecExpr variable = ctx.MkConst(variableName, ctx.MkBitVecSort(32)) as BitVecExpr; Assert.IsNotNull(variable); Solver s = ctx.MkSolver(); s.Assert(range.Contains(ctx, variable)); Status result = s.Check(); Assert.AreEqual(Status.SATISFIABLE, result); IPAddress binding; Assert.IsTrue(RetrieveModelValue.TryRetrieveAddress(variableName, s.Model, out binding)); Assert.IsTrue(AddressRangeTest.CompareAddresses(low, binding) >= 0); Assert.IsTrue(AddressRangeTest.CompareAddresses(high, binding) <= 0); } }
public void TestSingle() { using (var ctx = new Context()) { IPAddress single = IPAddress.Parse("192.168.0.1"); var range = new AddressRange { Low = single, High = single }; string variableName = "address"; BitVecExpr variable = ctx.MkConst(variableName, ctx.MkBitVecSort(32)) as BitVecExpr; Solver s = ctx.MkSolver(); s.Assert(range.Contains(ctx, variable)); Status result = s.Check(); Assert.AreEqual(Status.SATISFIABLE, result); IPAddress binding; Assert.IsTrue(RetrieveModelValue.TryRetrieveAddress(variableName, s.Model, out binding)); Assert.AreEqual(single, binding); } }