summaryrefslogtreecommitdiff
path: root/BKUCommonGUI/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'BKUCommonGUI/src/test')
-rw-r--r--BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java62
-rw-r--r--BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java199
-rw-r--r--BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/DummyFontLoader.java41
-rw-r--r--BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/SecureViewerDialogTest.java167
-rw-r--r--BKUCommonGUI/src/test/resources/commons-logging.properties1
-rw-r--r--BKUCommonGUI/src/test/resources/log4j.properties19
6 files changed, 489 insertions, 0 deletions
diff --git a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java
new file mode 100644
index 00000000..fdd58850
--- /dev/null
+++ b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java
@@ -0,0 +1,62 @@
+/*
+* Copyright 2008 Federal Chancellery Austria and
+* Graz University of Technology
+*
+* 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.
+*/
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package at.gv.egiz.bku.gui;
+
+import java.awt.Container;
+import java.awt.Dimension;
+import javax.swing.JFrame;
+import org.junit.Ignore;
+import org.junit.Test;
+
+
+/**
+ *
+ * @author clemens
+ */
+@Ignore
+public class BKUGUITest {
+
+ @Test
+ public void testBKUGUI() {
+ JFrame testFrame = new JFrame("BKUGUITest");
+ Container contentPane = testFrame.getContentPane();
+// contentPane.setPreferredSize(new Dimension(170, 150));
+ contentPane.setPreferredSize(new Dimension(290, 190));
+ BKUGUIFacade gui = new BKUGUIImpl(contentPane, null, BKUGUIFacade.Style.advanced, null, new DummyFontLoader(), null, null);
+ BKUGUIWorker worker = new BKUGUIWorker();
+ worker.init(gui);
+ testFrame.pack();
+ testFrame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+ testFrame.setVisible(true);
+ new Thread(worker).start();
+
+ while(true) ;
+ }
+
+ @Test
+ public void dummyTest() {
+ }
+
+// public static void main(String[] args) {
+// new BKUGUITest().testBKUGUI();
+// }
+}
diff --git a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java
new file mode 100644
index 00000000..a2a84d6e
--- /dev/null
+++ b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java
@@ -0,0 +1,199 @@
+/*
+ * Copyright 2008 Federal Chancellery Austria and
+ * Graz University of Technology
+ *
+ * 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.
+ */
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package at.gv.egiz.bku.gui;
+
+import at.gv.egiz.smcc.PINSpec;
+import at.gv.egiz.smcc.STARCOSCard;
+import at.gv.egiz.stal.HashDataInput;
+import at.gv.egiz.stal.impl.ByteArrayHashDataInput;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ * @author clemens
+ */
+public class BKUGUIWorker implements Runnable {
+
+ BKUGUIFacade gui;
+
+ public void init(BKUGUIFacade gui) {
+ this.gui = gui;
+ }
+
+ @Override
+ public void run() {
+ try {
+
+ final PINSpec signPinSpec = new PINSpec(6, 10, "[0-9]", "Test-PIN", (byte) 0x81, null);
+ final PINSpec cardPinSpec = new PINSpec(4, 4, "[0-9]", "Test-PIN", (byte) 0x01, null);
+
+
+ final ActionListener cancelListener = new ActionListener() {
+
+ public void actionPerformed(ActionEvent e) {
+ System.out.println("CANCEL EVENT OCCURED: " + e);
+ }
+ };
+ ActionListener okListener = new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ System.out.println("OK EVENT OCCURED: " + e);
+ }
+ };
+ final ActionListener signListener = new ActionListener() {
+
+ public void actionPerformed(ActionEvent e) {
+ System.out.println("SIGN EVENT OCCURED: " + e);
+ }
+ };
+ ActionListener hashdataListener = new ActionListener() {
+
+ public void actionPerformed(ActionEvent e) {
+ System.out.println("HASHDATA EVENT OCCURED: " + e);
+ ActionListener returnListener = new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ gui.showSignaturePINDialog(signPinSpec, -1, signListener, "sign", cancelListener, "cancel", null, "hashdata");
+ }
+ };
+ HashDataInput signedRef1 = new ByteArrayHashDataInput(
+ "Ich bin ein einfacher Text mit Umlauten: öäüßéç@€\n123\n456\n\tHello, world!\n\nlkjsd\nnksdjf".getBytes(),
+ "ref-id-0000000000000000000000001",
+ "text/plain",
+ "UTF-8",
+ "file.txt");
+
+ HashDataInput signedRef2 = new ByteArrayHashDataInput(
+ "<xml>HashDataInput_002</xml>".getBytes(),
+ "ref-id-000000002",
+ "application/xhtml+xml",
+ "UTF-8",
+ "file.xhtml");
+
+ HashDataInput signedRef3 = new ByteArrayHashDataInput(
+ "<xml>HashDataInput_003</xml>".getBytes(),
+ "ref-id-000000003",
+ "application/xhtml+xml",
+ "UTF-8",
+ "file2.xhtml");
+
+ HashDataInput signedRef4 = new ByteArrayHashDataInput(
+ "<xml>HashDataInput_004</xml>".getBytes(),
+ "ref-id-000000004",
+ "text/xml",
+ "UTF-8",
+ "file.xml");
+
+ //
+ List<HashDataInput> signedRefs = new ArrayList();
+ signedRefs.add(signedRef1);
+// signedRefs.add(signedRef2);
+// signedRefs.add(signedRef3);
+// signedRefs.add(signedRef4);
+// signedRefs.add(signedRef4);
+// signedRefs.add(signedRef4);
+// signedRefs.add(signedRef4);
+// signedRefs.add(signedRef4);
+// signedRefs = Collections.singletonList(signedRef1);
+ gui.showSecureViewer(signedRefs, returnListener, "return");
+ }
+ };
+
+
+
+// gui.showWelcomeDialog();
+//
+// Thread.sleep(2000);
+//
+// gui.showWaitDialog(null);
+//
+// Thread.sleep(1000);
+//
+// gui.showWaitDialog("test");
+//
+// Thread.sleep(1000);
+//
+//
+// gui.showInsertCardDialog(cancelListener, "cancel");
+//
+// Thread.sleep(2000);
+//
+// gui.showCardNotSupportedDialog(cancelListener, "cancel");
+//
+// Thread.sleep(2000);
+//
+// PINSpec cardPinSpec = new PINSpec(4, 4, "[0-9]", "Karten-PIN");
+//
+// gui.showCardPINDialog(cardPinSpec, okListener, "ok", cancelListener, "cancel");
+//
+// Thread.sleep(2000);
+//
+// gui.showSignaturePINDialog(signPinSpec, -1, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata");
+
+ gui.showSignatureDataDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata");
+ Thread.sleep(2000);
+
+ gui.showEnterPINDirect(signPinSpec, -1);
+//
+// Thread.sleep(4000);
+//
+
+// gui.showErrorDialog(BKUGUIFacade.ERR_NO_PCSC, null, null, null);
+
+// gui.showSignaturePINRetryDialog(signPinSpec, 2, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata");
+//
+// Thread.sleep(2000);
+//
+// gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, new Object[] {"Testfehler"}, null, null);
+//
+// Thread.sleep(2000);
+//
+// gui.showErrorDialog("error.test", new Object[] {"Testfehler", "noch ein TestFehler"});
+//
+// Thread.sleep(2000);
+//
+// gui.showErrorDialog("error.no.hashdata", null);
+//
+// Thread.sleep(2000);
+//
+// gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, new Object[] {"Testfehler"});
+//
+// Thread.sleep(2000);
+//
+// gui.showErrorDialog("error.unknown", null);
+
+
+// gui.showTextPlainHashDataInput("hallo,\n welt!", "12345", null, "cancel", null, "save");
+// gui.showTextPlainHashDataInput("hallo,\n welt!", "12345", null, "cancel", null, "save");
+// Thread.sleep(2000);
+
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ }
+ }
+}
diff --git a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/DummyFontLoader.java b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/DummyFontLoader.java
new file mode 100644
index 00000000..505c4247
--- /dev/null
+++ b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/DummyFontLoader.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2008 Federal Chancellery Austria and
+ * Graz University of Technology
+ *
+ * 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 at.gv.egiz.bku.gui;
+
+import at.gv.egiz.bku.gui.viewer.FontProviderException;
+import at.gv.egiz.bku.gui.viewer.FontProvider;
+import java.awt.Font;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ *
+ * @author Clemens Orthacker <clemens.orthacker@iaik.tugraz.at>
+ */
+public class DummyFontLoader implements FontProvider {
+
+ protected final static Log log = LogFactory.getLog(DummyFontLoader.class);
+
+ @Override
+ public Font getFont() throws FontProviderException {
+ log.debug("return font");
+ return new Font("monospaced", Font.PLAIN, 10);
+ }
+
+}
diff --git a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/SecureViewerDialogTest.java b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/SecureViewerDialogTest.java
new file mode 100644
index 00000000..9bbc1b1a
--- /dev/null
+++ b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/SecureViewerDialogTest.java
@@ -0,0 +1,167 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package at.gv.egiz.bku.gui;
+
+import at.gv.egiz.stal.impl.ByteArrayHashDataInput;
+import java.awt.Font;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.BufferedInputStream;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.ResourceBundle;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ *
+ * @author clemens
+ */
+@Ignore
+public class SecureViewerDialogTest {
+
+ static SecureViewerDialog secureViewer;
+ static ResourceBundle messages;
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ messages = ResourceBundle.getBundle("at/gv/egiz/bku/gui/Messages");
+ secureViewer = new SecureViewerDialog(null, messages,null, null, new DummyFontLoader(), null);
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+
+ @Test
+ @Ignore
+ public void testLatin1Supplement() throws UnsupportedEncodingException, FileNotFoundException, IOException {
+// StringBuilder data = new StringBuilder();
+// data.append("\nhttp://www.unicode.org/charts/PDF/U0080.pdf\n");
+// for (int i = 0x0080; i <= 0x00ff; i++) {
+// data.append((char) i);
+// }
+// System.out.println(data.toString());
+ BufferedInputStream bis = new BufferedInputStream(new FileInputStream("/home/clemens/IAIK/MOCCA/encoding/test_iso-8859-1.txt"));
+ byte[] bytes = new byte[bis.available()];
+ bis.read(bytes);
+ String s = new String(bytes, "iso-8859-1");
+ System.out.println("read iso-8859-1 bytes " + s);
+
+ secureViewer.setContent(new ByteArrayHashDataInput(s.getBytes("UTF-8"), "id-1", "text/plain", "iso-8859-1", "file.txt"));
+
+ }
+
+ @Test
+ @Ignore
+ public void testGreek() throws UnsupportedEncodingException {
+// Font fm = new Font(Font.MONOSPACED, Font.PLAIN, 10);
+ Font fm = new Font("Lucida Sans Typewriter", Font.PLAIN, 18); //GothicBBB-MediumH", Font.PLAIN, 10);
+ System.out.println(fm.getFontName() + ", " + fm.getPSName() + ", " + fm);
+
+ StringBuilder data = new StringBuilder();
+ data.append("\nhttp://www.unicode.org/charts/PDF/U0370.pdf\n");
+ for (int i = 0x0370; i <= 0x03ff; i++) {
+ if (!fm.canDisplay((char) i)) {
+ System.out.println("cannot display " + Integer.toHexString(i) );
+ }
+ data.append((char) i);
+ }
+
+ System.out.println(data.toString());
+ secureViewer.setContent(new ByteArrayHashDataInput(data.toString().getBytes("UTF-8"), "id-1", "text/plain", "UTF-8", "file.txt"));
+
+ }
+
+ /**
+ * Test of setContent method, of class SecureViewerDialog.
+ */
+ @Test
+// @Ignore
+ public void testCyrillic() throws UnsupportedEncodingException {
+
+ StringBuilder data = new StringBuilder("\n");
+
+ int[] mocca = new int[] {0x041c, 0x04a8, 0x0480, 0x0480, 0x0466 };
+
+ for (int i = 0; i < mocca.length; i++) {
+ data.append((char) mocca[i]);
+ }
+ data.append(" goes cyrillic\n");
+
+ data.append("\nCyrillic - http://www.unicode.org/charts/PDF/U0400.pdf\n");
+ for (int i = 0x0400; i <= 0x04ff; i++) {
+// System.out.printf("%c%04x=%c\t", (i & 7) == 0 ? '\n' : '\0', i, (char)i);
+// System.out.print((char) i);
+ data.append((char)i);
+ }
+
+ data.append("\n\nCyrillic Supplement - http://www.unicode.org/charts/PDF/U0500.pdf\n");
+ for (int i = 0x0500; i <= 0x0525; i++) {
+// System.out.printf("%c%04x=%c\t", (i & 7) == 0 ? '\n' : '\0', i, (char)i);
+// System.out.print((char) i);
+ data.append((char) i);
+ }
+
+ for (int i = 0; i < data.length(); i++) {
+ char c = data.charAt(i);
+ if (c >= '\u0400' && c <= '\u0525') {
+ System.out.println(c + "\tcyrillic");
+ } else if (c < '\u007f') {
+ System.out.println(c + "\tlatin");
+ } else {
+ System.out.println(c + "\tunknown");
+ }
+ }
+
+ System.out.println(data.toString());
+
+// char[] cyrillicChars = new char[] {(char) 0x0411, (char) 0x0444};
+// System.out.println(new String(cyrillicChars)); // + ": " + SMCCHelper.toString(cyrillicBytes));
+// byte[] cyrillicBytes = new byte[] {(byte) 0x11, (byte) 0x04, (byte) 0x0444};
+// System.out.println(new String(cyrillicBytes, "UTF-8") + ": " + SMCCHelper.toString(cyrillicBytes));
+
+// String encoding = "cp1252";
+// String data = "öäü߀";
+// byte[] bytes = data.getBytes(encoding);
+// System.out.println(data + "\t" + SMCCHelper.toString(bytes));
+// byte[] bytes2 = data.getBytes("cp1252");
+// System.out.println(data + "\t" + SMCCHelper.toString(bytes2));
+
+ secureViewer.setContent(new ByteArrayHashDataInput(data.toString().getBytes("UTF-8"), "id-1", "text/plain", "UTF-8", "file.txt"));
+
+ System.out.println("\n\n=============================\n");
+//
+//// int[] mocca = new int[] {0x0428, 0x0429, 0x04a8, 0x04e8, 0x047a, 0x042d, 0x042d, 0x0421, 0x0421, 0x04d0, 0x0466 };
+// int[] mocca = new int[] {0x0429, 0x04a8, 0x0480, 0x0480, 0x0466 };
+ for (int i = 0; i < mocca.length; i++) {
+ System.out.print((char) mocca[i]);
+ }
+// for (int i = 0; i < mocca.length; i++) {
+// System.out.printf(" 0x%04x", mocca[i]);
+// }
+//
+ System.out.println("\n=============================\n");
+
+ }
+
+
+} \ No newline at end of file
diff --git a/BKUCommonGUI/src/test/resources/commons-logging.properties b/BKUCommonGUI/src/test/resources/commons-logging.properties
new file mode 100644
index 00000000..29292562
--- /dev/null
+++ b/BKUCommonGUI/src/test/resources/commons-logging.properties
@@ -0,0 +1 @@
+org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
diff --git a/BKUCommonGUI/src/test/resources/log4j.properties b/BKUCommonGUI/src/test/resources/log4j.properties
new file mode 100644
index 00000000..053eac17
--- /dev/null
+++ b/BKUCommonGUI/src/test/resources/log4j.properties
@@ -0,0 +1,19 @@
+# loglever DEBUG, appender STDOUT
+log4j.rootLogger=TRACE, STDOUT
+#log4j.logger.at.gv.egiz.slbinding.RedirectEventFilter=DEBUG, STDOUT
+
+# STDOUT appender
+log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
+log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
+#log4j.appender.STDOUT.layout.ConversionPattern=%5p | %d{dd HH:mm:ss,SSS} | %20c | %10t | %m%n
+#log4j.appender.STDOUT.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
+log4j.appender.STDOUT.layout.ConversionPattern=%-5p |%d | %t | %c %x- %m%n
+
+### FILE appender
+#log4j.appender.file=org.apache.log4j.RollingFileAppender
+#log4j.appender.file.maxFileSize=100KB
+#log4j.appender.file.maxBackupIndex=9
+#log4j.appender.file.File=egovbus_ca.log
+#log4j.appender.file.threshold=info
+#log4j.appender.file.layout=org.apache.log4j.PatternLayout
+#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n \ No newline at end of file