Package: SpecificationTestBase$1

SpecificationTestBase$1

nameinstructionbranchcomplexitylinemethod
{...}
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: package org.overture.codegen.tests.output.util;
2:
3: import java.io.FileNotFoundException;
4: import java.io.IOException;
5: import java.lang.reflect.Type;
6: import java.util.List;
7:
8: import org.junit.Assert;
9: import org.overture.ast.analysis.AnalysisException;
10: import org.overture.ast.node.INode;
11: import org.overture.codegen.analysis.violations.InvalidNamesResult;
12: import org.overture.codegen.ir.IRSettings;
13: import org.overture.codegen.utils.GeneralCodeGenUtils;
14: import org.overture.codegen.utils.GeneratedData;
15: import org.overture.codegen.utils.GeneratedModule;
16: import org.overture.core.testing.ParamStandardTest;
17: import org.overture.parser.lex.LexException;
18: import org.overture.parser.syntax.ParserException;
19:
20: import com.google.gson.reflect.TypeToken;
21:
22: public abstract class SpecificationTestBase extends ParamStandardTest<String>
23: {
24:         protected static final String LINE_SEPARATOR = System.getProperty("line.separator");
25:         protected static final String QUOTE_SEPARATOR = ",";
26:         protected static final String MODULE_DELIMITER = LINE_SEPARATOR
27:                         + "##########" + LINE_SEPARATOR;
28:         protected static final String NAME_VIOLATION_INDICATOR = "*Name Violations*";
29:         protected static final String QUOTE_INDICATOR = "*Quotes*";
30:
31:         public SpecificationTestBase(String nameParameter, String inputParameter,
32:                         String resultParameter)
33:         {
34:                 super(nameParameter, inputParameter, resultParameter);
35:         }
36:
37:         public IRSettings getIrSettings()
38:         {
39:                 IRSettings irSettings = new IRSettings();
40:                 irSettings.setCharSeqAsString(false);
41:
42:                 return irSettings;
43:         }
44:
45:         @Override
46:         public String processModel(List<INode> ast)
47:         {
48:                 try
49:                 {
50:                         StringBuilder generatedCode = new StringBuilder();
51:                         GeneratedData data = genCode(ast);
52:                         List<GeneratedModule> classes = data.getClasses();
53:
54:                         for (GeneratedModule classCg : classes)
55:                         {
56:                                 generatedCode.append(classCg.getContent());
57:                                 generatedCode.append(MODULE_DELIMITER);
58:                         }
59:
60:                         List<GeneratedModule> quoteData = data.getQuoteValues();
61:
62:                         if (quoteData != null && !quoteData.isEmpty())
63:                         {
64:                                 generatedCode.append(QUOTE_INDICATOR + LINE_SEPARATOR);
65:                                 for (int i = 0; i < quoteData.size(); i++)
66:                                 {
67:                                         GeneratedModule q = quoteData.get(i);
68:
69:                                         generatedCode.append(q.getName());
70:
71:                                         if (i + 1 < quoteData.size())
72:                                         {
73:                                                 generatedCode.append(QUOTE_SEPARATOR);
74:                                         }
75:
76:                                 }
77:                                 generatedCode.append(MODULE_DELIMITER);
78:                         }
79:
80:                         InvalidNamesResult invalidNames = data.getInvalidNamesResult();
81:
82:                         if (invalidNames != null && !invalidNames.isEmpty())
83:                         {
84:                                 generatedCode.append(NAME_VIOLATION_INDICATOR + LINE_SEPARATOR);
85:                                 generatedCode.append(LINE_SEPARATOR
86:                                                 + GeneralCodeGenUtils.constructNameViolationsString(invalidNames));
87:                                 generatedCode.append(MODULE_DELIMITER);
88:                         }
89:
90:                         return generatedCode.toString();
91:
92:                 } catch (AnalysisException e)
93:                 {
94:                         Assert.fail("Unexpected problem encountered when attempting to code generate VDM model: "
95:                                         + e.getMessage());
96:                         e.printStackTrace();
97:                         return null;
98:                 }
99:         }
100:
101:         abstract public GeneratedData genCode(List<INode> ast)
102:                         throws AnalysisException;
103:
104:         @Override
105:         public Type getResultType()
106:         {
107:                 Type resultType = new TypeToken<String>()
108:                 {
109:                 }.getType();
110:                 return resultType;
111:         }
112:
113:         @Override
114:         public void compareResults(String actual, String expected)
115:         {
116:                 OutputTestUtil.compare(expected, actual);
117:         }
118:
119:         @Override
120:         public String deSerializeResult(String resultPath)
121:                         throws FileNotFoundException, IOException
122:         {
123:                 return OutputTestUtil.deSerialize(resultPath);
124:         }
125:
126:         @Override
127:         protected void testUpdate(String actual)
128:                         throws ParserException, LexException, IOException
129:         {
130:                 OutputTestUtil.testUpdate(actual, resultPath);
131:         }
132:
133:         @Override
134:         protected boolean updateCheck()
135:         {
136:                 if (frameworkUpdateCheck())
137:                 {
138:                         return true;
139:                 }
140:
141:                 if (System.getProperty(OutputTestUtil.UPDATE_ALL_OUTPUT_TESTS_PROPERTY) != null)
142:                 {
143:                         return true;
144:                 }
145:
146:                 return false;
147:         }
148:
149:         public boolean frameworkUpdateCheck()
150:         {
151:                 return super.updateCheck();
152:         }
153:
154:         protected abstract String getUpdatePropertyString();
155: }