1<?php
2/**
3 * Main code for test case generation
4 */
5
6require_once dirname(__FILE__) . '/gtAutoload.php';
7
8//Version check. Will not run on less than PHP53;
9
10list($major, $minor, $bug) = explode(".", phpversion(), 3);
11 if($major == 5) {
12       if($minor < 3) { die("Sorry, you need PHP version 5.3 or greater to run this.\n"); }
13   }
14   if ($major < 5) { die ("Seriously, you need to upgrade you PHP level\n"); }
15
16
17$options = new gtCommandLineOptions();
18$optionalSections = new gtOptionalSections();
19
20try{
21  $options->parse($argv);
22} catch (exception $e) {
23  echo $e->getMessage()."\n";
24  die();
25}
26
27if($options->hasOption('h')) {
28  die(gtText::get('help'));
29}
30
31try {
32  $preConditions = new gtPreConditionList();
33  $preConditions->check($options);
34} catch (exception $e) {
35  echo $e->getMessage()."\n";
36  die();
37}
38
39if($options->hasOption('s')) {
40  $optionalSections->setOptions($options);
41}
42
43
44
45if($options->hasOption('c')) {
46  $name = $options->getOption('c')."_".$options->getOption('m');
47  $method = new gtMethod($options->getOption('c'), $options->getOption('m'));
48
49  $method->setArgumentNames();
50  $method->setArgumentLists();
51  $method->setInitialisationStatements();
52
53  $method->setConstructorArgumentNames();
54  $method->setConstructorInitStatements();
55  $method->setConstructorArgumentList();
56}
57
58if($options->hasOption('f')) {
59  $name = $options->getOption('f');
60  $function = new gtFunction($name);
61  $function->setArgumentNames();
62  $function->setArgumentLists();
63  $function->setInitialisationStatements();
64}
65
66
67if($options->hasOption('b')) {
68  if($options->hasOption('c')) {
69    $testCase = gtBasicTestCase::getInstance($optionalSections, 'method');
70    $testCase->setMethod($method);
71  } else {
72    $testCase = gtBasicTestCase::getInstance($optionalSections);
73    $testCase->setFunction($function);
74  }
75
76  $testCase->constructTestCase();
77  gtTestCaseWriter::write($name, $testCase->toString(), 'b');
78}
79
80if($options->hasOption('e')) {
81  if($options->hasOption('c')) {
82    $testCase = gtErrorTestCase::getInstance($optionalSections, 'method');
83    $testCase->setMethod($method);
84  } else {
85    $testCase = gtErrorTestCase::getInstance($optionalSections);
86    $testCase->setFunction($function);
87  }
88
89  $testCase->constructTestCase();
90  gtTestCaseWriter::write($name, $testCase->toString(), 'e');
91}
92
93
94
95if($options->hasOption('v')) {
96  if($options->hasOption('c')) {
97    $testCaseContainer = gtVariationContainer::getInstance($optionalSections, 'method');
98    $testCaseContainer->setMethod($method);
99  } else {
100    $testCaseContainer = gtVariationContainer::getInstance ($optionalSections);
101    $testCaseContainer->setFunction($function);
102  }
103
104  $testCaseContainer->constructAll();
105
106  $tests = $testCaseContainer->getVariationTests();
107
108  $count = 1;
109  foreach($tests as $test) {
110    gtTestCaseWriter::write($name, $test, 'v', $count);
111    $count++;
112  }
113
114}
115?>
116