public void testTransliterate_2() { String target = "<html><head><base href=\"file:///" + System.getenv("JAVA_INUKTITUT") + "/unitTests/files_for_tests/testCSS_2.html\"><title>test de css</title>\n" .concat("<style type=\"text/css\">\n") .concat(".nuna { font-family:nunacom; }\n") .concat("#contenu #contenu_droite .soustitre .texte { margin:20px 0 20px 20px; }\n") .concat( ".nunacom { font-family:nunacom, Verdana, Arial, Helvetica, sans-serif; }\n") .concat("</style>\n</head>\n<body>\n") .concat("<div class=\"nuna\"><FONT face=arial>atsitaq</FONT></div>\n") .concat("<div id=\"container\">\n") .concat("<div id=\"contenu\">\n") .concat("<div id=\"contenu_droite\">\n") .concat("<div class=\"soustitre\">\n") .concat( "<div class=\"texte nunacom\"><FONT face=arial>atsitaq</FONT></div></div></div></div></div>\n") .concat("</body></html>"); target = target.replaceAll("\\s+", " "); NRC_HTMLDocumentByCobra doc = null; try { doc = new NRC_HTMLDocumentByCobra( "file:///" + System.getenv("JAVA_INUKTITUT") + "/unitTests/files_for_tests/testCSS_2.html"); Object[] ret = doc.transliterate(); doc.close(); String enc = (String) ret[0]; File fout = (File) ret[1]; InputStreamReader isr = new InputStreamReader(new FileInputStream(fout), enc); StringBuffer sb = new StringBuffer(); int c; while ((c = isr.read()) != -1) { sb.append((char) c); } isr.close(); fout.delete(); String res = sb.toString(); res = res.replaceAll("\\s+", " "); if (!res.equals(target)) { for (int i = 0; i < res.length(); i++) if (res.charAt(i) != target.charAt(i)) { System.out.println("attendu: " + (int) target.charAt(i)); System.out.println("reçu : " + (int) res.charAt(i)); assertEquals( "Le contenu retourné ne correspond pas au contenu escompté; différence à la position '" + i + "'", target.charAt(i), res.charAt(i)); } else { System.out.print(res.charAt(i)); } } } catch (Exception e) { e.printStackTrace(); if (doc != null) doc.close(); fail(); } }
public void testTransliterate() { String target = "<html><head><base href=\"file:///" + System.getenv("JAVA_INUKTITUT") + "/unitTests/files_for_tests/testTranslit.html\"><title>Lecture des polices</title>\n" .concat("<link href=\"styles.css\" rel=\"stylesheet\" type=\"text/css\">\n") .concat("<style type=\"text/css\">\n") .concat(".nunac { font-family:nunacom, Verdana, Arial, Helvetica, sans-serif; }\n") .concat("</style>\n</head>\n<body>\n") .concat( "Texte en nunacom: <div id=\"tnunacom\" class=nunac><FONT face=arial>inuuvik inuktitut uqausiit iglurama</FONT></div>\n") .concat( "Texte en naamajut: <div id=\"tnaamajut\" class=\"texte naamajut\"><FONT face=arial>inuuvik inuktitut uqausiit iglurama</FONT></div>\n") .concat( "Texte en Times New Roman: <div id=\"ttimes\" style=\"font-family:Times New Roman, Helvetica;\">inuuvik inuktitut</div>\n") .concat( "Texte en georgia:<br><font id=\"tgeorgia\" face=\"georgia\">inuuvik inuktitut</font>\n") .concat( "<p>\nTexte en prosyl: <div class=\"texte prosyl\"><div id=\"tprosyl\"><FONT face=arial>inuuvik inuktitut</FONT></div></div></p>\n") .concat("</body></html>"); target = target.replaceAll("\\s+", " "); NRC_HTMLDocumentByCobra doc = null; try { doc = new NRC_HTMLDocumentByCobra( "file:///" + System.getenv("JAVA_INUKTITUT") + "/unitTests/files_for_tests/testTranslit.html"); Object[] ret = doc.transliterate(); doc.close(); String enc = (String) ret[0]; File fout = (File) ret[1]; InputStreamReader isr = new InputStreamReader(new FileInputStream(fout), enc); StringBuffer sb = new StringBuffer(); int c; while ((c = isr.read()) != -1) { sb.append((char) c); } isr.close(); fout.delete(); String res = sb.toString(); res = res.replaceAll("\\s+", " "); if (!res.equals(target)) { for (int i = 0; i < res.length(); i++) if (res.charAt(i) != target.charAt(i)) { System.out.println("attendu: " + (int) target.charAt(i)); System.out.println("reçu : " + (int) res.charAt(i)); assertEquals( "Le contenu retourné ne correspond pas au contenu escompté; différence à la position '" + i + "'", target.charAt(i), res.charAt(i)); } else { System.out.print(res.charAt(i)); } } } catch (Exception e) { e.printStackTrace(); if (doc != null) doc.close(); fail(); } }