⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testsmcremoteserver.java

📁 UML for Java Programmers中文版源码
💻 JAVA
字号:
package com.objectmentor.SMCRemote.server;

import com.objectmentor.SMCRemote.transactions.CompileFileTransaction;
import com.objectmentor.SMCRemote.transactions.CompilerResultsTransaction;
import junit.framework.TestCase;
import junit.swingui.TestRunner;

import java.io.*;
import java.net.Socket;

public class TestSMCRemoteServer extends TestCase {
  public static void main(String[] args) {
    TestRunner.main(new String[]{"TestSMCRemoteServer"});
  }

  public TestSMCRemoteServer(String name) {
    super(name);
  }

  public void setUp() throws Exception {
  }

  public void tearDown() throws Exception {
  }

  public void testBuildCommand() throws Exception {
    assertEquals("BuildCommand",
                 "java -cp c:\\SMC\\smc.jar smc.Smc -f this that the other",
                 SMCRemoteServer.buildCommand(new String[]{"this",
                                                           "that",
                                                           "the",
                                                           "other"}));
  }

  public void testExecuteCommand() throws Exception {
    File smFile = new File("myFile.sm");
    File javaFile = new File("F.java");

    writeSourceFile(smFile);
    assertEquals("exitValue", 0, SMCRemoteServer.executeCommand("java -cp c:\\SMC\\smc.jar smc.Smc -f myFile.sm"));
    assertEquals("fileExists", true, javaFile.exists());
    assert("javaFile", javaFile.delete());
    assert("smFile", smFile.delete());
  }

  private void writeSourceFile(File smFile) throws IOException {
    PrintWriter w = new PrintWriter(new FileWriter(smFile));
    w.println("Context C");
    w.println("FSMName F");
    w.println("Initial I");
    w.println("{I{E I A}}");
    w.close();
  }

  public void testMakeTempDirectory() throws Exception {
    File f1 = SMCRemoteServer.makeTempDirectory();
    File f2 = SMCRemoteServer.makeTempDirectory();
    assertEquals("MakeTempDirectory", false, f1.getName().equals(f2.getName()));
    assert("f1",f1.delete());
    assert("f2",f2.delete());
  }

  public void testCompile() throws Exception {
    boolean javaFileExists = false;

    SMCRemoteServer server = new SMCRemoteServer(999);

    Socket client = new Socket("localhost", 999);
    ObjectInputStream is = new ObjectInputStream(client.getInputStream());
    ObjectOutputStream os = new ObjectOutputStream(client.getOutputStream());

    String headerLine = (String) is.readObject();
    assert("headerline", headerLine.startsWith("SMCR Server"));

    File sourceFile = new File("myFile.sm");
    writeSourceFile(sourceFile);

    CompileFileTransaction cft = new CompileFileTransaction(new String[]{"myFile.sm"});
    os.writeObject(cft);
    os.flush();
    CompilerResultsTransaction crt = (CompilerResultsTransaction) is.readObject();

    Thread.sleep(500);
    client.close();
    server.close();

    String filenames[] = crt.getFilenames();
    assertEquals("filenames", 1, filenames.length);
    assertEquals("F.java", "F.java", filenames[0]);

    crt.write();

    File javaFile = new File("F.java");
    assertEquals("Compile", true, javaFile.exists());
    javaFile.delete();
    sourceFile.delete();
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -