-
Notifications
You must be signed in to change notification settings - Fork 2
/
sequencediagramtester.cpp
173 lines (159 loc) · 5.38 KB
/
sequencediagramtester.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include "sequencediagramtester.h"
#include<vector>
#include "combinedfragment.h"
#include<iostream>
using namespace std;
SequenceDiagramTester::SequenceDiagramTester(SequenceDiagram sd)
{
//ctor
this->seq = sd.getStartNode();
}
int getPriority(int type)
{
switch(type)
{
case MESSAGE:
return MESSAGE_PRI;
case RETURN_MESSAGE:
return RETURN_MESSAGE_PRI;
case LOOP:
return LOOP_PRI;
case BREAK:
return BREAK_PRI;
case ALT:
return ALT_PRI;
case OPT:
return OPT_PRI;
default:
return 0;
}
}
void SequenceDiagramTester::duplicateElements(vector<TestSequence>& ts, int n)
{
vector<TestSequence> tmp;
for(unsigned int i=0; i<ts.size(); i++)
{
tmp.push_back(ts[i]);
}
for(unsigned int i =0; i<tmp.size(); i++)
{
TestSequence tmp_ts = tmp[i];
for(int j=0; j<n; j++)
{
ts.push_back(tmp_ts);
}
}
}
vector<TestSequence> SequenceDiagramTester::generate()
{
vector<TestSequence> TSList;
TestSequence temp;
TSList.push_back(temp);
this->generate(TSList);
return TSList;
}
void SequenceDiagramTester::generate(vector<TestSequence>& TSList)
{
Node nptr;
for(unsigned int x =0; x<(this->seq).size(); x++)
{
nptr = (this->seq)[x];
switch(nptr.getType())
{
case MESSAGE:
{
int tmp_pri = getPriority(nptr.getType());
Message tmp_msg = nptr.getmFrag();
for(unsigned i =0; i<TSList.size(); i++)
{
TSList[i].addMessage(tmp_msg);
TSList[i].incrementPriority(tmp_pri);
}
break;
}
case RETURN_MESSAGE:
break;
case LOOP:
case BREAK:
case ALT:
case OPT:
{
vector<TestSequence> tmp_TSList;
int ndup, beg;
if(nptr.getType()== ALT)
{
CombinedFragment alt_cf = nptr.getcFrag();
vector<TestSequence> tmp_tmp_TSList;
TestSequence tmp_ts;
vector<Node> alt_itr = (alt_cf.getStartNode());
for(int i=0,y=0; i<alt_cf.getNoOfPartitions(); i++)
{
vector<Node> alt_seq;
for(int j=0; j<alt_cf.getNoOfNodes(i); j++)
{
Node temp_node = alt_itr[y++];
alt_seq.push_back(temp_node);
}
SequenceDiagram alt_sd(alt_seq);
SequenceDiagramTester alt_sdt(alt_sd);
tmp_tmp_TSList = alt_sdt.generate();
vector<TestSequence> list_itr = tmp_tmp_TSList;
for(unsigned int z=0; z<list_itr.size();)
{
tmp_ts = list_itr[z++];
//list_itr++;
tmp_ts.incrementPriority(ALT_PRI * i);
if(i == (alt_cf.getNoOfPartitions()-1))
tmp_ts.decrementPriority(ALT_PRI);
tmp_TSList.push_back(tmp_ts);
}
}
ndup = tmp_TSList.size()-1;
beg =0;
}
else
{
CombinedFragment tmp_cf = nptr.getcFrag();
SequenceDiagram tmp_sd(tmp_cf.getStartNode());
SequenceDiagramTester tmp_sdt(tmp_sd);
tmp_TSList = tmp_sdt.generate();
ndup = tmp_TSList.size();
beg = TSList.size();
}
this->duplicateElements(TSList,ndup);
for(unsigned int i =0; i<TSList.size(); i++)
{
if(i<(unsigned)beg)
{
if(nptr.getType()== ALT)
{
CombinedFragment alt_cf = nptr.getcFrag();
int tmp_partition = alt_cf.getNoOfPartitions()-1;
TSList[i].incrementPriority(ALT_PRI * tmp_partition-1);
}
else
{
int tmp_prio = getPriority(nptr.getType());
TSList[i].incrementPriority(tmp_prio);
}
}
else
{
for(unsigned int j =0; j<tmp_TSList.size(); j++)
{
TSList[i].appendSequence(tmp_TSList[j]);
int tmp_prio = getPriority(nptr.getType());
TSList[i].incrementPriority(tmp_prio);
tmp_prio = tmp_TSList[j].getPriority();
TSList[i].incrementPriority(tmp_prio);
i++;
}
if(tmp_TSList.size() > 0)
i--;
}
}
break;
}
}
}
}