001package daikon.test.diff;
002
003import static java.util.logging.Level.INFO;
004import static org.junit.Assert.assertFalse;
005import static org.junit.Assert.assertTrue;
006
007import daikon.*;
008import daikon.diff.*;
009import daikon.inv.*;
010import java.lang.reflect.Method;
011import junit.framework.*;
012import org.junit.BeforeClass;
013import org.junit.Test;
014
015@SuppressWarnings("nullness") // testing code
016public class PrintDifferingInvariantsVisitorTester {
017
018  VarInfo[] vars = {
019    DiffTester.newIntVarInfo("x"), DiffTester.newIntVarInfo("y"), DiffTester.newIntVarInfo("z")
020  };
021
022  /** The program point that contains the test invariants. */
023  PptTopLevel ppt = new PptTopLevel("Foo:::OBJECT", vars);
024
025  /** The slice that contains the test invariants. */
026  PptSlice slice0 = ppt.joiner_view;
027
028  /** An invariant that is justified. */
029  Invariant null_1_just = new DiffDummyInvariant(slice0, "1", true);
030
031  /** An invariant that is justified but not worth printing. */
032  Invariant null_noprint = new DiffDummyInvariant(slice0, "0", true, false);
033
034  /** prepare for tests */
035  @BeforeClass
036  public static void setUpClass() {
037    daikon.LogHelper.setupLogs(INFO);
038    FileIO.new_decl_format = true;
039  }
040
041  @Test
042  public void testShouldPrint() throws Exception {
043    // Invoke private method using reflection
044    Method m =
045        PrintDifferingInvariantsVisitor.class.getDeclaredMethod(
046            "shouldPrint", new Class<?>[] {Invariant.class, Invariant.class});
047    m.setAccessible(true);
048
049    PrintDifferingInvariantsVisitor v = new PrintDifferingInvariantsVisitor(null, false, false);
050
051    Boolean b = (Boolean) m.invoke(v, new Object[] {null_noprint, null_noprint});
052    assertFalse(b.booleanValue());
053
054    b = (Boolean) m.invoke(v, new Object[] {null_1_just, null_noprint});
055    assertTrue(b.booleanValue());
056
057    b = (Boolean) m.invoke(v, new Object[] {null, null_noprint});
058    assertFalse(b.booleanValue());
059
060    b = (Boolean) m.invoke(v, new Object[] {null, null_1_just});
061    assertTrue(b.booleanValue());
062  }
063}