source: branches/dev-5819/Compiler/TestFramework/src/jastadd/CodeGenTestCase.jrag @ 13800

Last change on this file since 13800 was 13800, checked in by randersson, 6 weeks ago

#5819 Merged trunk into branch

File size: 2.5 KB
Line 
1/*
2    Copyright (C) 2009 Modelon AB
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, version 3 of the License.
7
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12
13    You should have received a copy of the GNU General Public License
14    along with this program.  If not, see <http://www.gnu.org/licenses/>.
15*/
16
17
18
19import java.io.BufferedReader;
20import java.io.PrintStream;
21import java.io.OutputStream;
22import java.io.StringReader;
23import java.io.ByteArrayOutputStream;
24import java.util.Collection;
25
26public abstract class CodeGenTestCase extends TestCase {
27    private String genCode = null;
28    private String template = null;
29
30    public abstract AbstractGenerator createGenerator(FClass fc);
31
32    /**
33     * Perform tests on flat class after transform canonical step.
34     *
35     * @return  <code>true</code> if test case shoule stop after this method
36     */
37    protected boolean testTransformed(FClass fc) {
38        ByteArrayOutputStream os = new ByteArrayOutputStream();
39        PrintStream ps = CodeStream.createPrintStream(os, options.getBooleanOption("debug_duplicate_generated"));
40        AbstractGenerator generator = createGenerator(fc);
41        generator.generate(createTemplateReader(), new UnitTestCodeStream(ps));
42        String test = os.toString();
43        String correct = filter(getGeneratedCode());
44       
45        GUIDManager guidManager = fc.guidManager();
46        ByteArrayOutputStream actual = new ByteArrayOutputStream();
47        guidManager.setSourceString(test);
48        guidManager.addDependentString(test, actual);
49        guidManager.processDependentFiles();
50       
51        compareResult("Generated code does not match expected.", correct, actual.toString());
52        return true;
53    }
54
55    public String getGeneratedCode() {
56        return genCode;
57    }
58
59    public void setGeneratedCode(String genCode) {
60        this.genCode = genCode;
61    }
62
63    public String getTemplate() {
64        return template;
65    }
66
67    public void setTemplate(String template) {
68        this.template = template;
69    }
70
71    public Reader createTemplateReader() {
72        return (template == null) ? null : new BufferedReader(new StringReader(getTemplate()));
73    }
74
75}
Note: See TracBrowser for help on using the repository browser.