MatOfByteTest.java 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package org.opencv.test.core;
  2. import java.util.Arrays;
  3. import org.opencv.core.Core;
  4. import org.opencv.core.CvException;
  5. import org.opencv.core.CvType;
  6. import org.opencv.core.Mat;
  7. import org.opencv.core.MatOfByte;
  8. import org.opencv.core.MatOfDouble;
  9. import org.opencv.test.OpenCVTestCase;
  10. import org.opencv.imgcodecs.Imgcodecs;
  11. public class MatOfByteTest extends OpenCVTestCase {
  12. public void testMatOfSubByteArray() {
  13. byte[] inputBytes = { 1,2,3,4,5 };
  14. MatOfByte m0 = new MatOfByte(inputBytes);
  15. MatOfByte m1 = new MatOfByte(0, inputBytes.length, inputBytes);
  16. MatOfByte m2 = new MatOfByte(1, inputBytes.length - 2, inputBytes);
  17. assertEquals(5.0, m0.size().height);
  18. assertEquals(1.0, m0.size().width);
  19. assertEquals(m0.get(0, 0)[0], m1.get(0, 0)[0]);
  20. assertEquals(m0.get((int) m0.size().height - 1, 0)[0], m1.get((int) m1.size().height - 1, 0)[0]);
  21. assertEquals(3.0, m2.size().height);
  22. assertEquals(1.0, m2.size().width);
  23. assertEquals(2.0, m2.get(0, 0)[0]);
  24. assertEquals(3.0, m2.get(1, 0)[0]);
  25. assertEquals(4.0, m2.get(2, 0)[0]);
  26. }
  27. public void testMatOfSubByteArray_BadArg() {
  28. byte[] inputBytes = { 1,2,3,4,5 };
  29. try {
  30. MatOfByte m1 = new MatOfByte(-1, inputBytes.length, inputBytes);
  31. fail("Missing check: offset < 0");
  32. } catch (IllegalArgumentException e) {
  33. // pass
  34. }
  35. try {
  36. MatOfByte m1 = new MatOfByte(0, inputBytes.length, null);
  37. fail("Missing check: NullPointerException");
  38. } catch (NullPointerException e) {
  39. // pass
  40. }
  41. try {
  42. MatOfByte m1 = new MatOfByte(0, -1, inputBytes);
  43. fail("Missing check: length < 0");
  44. } catch (IllegalArgumentException e) {
  45. // pass
  46. }
  47. try {
  48. MatOfByte m1 = new MatOfByte(1, inputBytes.length, inputBytes);
  49. fail("Missing check: buffer bounds");
  50. } catch (IllegalArgumentException e) {
  51. // pass
  52. }
  53. }
  54. }