00001 import unittest
00002 import win32com.client
00003 import os
00004 import GPyUnit.Regr.Mga.utils.Builder
00005 bd = GPyUnit.Regr.Mga.utils.Builder
00006 from GPyUnit.util import DispatchEx
00007
00008 from GPyUnit.util import dec_disable_early_binding
00009
00010 def _adjacent_file(file):
00011 import os.path
00012 return os.path.join(os.path.dirname(os.path.abspath(__file__)), file)
00013
00014 class TestCase1( unittest.TestCase ):
00015 """
00016 avoid if possible the overriding of __init__, yet if you override use the following form:
00017 def __init__(self, methodName='runTest'):
00018 unittest.TestCase.__init__(self, methodName)
00019 """
00020
00021 def setUp( self ):
00022 pass
00023
00024 def tearDown( self ):
00025 pass
00026
00027 def populateA(self, p):
00028 folder1 = p.RootFolder.CreateFolder( bd.folder( p, 'SheetFolder'))
00029 folder1.Name = 'SheetFolder1'
00030
00031 parsh1 = folder1.CreateRootObject( bd.kind( p, 'ParadigmSheet'))
00032 parsh1.Name = 'ParadigmSheet1'
00033
00034 at1 = bd.new( p, parsh1, 'Atom')
00035 at1.Name = 'Atom1'
00036
00037 at2 = bd.new( p, parsh1, 'Atom')
00038 at2.Name = 'Atom2'
00039
00040 at3 = bd.new( p, parsh1, 'Atom')
00041 at3.Name = 'Atom3'
00042
00043 ap1 = bd.new( p, parsh1, 'AtomProxy')
00044 ap1.Name = 'AtomProx1'
00045
00046 ap2a = bd.new( p, parsh1, 'AtomProxy')
00047 ap2a.Name = 'AtomProx2a'
00048
00049 ap2b = bd.new( p, parsh1, 'AtomProxy')
00050 ap2b.Name = 'AtomProx2b'
00051
00052 ap1.Referred = at1
00053 ap2a.Referred = at2
00054 ap2b.Referred = at2
00055
00056
00057 @dec_disable_early_binding
00058 def testA( self ):
00059 """ testA References
00060 testing getproperties of IMgaFCO
00061 ReferencedBy([out, retval] IMgaFCOs **pVal)
00062 """
00063
00064 mganame = _adjacent_file("_tc1_A_me.mga")
00065
00066
00067 project = bd.creaP( mganame, "MetaGME")
00068 if not project:
00069 self.fail("Create failed")
00070 try:
00071 self.populateA( project)
00072 except:
00073 bd.saveP( project)
00074 raise
00075 bd.saveP( project)
00076
00077
00078
00079 self.project = project
00080 try:
00081 project.Open( "MGA=" + mganame )
00082 except:
00083 project.Close(0)
00084 raise
00085
00086 trans = project.BeginTransactionInNewTerr(0)
00087
00088 at1 = bd.findInProj( project, "Atom1")
00089 at2 = bd.findInProj( project, "Atom2")
00090 at3 = bd.findInProj( project, "Atom3")
00091 atp1 = bd.findInProj( project, "AtomProx1")
00092 atp2a = bd.findInProj( project, "AtomProx2a")
00093 atp2b = bd.findInProj( project, "AtomProx2b")
00094
00095
00096 assert at1.ReferencedBy.Count == 1
00097 self.assertEquals(at1.ReferencedBy.Item(1).ID, atp1.ID)
00098
00099
00100
00101 refcoll = at2.ReferencedBy
00102 assert refcoll.Count == 2
00103 exp_refs = ( atp2a, atp2b )
00104 assert refcoll.Item( 1 ).ID in [obj.ID for obj in exp_refs]
00105 assert refcoll.Item( 2 ).ID in [obj.ID for obj in exp_refs]
00106
00107
00108
00109
00110
00111 assert at3.ReferencedBy.Count == 0
00112
00113
00114 project.AbortTransaction()
00115
00116 project.Save()
00117 project.Close(0)
00118
00119 pass
00120
00121 def populateB(self, p):
00122 folder1 = p.RootFolder.CreateFolder( bd.folder( p, 'SheetFolder'))
00123 folder1.Name = 'SheetFolder1'
00124
00125 parsh1 = folder1.CreateRootObject( bd.kind( p, 'ParadigmSheet'))
00126 parsh1.Name = 'ParadigmSheet1'
00127
00128 at1 = bd.new( p, parsh1, 'Atom')
00129 at1.Name = 'Atom1'
00130
00131 at2 = bd.new( p, parsh1, 'Atom')
00132 at2.Name = 'Atom2'
00133
00134 at3 = bd.new( p, parsh1, 'Atom')
00135 at3.Name = 'Atom3'
00136
00137 asp1 = bd.new( p, parsh1, 'Aspect')
00138 asp1.Name = 'Aspect1'
00139
00140 asp2 = bd.new( p, parsh1, 'Aspect')
00141 asp2.Name = 'Aspect2'
00142
00143 asp3 = bd.new( p, parsh1, 'Aspect')
00144 asp3.Name = 'Aspect3'
00145
00146
00147 asp1.AddMember(at1)
00148 asp2.AddMember(at1)
00149 asp3.AddMember(at1)
00150
00151
00152 asp2.addMember(at2)
00153
00154 @dec_disable_early_binding
00155 def xtestB( self ):
00156 """ testB Sets
00157 testing getproperties of IMgaFCO
00158 MemberOfSets([out, retval] IMgaFCOs **pVal)
00159 """
00160
00161 mganame = _adjacent_file("_tc1_B_me.mga")
00162
00163
00164 project = bd.creaP( mganame, "MetaGME")
00165 if not project:
00166 self.fail("Create failed")
00167 try:
00168 self.populateB( project)
00169 except:
00170 bd.saveP( project)
00171 raise
00172
00173 bd.saveP( project)
00174
00175
00176
00177 self.project = project
00178 try:
00179 project.Open( "MGA=" + mganame )
00180 except:
00181 project.Close(0)
00182 raise
00183
00184 trans = project.BeginTransactionInNewTerr(0)
00185
00186 as1 = bd.findInProj( project, "Aspect1")
00187 as2 = bd.findInProj( project, "Aspect2")
00188 as3 = bd.findInProj( project, "Aspect3")
00189 at1 = bd.findInProj( project, "Atom1")
00190 at2 = bd.findInProj( project, "Atom2")
00191 at3 = bd.findInProj( project, "Atom3")
00192
00193
00194 assert at3.MemberOfSets.Count == 0
00195
00196
00197 assert at2.MemberOfSets.Count == 1
00198 assert at2.MemberOfSets.Item( 1 ) == as2
00199 assert at2.MemberOfSets[0] == as2
00200
00201
00202 sets = at1.MemberOfSets
00203 assert sets.Count == 3
00204 exp_sets = ( as1, as2, as3 )
00205 assert sets.Item( 1 ) in exp_sets
00206 assert sets.Item( 2 ) in exp_sets
00207 assert sets.Item( 3 ) in exp_sets
00208 assert sets[0] in exp_sets
00209 assert sets[1] in exp_sets
00210 assert sets[2] in exp_sets
00211
00212
00213 project.AbortTransaction()
00214
00215 project.Save()
00216 project.Close(0)
00217
00218 pass
00219
00220 def populateC(self, p):
00221 folder1 = p.RootFolder.CreateFolder( bd.folder( p, 'SheetFolder'))
00222 folder1.Name = 'SheetFolder1'
00223
00224 parsh1 = folder1.CreateRootObject( bd.kind( p, 'ParadigmSheet'))
00225 parsh1.Name = 'ParadigmSheet1'
00226
00227 mo1 = bd.new( p, parsh1, 'Model')
00228 mo1.Name = 'Model1'
00229
00230 at1 = bd.new( p, parsh1, 'Atom')
00231 at1.Name = 'Atom1'
00232
00233 at2 = bd.new( p, parsh1, 'Atom')
00234 at2.Name = 'Atom2'
00235
00236 at3 = bd.new( p, parsh1, 'Atom')
00237 at3.Name = 'Atom3'
00238
00239
00240 connection1 = bd.new( p, parsh1, 'Connection')
00241 connection1.Name = 'AssocClass1'
00242
00243
00244 connector1 = bd.new( p, parsh1, 'Connector')
00245 connector1.Name = 'ConnPoint1'
00246
00247
00248
00249
00250
00251 z0 = DispatchEx("Mga.MgaFCOs")
00252
00253 try:
00254
00255 cc1 = parsh1.CreateSimpleConn( bd.role(p, parsh1, 'Containment'), at1, mo1, z0, z0)
00256 cc1.Name = 'Containment_a1_to_m'
00257 except:
00258 print 'Could not create containment1'
00259 raise
00260
00261 try:
00262
00263 cc2 = parsh1.CreateSimpleConn( bd.role(p, parsh1, 'Containment'), at2, mo1, z0, z0)
00264 cc2.Name = 'Containment_a2_to_m'
00265 except:
00266 print 'Could not create containment2'
00267 raise
00268
00269 try:
00270
00271 sc = parsh1.CreateSimpleConn( bd.role(p, parsh1, 'SourceToConnector'), at1, connector1, z0, z0)
00272 sc.Name = 'SourceToConnector_to_cp'
00273 except:
00274 print 'Could not create source2conn'
00275 raise
00276
00277 try:
00278
00279 dc = parsh1.CreateSimpleConn( bd.role(p, parsh1, 'ConnectorToDestination'), connector1, at1, z0, z0)
00280 dc.Name = 'ConnectorToDestination_from_cp'
00281 except:
00282 print 'Could not create conn2dest'
00283 raise
00284
00285 try:
00286 ac = parsh1.CreateSimpleConn( bd.role(p, parsh1, 'AssociationClass'), connection1, connector1, z0, z0)
00287 ac.Name = 'AssocLink'
00288 except:
00289 print 'Could not create assoc'
00290 raise
00291
00292
00293 @dec_disable_early_binding
00294 def testC( self ):
00295 """ testC connections in MetaGME
00296 testing getproperties of IMgaFCO
00297 PartOfConns([out, retval] IMgaConnPoints **pVal)
00298
00299 and getproperties of IMgaConnPoint
00300 Owner([out, retval] IMgaConnection **pVal)
00301 ConnRole([out, retval] BSTR *pVal)
00302 Target([out, retval] IMgaFCO **pVal)
00303 References([out, retval] IMgaFCOs **pVal)
00304
00305 """
00306 mganame = _adjacent_file("_tc1_C_me.mga")
00307
00308
00309 project = bd.creaP( mganame, "MetaGME")
00310 if not project:
00311 self.fail("Create failed")
00312 try:
00313 self.populateC( project)
00314 except:
00315 bd.saveP( project)
00316 raise
00317
00318 bd.saveP( project)
00319
00320
00321 self.project = project
00322 try:
00323 project.Open( "MGA=" + mganame )
00324 except:
00325 project.Close(0)
00326 raise
00327
00328 trans = project.BeginTransactionInNewTerr(0)
00329
00330 mo1 = bd.findInProj( project, "Model1")
00331 at1 = bd.findInProj( project, "Atom1")
00332 at2 = bd.findInProj( project, "Atom2")
00333 at3 = bd.findInProj( project, "Atom3")
00334 cp1 = bd.findInProj( project, "ConnPoint1")
00335
00336
00337 assert at3.PartOfConns.Count == 0
00338
00339
00340
00341 self.failUnless( at2.PartOfConns.Count == 1, 'Bad count:' + str( at2.PartOfConns.Count))
00342 assert at2.PartOfConns.Item( 1 ).Target.ID == at2.ID
00343 assert at2.PartOfConns.Item( 1 ).Owner.Name == "Containment_a2_to_m"
00344 assert at2.PartOfConns.Item( 1 ).ConnRole == "src"
00345 assert at2.PartOfConns.Item( 1 ).References.Count == 0
00346
00347
00348 cps = at1.PartOfConns
00349 self.failUnless( cps.Count == 3, 'Bad count:' + str( cps.Count))
00350
00351 conn_name_a = "Containment_a1_to_m"
00352 conn_name_b = "SourceToConnector_to_cp"
00353 conn_name_c = "ConnectorToDestination_from_cp"
00354
00355 conn_a = bd.findInProj( project, conn_name_a)
00356 conn_b = bd.findInProj( project, conn_name_b)
00357 conn_c = bd.findInProj( project, conn_name_c)
00358
00359
00360 exp_conns = ( conn_a, conn_b, conn_c )
00361 exp_conn_names = ( conn_name_a, conn_name_b, conn_name_c)
00362
00363
00364 exp_conn_role = { conn_name_a:"src", conn_name_b:"src", conn_name_c:"dst" }
00365
00366
00367 for cp in cps:
00368 assert cp.References.Count == 0
00369 assert cp.Target.ID == at1.ID
00370 assert cp.Owner.ID in [obj.ID for obj in exp_conns ]
00371
00372
00373 assert exp_conn_role.has_key( cp.Owner.Name )
00374 assert exp_conn_role[ cp.Owner.Name ] == cp.ConnRole
00375
00376
00377
00378 cps = cp1.PartOfConns
00379
00380 conn_name_a = "AssocLink"
00381 conn_name_b = "SourceToConnector_to_cp"
00382 conn_name_c = "ConnectorToDestination_from_cp"
00383
00384 conn_a = bd.findInProj( project, conn_name_a)
00385 conn_b = bd.findInProj( project, conn_name_b)
00386 conn_c = bd.findInProj( project, conn_name_c)
00387
00388
00389 exp_conns = ( conn_a, conn_b, conn_c )
00390 exp_conn_names = ( conn_name_a, conn_name_b, conn_name_c)
00391
00392
00393 exp_conn_role = { conn_name_a:"dst", conn_name_b:"dst", conn_name_c:"src" }
00394
00395
00396 for cp in cps:
00397 assert cp.References.Count == 0
00398 assert cp.Target.ID == cp1.ID
00399 assert cp.Owner.ID in [obj.ID for obj in exp_conns]
00400
00401
00402 assert exp_conn_role.has_key( cp.Owner.Name )
00403 self.failUnless( exp_conn_role[ cp.Owner.Name ] == cp.ConnRole, 'Got: ' + cp.ConnRole + ' Expected: ' + exp_conn_role[ cp.Owner.Name ] )
00404
00405
00406
00407
00408 project.AbortTransaction()
00409
00410 project.Save()
00411 project.Close(0)
00412
00413
00414 pass
00415
00416 def populateD(self, p):
00417 folder1 = p.RootFolder.CreateFolder( bd.folder( p, 'Folder'))
00418 folder1.Name = 'Folder1'
00419
00420 folder2 = p.RootFolder.CreateFolder( bd.folder( p, 'Folder'))
00421 folder2.Name = 'Folder2'
00422
00423 comp1 = p.RootFolder.CreateRootObject( bd.kind( p, 'Compound'))
00424 comp1.Name = 'Compound1'
00425
00426 comp2 = p.RootFolder.CreateRootObject( bd.kind( p, 'Compound'))
00427 comp2.Name = 'Compound2'
00428
00429 is1 = bd.new( p, comp1, 'InputSignals')
00430 is1.Name = 'Is'
00431
00432 os1 = bd.new( p, comp1, 'OutputSignals')
00433 os1.Name = 'Os'
00434
00435 compA = bd.new( p, comp1, 'CompoundParts')
00436 compA.Name = 'CompoundPartsA'
00437
00438 compB = bd.new( p, comp1, 'CompoundParts')
00439 compB.Name = 'CompoundPartsB'
00440
00441 portIsA = bd.new( p, compA, 'InputSignals')
00442 portIsA.Name = 'IsA1'
00443 portOsA = bd.new( p, compA, 'OutputSignals')
00444 portOsA.Name = 'OsA1'
00445
00446 portIpA = bd.new( p, compA, 'InputParameters')
00447 portIpA.Name = 'IpA1'
00448 portOpA = bd.new( p, compA, 'OutputParameters')
00449 portOpA.Name = 'OpA1'
00450
00451 portIsB = bd.new( p, compB, 'InputSignals')
00452 portIsB.Name = 'IsB1'
00453 portOsB = bd.new( p, compB, 'OutputSignals')
00454 portOsB.Name = 'OsB1'
00455
00456 portIpB = bd.new( p, compB, 'InputParameters')
00457 portIpB.Name = 'IpB1'
00458 portOpB = bd.new( p, compB, 'OutputParameters')
00459 portOpB.Name = 'OpB1'
00460
00461
00462 z0 = DispatchEx("Mga.MgaFCOs")
00463
00464 try:
00465
00466 dfc0 = comp1.CreateSimpleConn( bd.role(p, comp1, 'DFC'), is1, os1, z0, z0)
00467 dfc0.Name = 'DFC0'
00468 except:
00469 print 'Could not create DFC0'
00470 raise
00471
00472 try:
00473
00474 dfc1 = comp1.CreateSimpleConn( bd.role(p, comp1, 'DFC'), portIsA, portOsB, z0, z0)
00475 dfc1.Name = 'DFC1'
00476
00477
00478 dfc2 = comp1.CreateSimpleConn( bd.role(p, comp1, 'DFC'), portIsB, portOsA, z0, z0)
00479 dfc2.Name = 'DFC2'
00480 except:
00481 print 'Could not create DFC1, DFC2'
00482 raise
00483
00484 try:
00485
00486 pc1 = comp1.CreateSimpleConn( bd.role(p, comp1, 'PC'), portIpA, portOpB, z0, z0)
00487 pc1.Name = 'PC1'
00488
00489
00490
00491 pc2 = bd.connect( p, comp1, portIpB, portOpA, 'PC')
00492 pc2.Name = 'PC2'
00493 except:
00494 print 'Could not create PC1, PC2'
00495 raise
00496 pass
00497
00498 @dec_disable_early_binding
00499 def testD( self ):
00500 """ testD Connections in SF
00501 testing getproperties of IMgaFCO
00502 PartOfConns([out, retval] IMgaConnPoints **pVal)
00503
00504 and getproperties of IMgaConnPoint
00505 Owner([out, retval] IMgaConnection **pVal)
00506 ConnRole([out, retval] BSTR *pVal)
00507 Target([out, retval] IMgaFCO **pVal)
00508 References([out, retval] IMgaFCOs **pVal)
00509 """
00510
00511 mganame = _adjacent_file("_tc1_D_sf.mga")
00512
00513
00514 project = bd.creaP( mganame, "SF")
00515 if not project:
00516 self.fail("Create failed")
00517 try:
00518 self.populateD( project)
00519 except:
00520 bd.saveP( project)
00521 raise
00522 bd.saveP( project)
00523
00524
00525
00526 self.project = project
00527 try:
00528 project.Open( "MGA=" + mganame )
00529 except:
00530 project.Close(0)
00531 raise
00532
00533 trans = project.BeginTransactionInNewTerr()
00534
00535 mo1 = bd.findInProj( project, "Compound1")
00536 is1 = bd.findInProj( project, "Is")
00537 os1 = bd.findInProj( project, "Os")
00538 dc0 = bd.findInProj( project, "DFC0")
00539
00540 pISA = bd.findInProj( project, "IsA1")
00541 pOSA = bd.findInProj( project, "OsA1")
00542 pISB = bd.findInProj( project, "IsB1")
00543 pOSB = bd.findInProj( project, "OsB1")
00544 dc1 = bd.findInProj( project, "DFC1")
00545 dc2 = bd.findInProj( project, "DFC2")
00546
00547
00548 assert mo1.PartOfConns.Count == 0
00549
00550
00551 assert is1.PartOfConns.Count == 1
00552 assert os1.PartOfConns.Count == 1
00553
00554 assert is1.PartOfConns.Item( 1 ).Target.ID == is1.ID
00555 assert is1.PartOfConns.Item( 1 ).Owner.Name == "DFC0"
00556 assert is1.PartOfConns.Item( 1 ).ConnRole == "src"
00557 assert is1.PartOfConns.Item( 1 ).References.Count == 0
00558
00559 assert os1.PartOfConns.Item( 1 ).Target.ID == os1.ID
00560 assert os1.PartOfConns.Item( 1 ).Owner.Name == "DFC0"
00561 assert os1.PartOfConns.Item( 1 ).ConnRole == "dst"
00562 assert os1.PartOfConns.Item( 1 ).References.Count == 0
00563
00564 assert dc1.ConnPoints.Count == 2
00565 for cp in dc1.ConnPoints:
00566 assert cp.Owner.ID == dc1.ID
00567 assert cp.References.Count == 0
00568
00569 if cp.ConnRole == 'src':
00570 assert cp.Target.ID == pISA.ID
00571 elif cp.ConnRole == 'dst':
00572 assert cp.Target.ID == pOSB.ID
00573
00574 assert dc2.ConnPoints.Count == 2
00575 for cp in dc2.ConnPoints:
00576 assert cp.Owner.ID == dc2.ID
00577 assert cp.References.Count == 0
00578
00579 if cp.ConnRole == 'src':
00580 assert cp.Target.ID == pISB.ID
00581 elif cp.ConnRole == 'dst':
00582 assert cp.Target.ID == pOSA.ID
00583
00584
00585
00586 project.AbortTransaction()
00587
00588 project.Save()
00589 project.Close(0)
00590
00591 """
00592 Let's produce the test suites
00593 """
00594
00595 def suites():
00596 suite = unittest.makeSuite(TestCase1,'test')
00597 return suite
00598
00599
00600 def suites2():
00601 suite = unittest.TestSuite()
00602
00603
00604 return suite
00605
00606
00607
00608
00609 if __name__ == "__main__":
00610 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00611 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00612 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00613 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00614 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00615 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TEST BEGINS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00616 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00617 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00618 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00619 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00620 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00621
00622
00623 unittest.main()
00624
00625
00626
00627
00628
00629
00630
00631