compiler/tests/extras/PPCSetUpBeforeTearDownAfterResource.st
changeset 510 869853decf31
child 513 7b8093caf796
equal deleted inserted replaced
509:fd22630c7e62 510:869853decf31
       
     1 "{ Package: 'stx:goodies/petitparser/compiler/tests/extras' }"
       
     2 
       
     3 "{ NameSpace: Smalltalk }"
       
     4 
       
     5 TestResource subclass:#PPCSetUpBeforeTearDownAfterResource
       
     6 	instanceVariableNames:''
       
     7 	classVariableNames:'CachedResources'
       
     8 	poolDictionaries:''
       
     9 	category:'PetitCompiler-Extras-Tests-Support'
       
    10 !
       
    11 
       
    12 PPCSetUpBeforeTearDownAfterResource class instanceVariableNames:'testCaseClass'
       
    13 
       
    14 "
       
    15  The following class instance variables are inherited by this class:
       
    16 
       
    17 	TestResource - current
       
    18 	TestAsserter - 
       
    19 	Object - 
       
    20 "
       
    21 !
       
    22 
       
    23 !PPCSetUpBeforeTearDownAfterResource class methodsFor:'initialization'!
       
    24 
       
    25 initialize
       
    26     "Invoked at system start or when the class is dynamically loaded."
       
    27 
       
    28     "/ please change as required (and remove this comment)
       
    29     "/ testCaseClass := nil.
       
    30 
       
    31     CachedResources := Dictionary new
       
    32 
       
    33     "Modified: / 30-07-2015 / 07:47:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    34 ! !
       
    35 
       
    36 !PPCSetUpBeforeTearDownAfterResource class methodsFor:'accessing'!
       
    37 
       
    38 testCaseClass
       
    39     ^ testCaseClass
       
    40 
       
    41     "Created: / 29-07-2015 / 16:19:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    42 !
       
    43 
       
    44 testCaseClass: aClass
       
    45     testCaseClass := aClass
       
    46 
       
    47     "Created: / 29-07-2015 / 16:19:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    48 ! !
       
    49 
       
    50 !PPCSetUpBeforeTearDownAfterResource class methodsFor:'queries'!
       
    51 
       
    52 isAbstract
       
    53     "Return if this class is an abstract class.
       
    54      True is returned here for myself only; false for subclasses.
       
    55      Abstract subclasses must redefine again."
       
    56     
       
    57     ^ self == PPCSetUpBeforeTearDownAfterResource.
       
    58 ! !
       
    59 
       
    60 !PPCSetUpBeforeTearDownAfterResource class methodsFor:'running'!
       
    61 
       
    62 availableFor: aTestAsserter
       
    63         aTestAsserter
       
    64                 assert: self isAvailable
       
    65                 description: 'Unavailable resource ', PPCSetUpBeforeTearDownAfterResource name ,' for: ', testCaseClass name , ' requested by ', aTestAsserter printString.
       
    66 
       
    67     "Created: / 29-07-2015 / 16:42:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    68 ! !
       
    69 
       
    70 !PPCSetUpBeforeTearDownAfterResource class methodsFor:'subclass creation'!
       
    71 
       
    72 for: aClass
       
    73     ^ CachedResources at: aClass ifAbsentPut:[
       
    74         | resourceMeta resourceClass |
       
    75 
       
    76         resourceMeta := Metaclass new.
       
    77         resourceMeta setSuperclass: self class.
       
    78         resourceMeta instSize: self class instSize.  
       
    79         resourceClass := resourceMeta new.
       
    80         resourceClass setSuperclass: self.
       
    81         resourceClass instSize: self instSize.  
       
    82         resourceClass testCaseClass: aClass.
       
    83         resourceClass
       
    84     ]
       
    85 
       
    86     "Created: / 29-07-2015 / 16:17:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    87     "Modified (format): / 30-07-2015 / 07:48:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    88 ! !
       
    89 
       
    90 !PPCSetUpBeforeTearDownAfterResource methodsFor:'setup & teardown'!
       
    91 
       
    92 setUp
       
    93     | testCaseClass |
       
    94 
       
    95     testCaseClass := self class testCaseClass.
       
    96     (testCaseClass lookupSelector: #setUpBefore) notNil ifTrue:[ 
       
    97         testCaseClass new setUpBefore.
       
    98     ].
       
    99 
       
   100     "Created: / 29-07-2015 / 16:33:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   101 !
       
   102 
       
   103 tearDown
       
   104     | testCaseClass |
       
   105 
       
   106     testCaseClass := self class testCaseClass.
       
   107     (testCaseClass lookupSelector: #tearDownAfter) notNil ifTrue:[ 
       
   108         testCaseClass new tearDownAfter
       
   109     ].
       
   110 
       
   111     "Created: / 29-07-2015 / 16:33:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   112 ! !
       
   113 
       
   114 
       
   115 PPCSetUpBeforeTearDownAfterResource initialize!