/*
 * This file is covered by the terms of the Common Public License v1.0.
 *
 * Copyright (c) SZEDER Gábor
 *
 * Parts of this software were developed within the JEOPARD research
 * project, which received funding from the European Union's Seventh
 * Framework Programme under grant agreement No. 216682.
 */

package de.fzi.cjunit.jpf.outside;

import gov.nasa.jpf.Error;
import gov.nasa.jpf.Property;
import gov.nasa.jpf.report.Reporter;
import gov.nasa.jpf.search.Search;
import gov.nasa.jpf.search.SearchListener;

import de.fzi.cjunit.JPFPropertyViolated;
import de.fzi.cjunit.jpf.util.TestReporter;


public class ResultCollector implements TestProperty, SearchListener {

	protected TestReporter reporter;

	protected Throwable exception;

	public ResultCollector(Reporter reporter) {
		this.reporter = (TestReporter) reporter;
	}

	// from TestProperty
	@Override
	public boolean getTestResult() {
		return exception == null;
	}

	@Override
	public Throwable getException() {
		return exception;
	}

	// from SearchListener
	@Override
	public void propertyViolated(Search search) {
		Error error = getLastSearchError(search);
		exception = getExceptionFromProperty(error.getProperty());
		reporter.publishError(error);
	}

	protected Throwable getExceptionFromProperty(Property property) {
		if (property instanceof TestProperty) {
			return ((TestProperty) property).getException();
		} else {
			return new JPFPropertyViolated(property);
		}
	}

	protected Error getLastSearchError(Search search) {
		return search.getLastError();
	}

	@Override
	public void searchFinished(Search search) {}

	@Override
	public void searchStarted(Search search) {}

	@Override
	public void searchConstraintHit(Search search) {}

	@Override
	public void stateAdvanced(Search search) {}

	@Override
	public void stateBacktracked(Search search) {}

	@Override
	public void stateProcessed(Search search) {}

	@Override
	public void stateRestored(Search search) {}

	@Override
	public void stateStored(Search search) {}
}

@@ -673,16 +673,43 @@
 ener %7B%0A%0A
+%09protected Search search;%0A%0A
 %09protect
@@ -734,16 +734,16 @@
 porter;%0A
-
 %0A%09protec
@@ -1146,22 +1146,16 @@
 chError(
-search
 );%0A%09%09exc
@@ -1507,29 +1507,16 @@
 chError(
-Search search
 ) %7B%0A%09%09re
@@ -1608,32 +1608,32 @@
  %7B%7D%0A%0A%09@Override%0A
-
 %09public void sea
@@ -1651,32 +1651,58 @@
 Search search) %7B
+%0A%09%09this.search = search;%0A%09
 %7D%0A%0A%09@Override%0A%09p

store Search instance in a member variable