#!/usr/bin/env python
#
#
# Tests whether Python immutable values are correctly
# coerced into their Coral equivalents.
#

import coral

L = coral.Language("Test", 1, 0)
M = coral.ElementDefinition(L, "Foobar")

P1 = coral.Property("pString", coral.String, "", 0, -1,
                    coral.kind_t.KIND_COMPOSITION | coral.kind_t.KIND_ORDERED, "")
P2 = coral.Property("pInt", coral.Integer, "", 0, -1,
                    coral.kind_t.KIND_COMPOSITION | coral.kind_t.KIND_ORDERED, "")
P3 = coral.Property("pDouble", coral.Double, "", 0, -1,
                    coral.kind_t.KIND_COMPOSITION | coral.kind_t.KIND_ORDERED, "")
P4 = coral.Property("pEnum", coral.Boolean, "", 0, -1,
                    coral.kind_t.KIND_COMPOSITION | coral.kind_t.KIND_ORDERED, "")
P5 = coral.Property("pObject", coral.coralPyObj, "", 0, -1,
                    coral.kind_t.KIND_COMPOSITION | coral.kind_t.KIND_ORDERED, "")

M.addPropertyRecursive(P1)
M.addPropertyRecursive(P2)
M.addPropertyRecursive(P3)
M.addPropertyRecursive(P4)
M.addPropertyRecursive(P5)

m = M()

m.pString.add("foo")
m.pString.add("bar")
assert m.pString[0] == "foo"
assert m.pString[1] == "bar"
assert len(m.pString) == 2

m.pInt.add(3)
m.pInt.add(4)
assert m.pInt[0] == 3
assert m.pInt[1] == 4
assert len(m.pInt) == 2

m.pDouble.add(3.2)
m.pDouble.add(4)
assert m.pDouble[0] == 3.2
assert m.pDouble[1] == 4
assert len(m.pDouble) == 2

m.pEnum.add("true")
m.pEnum.add("false")
assert m.pEnum[0] == "true"
assert m.pEnum[1] == "false"
assert len(m.pEnum) == 2

class A:
    pass

a1 = A()
a2 = A()
m.pObject.add(a1)
m.pObject.add(a2)
#assert m.pObject[0] == a1
#assert m.pObject[1] == a2
assert len(m.pObject) == 2

print "OK"

