« lib/VSGDR/UnitTest/TestSet/Test.pm
↑ Summary
lib/VSGDR/UnitTest/TestSet/Representation/NET/CS.pm »
| 1 | package VSGDR::UnitTest::TestSet::Representation::NET2; | ||
| 2 | |||
| 3 | use 5.010; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | |||
| 7 | |||
| 8 | #our \$VERSION = '1.00'; | ||
| 9 | |||
| 10 | |||
| 11 | use parent qw(VSGDR::UnitTest::TestSet::Representation) ; | ||
| 12 | |||
| 13 | use Carp ; | ||
| 14 | |||
| 15 | use VSGDR::UnitTest::TestSet; | ||
| 16 | use VSGDR::UnitTest::TestSet::Test; | ||
| 17 | use VSGDR::UnitTest::TestSet::Representation; | ||
| 18 | |||
| 19 | |||
| 20 | use Storable qw(dclone); | ||
| 21 | |||
| 22 | use Data::Dumper ; | ||
| 23 | use autodie ; | ||
| 24 | |||
| 25 | our %Globals ; ## temp | ||
| 26 | |||
| 27 | |||
| 28 | |||
| 29 | #TODO: 1. This needs abstracting away - $condition->testConditionAttributeType(${conditionAttribute}) eq 'quoted' ne 'literalcode' | ||
| 30 | |||
| 31 | sub parser1 { | ||
| 32 | local $_ = undef; | ||
| 33 | my $self = shift or croak 'no self'; | ||
| 34 | return $self->{PARSER1} ; | ||
| 35 | } | ||
| 36 | sub parser2 { | ||
| 37 | local $_ = undef; | ||
| 38 | my $self = shift or croak 'no self'; | ||
| 39 | return $self->{PARSER2} ; | ||
| 40 | } | ||
| 41 | |||
| 42 | |||
| 43 | sub parse { | ||
| 44 | local $_ = undef; | ||
| 45 | my $self = shift or croak 'no self'; | ||
| 46 | my $code = shift or croak 'no code' ; | ||
| 47 | |||
| 48 | $code = $self->trim($code) ; | ||
| 49 | |||
| 50 | my $res1 = $self->parser1()->start(${code}); | ||
| 51 | #warn Dumper $res1; | ||
| 52 | my $globals = dclone($res1->{GLOBALS}); | ||
| 53 | my $res2 = $self->parser2()->start(${code},1,$globals); | ||
| 54 | |||
| 55 | my $res ; | ||
| 56 | $res->{GLOBALS} = $res1->{GLOBALS}; | ||
| 57 | $res->{ACTIONS} = $res2->{ACTIONS}; | ||
| 58 | $res->{TESTACTIONS} = $res2->{TESTACTIONS}; | ||
| 59 | $res->{RESOURCES} = $res2->{RESOURCES}; | ||
| 60 | $res->{TESTCONDITIONS} = $res2->{TESTCONDITIONS}; | ||
| 61 | $res->{TESTCONDITIONS_DETAILS} = $res2->{TESTCONDITIONS_DETAILS}; | ||
| 62 | |||
| 63 | # my $res=$self->start(${code}); | ||
| 64 | |||
| 65 | #warn Dumper $res1 ; | ||
| 66 | #warn Dumper $res ; | ||
| 67 | #exit; | ||
| 68 | |||
| 69 | |||
| 70 | my $nameSpace = $$res{GLOBALS}{NAMESPACE} ; | ||
| 71 | my $className = $$res{GLOBALS}{CLASSNAME} ; | ||
| 72 | my $cleanupAction = $$res{GLOBALS}{CLEANUPACTION} ; | ||
| 73 | my $initializeAction = $$res{GLOBALS}{INITIALIZEACTION} ; | ||
| 74 | |||
| 75 | my $testSet = VSGDR::UnitTest::TestSet->new( { NAMESPACE => $nameSpace | ||
| 76 | , CLASSNAME => $className | ||
| 77 | } | ||
| 78 | ) ; | ||
| 79 | my @tests = keys %{$$res{GLOBALS}{TESTS}} ; | ||
| 80 | my %testActions = map { $_ => $$res{GLOBALS}{TESTS}{$_}{ACTION}} keys %{$$res{GLOBALS}{TESTS}} ; | ||
| 81 | |||
| 82 | |||
| 83 | my %testActionLinkage = map { $_ => $$res{TESTACTIONS}{$_}} keys %{$$res{TESTACTIONS}} ; | ||
| 84 | |||
| 85 | #warn Dumper %testActions ; | ||
| 86 | #warn Dumper %testActionLinkage ; | ||
| 87 | my %revTestActions = map { $$res{GLOBALS}{TESTS}{$_}{ACTION} => $_ } keys %{$$res{GLOBALS}{TESTS}} ; | ||
| 88 | my %testActionsData = map { $revTestActions{$_} => $$res{ACTIONS}{$_}} values %testActions ; | ||
| 89 | #warn Dumper $$res{ACTIONS} ; | ||
| 90 | #warn Dumper %testActionsData ; | ||
| 91 | |||
| 92 | my %conditions = () ; | ||
| 93 | #warn Dumper $$res{RESOURCES}{CONDITIONS} ; | ||
| 94 | %conditions = %{$$res{RESOURCES}{CONDITIONS}} if defined $$res{RESOURCES}{CONDITIONS} ; | ||
| 95 | my %testSetActions = () ; | ||
| 96 | %testSetActions = map { $_ => $$res{RESOURCES}{$_} } | ||
| 97 | grep { $_ ne 'CONDITIONS'} keys %{$$res{RESOURCES}} | ||
| 98 | if defined $$res{RESOURCES} ; | ||
| 99 | |||
| 100 | |||
| 101 | if ( exists $testSetActions{testInitializeAction} ) { | ||
| 102 | $testSet->initializeAction('testInitializeAction') ; | ||
| 103 | } | ||
| 104 | if ( exists $testSetActions{testCleanupAction} ) { | ||
| 105 | $testSet->cleanupAction('testCleanupAction') ; | ||
| 106 | } | ||
| 107 | |||
| 108 | #warn Dumper %testSetActions; | ||
| 109 | #warn Dumper $testSet->initializeAction() ; | ||
| 110 | #exit; | ||
| 111 | my %testSetConditions = map { $_ => $$res{RESOURCES}{CONDITIONS}{$_} } qw(testInitializeAction testCleanupAction) ; | ||
| 112 | |||
| 113 | |||
| 114 | my %testConditions = map { $_ => $$res{RESOURCES}{CONDITIONS}{$_} } | ||
| 115 | grep { $_ ne 'testInitializeAction'and $_ ne 'testCleanupAction'} keys %{$$res{RESOURCES}{CONDITIONS}} ; | ||
| 116 | |||
| 117 | my %testConditionTypes = %{$$res{TESTCONDITIONS}} ; | ||
| 118 | my %testConditionDetails = %{$$res{TESTCONDITIONS_DETAILS}} ; | ||
| 119 | |||
| 120 | |||
| 121 | my @testInitObjects = () ; | ||
| 122 | my @testCleanupObjects = () ; | ||
| 123 | foreach my $testCondition ( @{$testSetConditions{'testInitializeAction'}} ) { | ||
| 124 | my %testConditionConstructor = map { ( my $key = "CONDITION" . uc($_) ) ; | ||
| 125 | ( my $val = $testConditionDetails{$testCondition}{$_} ) =~ s/^\s*(.*?)\s*$/$1/x; | ||
| 126 | $key => $val ; | ||
| 127 | } keys %{$testConditionDetails{$testCondition}} ; | ||
| 128 | |||
| 129 | ( my $testConditionType = $testConditionTypes{$testCondition} ) =~ s{Condition$}{}x; | ||
| 130 | $testConditionConstructor{TESTCONDITIONTYPE} = $testConditionType ; | ||
| 131 | $testConditionConstructor{CONDITIONNAME} = $testCondition ; | ||
| 132 | $testConditionConstructor{CONDITIONTESTACTIONNAME} = 'testInitializeAction' ; | ||
| 133 | my $testConditionObject = VSGDR::UnitTest::TestSet::Test::TestCondition->make(\%testConditionConstructor) ; | ||
| 134 | |||
| 135 | unshift @testInitObjects, $testConditionObject ; | ||
| 136 | } | ||
| 137 | $testSet->initializeConditions(\@testInitObjects); | ||
| 138 | foreach my $testCondition ( @{$testSetConditions{'testCleanupAction'}} ) { | ||
| 139 | my %testConditionConstructor = map { ( my $key = "CONDITION" . uc($_) ) ; | ||
| 140 | ( my $val = $testConditionDetails{$testCondition}{$_} ) =~ s{^\s*(.*?)\s*$}{$1}x; | ||
| 141 | $key => $val ; | ||
| 142 | } keys %{$testConditionDetails{$testCondition}} ; | ||
| 143 | |||
| 144 | ( my $testConditionType = $testConditionTypes{$testCondition} ) =~ s{Condition$}{}x; | ||
| 145 | $testConditionConstructor{TESTCONDITIONTYPE} = $testConditionType ; | ||
| 146 | $testConditionConstructor{CONDITIONNAME} = $testCondition ; | ||
| 147 | $testConditionConstructor{CONDITIONTESTACTIONNAME} = 'testCleanupAction' ; | ||
| 148 | my $testConditionObject = VSGDR::UnitTest::TestSet::Test::TestCondition->make(\%testConditionConstructor) ; | ||
| 149 | |||
| 150 | unshift @testCleanupObjects, $testConditionObject ; | ||
| 151 | } | ||
| 152 | $testSet->cleanupConditions(\@testCleanupObjects); | ||
| 153 | |||
| 154 | my @testObjects = () ; | ||
| 155 | |||
| 156 | my @preTest_testConditionObjects = undef ; | ||
| 157 | my @test_testConditionObjects = undef ; | ||
| 158 | my @postTest_testConditionObjects = undef ; | ||
| 159 | |||
| 160 | foreach my $test (@tests) { | ||
| 161 | # my @testConditionObjects = () ; | ||
| 162 | #warn Dumper $test ; | ||
| 163 | #warn Dumper $testActions{$test} ; | ||
| 164 | #warn Dumper $testActionsData{$test} ; | ||
| 165 | @preTest_testConditionObjects = () ; | ||
| 166 | @test_testConditionObjects = () ; | ||
| 167 | @postTest_testConditionObjects = () ; | ||
| 168 | |||
| 169 | my $testObject = VSGDR::UnitTest::TestSet::Test->new( { TESTNAME => $test | ||
| 170 | , TESTACTIONDATANAME => $testActions{$test} | ||
| 171 | , PRETESTACTION => $testActionsData{$test}{PretestAction} | ||
| 172 | , TESTACTION => $testActionsData{$test}{TestAction} | ||
| 173 | , POSTTESTACTION => $testActionsData{$test}{PosttestAction} | ||
| 174 | } ) ; | ||
| 175 | |||
| 176 | # foreach my $testAction ( keys %testConditions ) { | ||
| 177 | #warn Dumper keys %testConditions ; | ||
| 178 | # foreach my $testAction ( grep { $_ =~ m{^${test}_(?:Test|Pretest|PostTest)Action}x } keys %testConditions ) { | ||
| 179 | foreach my $testAction ( grep { my $x = $_ ; | ||
| 180 | # $x =~ s{ _(?: Test|Pretest|PostTest ) Action \z}{}x ; | ||
| 181 | $x =~ s{ _(?: Test|Pretest|Posttest ) Action \z}{}x ; | ||
| 182 | $testActionLinkage{$x} =~ m{^${test}Data}x | ||
| 183 | } keys %testConditions ) { | ||
| 184 | foreach my $testCondition ( @{$conditions{$testAction}} ) { | ||
| 185 | #warn Dumper $testCondition ; | ||
| 186 | my %testConditionConstructor = map { ( my $key = "CONDITION" . uc($_) ) ; | ||
| 187 | ( my $val = $testConditionDetails{$testCondition}{$_} ) =~ s/^\s*(.*?)\s*$/$1/x; | ||
| 188 | $key => $val ; | ||
| 189 | } keys %{$testConditionDetails{$testCondition}} ; | ||
| 190 | |||
| 191 | ( my $testConditionType = $testConditionTypes{$testCondition} ) =~ s{Condition$}{}x; | ||
| 192 | $testConditionConstructor{TESTCONDITIONTYPE} = $testConditionType ; | ||
| 193 | $testConditionConstructor{CONDITIONNAME} = $testCondition ; | ||
| 194 | $testConditionConstructor{CONDITIONTESTACTIONNAME} = $testAction ; | ||
| 195 | #warn Dumper %testConditionConstructor ; | ||
| 196 | my $testConditionObject = VSGDR::UnitTest::TestSet::Test::TestCondition->make(\%testConditionConstructor) ; | ||
| 197 | |||
| 198 | |||
| 199 | #warn Dumper $testConditionObject->conditionName() ; | ||
| 200 | #warn Dumper $testAction ; | ||
| 201 | #( my $testActionBase = $testAction ) =~ s{ _(?: Test|Pretest|PostTest ) Action \z}{}x ; | ||
| 202 | ( my $testActionBase = $testAction ) =~ s{ _(?: Test|Pretest|Posttest ) Action \z}{}x ; | ||
| 203 | |||
| 204 | #warn Dumper $test ; | ||
| 205 | #warn Dumper $testActionBase ; | ||
| 206 | #warn Dumper %testActionLinkage ; | ||
| 207 | #warn Dumper $$res{ACTIONS}{$testActionLinkage{$testActionBase}} ; | ||
| 208 | #warn Dumper $testActionLinkage{$testActionBase} ; | ||
| 209 | #warn Dumper $testObject->testActionLiteral() ; | ||
| 210 | #warn Dumper $testActionLinkage{$testActionBase} ; | ||
| 211 | |||
| 212 | # this needs simlifying ! | ||
| 213 | # if ( $test ."_". $testObject->testActionLiteral() eq $testAction ) { | ||
| 214 | if ( $$res{ACTIONS}{ $testActionLinkage{$testActionBase} }{$testObject->testActionLiteral()} eq $testAction ) { | ||
| 215 | unshift @test_testConditionObjects, $testConditionObject ; | ||
| 216 | } | ||
| 217 | # if ( $test ."_". $testObject->preTestActionLiteral() eq $testAction ) { | ||
| 218 | if ( $$res{ACTIONS}{ $testActionLinkage{$testActionBase} }{$testObject->preTestActionLiteral()} eq $testAction ) { | ||
| 219 | unshift @preTest_testConditionObjects, $testConditionObject ; | ||
| 220 | } | ||
| 221 | # if ( $test ."_". $testObject->postTestActionLiteral() eq $testAction ) { | ||
| 222 | if ( $$res{ACTIONS}{ $testActionLinkage{$testActionBase} }{$testObject->postTestActionLiteral()} eq $testAction ) { | ||
| 223 | unshift @postTest_testConditionObjects, $testConditionObject ; | ||
| 224 | } | ||
| 225 | |||
| 226 | } | ||
| 227 | $testObject->preTest_conditions(\@preTest_testConditionObjects) ; | ||
| 228 | $testObject->test_conditions(\@test_testConditionObjects) ; | ||
| 229 | $testObject->postTest_conditions(\@postTest_testConditionObjects) ; | ||
| 230 | |||
| 231 | } | ||
| 232 | #warn Dumper $testObject ; | ||
| 233 | unshift @testObjects, $testObject ; | ||
| 234 | } | ||
| 235 | |||
| 236 | $testSet->tests(\@testObjects) ; | ||
| 237 | # $testSet->actions(\%testSetActions) ; | ||
| 238 | #print Dumper $testSet ; | ||
| 239 | return $testSet ; | ||
| 240 | |||
| 241 | } | ||
| 242 | |||
| 243 | |||
| 244 | |||
| 245 | sub deparse { | ||
| 246 | my $self = shift or croak 'no self' ; | ||
| 247 | my $testSet = shift or croak 'no test' ; | ||
| 248 | my $ast = $testSet->AST() ; | ||
| 249 | |||
| 250 | #print Dumper $ast ; | ||
| 251 | |||
| 252 | #print Dumper keys %$ast; | ||
| 253 | #print Dumper $$ast{INITIALIZECONDITIONS} ; | ||
| 254 | #print Dumper $$ast{CLEANUPCONDITIONS} ; | ||
| 255 | #exit ; | ||
| 256 | |||
| 257 | return $self->Header($$ast{HEAD}{NAMESPACE},$$ast{HEAD}{CLASSNAME}) . | ||
| 258 | $self->Tests($$ast{BODY}) . | ||
| 259 | $self->icHeader() . | ||
| 260 | $self->icResourceModel($testSet) . | ||
| 261 | $self->icDeclareTestActions($testSet) . | ||
| 262 | $self->icDeclareTestConditions($testSet) . | ||
| 263 | $self->icInitialiseTestActionData($testSet) . | ||
| 264 | $self->icInitialiseTestActions($testSet) . | ||
| 265 | $self->icInitialiseTestConditions($testSet) . | ||
| 266 | $self->icAssignTestActions($testSet) . | ||
| 267 | $self->icAddTestActionConditions($testSet) . | ||
| 268 | $self->icDefineTestConditions($testSet) . | ||
| 269 | $self->icDefineTestInitialiseCleanupActions($testSet) . | ||
| 270 | $self->icFooter() . | ||
| 271 | $self->Footer($$ast{BODY}) ; | ||
| 272 | |||
| 273 | } | ||
| 274 | |||
| 275 | |||
| 276 | sub icDefineTestInitialiseCleanupActions { | ||
| 277 | |||
| 278 | local $_ = undef; | ||
| 279 | my $self = shift or croak 'no self' ; | ||
| 280 | my $testSet = shift or croak 'no testSet' ; | ||
| 281 | my $ra_tests = $testSet->tests() ; | ||
| 282 | my @tests = @$ra_tests; | ||
| 283 | |||
| 284 | my $p3 = ' '; | ||
| 285 | my $res = "" ; | ||
| 286 | |||
| 287 | if ( $testSet->initializeAction() or $testSet->cleanupAction() ) { | ||
| 288 | $res .= $testSet->commentifyClassName($self->quoteChars()); | ||
| 289 | if ( $testSet->initializeAction() ) { | ||
| 290 | $res .= "${p3}" . $self->selfKeyWord() . ".TestInitializeAction = " . $testSet->initializeAction() . $self->lineTerminator() . "\n" ; | ||
| 291 | } | ||
| 292 | if ( $testSet->cleanupAction() ) { | ||
| 293 | $res .= "${p3}" . $self->selfKeyWord() . ".TestCleanupAction = " . $testSet->cleanupAction() . $self->lineTerminator() . "\n" ; | ||
| 294 | } | ||
| 295 | } | ||
| 296 | |||
| 297 | return $res; | ||
| 298 | } | ||
| 299 | |||
| 300 | |||
| 301 | sub icInitialiseTestActionData { | ||
| 302 | local $_ = undef; | ||
| 303 | my $self = shift or croak 'no self' ; | ||
| 304 | my $testSet = shift or croak 'no testSet'; | ||
| 305 | my $ra_tests = $testSet->tests() ; #@{$$ast{BODY}} ; | ||
| 306 | my @tests = @$ra_tests; | ||
| 307 | my $ra_cleanupConditions = $testSet->cleanupConditions(); | ||
| 308 | my $ra_initializeConditions = $testSet->initializeConditions(); | ||
| 309 | my @cleanupConditions = @{$ra_cleanupConditions} ; | ||
| 310 | my @initializeConditions = @{$ra_initializeConditions} ; | ||
| 311 | |||
| 312 | my $p3 = ' '; | ||
| 313 | my $res = "" ; | ||
| 314 | |||
| 315 | |||
| 316 | foreach my $test (@tests) { | ||
| 317 | $res .= "${p3}" . $self->selfKeyWord() . "." . $test->testActionDataName() . " = " . $self->newKeyWord() . " Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestActions" . $self->functionDelimiters() . $self->lineTerminator() . "\n"; | ||
| 318 | } | ||
| 319 | |||
| 320 | return $res ; | ||
| 321 | } | ||
| 322 | |||
| 323 | |||
| 324 | sub icDefineTestConditions { | ||
| 325 | |||
| 326 | local $_ = undef; | ||
| 327 | my $self = shift or croak 'no self' ; | ||
| 328 | my $testSet = shift or croak 'no testSet'; | ||
| 329 | my $ra_tests = $testSet->tests() ; #@{$$ast{BODY}} ; | ||
| 330 | my @tests = @$ra_tests; | ||
| 331 | my $ra_cleanupConditions = $testSet->cleanupConditions(); | ||
| 332 | my $ra_initializeConditions = $testSet->initializeConditions(); | ||
| 333 | my @cleanupConditions = @{$ra_cleanupConditions} ; | ||
| 334 | my @initializeConditions = @{$ra_initializeConditions} ; | ||
| 335 | |||
| 336 | my $p3 = ' '; | ||
| 337 | my $res = "" ; | ||
| 338 | |||
| 339 | |||
| 340 | foreach my $condition (@initializeConditions, @cleanupConditions ) { | ||
| 341 | |||
| 342 | $res .= $condition->commentifyName($self->quoteChars()); | ||
| 343 | |||
| 344 | #warn "\n"; | ||
| 345 | |||
| 346 | foreach my $conditionAttribute ( grep { $_ ne 'conditionTestActionName' } @{[$condition->testConditionAttributes()]} ) { | ||
| 347 | my $conditionAttributeName = $condition->testConditionAttributeName(${conditionAttribute}); | ||
| 348 | #warn Dumper $conditionAttributeName; | ||
| 349 | #warn Dumper $condition->$conditionAttribute(); | ||
| 350 | #This needs some heavy method subtyping now................. | ||
| 351 | |||
| 352 | if ( $condition->testConditionAttributeType(${conditionAttribute}) ne 'literalcode' ) { | ||
| 353 | $res .= "${p3}" . $condition->conditionName() . ".${conditionAttributeName}" . " = " | ||
| 354 | . ( ( $condition->testConditionAttributeType(${conditionAttribute}) eq 'quoted' ) ? '"' : '' ) | ||
| 355 | . $self->convertKeyWord($condition->$conditionAttribute() ) | ||
| 356 | . ( ( $condition->testConditionAttributeType(${conditionAttribute}) eq 'quoted' ) ? '"' : '' ) | ||
| 357 | . "" . $self->lineTerminator() . "\n" ; | ||
| 358 | } | ||
| 359 | else { | ||
| 360 | $res .= "${p3}" . $self->convertKeyWord($condition->$conditionAttribute() ) | ||
| 361 | . "" . $self->lineTerminator() . "\n" ; | ||
| 362 | } | ||
| 363 | |||
| 364 | } | ||
| 365 | } | ||
| 366 | |||
| 367 | |||
| 368 | foreach my $test (@tests) { | ||
| 369 | |||
| 370 | #warn "\n\n"; | ||
| 371 | my $ra_conditions = $test->conditions() ; | ||
| 372 | foreach my $condition (@$ra_conditions) { | ||
| 373 | |||
| 374 | $res .= $condition->commentifyName($self->quoteChars()); | ||
| 375 | |||
| 376 | #warn "\n"; | ||
| 377 | |||
| 378 | foreach my $conditionAttribute ( grep { $_ ne 'conditionTestActionName' } @{[$condition->testConditionAttributes()]} ) { | ||
| 379 | my $conditionAttributeName = $condition->testConditionAttributeName(${conditionAttribute}); | ||
| 380 | #warn Dumper $conditionAttributeName; | ||
| 381 | #warn Dumper $condition->$conditionAttribute(); | ||
| 382 | |||
| 383 | #This needs some heavy method subtyping now................. | ||
| 384 | |||
| 385 | if ( $condition->testConditionAttributeType(${conditionAttribute}) ne 'literalcode' ) { | ||
| 386 | $res .= "${p3}" . $condition->conditionName() . ".${conditionAttributeName}" . " = " | ||
| 387 | . ( ( $condition->testConditionAttributeType(${conditionAttribute}) eq 'quoted' ) ? '"' : '' ) | ||
| 388 | . $self->convertKeyWord($condition->$conditionAttribute() ) | ||
| 389 | . ( ( $condition->testConditionAttributeType(${conditionAttribute}) eq 'quoted' ) ? '"' : '' ) | ||
| 390 | . "" . $self->lineTerminator() . "\n" ; | ||
| 391 | } | ||
| 392 | else { | ||
| 393 | $res .= "${p3}" . $self->convertKeyWord($condition->$conditionAttribute() ) | ||
| 394 | . "" . $self->lineTerminator() . "\n" ; | ||
| 395 | } | ||
| 396 | |||
| 397 | } | ||
| 398 | } | ||
| 399 | } | ||
| 400 | |||
| 401 | return $res; | ||
| 402 | } | ||
| 403 | |||
| 404 | |||
| 405 | sub icInitialiseTestConditions { | ||
| 406 | |||
| 407 | local $_ = undef; | ||
| 408 | my $self = shift or croak 'no self' ; | ||
| 409 | my $testSet = shift or croak 'no testSet'; | ||
| 410 | my $ra_tests = $testSet->tests() ; #@{$$ast{BODY}} ; | ||
| 411 | my @tests = @$ra_tests; | ||
| 412 | |||
| 413 | my $ra_cleanupConditions = $testSet->cleanupConditions(); | ||
| 414 | my $ra_initializeConditions = $testSet->initializeConditions(); | ||
| 415 | my @cleanupConditions = @{$ra_cleanupConditions} ; | ||
| 416 | my @initializeConditions = @{$ra_initializeConditions} ; | ||
| 417 | |||
| 418 | my $p3 = ' '; | ||
| 419 | my $res = "" ; | ||
| 420 | |||
| 421 | |||
| 422 | foreach my $condition (@initializeConditions, @cleanupConditions ) { | ||
| 423 | $res .= "${p3}" . $condition->conditionName() . " = " . $self->newKeyWord() . " Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.". $condition->testConditionMSType() . $self->functionDelimiters() . $self->lineTerminator() . "\n"; | ||
| 424 | } | ||
| 425 | |||
| 426 | |||
| 427 | foreach my $test (@tests) { | ||
| 428 | my $ra_conditions = $test->conditions() ; | ||
| 429 | foreach my $condition (@$ra_conditions) { | ||
| 430 | $res .= "${p3}" . $condition->conditionName() . " = " . $self->newKeyWord() . " Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.". $condition->testConditionMSType() . $self->functionDelimiters() . $self->lineTerminator() . "\n"; | ||
| 431 | } | ||
| 432 | |||
| 433 | } | ||
| 434 | |||
| 435 | |||
| 436 | return $res; | ||
| 437 | } | ||
| 438 | |||
| 439 | sub icDeclareTestConditions { | ||
| 440 | |||
| 441 | local $_ = undef; | ||
| 442 | my $self = shift or croak 'no self' ; | ||
| 443 | my $testSet = shift or croak 'no testSet'; | ||
| 444 | my $ra_tests = $testSet->tests() ; #@{$$ast{BODY}} ; | ||
| 445 | my @tests = @$ra_tests; | ||
| 446 | my $ra_cleanupConditions = $testSet->cleanupConditions(); | ||
| 447 | my $ra_initializeConditions = $testSet->initializeConditions(); | ||
| 448 | #print Dumper $testSet; | ||
| 449 | #print Dumper $ra_initializeConditions; | ||
| 450 | #print Dumper $ra_cleanupConditions; | ||
| 451 | my @cleanupConditions = @{$ra_cleanupConditions} ; | ||
| 452 | my @initializeConditions = @{$ra_initializeConditions} ; | ||
| 453 | |||
| 454 | my $p3 = ' '; | ||
| 455 | my $res = "" ; | ||
| 456 | |||
| 457 | |||
| 458 | foreach my $condition (@initializeConditions, @cleanupConditions ) { | ||
| 459 | # $res .= "${p3}Microsoft.Data.Schema.UnitTesting.Conditions.". $condition->testConditionMSType() . " " . $condition->conditionName() . $self->lineTerminator() . "\n"; | ||
| 460 | $res .= "${p3}" . $self->declareVariable( " Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.". $condition->testConditionMSType() | ||
| 461 | , $condition->conditionName() | ||
| 462 | ) . $self->lineTerminator() . "\n"; | ||
| 463 | } | ||
| 464 | foreach my $test (@tests) { | ||
| 465 | my $ra_conditions = $test->conditions() ; | ||
| 466 | #warn Dumper $ra_conditions ; | ||
| 467 | foreach my $condition (@$ra_conditions) { | ||
| 468 | #warn Dumper $condition ; | ||
| 469 | # $res .= "${p3}Microsoft.Data.Schema.UnitTesting.Conditions.". $condition->testConditionMSType() . " " . $condition->conditionName() . $self->lineTerminator() . "\n"; | ||
| 470 | $res .= "${p3}" . $self->declareVariable( " Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.". $condition->testConditionMSType() | ||
| 471 | , $condition->conditionName() | ||
| 472 | ) . $self->lineTerminator() . "\n"; | ||
| 473 | } | ||
| 474 | } | ||
| 475 | |||
| 476 | return $res; | ||
| 477 | } | ||
| 478 | |||
| 479 | |||
| 480 | sub icDeclareTestActions { | ||
| 481 | |||
| 482 | local $_ = undef; | ||
| 483 | my $self = shift or croak 'no self' ; | ||
| 484 | my $testSet = shift or croak 'no testSet'; | ||
| 485 | my $ra_tests = $testSet->tests() ; #@{$$ast{BODY}} ; | ||
| 486 | my @tests = @$ra_tests; | ||
| 487 | |||
| 488 | my $p3 = ' '; | ||
| 489 | my $res = "" ; | ||
| 490 | |||
| 491 | |||
| 492 | if ( $testSet->initializeAction() ) { | ||
| 493 | $res .= "${p3}" . $self->declareVariable("Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction", $testSet->initializeAction()) . $self->lineTerminator() . "\n" ; | ||
| 494 | } | ||
| 495 | if ( $testSet->cleanupAction() ) { | ||
| 496 | $res .= "${p3}". $self->declareVariable("Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction", $testSet->cleanupAction()) . $self->lineTerminator() . "\n" ; | ||
| 497 | } | ||
| 498 | |||
| 499 | foreach my $test (@tests) { | ||
| 500 | if ( defined $test->preTestAction() and $test->preTestAction() !~ m{^null|nothing$}ix) { | ||
| 501 | $res .= "${p3}" . $self->declareVariable("Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction", $test->preTestAction()) . $self->lineTerminator() . "\n" ; | ||
| 502 | } | ||
| 503 | if ( defined $test->testAction() and $test->testAction() !~ m{^null|nothing$}ix) { | ||
| 504 | $res .= "${p3}" . $self->declareVariable("Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction", $test->testAction()) . $self->lineTerminator() . "\n" ; | ||
| 505 | } | ||
| 506 | if ( defined $test->postTestAction() and $test->postTestAction() !~ m{^null|nothing$}ix) { | ||
| 507 | $res .= "${p3}" . $self->declareVariable("Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction", $test->postTestAction()) . $self->lineTerminator() . "\n" ; | ||
| 508 | } | ||
| 509 | } | ||
| 510 | |||
| 511 | return $res; | ||
| 512 | } | ||
| 513 | |||
| 514 | |||
| 515 | sub icInitialiseTestActions { | ||
| 516 | |||
| 517 | local $_ = undef; | ||
| 518 | my $self = shift or croak 'no self' ; | ||
| 519 | my $testSet = shift or croak 'no testSet' ; | ||
| 520 | my $ra_tests = $testSet->tests() ; #@{$$ast{BODY}} ; | ||
| 521 | my @tests = @$ra_tests; | ||
| 522 | |||
| 523 | my $p3 = ' '; | ||
| 524 | my $res = "" ; | ||
| 525 | |||
| 526 | |||
| 527 | if ( $testSet->initializeAction() ) { | ||
| 528 | $res .= "${p3}".$testSet->initializeAction() . " = " . $self->newKeyWord() . " Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction" . $self->functionDelimiters() . $self->lineTerminator() . "\n" ; | ||
| 529 | } | ||
| 530 | if ($testSet->cleanupAction() ) { | ||
| 531 | $res .= "${p3}".$testSet->cleanupAction() . " = " . $self->newKeyWord() . " Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction" . $self->functionDelimiters() . $self->lineTerminator() . "\n" ; | ||
| 532 | } | ||
| 533 | |||
| 534 | foreach my $test (@tests) { | ||
| 535 | |||
| 536 | if ( defined $test->preTestAction() and $test->preTestAction() !~ m{^null|nothing$}ix) { | ||
| 537 | $res .= "${p3}" . $test->preTestAction() . " = " . $self->newKeyWord() . " Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction" . $self->functionDelimiters() . $self->lineTerminator() . "\n" ; | ||
| 538 | } | ||
| 539 | if ( defined $test->testAction() and $test->testAction() !~ m{^null|nothing$}ix) { | ||
| 540 | $res .= "${p3}" . $test->testAction() . " = " . $self->newKeyWord() . " Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction" . $self->functionDelimiters() . $self->lineTerminator() . "\n" ; | ||
| 541 | } | ||
| 542 | if ( defined $test->postTestAction() and $test->postTestAction() !~ m{^null|nothing$}ix) { | ||
| 543 | $res .= "${p3}" . $test->postTestAction() . " = " . $self->newKeyWord() . " Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction" . $self->functionDelimiters() . $self->lineTerminator() . "\n" ; | ||
| 544 | } | ||
| 545 | |||
| 546 | } | ||
| 547 | |||
| 548 | return $res; | ||
| 549 | } | ||
| 550 | |||
| 551 | |||
| 552 | sub icAssignTestActions { | ||
| 553 | |||
| 554 | local $_ = undef; | ||
| 555 | my $self = shift or croak 'no self' ; | ||
| 556 | my $testSet = shift or croak 'no testSet'; | ||
| 557 | my $ra_tests = $testSet->tests() ; #@{$$ast{BODY}} ; | ||
| 558 | my @tests = @$ra_tests; | ||
| 559 | |||
| 560 | my $p3 = ' '; | ||
| 561 | my $res = "" ; | ||
| 562 | |||
| 563 | foreach my $test (@tests) { | ||
| 564 | |||
| 565 | $res .= $test->commentifyActionDataName($self->quoteChars()); | ||
| 566 | if ( defined $test->preTestAction() and $test->preTestAction() !~ m{^null|nothing$}ix) { | ||
| 567 | $res .= "${p3}" . $self->selfKeyWord() . "." . $test->testActionDataName() . "." . $test->preTestActionLiteral() . " = " . $test->preTestAction(). "" . $self->lineTerminator() . "\n" ; | ||
| 568 | } | ||
| 569 | else { | ||
| 570 | $res .= "${p3}" . $self->selfKeyWord() . "." . $test->testActionDataName() . "." . $test->preTestActionLiteral() . " = " . $self->null() . "" . $self->lineTerminator() . "\n" ; | ||
| 571 | } | ||
| 572 | if ( defined $test->testAction() and $test->testAction() !~ m{^null|nothing$}ix) { | ||
| 573 | $res .= "${p3}" . $self->selfKeyWord() . "." . $test->testActionDataName() . "." . $test->testActionLiteral() . " = " . $test->testAction(). "" . $self->lineTerminator() . "\n" ; | ||
| 574 | } | ||
| 575 | else { | ||
| 576 | $res .= "${p3}" . $self->selfKeyWord() . "." . $test->testActionDataName() . "." . $test->testActionLiteral() . " = " . $self->null() . "" . $self->lineTerminator() . "\n" ; | ||
| 577 | } | ||
| 578 | if ( defined $test->postTestAction() and $test->postTestAction() !~ m{^null|nothing$}ix) { | ||
| 579 | $res .= "${p3}" . $self->selfKeyWord() . "." . $test->testActionDataName() . "." . $test->postTestActionLiteral() . " = " . $test->postTestAction(). "" . $self->lineTerminator() . "\n" ; | ||
| 580 | } | ||
| 581 | else { | ||
| 582 | $res .= "${p3}" . $self->selfKeyWord() . "." . $test->testActionDataName() . "." . $test->postTestActionLiteral() . " = " . $self->null() . "" . $self->lineTerminator() . "\n" ; | ||
| 583 | } | ||
| 584 | |||
| 585 | } | ||
| 586 | |||
| 587 | return $res; | ||
| 588 | } | ||
| 589 | |||
| 590 | sub icAddTestActionConditions { | ||
| 591 | |||
| 592 | local $_ = undef; | ||
| 593 | my $self = shift or croak 'no self' ; | ||
| 594 | my $testSet = shift or croak 'no testSet' ; | ||
| 595 | my $ra_tests = $testSet->tests() ; #@{$$ast{BODY}} ; | ||
| 596 | my @tests = @$ra_tests; | ||
| 597 | my $ra_cleanupConditions = $testSet->cleanupConditions(); | ||
| 598 | my $ra_initializeConditions = $testSet->initializeConditions(); | ||
| 599 | my @cleanupConditions = @{$ra_cleanupConditions} ; | ||
| 600 | my @initializeConditions = @{$ra_initializeConditions} ; | ||
| 601 | |||
| 602 | my $p3 = ' '; | ||
| 603 | my $res = "" ; | ||
| 604 | |||
| 605 | |||
| 606 | |||
| 607 | my $rh_actions = $testSet->actions(); | ||
| 608 | my %actions = %{$rh_actions} ; | ||
| 609 | # my %Usedactions = (); | ||
| 610 | |||
| 611 | |||
| 612 | if ($testSet->initializeAction() ) { | ||
| 613 | $res .= $testSet->commentifyInitializeAction($self->quoteChars()) ; | ||
| 614 | foreach my $condition (@initializeConditions) { | ||
| 615 | $res .= "${p3}".$condition->testAction(). ".Conditions.Add(".$condition->conditionName() . ")" . $self->lineTerminator() . "\n" ; | ||
| 616 | } | ||
| 617 | $res .= "${p3}resources.ApplyResources(" . $testSet->initializeAction() . ', "'.$testSet->initializeAction() . '")' . $self->lineTerminator() ."\n"; | ||
| 618 | # $Usedactions{$testSet->initializeAction()}{PROCESSED} = 1; | ||
| 619 | } | ||
| 620 | if ($testSet->cleanupAction() ) { | ||
| 621 | $res .= $testSet->commentifyCleanupAction($self->quoteChars()) ; | ||
| 622 | foreach my $condition (@cleanupConditions ) { | ||
| 623 | $res .= "${p3}".$condition->testAction(). ".Conditions.Add(".$condition->conditionName() . ")" . $self->lineTerminator() ."\n" ; | ||
| 624 | } | ||
| 625 | $res .= "${p3}resources.ApplyResources(" . $testSet->cleanupAction() . ', "'.$testSet->cleanupAction() . '")'. $self->lineTerminator() ."\n"; | ||
| 626 | # $Usedactions{$testSet->cleanupAction()}{PROCESSED} = 1; | ||
| 627 | } | ||
| 628 | |||
| 629 | |||
| 630 | foreach my $test (@tests) { | ||
| 631 | |||
| 632 | if ( $test->preTestAction() !~ m{^null|nothing$}ix ) { | ||
| 633 | $res .= $test->commentifyPreTestAction($self->quoteChars()); | ||
| 634 | my $conditions = $test->preTest_conditions() ; | ||
| 635 | foreach my $condition (@$conditions) { | ||
| 636 | $res .= "${p3}".$condition->testAction(). ".Conditions.Add(".$condition->conditionName() . ")" . $self->lineTerminator(). "\n" ; | ||
| 637 | } | ||
| 638 | $res .= "${p3}resources.ApplyResources(" . $test->preTestAction() . ', "'.$test->preTestAction() . '")'. $self->lineTerminator() ."\n"; | ||
| 639 | # $Usedactions{$test->preTestAction()}{PROCESSED} = 1; | ||
| 640 | } | ||
| 641 | |||
| 642 | if ( $test->testAction() !~ m{^null|nothing$}ix ) { | ||
| 643 | $res .= $test->commentifyTestAction($self->quoteChars()); | ||
| 644 | my $conditions = $test->test_conditions() ; | ||
| 645 | foreach my $condition (@$conditions) { | ||
| 646 | $res .= "${p3}".$condition->testAction(). ".Conditions.Add(".$condition->conditionName(). ")" . $self->lineTerminator(). "\n" ; | ||
| 647 | } | ||
| 648 | $res .= "${p3}resources.ApplyResources(" . $test->testAction() . ', "'.$test->testAction() . '")' . $self->lineTerminator() ."\n"; | ||
| 649 | # $Usedactions{$test->testAction()}{PROCESSED} = 1; | ||
| 650 | } | ||
| 651 | if ( $test->postTestAction() !~ m{^null|nothing$}ix ) { | ||
| 652 | $res .= $test->commentifyPostTestAction($self->quoteChars()); | ||
| 653 | my $conditions = $test->postTest_conditions() ; | ||
| 654 | foreach my $condition (@$conditions) { | ||
| 655 | $res .= "${p3}".$condition->testAction(). ".Conditions.Add(".$condition->conditionName(). ")" . $self->lineTerminator() . "\n" ; | ||
| 656 | } | ||
| 657 | $res .= "${p3}resources.ApplyResources(" . $test->postTestAction() . ', "'.$test->postTestAction() . '")' . $self->lineTerminator() ."\n"; | ||
| 658 | # $Usedactions{$test->postTestAction()}{PROCESSED} = 1; | ||
| 659 | } | ||
| 660 | } | ||
| 661 | |||
| 662 | # foreach my $action ( keys %actions ) { | ||
| 663 | # if ( not defined ($Usedactions{$action}{PROCESSED})) { | ||
| 664 | # $res .= $testSet->commentifyAny($self->quoteChars(),$action); | ||
| 665 | # $res .= "${p3}resources.ApplyResources(" . $action . ', "'.$action . '")' . $self->lineTerminator() ."\n"; | ||
| 666 | # } | ||
| 667 | # } | ||
| 668 | |||
| 669 | return $res; | ||
| 670 | } | ||
| 671 | |||
| 672 | |||
| 673 | sub icResourceModel { | ||
| 674 | |||
| 675 | local $_ = undef; | ||
| 676 | my $self = shift or croak 'no self' ; | ||
| 677 | # my $Class = shift or croak 'no class' ; | ||
| 678 | my $testSet = shift or croak 'no test set' ; | ||
| 679 | my $Class = $testSet->className(); | ||
| 680 | |||
| 681 | my $p3 = ' '; | ||
| 682 | my $res = "" ; | ||
| 683 | |||
| 684 | my $ra_tests = $testSet->tests() ; #@{$$ast{BODY}} ; | ||
| 685 | my @tests = @$ra_tests; | ||
| 686 | |||
| 687 | # only output this if we have test action that needs resources creating | ||
| 688 | # horrible code esp :- | ||
| 689 | # $testSet->initializeAction() ne '' or $testSet->cleanupAction() ne '' | ||
| 690 | |||
| 691 | foreach my $test (@tests) { | ||
| 692 | if ( $test->testAction() !~ m{^null|nothing$}ix or $test->preTestAction() !~ m{^null|nothing$}ix or $test->postTestAction() !~ m{^null|nothing$}ix or | ||
| 693 | defined $testSet->initializeAction() or defined $testSet->cleanupAction() | ||
| 694 | ) { | ||
| 695 | $res = "${p3}" . $self->declareAndCreateVariable( 'System.ComponentModel.ComponentResourceManager' | ||
| 696 | , 'resources' | ||
| 697 | , "System.ComponentModel.ComponentResourceManager(@{[$self->typeExtractor()]}(${Class}))" | ||
| 698 | ) . $self->lineTerminator() . "\n"; | ||
| 699 | } | ||
| 700 | } | ||
| 701 | |||
| 702 | return $res ; | ||
| 703 | |||
| 704 | } | ||
| 705 | |||
| 706 | |||
| 707 | |||
| 708 | 1; | ||
| 709 | |||
| 710 | |||
| 711 | ########################################################### | ||
| 712 | ########################################################### | ||
| 713 | ########################################################### | ||
| 714 | ########################################################### | ||
| 715 | ########################################################### | ||
| 716 | ########################################################### | ||
| 717 | ########################################################### | ||
| 718 | ########################################################### | ||
| 719 | ########################################################### | ||
| 720 | ########################################################### | ||
| 721 | |||
| 722 | __DATA__ |