use of junit.framework.AssertionFailedError in project robovm by robovm.
the class SerializationTester method test.
public void test() {
try {
if (golden == null || golden.length() == 0) {
fail("No golden value supplied! Consider using this: " + hexEncode(serialize(value)));
}
// deserialize should return the proper type
@SuppressWarnings("unchecked") T deserialized = (T) deserialize(hexDecode(golden));
assertTrue("User-constructed value doesn't equal deserialized golden value", equals(value, deserialized));
// deserialize should return the proper type
@SuppressWarnings("unchecked") T reserialized = (T) deserialize(serialize(value));
assertTrue("User-constructed value doesn't equal itself, reserialized", equals(value, reserialized));
// just a sanity check! if this fails, verify() is probably broken
verify(value);
verify(deserialized);
verify(reserialized);
} catch (Exception e) {
Error failure = new AssertionFailedError();
failure.initCause(e);
throw failure;
}
}
use of junit.framework.AssertionFailedError in project platform_frameworks_base by android.
the class Camera2RecordingTest method videoSnapshotTestByCamera.
/**
* Test video snapshot for each available CamcorderProfile for a given camera.
*
* <p>
* Preview size is set to the video size. For the burst test, frame drop and jittering
* is not checked.
* </p>
*
* @param burstTest Perform burst capture or single capture. For burst capture
* {@value #BURST_VIDEO_SNAPSHOT_NUM} capture requests will be sent.
*/
private void videoSnapshotTestByCamera(boolean burstTest) throws Exception {
final int NUM_SINGLE_SHOT_TEST = 5;
final int FRAMEDROP_TOLERANCE = 8;
final int FRAME_SIZE_15M = 15000000;
final float FRAME_DROP_TOLERENCE_FACTOR = 1.5f;
int kFrameDrop_Tolerence = FRAMEDROP_TOLERANCE;
for (int profileId : mCamcorderProfileList) {
int cameraId = Integer.parseInt(mCamera.getId());
if (!CamcorderProfile.hasProfile(cameraId, profileId) || allowedUnsupported(cameraId, profileId)) {
continue;
}
CamcorderProfile profile = CamcorderProfile.get(cameraId, profileId);
Size videoSz = new Size(profile.videoFrameWidth, profile.videoFrameHeight);
Size maxPreviewSize = mOrderedPreviewSizes.get(0);
if (mStaticInfo.isHardwareLevelLegacy() && (videoSz.getWidth() > maxPreviewSize.getWidth() || videoSz.getHeight() > maxPreviewSize.getHeight())) {
// Skip. Legacy mode can only do recording up to max preview size
continue;
}
if (!mSupportedVideoSizes.contains(videoSz)) {
mCollector.addMessage("Video size " + videoSz.toString() + " for profile ID " + profileId + " must be one of the camera device supported video size!");
continue;
}
// For LEGACY, find closest supported smaller or equal JPEG size to the current video
// size; if no size is smaller than the video, pick the smallest JPEG size. The assert
// for video size above guarantees that for LIMITED or FULL, we select videoSz here.
// Also check for minFrameDuration here to make sure jpeg stream won't slow down
// video capture
Size videoSnapshotSz = mOrderedStillSizes.get(mOrderedStillSizes.size() - 1);
// Allow a bit tolerance so we don't fail for a few nano seconds of difference
final float FRAME_DURATION_TOLERANCE = 0.01f;
long videoFrameDuration = (long) (1e9 / profile.videoFrameRate * (1.0 + FRAME_DURATION_TOLERANCE));
HashMap<Size, Long> minFrameDurationMap = mStaticInfo.getAvailableMinFrameDurationsForFormatChecked(ImageFormat.JPEG);
for (int i = mOrderedStillSizes.size() - 2; i >= 0; i--) {
Size candidateSize = mOrderedStillSizes.get(i);
if (mStaticInfo.isHardwareLevelLegacy()) {
// Legacy level doesn't report min frame duration
if (candidateSize.getWidth() <= videoSz.getWidth() && candidateSize.getHeight() <= videoSz.getHeight()) {
videoSnapshotSz = candidateSize;
}
} else {
Long jpegFrameDuration = minFrameDurationMap.get(candidateSize);
assertTrue("Cannot find minimum frame duration for jpeg size " + candidateSize, jpegFrameDuration != null);
if (candidateSize.getWidth() <= videoSz.getWidth() && candidateSize.getHeight() <= videoSz.getHeight() && jpegFrameDuration <= videoFrameDuration) {
videoSnapshotSz = candidateSize;
}
}
}
/**
* Only test full res snapshot when below conditions are all true.
* 1. Camera is a FULL device
* 2. video size is up to max preview size, which will be bounded by 1080p.
* 3. Full resolution jpeg stream can keep up to video stream speed.
* When full res jpeg stream cannot keep up to video stream speed, search
* the largest jpeg size that can susptain video speed instead.
*/
if (mStaticInfo.isHardwareLevelFull() && videoSz.getWidth() <= maxPreviewSize.getWidth() && videoSz.getHeight() <= maxPreviewSize.getHeight()) {
for (Size jpegSize : mOrderedStillSizes) {
Long jpegFrameDuration = minFrameDurationMap.get(jpegSize);
assertTrue("Cannot find minimum frame duration for jpeg size " + jpegSize, jpegFrameDuration != null);
if (jpegFrameDuration <= videoFrameDuration) {
videoSnapshotSz = jpegSize;
break;
}
if (jpegSize.equals(videoSz)) {
throw new AssertionFailedError("Cannot find adequate video snapshot size for video size" + videoSz);
}
}
}
Log.i(TAG, "Testing video snapshot size " + videoSnapshotSz + " for video size " + videoSz);
if (videoSnapshotSz.getWidth() * videoSnapshotSz.getHeight() > FRAME_SIZE_15M)
kFrameDrop_Tolerence = (int) (FRAMEDROP_TOLERANCE * FRAME_DROP_TOLERENCE_FACTOR);
createImageReader(videoSnapshotSz, ImageFormat.JPEG, MAX_VIDEO_SNAPSHOT_IMAGES, /*listener*/
null);
if (VERBOSE) {
Log.v(TAG, "Testing camera recording with video size " + videoSz.toString());
}
// Configure preview and recording surfaces.
mOutMediaFileName = VIDEO_FILE_PATH + "/test_video.mp4";
if (DEBUG_DUMP) {
mOutMediaFileName = VIDEO_FILE_PATH + "/test_video_" + cameraId + "_" + videoSz.toString() + ".mp4";
}
int numTestIterations = burstTest ? 1 : NUM_SINGLE_SHOT_TEST;
int totalDroppedFrames = 0;
for (int numTested = 0; numTested < numTestIterations; numTested++) {
prepareRecordingWithProfile(profile);
// prepare video snapshot
SimpleCaptureCallback resultListener = new SimpleCaptureCallback();
SimpleImageReaderListener imageListener = new SimpleImageReaderListener();
CaptureRequest.Builder videoSnapshotRequestBuilder = mCamera.createCaptureRequest((mStaticInfo.isHardwareLevelLegacy()) ? CameraDevice.TEMPLATE_RECORD : CameraDevice.TEMPLATE_VIDEO_SNAPSHOT);
// prepare preview surface by using video size.
updatePreviewSurfaceWithVideo(videoSz, profile.videoFrameRate);
prepareVideoSnapshot(videoSnapshotRequestBuilder, imageListener);
CaptureRequest request = videoSnapshotRequestBuilder.build();
// Start recording
startRecording(/* useMediaRecorder */
true, resultListener, /*useVideoStab*/
false);
long startTime = SystemClock.elapsedRealtime();
// Record certain duration.
SystemClock.sleep(RECORDING_DURATION_MS / 2);
// take video snapshot
if (burstTest) {
List<CaptureRequest> requests = new ArrayList<CaptureRequest>(BURST_VIDEO_SNAPSHOT_NUM);
for (int i = 0; i < BURST_VIDEO_SNAPSHOT_NUM; i++) {
requests.add(request);
}
mSession.captureBurst(requests, resultListener, mHandler);
} else {
mSession.capture(request, resultListener, mHandler);
}
// make sure recording is still going after video snapshot
SystemClock.sleep(RECORDING_DURATION_MS / 2);
// Stop recording and preview
int durationMs = stopRecording(/* useMediaRecorder */
true);
// of frames to estimate duration
if (!burstTest) {
durationMs = (int) (resultListener.getTotalNumFrames() * 1000.0f / profile.videoFrameRate);
}
// Validation recorded video
validateRecording(videoSz, durationMs);
if (burstTest) {
for (int i = 0; i < BURST_VIDEO_SNAPSHOT_NUM; i++) {
Image image = imageListener.getImage(CAPTURE_IMAGE_TIMEOUT_MS);
validateVideoSnapshotCapture(image, videoSnapshotSz);
image.close();
}
} else {
// validate video snapshot image
Image image = imageListener.getImage(CAPTURE_IMAGE_TIMEOUT_MS);
validateVideoSnapshotCapture(image, videoSnapshotSz);
// validate if there is framedrop around video snapshot
totalDroppedFrames += validateFrameDropAroundVideoSnapshot(resultListener, image.getTimestamp());
//TODO: validate jittering. Should move to PTS
//validateJittering(resultListener);
image.close();
}
}
if (!burstTest) {
Log.w(TAG, String.format("Camera %d Video size %s: Number of dropped frames " + "detected in %d trials is %d frames.", cameraId, videoSz.toString(), numTestIterations, totalDroppedFrames));
mCollector.expectLessOrEqual(String.format("Camera %d Video size %s: Number of dropped frames %d must not" + " be larger than %d", cameraId, videoSz.toString(), totalDroppedFrames, kFrameDrop_Tolerence), kFrameDrop_Tolerence, totalDroppedFrames);
}
closeImageReader();
}
}
use of junit.framework.AssertionFailedError in project platform_frameworks_base by android.
the class UiAutomatorInstrumentationTestRunner method getAndroidTestRunner.
@Override
protected AndroidTestRunner getAndroidTestRunner() {
AndroidTestRunner testRunner = super.getAndroidTestRunner();
testRunner.addTestListener(new TestListener() {
@Override
public void startTest(Test test) {
if (test instanceof UiAutomatorTestCase) {
((UiAutomatorTestCase) test).initialize(getArguments());
}
}
@Override
public void endTest(Test test) {
}
@Override
public void addFailure(Test test, AssertionFailedError e) {
}
@Override
public void addError(Test test, Throwable t) {
}
});
return testRunner;
}
use of junit.framework.AssertionFailedError in project platform_frameworks_base by android.
the class TextViewAssertions method hasInsertionPointerAtIndex.
/**
* Returns a {@link ViewAssertion} that asserts that the text view insertion pointer is at
* a specified index.<br>
* <br>
* View constraints:
* <ul>
* <li>must be a text view displayed on screen
* <ul>
*
* @param index A matcher representing the expected index.
*/
public static ViewAssertion hasInsertionPointerAtIndex(final Matcher<Integer> index) {
return new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException exception) {
if (view instanceof TextView) {
TextView textView = (TextView) view;
int selectionStart = textView.getSelectionStart();
int selectionEnd = textView.getSelectionEnd();
try {
assertThat(selectionStart, index);
assertThat(selectionEnd, index);
} catch (IndexOutOfBoundsException e) {
throw new AssertionFailedError(e.getMessage());
}
} else {
throw new AssertionFailedError("TextView not found");
}
}
};
}
use of junit.framework.AssertionFailedError in project platform_frameworks_base by android.
the class InstrumentationCoreTestRunner method getAndroidTestRunner.
@Override
protected AndroidTestRunner getAndroidTestRunner() {
AndroidTestRunner runner = super.getAndroidTestRunner();
runner.addTestListener(new TestListener() {
/**
* The last test class we executed code from.
*/
private Class<?> lastClass;
/**
* The minimum time we expect a test to take.
*/
private static final int MINIMUM_TIME = 100;
/**
* The start time of our current test in System.currentTimeMillis().
*/
private long startTime;
public void startTest(Test test) {
if (test.getClass() != lastClass) {
lastClass = test.getClass();
printMemory(test.getClass());
}
Thread.currentThread().setContextClassLoader(test.getClass().getClassLoader());
startTime = System.currentTimeMillis();
}
public void endTest(Test test) {
if (test instanceof TestCase) {
cleanup((TestCase) test);
/*
* Make sure all tests take at least MINIMUM_TIME to
* complete. If they don't, we wait a bit. The Cupcake
* Binder can't handle too many operations in a very
* short time, which causes headache for the CTS.
*/
long timeTaken = System.currentTimeMillis() - startTime;
if (timeTaken < MINIMUM_TIME) {
try {
Thread.sleep(MINIMUM_TIME - timeTaken);
} catch (InterruptedException ignored) {
// We don't care.
}
}
}
}
public void addError(Test test, Throwable t) {
// This space intentionally left blank.
}
public void addFailure(Test test, AssertionFailedError t) {
// This space intentionally left blank.
}
/**
* Dumps some memory info.
*/
private void printMemory(Class<? extends Test> testClass) {
Runtime runtime = Runtime.getRuntime();
long total = runtime.totalMemory();
long free = runtime.freeMemory();
long used = total - free;
Log.d(TAG, "Total memory : " + total);
Log.d(TAG, "Used memory : " + used);
Log.d(TAG, "Free memory : " + free);
Log.d(TAG, "Now executing : " + testClass.getName());
}
/**
* Nulls all non-static reference fields in the given test class.
* This method helps us with those test classes that don't have an
* explicit tearDown() method. Normally the garbage collector should
* take care of everything, but since JUnit keeps references to all
* test cases, a little help might be a good idea.
*/
private void cleanup(TestCase test) {
Class<?> clazz = test.getClass();
while (clazz != TestCase.class) {
Field[] fields = clazz.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
Field f = fields[i];
if (!f.getType().isPrimitive() && !Modifier.isStatic(f.getModifiers())) {
try {
f.setAccessible(true);
f.set(test, null);
} catch (Exception ignored) {
// Nothing we can do about it.
}
}
}
clazz = clazz.getSuperclass();
}
}
});
return runner;
}
Aggregations