'''
Created on May 23, 2013

@author: hsorby
'''
import unittest

from opencmiss.zinc.context import Context
from opencmiss.zinc.fieldmodule import Fieldmodule, Fieldmodulenotifier, Fieldmoduleevent
import opencmiss.zinc.status

lastfieldevent = Fieldmoduleevent.CHANGE_FLAG_NONE

def fieldmoduleCallback(event):
    global lastfieldevent 
    lastfieldevent = event


class FieldmodulenotifierTestCase(unittest.TestCase):


    def setUp(self):
        self.context = Context("fieldmodulenotifier")
        root_region = self.context.getDefaultRegion()
        self.field_module = root_region.getFieldmodule()


    def tearDown(self):
        del self.field_module
        del self.context


    def testFieldmodulenotifierFieldCreate(self):
        self.assertRaises(TypeError, self.field_module.createFieldmodulenotifier, [1])
        
        notifier = self.field_module.createFieldmodulenotifier()
        self.assertTrue(notifier.isValid())
        
        notifier.setCallback(fieldmoduleCallback)
        joe = self.field_module.createFieldConstant([2.0])
        self.assertTrue(joe.isValid())
        
        self.assertEqual(Fieldmoduleevent.CHANGE_FLAG_ADD, lastfieldevent.getChangeFlags())

        self.assertEqual(opencmiss.zinc.status.OK, joe.setName("joe"))
        self.assertEqual(Fieldmoduleevent.CHANGE_FLAG_IDENTIFIER, lastfieldevent.getChangeFlags())
        
        cache = self.field_module.createFieldcache()
        self.assertEqual(opencmiss.zinc.status.OK, joe.assignReal(cache, [4.5]))
        self.assertEqual(Fieldmoduleevent.CHANGE_FLAG_DEFINITION, lastfieldevent.getChangeFlags())
        
        self.assertEqual(opencmiss.zinc.status.OK, joe.setManaged(True));
        self.assertEqual(Fieldmoduleevent.CHANGE_FLAG_METADATA, lastfieldevent.getChangeFlags())

        fred = self.field_module.createFieldMagnitude(joe)
        self.assertTrue(fred.isValid())
        self.assertEqual(Fieldmoduleevent.CHANGE_FLAG_ADD, lastfieldevent.getChangeFlags())
        self.assertEqual(Fieldmoduleevent.CHANGE_FLAG_ADD, lastfieldevent.getFieldChangeFlags(fred))
        self.assertEqual(Fieldmoduleevent.CHANGE_FLAG_NONE, lastfieldevent.getFieldChangeFlags(joe))

        self.assertEqual(opencmiss.zinc.status.OK, joe.assignReal(cache, [4.5]))
        self.assertEqual(Fieldmoduleevent.CHANGE_FLAG_DEFINITION | Fieldmoduleevent.CHANGE_FLAG_DEPENDENCY,
            lastfieldevent.getChangeFlags())
        self.assertEqual(Fieldmoduleevent.CHANGE_FLAG_DEFINITION, lastfieldevent.getFieldChangeFlags(joe))
        self.assertEqual(Fieldmoduleevent.CHANGE_FLAG_DEPENDENCY, lastfieldevent.getFieldChangeFlags(fred))

        self.assertEqual(opencmiss.zinc.status.OK, joe.setManaged(False))
        joe = 0
        fred = 0
        self.assertEqual(Fieldmoduleevent.CHANGE_FLAG_REMOVE, lastfieldevent.getChangeFlags())

        self.assertEqual(opencmiss.zinc.status.OK, notifier.clearCallback())


def suite():
    #import ImportTestCase
    tests = unittest.TestSuite()
    tests.addTests(unittest.TestLoader().loadTestsFromTestCase(FieldmodulenotifierTestCase))
    return tests

if __name__ == '__main__':
    unittest.TextTestRunner().run(suite())

@@ -192,16 +192,55 @@
 leevent%0A
+from opencmiss.zinc.field import Field%0A
 import o
@@ -279,35 +279,24 @@
 vent = Field
-moduleevent
 .CHANGE_FLAG
@@ -1162,35 +1162,24 @@
 tEqual(Field
-moduleevent
 .CHANGE_FLAG
@@ -1194,32 +1194,44 @@
 stfieldevent.get
+SummaryField
 ChangeFlags())%0A%0A
@@ -1327,35 +1327,24 @@
 tEqual(Field
-moduleevent
 .CHANGE_FLAG
@@ -1366,32 +1366,44 @@
 stfieldevent.get
+SummaryField
 ChangeFlags())%0A 
@@ -1570,35 +1570,24 @@
 tEqual(Field
-moduleevent
 .CHANGE_FLAG
@@ -1589,32 +1589,64 @@
 _FLAG_DEFINITION
+ %7C Field.CHANGE_FLAG_FULL_RESULT
 , lastfieldevent
@@ -1641,32 +1641,44 @@
 stfieldevent.get
+SummaryField
 ChangeFlags())%0A 
@@ -1785,35 +1785,24 @@
 tEqual(Field
-moduleevent
 .CHANGE_FLAG
@@ -1806,16 +1806,18 @@
 LAG_
-METADATA
+DEFINITION
 , la
@@ -1824,32 +1824,44 @@
 stfieldevent.get
+SummaryField
 ChangeFlags())%0A%0A
@@ -1985,35 +1985,24 @@
 tEqual(Field
-moduleevent
 .CHANGE_FLAG
@@ -2017,32 +2017,44 @@
 stfieldevent.get
+SummaryField
 ChangeFlags())%0A 
@@ -2078,35 +2078,24 @@
 tEqual(Field
-moduleevent
 .CHANGE_FLAG
@@ -2168,35 +2168,24 @@
 tEqual(Field
-moduleevent
 .CHANGE_FLAG
@@ -2340,35 +2340,24 @@
 tEqual(Field
-moduleevent
 .CHANGE_FLAG
@@ -2371,35 +2371,24 @@
 TION %7C Field
-moduleevent
 .CHANGE_FLAG
@@ -2388,26 +2388,27 @@
 GE_FLAG_
-DEPENDENCY
+FULL_RESULT
 ,%0A      
@@ -2423,32 +2423,44 @@
 stfieldevent.get
+SummaryField
 ChangeFlags())%0A 
@@ -2484,35 +2484,24 @@
 tEqual(Field
-moduleevent
 .CHANGE_FLAG
@@ -2503,32 +2503,64 @@
 _FLAG_DEFINITION
+ %7C Field.CHANGE_FLAG_FULL_RESULT
 , lastfieldevent
@@ -2612,35 +2612,24 @@
 tEqual(Field
-moduleevent
 .CHANGE_FLAG
@@ -2633,18 +2633,19 @@
 LAG_
-DEPENDENCY
+FULL_RESULT
 , la
@@ -2773,17 +2773,20 @@
   joe = 
-0
+None
 %0A       
@@ -2793,17 +2793,20 @@
  fred = 
-0
+None
 %0A       
@@ -2828,27 +2828,16 @@
 al(Field
-moduleevent
 .CHANGE_
@@ -2867,16 +2867,28 @@
 vent.get
+SummaryField
 ChangeFl

Update python unit tests to adopt the fieldmoduleevent changes. https://tracker.physiomeproject.org/show_bug.cgi?id=3231