<html>
<head>
<style><!--
  body {background-color:#ffffff;}
  .file {border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em;}
  .pathname {font-family:monospace; float:right;}
  .fileheader {margin-bottom:.5em;}
  .diff {margin:0;}
  .tasklist {padding:4px;border:1px dashed #000000;margin-top:1em;}
  .tasklist ul {margin-top:0;margin-bottom:0;}
  tr.alt {background-color:#eeeeee}
  #added {background-color:#ddffdd;}
  #addedchars {background-color:#99ff99;font-weight:bolder;}
  tr.alt #added {background-color:#ccf7cc;}
  #removed {background-color:#ffdddd;}
  #removedchars {background-color:#ff9999;font-weight:bolder;}
  tr.alt #removed {background-color:#f7cccc;}
  #copied {background-color:#ccccff;}
  tr.alt #copied {background-color:#bbbbf7;}
  #info {color:#888888;}
  #context {background-color:#eeeeee;}
  td {padding-left:.3em;padding-right:.3em;}
  tr.head {border-bottom-width:1px;border-bottom-style:solid;}
  tr.head td {padding:0;padding-top:.2em;}
  .task {background-color:#ffff00;}
  .comment {white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;padding:4px;border:1px dashed #000000;background-color:#ffffdd}
  .error {color:red;}
  hr {border-width:0px;height:2px;background:black;}
--></style>
</head>
<body>
<table cellspacing="0" cellpadding="0" border="0" rules="cols">
<tr class="head"><td colspan="5">Commit in <b><tt>asxsd/trunk/src/test/java/uk/co/badgersinfoil/asxsd/schemas</tt></b></td></tr>
<tr><td><tt><a href="#file1">SchemaTestCase.java</a></tt> </td><td></td><td align="right" id="added">+95</td><td align="right" id="removed">-4</td><td nowrap="nowrap" align="center">159 -&gt; 160</td></tr>
</table>
<div class="tasklist"><ul>
<li><a href="#task1">TODO: finish staring at javap output to work out how to invoke the compiler directly</a></li>
<li><a href="#task2">TODO Auto-generated method stub</a></li>
</ul></div>
<pre class="comment">
further assert correctness of generated code by trying to compile it
</pre>
<hr /><a name="file1" /><div class="file">
<span class="pathname">asxsd/trunk/src/test/java/uk/co/badgersinfoil/asxsd/schemas</span><br />
<div class="fileheader"><big><b>SchemaTestCase.java</b></big> <small id="info">159 -&gt; 160</small></div>
<pre class="diff"><small id="info">--- trunk/src/test/java/uk/co/badgersinfoil/asxsd/schemas/SchemaTestCase.java        2007-10-07 01:03:06 UTC (rev 159)
+++ trunk/src/test/java/uk/co/badgersinfoil/asxsd/schemas/SchemaTestCase.java        2007-10-07 20:24:49 UTC (rev 160)
@@ -1,7 +1,9 @@
</small></pre><pre class="diff" id="context"> package uk.co.badgersinfoil.asxsd.schemas;
 
</pre><pre class="diff" id="added">+import java.io.ByteArrayOutputStream;
+import java.io.File;
</pre><pre class="diff" id="context"> import java.io.IOException;
</pre><pre class="diff" id="removed">-import java.io.OutputStreamWriter;
</pre><pre class="diff" id="added">+import java.io.InputStream;
</pre><pre class="diff" id="context"> import java.net.URL;
 import java.util.Iterator;
 import java.util.List;
</pre><pre class="diff"><small id="info">@@ -25,18 +27,107 @@
</small></pre><pre class="diff" id="context">         static {
                 Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xsd", new XSDResourceFactoryImpl());
         }
</pre><pre class="diff" id="removed">-        
</pre><pre class="diff" id="added">+
+        private File tmpDir;
</pre><pre class="diff" id="context">         protected ActionScriptProject project;
         protected ActionScriptFactory fact = new ActionScriptFactory();
</pre><pre class="diff" id="removed">-        
</pre><pre class="diff" id="added">+
</pre><pre class="diff" id="context">         protected void setUp() throws IOException {
</pre><pre class="diff" id="added">+                tmpDir = new File(System.getProperty("java.io.tmpdir"), "asxsd-schema-test");
+                tmpDir.mkdir();
</pre><pre class="diff" id="context">                 String cname = getClass().getName();
                 cname = cname.substring(cname.lastIndexOf('.')+1);
                 project = processSchema(cname);
         }
 
</pre><pre class="diff" id="added">+        public void tearDown() throws Exception {
+                try {
+                        try {
+                                project.performAutoImport();
+                                project.writeAll();
+                                assertCompilable(tmpDir);
+                        } finally {
+                                rmdir(tmpDir);
+                        }
+                } catch (IOException e) {
+                        e.printStackTrace();
+                }
+        }
+
+        private static void assertCompilable(File srcDir) throws Exception {
<a name="task1" />+/*                <span class="task">TODO</span>: finish staring at javap output to work out how to invoke the compiler directly
+
+                CompilerConfiguration compConf = new CompilerConfiguration();
+                CompcConfiguration compcConf = new CompcConfiguration();
+                LicensesConfiguration licensesConf = compcConf.getLicensesConfiguration();
+                List[] virtualFiles = API.getVirtualFileList(paths, mimetypes, list);
+                CompilerSwcContext swcContext = new CompilerSwcContext();
+
+                FileSpec fileSpec = new FileSpec(new ArrayList(), new String[0]);
+                SourceList sourceList = new SourceList(virtualFiles[0],
+                                                       compConf.getSourcePath(),
+                                                       null,
+                                                       flex2.tools.API.getSourcePathMimeTypes(),
+                                                       false);
+                Collection classes;
+                List sources = new ArrayList();
+                API.compile(fileSpec,
+                            sourceList,
+                            classes,
+                            sourcePath,
+                            resources,
+                            bundlePath,
+                            swcContext,
+                            configuration,
+                            compilers,
+                            preLink,
+                            licensesConf.getLicenseMap(),
+                            sources);
+*/
+                String flexHome = System.getProperty("flex.home");
+                if (flexHome == null) {
+                        System.err.println("Property flex.home not defined; will not attempt to check code compiles");
+                        return;
+                }
+                File flexBin = new File(flexHome, "bin");
+                File compc = new File(flexBin, "compc");
+                if (!compc.exists()) {
+                        fail(compc+" does not exist");
+                }
+                ProcessBuilder procBuild = new ProcessBuilder(new String[] {
+                        compc.getPath(),
+                        "-output=test.swc",
+                        "-compiler.source-path=.",
+                        "-compiler.optimize=false",  // faster compilation?
+                        "org.example.test.Marshaler",
+                        "org.example.test.Unmarshaler"
+                });
+                procBuild.directory(srcDir);
+                procBuild.redirectErrorStream(true);
+                Process compile = procBuild.start();
+                byte[] compilerOutput = grabOutput(compile);
+                if (compile.waitFor() != 0) {
+                        fail(new String(compilerOutput));
+                }
+        }
+
+        private static byte[] grabOutput(Process compile) throws IOException {
+                InputStream in = compile.getInputStream();
+                ByteArrayOutputStream output = new ByteArrayOutputStream();
+                byte[] buf = new byte[1024];
+                int c;
+                while ((c = in.read(buf)) &gt; 0) {
+                        output.write(buf, 0, c);
+                }
+                return output.toByteArray();
+        }
+
+        private static void rmdir(File dir) throws IOException {
<a name="task2" />+                // <span class="task">TODO</span> Auto-generated method stub
+        }
+
</pre><pre class="diff" id="context">         private ActionScriptProject processSchema(String fileNameFragment) throws IOException {
</pre><pre class="diff" id="removed">-                ActionScriptProject project = fact.newEmptyASProject(<span id="removedchars">"."</span>);
</pre><pre class="diff" id="added">+                ActionScriptProject project = fact.newEmptyASProject(<span id="addedchars">tmpDir.getPath()</span>);
</pre><pre class="diff" id="context">                 MappingCodeGenerator generator  = new MappingCodeGenerator(fact, project);
                 XSDSchema schema = loadTestSchemaResource(fileNameFragment);
                 generator.processSchema(schema);
</pre></div>
<center><small><a href="http://www.badgers-in-foil.co.uk/projects/cvsspam/" title="commit -&gt; email">CVSspam</a> 0.2.12</small></center>
</body></html>