[LIB-9] Fix name of chesshog-dbetude module
[chesshog.git] / chesshog-qrcode / src / test / java / org / hedgecode / chess / qrcode / ChessQRCodeWriterTest.java
diff --git a/chesshog-qrcode/src/test/java/org/hedgecode/chess/qrcode/ChessQRCodeWriterTest.java b/chesshog-qrcode/src/test/java/org/hedgecode/chess/qrcode/ChessQRCodeWriterTest.java
new file mode 100644 (file)
index 0000000..f4a606f
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2018-2019. Developed by Hedgecode.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.hedgecode.chess.qrcode;
+
+import java.io.File;
+
+import javax.imageio.ImageIO;
+
+import org.hedgecode.chess.img.DiagramBuilder;
+import org.hedgecode.chess.img.ImageFormat;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import org.hedgecode.chess.Builders;
+import org.hedgecode.chess.Parsers;
+import org.hedgecode.chess.position.Position;
+
+/**
+ * Tests for {@link ChessQRCodeWriter}.
+ *
+ * @author Dmitry Samoshin aka gotty
+ */
+@RunWith(JUnit4.class)
+public class ChessQRCodeWriterTest extends Assert {
+
+    private static final String QR_CODE_IMAGE_PATH = "./QRCodeTest.png";
+
+    @Test
+    public void generate() throws Exception {
+        //String expected = "rnbqkbnr/ppp1pppp/8/3p4/4P3/8/PPPP1PPP/RNBQKBNR w KQkq d6 0 2";
+        String expected = "1r2k1r1/pbppnp1p/1b3P2/8/Q7/B1PB1q2/P4PPP/3R2K1 w - - 0 21";
+        //String expected = "4kb1r/p2n1ppp/4q3/4p1B1/4P3/1Q6/PPP2PPP/2KR4 w k - 0 16";
+
+        Position expectedPosition = Parsers.FEN.parser().parse(
+                expected
+        );
+
+        ChessQRCodeWriter.getInstance().write(
+                ChessQRCodeMode.TCD,
+                Builders.TCD.builder().build(expectedPosition),
+                ImageFormat.PNG,
+                QR_CODE_IMAGE_PATH
+        );
+
+        File file = new File(QR_CODE_IMAGE_PATH);
+        String actual = ChessQRCodeReader.getInstance().read(
+                file
+        ).getContents();
+
+        Position actualPosition = Parsers.TCD.parser().parse(
+                actual
+        );
+
+
+/*
+        assertNotNull(actual);
+        assertEquals(expected, actual);
+*/
+
+        System.out.println(actual);
+
+        ImageIO.write(
+                DiagramBuilder.getInstance().build(actualPosition, "test", "shade"),
+                "PNG",
+                new File("chessboard.png")
+        );
+
+
+        System.out.println(
+                Builders.ASCII.builder().build(actualPosition)
+        );
+
+
+    }
+
+}
\ No newline at end of file