#!/usr/bin/env python
import coral
import os

DI = coral.lang.XMIDI20

turns = 0

filename = "2classes_with_association.xmi"
while 1:

    input_fd = os.popen("grep -A 1000 'GraphEdge.waypoints' " + filename + " | grep -B 1000 '</UML:GraphEdge.waypoints' | grep 'XMI.field>0.0<' | wc -l")
    empty_xmi_fields = int(input_fd.readline())
    input_fd.close()
    assert empty_xmi_fields == 8

    
    P = coral.loadDocument(filename)
    
    e = None
    for r in P.contents():
        e = r.__getAllParts__().select(lambda x: x.oclIsKindOf(DI.GraphEdge))
        if e:
            e = e[0]
            break
    
    assert e
    
    assert len(e.waypoints) == 2
    for wp in e.waypoints:
        assert wp.x != 0.0
        assert wp.y != 0.0

    if turns == 1:
        break

    filename = "tmp/2classes_with_association.xmi"
    P.setFilename(filename)
    P.setXMIFormat("1.2")
    coral.saveDocument(P)
    P.invalidate()
    turns += 1
    
