/*******************************************************************************
 * Copyright (c) 2019 Microsoft Research. All rights reserved. 
 *
 * The MIT License (MIT)
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy 
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is furnished to do
 * so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software. 
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * Contributors:
 *   Markus Alexander Kuppe - initial API and implementation
 ******************************************************************************/
package tlc2.tool;

import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

import org.junit.Test;

import tlc2.output.EC;
import tlc2.output.EC.ExitStatus;
import tlc2.tool.liveness.ModelCheckerTestCase;

public class Github407Test extends ModelCheckerTestCase {

	public Github407Test() {
		super("Github407",
				new String[] { "-dump", System.getProperty("java.io.tmpdir") + File.separator + "Github407" },
				ExitStatus.SUCCESS);
	}

	@Test
	public void testSpec() throws FileNotFoundException, IOException {
		assertTrue(recorder.recorded(EC.TLC_FINISHED));
		assertTrue(recorder.recordedWithStringValues(EC.TLC_STATS, "9", "4", "0"));
		assertTrue(recorder.recordedWithStringValue(EC.TLC_SEARCH_DEPTH, "3"));
		
		final File dumpFile = new File(System.getProperty("java.io.tmpdir") + File.separator + "Github407.dump");
		assertTrue(dumpFile.exists());
		
		// If the file exist, simply compare it to a correct and manually checked version.
		final InputStream master = getClass().getResourceAsStream("Github407.dump");
		assertTrue(Arrays.equals(DumpAsDotTest.getBytes(master), DumpAsDotTest.getBytes(new FileInputStream(dumpFile))));

		assertZeroUncovered();
		
	}

	@Override
	protected boolean doDump() {
		// Create the non-dot dump explicitly through constructor above.
		return false;
	}
}

@@ -1465,14 +1465,90 @@
 sert
-True;%0A
+Equals;%0Aimport static org.junit.Assert.assertTrue;%0A%0Aimport java.io.BufferedReader;
 %0Aimp
@@ -1707,19 +1707,168 @@
 ava.
-util.Arrays
+io.InputStreamReader;%0Aimport java.nio.file.Files;%0Aimport java.nio.file.Path;%0Aimport java.nio.file.Paths;%0Aimport java.util.Arrays;%0Aimport java.util.stream.Stream
 ;%0A%0Ai
@@ -2053,16 +2053,127 @@
 stCase %7B
+%0A%09%0A%09private static final Path dumpFilePath = Paths.get(System.getProperty(%22java.io.tmpdir%22), %22Github407.dump%22);
 %0A%0A%09publi
@@ -2245,75 +2245,45 @@
 p%22, 
-System.getProperty(%22java.io.tmpdir%22) + File.separator + %22Github407%22
+Github407Test.dumpFilePath.toString()
  %7D,%0A
@@ -2597,143 +2597,58 @@
 %09%0A%09%09
-final File dumpFile = new File(System.getProperty(%22java.io.tmpdir%22) + File.separator + %22Github407.dump%22);%0A%09%09assertTrue(dumpFile.exists(
+assertTrue(Files.exists(Github407Test.dumpFilePath
 ));%0A
@@ -2735,16 +2735,25 @@
 ersion.%0A
+%09%09try (%0A%09
 %09%09final 
@@ -2764,22 +2764,24 @@
 tStream 
-master
+expected
  = getCl
@@ -2831,121 +2831,555 @@
 ;%0A%09%09
-assertTrue(Arrays.equals(DumpAsDotTest.getBytes(master), DumpAsDotTest.getBytes(new FileInputStream(dumpFile))));
+%09final FileInputStream actual = new FileInputStream(Github407Test.dumpFilePath.toFile());%0A%09%09%09) %7B%0A%09%09%09BufferedReader expectedReader = new BufferedReader(new InputStreamReader(expected));%0A%09%09%09BufferedReader actualReader = new BufferedReader(new InputStreamReader(actual));%0A%09%09%09while (expectedReader.ready() && actualReader.ready()) %7B%0A%09%09%09%09String expectedLine = expectedReader.readLine();%0A%09%09%09%09String actualLine = actualReader.readLine();%0A%09%09%09%09assertEquals(expectedLine, actualLine);%0A%09%09%09%7D%0A%0A%09%09%09assertEquals(expectedReader.ready(), actualReader.ready());%0A%09%09%7D
 %0A%0A%09%09

Test tlc2.tool.Github407Test now passes on Windows Failure was due to line ending differences.