Beispiel #1
0
 public void testKbdInputBuffer() throws Exception {
   Application app = new Application(null, null, null);
   app.setKbd("3 45 67");
   assertEquals(app.readNextFromKbd(), 3);
   assertEquals(app.readNextFromKbd(), 45);
   assertEquals(app.readNextFromKbd(), 67);
   try {
     app.readNextFromKbd();
     fail("Should have thrown an exception now: no more data.");
   } catch (TTK91NoKbdData err) {
   }
   app.setKbd("-3 ;: 6;:\n\r\n7");
   assertEquals(app.readNextFromKbd(), -3);
   assertEquals(app.readNextFromKbd(), 6);
   assertEquals(app.readNextFromKbd(), 7);
   try {
     app.readNextFromKbd();
     fail("Should have thrown an exception now: no more data.");
   } catch (TTK91NoKbdData err) {
   }
   try {
     app.setKbd("-3 5 a");
     fail("Should have thrown an exception now: invalid input.");
   } catch (IllegalArgumentException err) {
   }
 }
Beispiel #2
0
  public void testConstructor() {
    class __stub_memoryline extends MemoryLine {
      public __stub_memoryline() {
        super(1, "foo");
      }

      public int getBinary() {
        return 60;
      }
    }

    Application app;
    // The stub_memorylines always return 60 for their getBinary().
    __stub_memoryline[] foo = {new __stub_memoryline()};
    // Null variables should be replaced by empty actual variables
    // by the application.
    app = new Application(null, null, null);
    assertEquals(app.getCode().length, 0);
    assertEquals(app.getInitialData().length, 0);
    assertTrue(app.getSymbolTable() != null);
    // Then try one which has content.
    app = new Application(foo, foo, new SymbolTable());
    assertEquals("One-length code area", app.getCode().length, 1);
    assertEquals(app.getCode()[0].getBinary(), 60);
    assertEquals("One-length data area", app.getInitialData().length, 1);
    assertEquals(app.getInitialData()[0].getBinary(), 60);
    assertTrue(app.getSymbolTable() != null);
  }
Beispiel #3
0
 public void testInputCheck() {
   assertTrue(Application.checkInput("3 45 67"));
   assertTrue(Application.checkInput("-3 ;: 6;:\n\r\n7"));
   assertTrue(!Application.checkInput("-3 5 a"));
 }
Beispiel #4
0
 public void testWrites() {
   Application app;
   app = new Application(null, null, null);
   // STDOUT writing.
   assertEquals(app.readStdOut(), "");
   app.writeToStdOut(30);
   app.writeToStdOut(3);
   assertEquals(
       "App read",
       app.readStdOut(),
       "30"
           + System.getProperty("line.separator", "\n")
           + "3"
           + System.getProperty("line.separator", "\n"));
   // The read should also have emptied the buffer.
   assertEquals(app.readStdOut(), "");
   // CRT writing.
   assertEquals(app.readCrt(), "");
   app.writeToCrt(42);
   app.writeToCrt(4);
   assertEquals(
       "Crt read",
       app.readCrt(),
       "42"
           + System.getProperty("line.separator", "\n")
           + "4"
           + System.getProperty("line.separator", "\n"));
   assertEquals(app.readCrt(), "");
 }