PageRenderTime 70ms CodeModel.GetById 36ms RepoModel.GetById 0ms app.codeStats 0ms

/ojc-core/encodersl/encoder-coco/test/com/sun/encoder/coco/CocoEncoderTest.java

https://bitbucket.org/pymma/openesb-components
Java | 688 lines | 563 code | 44 blank | 81 comment | 104 complexity | efa74443778bf59824fb3fec44526520 MD5 | raw file
  1. /*
  2. * BEGIN_HEADER - DO NOT EDIT
  3. *
  4. * The contents of this file are subject to the terms
  5. * of the Common Development and Distribution License
  6. * (the "License"). You may not use this file except
  7. * in compliance with the License.
  8. *
  9. * You can obtain a copy of the license at
  10. * https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
  11. * See the License for the specific language governing
  12. * permissions and limitations under the License.
  13. *
  14. * When distributing Covered Code, include this CDDL
  15. * HEADER in each file and include the License file at
  16. * https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
  17. * If applicable add the following below this CDDL HEADER,
  18. * with the fields enclosed by brackets "[]" replaced with
  19. * your own identifying information: Portions Copyright
  20. * [year] [name of copyright owner]
  21. */
  22. /*
  23. * @(#)CocoEncoderTest.java
  24. *
  25. * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
  26. *
  27. * END_HEADER - DO NOT EDIT
  28. */
  29. package com.sun.encoder.coco;
  30. import com.sun.encoder.coco.runtime.HexDump;
  31. import com.sun.encoder.coco.xsdbuilder.CocoXsdBuilder;
  32. import com.sun.encoder.coco.xsdbuilder.CocoXsdBuilderException;
  33. import com.sun.encoder.coco.xsdbuilder.CocoXsdBuilderSpec;
  34. import com.sun.encoder.tools.xml.SchemaLocationAttributes;
  35. import java.io.BufferedReader;
  36. import java.io.File;
  37. import java.io.FileInputStream;
  38. import java.io.FileNotFoundException;
  39. import java.io.FileOutputStream;
  40. import java.io.IOException;
  41. import java.io.InputStreamReader;
  42. import java.io.LineNumberReader;
  43. import java.io.StringWriter;
  44. import java.util.Properties;
  45. import java.util.StringTokenizer;
  46. import javax.xml.namespace.QName;
  47. import javax.xml.transform.Source;
  48. import javax.xml.transform.Transformer;
  49. import javax.xml.transform.TransformerConfigurationException;
  50. import javax.xml.transform.TransformerException;
  51. import javax.xml.transform.TransformerFactory;
  52. import javax.xml.transform.TransformerFactoryConfigurationError;
  53. import javax.xml.transform.stream.StreamResult;
  54. import javax.xml.transform.stream.StreamSource;
  55. import junit.framework.Test;
  56. import junit.framework.TestCase;
  57. import junit.framework.TestResult;
  58. import junit.framework.TestSuite;
  59. import com.sun.encoder.Encoder;
  60. import com.sun.encoder.EncoderConfigurationException;
  61. import com.sun.encoder.EncoderException;
  62. import com.sun.encoder.EncoderFactory;
  63. import com.sun.encoder.EncoderType;
  64. import com.sun.encoder.MetaRef;
  65. import com.sun.encoder.util.UnicodeFile;
  66. import java.util.logging.Level;
  67. import java.util.logging.Logger;
  68. /**
  69. * A simple test suite for unit testing COBOL Copybook encoder.
  70. *
  71. * @author Jun Xu
  72. * @since 6.0
  73. */
  74. public class CocoEncoderTest extends TestSuite {
  75. //Fields:
  76. // test case type ("B" for building XSD,
  77. // "E" for encode to bytes,
  78. // "D" for decode from bytes,
  79. // "ES" for encode to string,
  80. // "DS" for decode from string)
  81. // test case name
  82. // expected result ("T" for succeed and "F" for fail)
  83. // XML Schema file (if case type is "B" put build spec property
  84. // file name here)
  85. // root element qualified name (absent if case type is "B")
  86. // input file (for case type "B", put COBOL Copybook file name here)
  87. // output file (optional for case type "D" or "E".
  88. // for case type "B", put XSD file name here)
  89. // expected result file (optional)
  90. private static final int NUM_OF_FIELDS = 8;
  91. private static final int CASE_TYPE = 0;
  92. private static final int CASE_NAME = 1;
  93. private static final int EXPECTED_RESULT = 2;
  94. private static final int SCHEMA_OR_SPEC_FILE = 3;
  95. private static final int ROOT_ELEMENT = 4;
  96. private static final int INPUT_FILE = 5;
  97. private static final int OUTPUT_FILE = 6;
  98. private static final int EXPECTED_OUTPUT = 7;
  99. static Logger sLog = Logger.getLogger(CocoEncoderTest.class.getName());
  100. /** Creates a new instance of CocoEncoderTest */
  101. public CocoEncoderTest(String testName) {
  102. super(testName);
  103. }
  104. /**
  105. * suite method automatically generated by JUnit module
  106. */
  107. public static Test suite() {
  108. TestSuite suite =
  109. new CocoEncoderTest(
  110. "COBOL Copybook Encoder Test Suite");
  111. LineNumberReader lnReader = null;
  112. try {
  113. lnReader =
  114. new LineNumberReader(
  115. new BufferedReader(
  116. new InputStreamReader(
  117. new FileInputStream("test/testcases.txt"),
  118. UnicodeFile.ENC)));
  119. String line;
  120. while ((line = lnReader.readLine()) != null) {
  121. line = line.trim();
  122. if (line.length() == 0 || line.charAt(0) == '#') {
  123. continue;
  124. }
  125. StringTokenizer st = new StringTokenizer(line, ",");
  126. if (st.countTokens() != NUM_OF_FIELDS) {
  127. throw new RuntimeException(
  128. "Invalid test case entry. count="
  129. + st.countTokens() + ", line=" + line);
  130. }
  131. String tokens[] = new String[NUM_OF_FIELDS];
  132. for (int i = 0; i < NUM_OF_FIELDS; i++) {
  133. tokens[i] = st.nextToken();
  134. }
  135. boolean isPositiveTest = true;
  136. if ("F".equals(tokens[EXPECTED_RESULT].trim())) {
  137. isPositiveTest = false;
  138. }
  139. QName rootElement = null;
  140. if (!tokens[CASE_TYPE].equals("B")) {
  141. String rootElementName = tokens[ROOT_ELEMENT].trim();
  142. if (rootElementName.charAt(0) == '{') {
  143. int pos = rootElementName.indexOf('}');
  144. rootElement =
  145. new QName(rootElementName.substring(1, pos),
  146. rootElementName.substring(pos + 1));
  147. } else {
  148. rootElement = new QName(rootElementName);
  149. }
  150. }
  151. File outputFile = null;
  152. tokens[OUTPUT_FILE] = tokens[OUTPUT_FILE].trim();
  153. if (tokens[OUTPUT_FILE].length() > 0) {
  154. outputFile = new File(tokens[OUTPUT_FILE]);
  155. }
  156. File expectedFile = null;
  157. tokens[EXPECTED_OUTPUT] = tokens[EXPECTED_OUTPUT].trim();
  158. if (tokens[EXPECTED_OUTPUT].length() > 0) {
  159. expectedFile = new File(tokens[EXPECTED_OUTPUT]);
  160. }
  161. if ("B".equals(tokens[CASE_TYPE])) {
  162. //XSD builder test case
  163. suite.addTest(
  164. new XsdBuilderTest(
  165. tokens[CASE_NAME].trim(),
  166. isPositiveTest,
  167. new File(tokens[SCHEMA_OR_SPEC_FILE].trim()),
  168. new File(tokens[INPUT_FILE].trim()),
  169. outputFile,
  170. expectedFile) {
  171. @Override
  172. public void runTest() {
  173. testXsdBuilder();
  174. }
  175. }
  176. );
  177. } else if ("D".equals(tokens[CASE_TYPE])
  178. || "DS".equals(tokens[CASE_TYPE])) {
  179. //decode test case
  180. suite.addTest(
  181. new DecodeTest(
  182. tokens[CASE_NAME].trim(),
  183. "DS".equals(tokens[CASE_TYPE]),
  184. isPositiveTest,
  185. new File(tokens[SCHEMA_OR_SPEC_FILE].trim()),
  186. rootElement,
  187. new File(tokens[INPUT_FILE].trim()),
  188. outputFile,
  189. expectedFile) {
  190. @Override
  191. public void runTest() {
  192. testDecode();
  193. }
  194. });
  195. } else {
  196. //encode test case
  197. suite.addTest(
  198. new EncodeTest(
  199. tokens[CASE_NAME].trim(),
  200. "ES".equals(tokens[CASE_TYPE]),
  201. isPositiveTest,
  202. new File(tokens[SCHEMA_OR_SPEC_FILE].trim()),
  203. rootElement,
  204. new File(tokens[INPUT_FILE].trim()),
  205. outputFile,
  206. expectedFile) {
  207. @Override
  208. public void runTest() {
  209. testEncode();
  210. }
  211. });
  212. }
  213. }
  214. return suite;
  215. } catch (IOException e) {
  216. throw new RuntimeException("Failed to load test cases.", e);
  217. } finally {
  218. if (lnReader != null) {
  219. try {
  220. lnReader.close();
  221. } catch (Exception e) {
  222. //Ignore
  223. }
  224. }
  225. }
  226. }
  227. /**
  228. * XSD builder test.
  229. */
  230. public static class XsdBuilderTest extends TestCase {
  231. private final boolean mIsPositiveTest;
  232. private final File mBuildSpecFile;
  233. private final File mCopybookFile;
  234. private final File mXsdFile;
  235. private final File mExpectedFile;
  236. public XsdBuilderTest(String testName, boolean isPositiveTest,
  237. File buildSpecFile, File copybookFile,
  238. File xsdFile, File expectedFile) {
  239. super(testName);
  240. mIsPositiveTest = isPositiveTest;
  241. mBuildSpecFile = buildSpecFile;
  242. mCopybookFile = copybookFile;
  243. mXsdFile = xsdFile;
  244. mExpectedFile = expectedFile;
  245. }
  246. @Override
  247. protected void setUp() throws Exception {
  248. }
  249. @Override
  250. protected void tearDown() throws Exception {
  251. }
  252. public void testXsdBuilder() {
  253. sLog.info("testXsdBuilder --> [" + getName() + "]");
  254. // expected content
  255. String expected = null;
  256. try {
  257. if (mExpectedFile != null && mExpectedFile.exists()) {
  258. expected = UnicodeFile.getText(mExpectedFile);
  259. }
  260. Properties props = new Properties();
  261. props.load(new FileInputStream(mBuildSpecFile));
  262. CocoXsdBuilderSpec buildSpec = new CocoXsdBuilderSpec();
  263. buildSpec.setCheckNamesForReservedWords(
  264. Boolean.valueOf(
  265. props.getProperty(
  266. CocoXsdBuilderSpec
  267. .CHECK_NAMES_FOR_RESERVED_WORDS)));
  268. buildSpec.setCopybookCharEncoding(
  269. props.getProperty(
  270. CocoXsdBuilderSpec.COPYBOOK_CHAR_ENCODING));
  271. buildSpec.setDisplay1CharEncoding(
  272. props.getProperty(
  273. CocoXsdBuilderSpec.DISPLAY1_CHAR_ENCODING));
  274. buildSpec.setDisplayCharEncoding(
  275. props.getProperty(
  276. CocoXsdBuilderSpec.DISPLAY_CHAR_ENCODING));
  277. buildSpec.setIgnoreContentBeyondCol72(
  278. Boolean.valueOf(
  279. props.getProperty(
  280. CocoXsdBuilderSpec
  281. .IGNORE_CONTENT_BEYOND_COLUMN72)));
  282. buildSpec.setTargetNamespace(
  283. props.getProperty(
  284. CocoXsdBuilderSpec.TARGET_NAMESPACE));
  285. if (props.containsKey(
  286. CocoXsdBuilderSpec.PREDECODE_CHAR_CODING)) {
  287. buildSpec.setPreDecodeCharCoding(
  288. props.getProperty(
  289. CocoXsdBuilderSpec.PREDECODE_CHAR_CODING));
  290. }
  291. if (props.containsKey(
  292. CocoXsdBuilderSpec.POSTENCODE_CHAR_CODING)) {
  293. buildSpec.setPostEncodeCharCoding(
  294. props.getProperty(
  295. CocoXsdBuilderSpec.POSTENCODE_CHAR_CODING));
  296. }
  297. buildSpec.setCopybookLocation(mCopybookFile.getPath());
  298. buildSpec.setXsdLocation(mXsdFile.getPath());
  299. CocoXsdBuilder builder = new CocoXsdBuilder();
  300. builder.setOtdBuilderSpec(buildSpec);
  301. builder.buildXsd();
  302. String result = UnicodeFile.getText(mXsdFile);
  303. result = result.replaceAll("\r\n", "\n");
  304. String copybookPath;
  305. try {
  306. copybookPath = mCopybookFile.getCanonicalPath();
  307. } catch (IOException e) {
  308. copybookPath = mCopybookFile.getAbsolutePath();
  309. }
  310. String xsdPath;
  311. try {
  312. xsdPath = mXsdFile.getCanonicalPath();
  313. } catch (IOException e) {
  314. xsdPath = mXsdFile.getAbsolutePath();
  315. }
  316. copybookPath = copybookPath.replaceAll("\\\\", "\\\\\\\\");
  317. xsdPath = xsdPath.replaceAll("\\\\", "\\\\\\\\");
  318. if (mIsPositiveTest && expected != null) {
  319. expected = expected.replaceAll("\\$\\{COPYBOOK_LOCATION\\}",
  320. copybookPath);
  321. expected = expected.replaceAll("\\$\\{XSD_LOCATION\\}",
  322. xsdPath);
  323. expected = expected.replaceAll("\\$\\{BUILDER_VERSION\\}",
  324. CocoXsdBuilder.BUILDER_VERSION);
  325. expected = expected.replaceAll("\r\n", "\n");
  326. }
  327. if (mIsPositiveTest) {
  328. assertEquals("Check result with expected: "
  329. + getName(), expected, result);
  330. } else {
  331. if (expected.equals(result)) {
  332. fail("Expecting difference but got same: "
  333. + getName());
  334. }
  335. }
  336. } catch (FileNotFoundException e) {
  337. fail(getName() + " - " + e.toString());
  338. } catch (CocoXsdBuilderException e) {
  339. if (mIsPositiveTest) {
  340. fail(getName() + " - " + e.toString());
  341. } else {
  342. // handle negative test with expected exception message
  343. if (expected != null) {
  344. assertEquals("Check " + e.getClass().getName()
  345. + " with expected error message: "
  346. + getName(), expected, e.getMessage());
  347. }
  348. return;
  349. }
  350. } catch (IOException e) {
  351. fail(getName() + " - " + e.toString());
  352. } catch (TransformerFactoryConfigurationError e) {
  353. //fatal error
  354. throw new RuntimeException(e);
  355. }
  356. if (!mIsPositiveTest) {
  357. fail("Expecting failure but no error occurred: "
  358. + getName());
  359. }
  360. }
  361. }
  362. public static String[] getExpectedXMLContent(File expectedFile,
  363. String schemaLocation, String testName)
  364. throws IOException {
  365. String[] expectedContent = null;
  366. if (expectedFile != null) {
  367. expectedContent = UnicodeFile.getTexts(expectedFile.getPath());
  368. if (expectedContent.length > 1 && sLog.isLoggable(Level.INFO)) {
  369. sLog.info("There are " + expectedContent.length
  370. + " expected files for decode: " + testName);
  371. }
  372. if (schemaLocation != null) {
  373. // replace ${SCHEMA_LOCATION} in expected contents
  374. // with actual mSchemaLocation.
  375. for (int i = 0; i < expectedContent.length; i++) {
  376. expectedContent[i] = expectedContent[i].replaceAll(
  377. "\\$\\{SCHEMA_LOCATION\\}", schemaLocation);
  378. }
  379. }
  380. }
  381. // remove "/bld" in expected content if present
  382. if (expectedContent != null) {
  383. for (int i = 0; i < expectedContent.length; i++) {
  384. if (expectedContent[i] != null) {
  385. expectedContent[i] = expectedContent[i].replaceAll("/bld/", "/").trim();
  386. }
  387. }
  388. }
  389. return expectedContent;
  390. }
  391. /**
  392. * Decode test.
  393. */
  394. public static class DecodeTest extends TestCase {
  395. private final boolean mFromString;
  396. private final boolean mIsPositiveTest;
  397. private final File mSchemaFile;
  398. private final QName mRootElement;
  399. private final File mInputFile;
  400. private final File mOutputFile;
  401. private final File mExpectedFile;
  402. private String mSchemaLocation = null;
  403. public DecodeTest(String testName, boolean fromString,
  404. boolean isPositiveTest, File schemaFile, QName rootElement,
  405. File inputFile, File outputFile, File expectedFile) {
  406. super(testName);
  407. mFromString = fromString;
  408. mIsPositiveTest = isPositiveTest;
  409. mSchemaFile = schemaFile;
  410. mRootElement = rootElement;
  411. mInputFile = inputFile;
  412. mOutputFile = outputFile;
  413. mExpectedFile = expectedFile;
  414. }
  415. @Override
  416. protected void setUp() throws Exception {
  417. SchemaLocationAttributes schemaLocationAttr =
  418. new SchemaLocationAttributes(mRootElement.getNamespaceURI(),
  419. mSchemaFile.toURL());
  420. if (schemaLocationAttr.getLength() > 0) {
  421. mSchemaLocation = schemaLocationAttr.getValue(0);
  422. }
  423. }
  424. @Override
  425. protected void tearDown() throws Exception {
  426. }
  427. public void testDecode() {
  428. sLog.info("testDecode --> [" + getName() + "]");
  429. EncoderFactory factory;
  430. // expected content
  431. String[] expected = null;
  432. try {
  433. expected = getExpectedXMLContent(mExpectedFile,
  434. mSchemaLocation, getName());
  435. factory = EncoderFactory.newInstance();
  436. EncoderType type = factory.makeType(CocoEncoderProvider.STYLE_ID);
  437. MetaRef metaRef =
  438. factory.makeMeta(mSchemaFile.getAbsolutePath(),
  439. mRootElement);
  440. Encoder encoder = factory.newEncoder(type, metaRef);
  441. Source source;
  442. if (mFromString) {
  443. source = encoder.decodeFromString(
  444. UnicodeFile.getText(mInputFile));
  445. } else {
  446. source = encoder.decodeFromBytes(getBytes(mInputFile));
  447. }
  448. StringWriter swResult = new StringWriter();
  449. StreamResult streamResult = new StreamResult(swResult);
  450. Transformer transformer =
  451. TransformerFactory.newInstance().newTransformer();
  452. transformer.transform(source, streamResult);
  453. String resultGot = swResult.toString();
  454. if (mOutputFile != null) {
  455. UnicodeFile.setText(mOutputFile, resultGot);
  456. }
  457. // remove "/bld" if present
  458. if (resultGot != null) {
  459. resultGot = resultGot.replaceAll("/bld/", "/").trim();
  460. }
  461. boolean matchFound = false;
  462. for (int i = 0; i < expected.length; i++) {
  463. if (expected[i] != null && expected[i].equals(resultGot)) {
  464. matchFound = true;
  465. break;
  466. }
  467. }
  468. if (mIsPositiveTest) {
  469. if (!matchFound) {
  470. for (int i = 0; i < expected.length; i++) {
  471. assertEquals("Check result with expected #" + i
  472. + ": " + getName(), expected[i], resultGot);
  473. }
  474. }
  475. } else {
  476. if (matchFound) {
  477. fail("Expecting difference but got same: "
  478. + getName());
  479. }
  480. }
  481. } catch (EncoderConfigurationException e) {
  482. //fatal error
  483. throw new RuntimeException(e);
  484. } catch (FileNotFoundException e) {
  485. fail(getName() + " - " + e.toString());
  486. } catch (IOException e) {
  487. fail(getName() + " - " + e.toString());
  488. } catch (TransformerConfigurationException e) {
  489. //fatal error
  490. throw new RuntimeException(e);
  491. } catch (TransformerFactoryConfigurationError e) {
  492. //fatal error
  493. throw new RuntimeException(e);
  494. } catch (EncoderException e) {
  495. if (mIsPositiveTest) {
  496. fail(getName() + " - " + e.toString());
  497. } else {
  498. // handle negative test with expected exception message
  499. if (expected != null && expected.length > 0 && expected[0] != null) {
  500. assertEquals("Check " + e.getClass().getName()
  501. + " with expected error message: "
  502. + getName(), expected[0], e.getMessage());
  503. }
  504. return;
  505. }
  506. } catch (TransformerException e) {
  507. if (mIsPositiveTest) {
  508. fail(getName() + " - " + e.toString());
  509. } else {
  510. // handle negative test with expected exception message
  511. if (expected != null && expected.length > 0 && expected[0] != null) {
  512. assertEquals("Check " + e.getClass().getName()
  513. + " with expected error message: "
  514. + getName(), expected[0], e.getMessage());
  515. }
  516. return;
  517. }
  518. }
  519. if (!mIsPositiveTest) {
  520. fail("Expecting failure but no error occurred: "
  521. + getName());
  522. }
  523. }
  524. }
  525. /**
  526. * Encode test.
  527. */
  528. public static class EncodeTest extends TestCase {
  529. private final boolean mToString;
  530. private final boolean mIsPositiveTest;
  531. private final File mSchemaFile;
  532. private final QName mRootElement;
  533. private final File mInputFile;
  534. private final File mOutputFile;
  535. private final File mExpectedFile;
  536. public EncodeTest(String testName, boolean toString,
  537. boolean isPositiveTest, File schemaFile, QName rootElement,
  538. File inputFile, File outputFile, File expectedFile) {
  539. super(testName);
  540. mToString = toString;
  541. mIsPositiveTest = isPositiveTest;
  542. mSchemaFile = schemaFile;
  543. mRootElement = rootElement;
  544. mInputFile = inputFile;
  545. mOutputFile = outputFile;
  546. mExpectedFile = expectedFile;
  547. }
  548. @Override
  549. protected void setUp() throws Exception {
  550. }
  551. @Override
  552. protected void tearDown() throws Exception {
  553. }
  554. public void testEncode() {
  555. sLog.info("testEncode --> [" + getName() + "]");
  556. EncoderFactory factory;
  557. String expected = null;
  558. String result = null;
  559. try {
  560. if (mToString) {
  561. if (mExpectedFile != null) {
  562. expected = UnicodeFile.getText(mExpectedFile);
  563. }
  564. } else {
  565. if (mExpectedFile != null) {
  566. StringBuffer buf = new StringBuffer();
  567. HexDump.dump(getBytes(mExpectedFile), buf, 0);
  568. expected = buf.toString();
  569. }
  570. }
  571. factory = EncoderFactory.newInstance();
  572. EncoderType type = factory.makeType(CocoEncoderProvider.STYLE_ID);
  573. MetaRef metaRef =
  574. factory.makeMeta(mSchemaFile.getAbsolutePath(),
  575. mRootElement);
  576. Encoder encoder = factory.newEncoder(type, metaRef);
  577. StreamSource streamSource = new StreamSource(mInputFile);
  578. if (mToString) {
  579. result = encoder.encodeToString(streamSource);
  580. if (mOutputFile != null) {
  581. UnicodeFile.setText(mOutputFile, result);
  582. }
  583. } else {
  584. byte[] resultBytes = encoder.encodeToBytes(streamSource);
  585. if (mOutputFile != null) {
  586. FileOutputStream out =
  587. new FileOutputStream(mOutputFile);
  588. out.write(resultBytes);
  589. out.close();
  590. }
  591. StringBuffer buf = new StringBuffer();
  592. HexDump.dump(resultBytes, buf, 0);
  593. result = buf.toString();
  594. }
  595. if (expected != null) {
  596. if (mIsPositiveTest) {
  597. assertEquals("Check result with expected: "
  598. + getName(), expected, result);
  599. } else {
  600. if (expected.equals(result)) {
  601. fail("Expecting difference but got same: "
  602. + getName());
  603. }
  604. }
  605. }
  606. } catch (EncoderConfigurationException e) {
  607. //fatal error
  608. throw new RuntimeException(e);
  609. } catch (FileNotFoundException e) {
  610. fail(getName() + " - " + e.toString());
  611. } catch (IOException e) {
  612. fail(getName() + " - " + e.toString());
  613. } catch (TransformerFactoryConfigurationError e) {
  614. //fatal error
  615. throw new RuntimeException(e);
  616. } catch (EncoderException e) {
  617. if (mIsPositiveTest) {
  618. fail(getName() + " - " + e.toString());
  619. } else {
  620. if (expected != null) {
  621. assertEquals("Check " + e.getClass().getName()
  622. + " with expected error message: "
  623. + getName(), expected, e.getMessage());
  624. }
  625. return;
  626. }
  627. }
  628. if (!mIsPositiveTest) {
  629. fail("Expecting failure but no error occurred: "
  630. + getName());
  631. }
  632. }
  633. }
  634. private static byte[] getBytes(File file)
  635. throws IOException {
  636. FileInputStream fis = new FileInputStream(file);
  637. byte[] bytes = new byte[(int) file.length()];
  638. fis.read(bytes);
  639. return bytes;
  640. }
  641. public static void main(String arg[]) {
  642. CocoEncoderTest.suite().run(new TestResult());
  643. }
  644. }