package som.tests;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

import som.VMOptions;


public class VMTests {

  @Test
  public void testProcessArgumentsNothing() {
    VMOptions opts = new VMOptions(new String[0]);
    assertEquals(opts.platformFile, VMOptions.STANDARD_PLATFORM_FILE);
    assertNull(opts.args);
  }

  @Test
  public void testProcessArgumentsWithPlatformFile() {
    VMOptions opts = new VMOptions(
        new String[] {"--platform", "foo.som"});
    assertEquals(opts.platformFile, "foo.som");
    assertNull(opts.args);
  }

  @Test
  public void testProcessArgumentsWithKernelFile() {
    VMOptions opts = new VMOptions(
        new String[] {"--kernel", "foo.som"});
    assertEquals(opts.kernelFile, "foo.som");
    assertNull(opts.args);
  }

  @Test
  public void testProcessArgumentsWithAppFile() {
    VMOptions opts = new VMOptions(
        new String[] {"app.som"});
    assertEquals(opts.platformFile, VMOptions.STANDARD_PLATFORM_FILE);
    assertArrayEquals(opts.args, new String[] {"app.som"});
  }

  @Test
  public void testProcessArgumentsWithAppFileAndArgs() {
    VMOptions opts = new VMOptions(
        new String[] {"app.som", "Foo", "1", "2"});
    assertEquals(opts.platformFile, VMOptions.STANDARD_PLATFORM_FILE);
    assertArrayEquals(opts.args, new String[] {"app.som", "Foo", "1", "2"});
  }

  @Test
  public void testProfileFlag() {
    VMOptions opts = new VMOptions(
        new String[] {"--profile"});
    assertEquals(opts.platformFile, VMOptions.STANDARD_PLATFORM_FILE);
    assertTrue(opts.profilingEnabled);
    assertFalse(opts.highlightingEnabled);
    assertNull(opts.args);
  }

  @Test
  public void testHighlightFlag() {
    VMOptions opts = new VMOptions(
        new String[] {"--highlight"});
    assertEquals(opts.platformFile, VMOptions.STANDARD_PLATFORM_FILE);
    assertTrue(opts.highlightingEnabled);
    assertFalse(opts.profilingEnabled);
    assertNull(opts.args);
  }

  @Test
  public void testDebugFlag() {
    VMOptions opts = new VMOptions(
        new String[] {"--debug"});
    assertEquals(opts.platformFile, VMOptions.STANDARD_PLATFORM_FILE);
    assertTrue(opts.debuggerEnabled);
    assertFalse(opts.profilingEnabled);
    assertNull(opts.args);
  }
}

@@ -285,16 +285,39 @@
 ptions;%0A
+import som.VmSettings;%0A
 %0A%0Apublic
@@ -1597,32 +1597,62 @@
 ProfileFlag() %7B%0A
+    enableInstrumentation();%0A%0A
     VMOptions op
@@ -1663,32 +1663,32 @@
  new VMOptions(%0A
-
         new Stri
@@ -1929,32 +1929,62 @@
 ghlightFlag() %7B%0A
+    enableInstrumentation();%0A%0A
     VMOptions op
@@ -2263,24 +2263,54 @@
 bugFlag() %7B%0A
+    enableInstrumentation();%0A%0A
     VMOption
@@ -2509,32 +2509,32 @@
 filingEnabled);%0A
-
     assertNull(o
@@ -2547,11 +2547,128 @@
 gs);%0A  %7D
+%0A%0A  public static void enableInstrumentation() %7B%0A    System.setProperty(VmSettings.INSTRUMENTATION_PROP, %22true%22);%0A  %7D
 %0A%7D%0A

Set instrumentation property to allow tests to pass