//
// Copyright (C) 2012 United States Government as represented by the
// Administrator of the National Aeronautics and Space Administration
// (NASA). All Rights Reserved.
//
// This software is distributed under the NASA Open Source Agreement
// (NOSA), version 1.3. The NOSA has been approved by the Open Source
// Initiative. See the file NOSA-1.3-JPF at the top of the distribution
// directory tree for the complete NOSA document.
//
// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
//
package gov.nasa.jpf.conformanceChecker.checkers;
import static gov.nasa.jpf.conformanceChecker.util.MaybeVersion.*;
import static gov.nasa.jpf.conformanceChecker.util.MockFactory.*;
import static java.lang.reflect.Modifier.*;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
import gov.nasa.jpf.conformanceChecker.Inconsistency.InconsistencyType;
import gov.nasa.jpf.conformanceChecker.providers.ProviderFactory;
import gov.nasa.jpf.conformanceChecker.providers.StandardClassProvider;
import gov.nasa.jpf.conformanceChecker.util.MaybeVersion;
import gov.nasa.jpf.jvm.ClassInfo;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
/**
* @author Matteo Ceccarello <matteo.ceccarello AT gmail.com>
*
*/
public class StateCheckerTest {
static class TestStateCheckerImpl extends StateChecker {
@Override
protected InconsistencyType getInconsistencyType() {
return InconsistencyType.INCONSISTENT_CLASS_STATE;
}
@Override
public boolean check(ClassInfo cls) {
throw new UnsupportedOperationException();
}
}
@Test
public void testSuccess1() {
ClassInfo model =
cls("java.lang.Object",
field(PUBLIC, "java.lang.String", "toString"),
field(PROTECTED, "java.lang.String", "name"),
field(PRIVATE, "java.lang.String", "other")
);
ClassInfo standard =
cls("java.lang.Object",
field(PUBLIC, "java.lang.String", "toString"),
field(PROTECTED, "java.lang.String", "name"),
field(PRIVATE, "java.lang.String", "other")
);
Map<MaybeVersion, ClassInfo> versions = new HashMap<MaybeVersion, ClassInfo>();
versions.put(just(6), standard);
StandardClassProvider provider = createMock(StandardClassProvider.class);
expect(provider.loadClassInfo("java.lang.Object")).andReturn(versions);
replay(provider);
ProviderFactory.setStandardProvider(provider);
StateChecker checker = new TestStateCheckerImpl();
assertTrue(checker.compareArraysFast(
model.getDeclaredInstanceFields(), standard.getDeclaredInstanceFields(), just(6)));
}
@Test
public void testSuccess2() {
ClassInfo model =
cls("java.lang.Object",
field(PUBLIC | STATIC, "java.lang.String", "toString"),
field(PROTECTED | STATIC, "java.lang.String", "name"),
field(PRIVATE, "java.lang.String", "other")
);
ClassInfo standard =
cls("java.lang.Object",
field(PUBLIC | STATIC, "java.lang.String", "toString"),
field(PROTECTED |STATIC, "java.lang.String", "name"),
field(PRIVATE, "java.lang.String", "other")
);
Map<MaybeVersion, ClassInfo> versions = new HashMap<MaybeVersion, ClassInfo>();
versions.put(just(6), standard);
StandardClassProvider provider = createMock(StandardClassProvider.class);
expect(provider.loadClassInfo("java.lang.Object")).andReturn(versions);
replay(provider);
ProviderFactory.setStandardProvider(provider);
StateChecker checker = new TestStateCheckerImpl();
assertTrue(checker.compareArraysFast(
model.getDeclaredStaticFields(), standard.getDeclaredStaticFields(), just(6)));
}
@Test
public void testFailure1() {
ClassInfo model =
cls("java.lang.Object",
field(PUBLIC, "java.lang.String", "toString"),
field(PROTECTED, "java.lang.String", "name"),
field(PRIVATE, "java.lang.String", "otherWrong")
);
ClassInfo standard =
cls("java.lang.Object",
field(PUBLIC, "java.lang.String", "toString"),
field(PROTECTED, "java.lang.String", "name"),
field(PRIVATE, "java.lang.String", "other")
);
Map<MaybeVersion, ClassInfo> versions = new HashMap<MaybeVersion, ClassInfo>();
versions.put(just(6), standard);
StandardClassProvider provider = createMock(StandardClassProvider.class);
expect(provider.loadClassInfo("java.lang.Object")).andReturn(versions);
replay(provider);
ProviderFactory.setStandardProvider(provider);
StateChecker checker = new TestStateCheckerImpl();
assertFalse(checker.compareArraysFast(
model.getDeclaredInstanceFields(), standard.getDeclaredInstanceFields(), just(6)));
}
}