Пример #1
0
  @Test
  public void testReadConfig() throws FileNotFoundException {
    printlnMethodName();

    final Map<Integer, IJVMCommand> expected = new HashMap<Integer, IJVMCommand>();
    expected.put(0x00, new IJVMCommand("NOP"));
    expected.put(0x10, new IJVMCommand("BIPUSH", IJVMCommandArgument.BYTE));
    expected.put(0x13, new IJVMCommand("LDC_W", IJVMCommandArgument.INDEX));
    expected.put(0x15, new IJVMCommand("ILOAD", IJVMCommandArgument.VARNUM));
    expected.put(0x36, new IJVMCommand("ISTORE", IJVMCommandArgument.VARNUM));
    expected.put(0x57, new IJVMCommand("POP"));
    expected.put(0x59, new IJVMCommand("DUP"));
    expected.put(0x5F, new IJVMCommand("SWAP"));
    expected.put(0x60, new IJVMCommand("IADD"));
    expected.put(0x64, new IJVMCommand("ISUB"));
    expected.put(0x7E, new IJVMCommand("IAND"));
    expected.put(0x80, new IJVMCommand("IOR"));
    expected.put(
        0x84, new IJVMCommand("IINC", IJVMCommandArgument.VARNUM, IJVMCommandArgument.CONST));
    expected.put(0x99, new IJVMCommand("IFEQ", IJVMCommandArgument.LABEL));
    expected.put(0x9B, new IJVMCommand("IFLT", IJVMCommandArgument.LABEL));
    expected.put(0x9F, new IJVMCommand("IF_ICMPEQ", IJVMCommandArgument.LABEL));
    expected.put(0xA7, new IJVMCommand("GOTO", IJVMCommandArgument.LABEL));
    expected.put(0xAC, new IJVMCommand("IRETURN"));
    expected.put(0xB6, new IJVMCommand("INVOKEVIRTUAL", IJVMCommandArgument.OFFSET));
    expected.put(0xC4, new IJVMCommand("WIDE"));
    expected.put(0xF0, new IJVMCommand("SRA1"));
    expected.put(0xF1, new IJVMCommand("SLL8"));
    expected.put(0xFC, new IJVMCommand("IN"));
    expected.put(0xFD, new IJVMCommand("OUT"));
    expected.put(0xFE, new IJVMCommand("ERR"));
    expected.put(0xFF, new IJVMCommand("HALT"));
    assertThat(READER.readConfig(getClass().getClassLoader().getResourceAsStream("ijvm.conf")))
        .isEqualTo(expected);
  }
Пример #2
0
  @Test
  public void testReadConfig_SingleLine() {
    printlnMethodName();

    final Map<Integer, IJVMCommand> expected = new HashMap<Integer, IJVMCommand>();
    expected.put(16, new IJVMCommand("BIPUSH", IJVMCommandArgument.BYTE));
    assertThat(
            READER.readConfig(
                new ByteArrayInputStream("0x10 BIPUSH byte // Push byte onto stack".getBytes())))
        .isEqualTo(expected);
    assertThat(
            READER.readConfig(
                new ByteArrayInputStream("0x10 BIPUSH byte// Push byte onto stack".getBytes())))
        .isEqualTo(expected);
    assertThat(READER.readConfig(new ByteArrayInputStream("0x10 BIPUSH byte".getBytes())))
        .isEqualTo(expected);
  }
Пример #3
0
 @Test
 public void testReadConfig_Empty_OnlyComments() {
   printlnMethodName();
   assertThat(
           READER.readConfig(
               new ByteArrayInputStream(" // nothing\n\n//also empty here".getBytes())))
       .isEmpty();
 }
Пример #4
0
 @Test
 public void testReadConfig_Empty_LineDoesntMatchRegex() {
   printlnMethodName();
   assertThat(READER.readConfig(new ByteArrayInputStream("xyz? What is that?".getBytes())))
       .isEmpty();
 }
Пример #5
0
 @Test
 public void testReadConfig_Empty_Null() {
   printlnMethodName();
   assertThat(READER.readConfig(null)).isEmpty();
 }
Пример #6
0
 @Test
 public void testReadConfig_Empty_EmptyFile() {
   printlnMethodName();
   assertThat(READER.readConfig(new ByteArrayInputStream("".getBytes()))).isEmpty();
 }