From 4836f3ab7916c681450d06f118b90c31f0bcdc8c Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Wed, 25 Aug 2010 12:59:35 +0200 Subject: added new CL_INVALID_PROPERTY exception + CLException junit test. --- src/com/jogamp/opencl/CLException.java | 20 +++++++++++++--- test/com/jogamp/opencl/CLExceptionTest.java | 37 +++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 test/com/jogamp/opencl/CLExceptionTest.java diff --git a/src/com/jogamp/opencl/CLException.java b/src/com/jogamp/opencl/CLException.java index e7133994..4955cc42 100644 --- a/src/com/jogamp/opencl/CLException.java +++ b/src/com/jogamp/opencl/CLException.java @@ -14,8 +14,9 @@ public class CLException extends RuntimeException { public final int errorcode; public final String error; - private final static String ERROR_CODE_DOC = - "http://www.khronos.org/opencl/sdk/1.1/docs/man/xhtml/errors.html"; + //man page no longer exists +// private final static String ERROR_CODE_DOC = +// "http://www.khronos.org/opencl/sdk/1.1/docs/man/xhtml/errors.html"; public CLException(String message) { super(message); @@ -24,7 +25,7 @@ public class CLException extends RuntimeException { } private CLException(int errorcode, String errorStr, String message) { - super(message + "\nerror: " + errorStr + " (man page: "+ERROR_CODE_DOC+")"); + super(message + "\nerror: " + errorStr/* + " (man page: "+ERROR_CODE_DOC+")"*/); this.error = errorStr; this.errorcode = errorcode; } @@ -113,6 +114,7 @@ public class CLException extends RuntimeException { case CL_INVALID_BUFFER_SIZE: return "CL_INVALID_BUFFER_SIZE"; case CL_INVALID_MIP_LEVEL: return "CL_INVALID_MIP_LEVEL"; case CL_INVALID_GLOBAL_WORK_SIZE: return "CL_INVALID_GLOBAL_WORK_SIZE"; + case CL_INVALID_PROPERTY: return "CL_INVALID_PROPERTY"; case CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR: return "CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR"; case CL_PLATFORM_NOT_FOUND_KHR: return "CL_PLATFORM_NOT_FOUND_KHR"; case CL_MISALIGNED_SUB_BUFFER_OFFSET: return "CL_MISALIGNED_SUB_BUFFER_OFFSET"; @@ -169,6 +171,7 @@ public class CLException extends RuntimeException { case CL_INVALID_BUFFER_SIZE: return new CLInvalidBufferSizeException(message); case CL_INVALID_MIP_LEVEL: return new CLInvalidMipLevelException(message); case CL_INVALID_GLOBAL_WORK_SIZE: return new CLInvalidGlobalWorkSizeException(message); + case CL_INVALID_PROPERTY: return new CLInvalidPropertyException(message); case CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR: return new CLInvalidGLSharegroupReferenceKhrException(message); case CL_PLATFORM_NOT_FOUND_KHR: return new CLPlatformNotFoundKhrException(message); case CL_MISALIGNED_SUB_BUFFER_OFFSET: return new CLMisalignedSubBufferOffsetException(message); @@ -683,6 +686,17 @@ public class CLException extends RuntimeException { } } + /** + * {@link CLException} thrown on CL.CL_INVALID_PROPERTY errors. + * @author Michael Bien + */ + public final static class CLInvalidPropertyException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_PROPERTY; + public CLInvalidPropertyException(String message) { + super(CL_INVALID_PROPERTY, "CL_INVALID_PROPERTY", message); + } + } + /** * {@link CLException} thrown on CL.CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR errors. * @author Michael Bien diff --git a/test/com/jogamp/opencl/CLExceptionTest.java b/test/com/jogamp/opencl/CLExceptionTest.java new file mode 100644 index 00000000..f6d7ca7b --- /dev/null +++ b/test/com/jogamp/opencl/CLExceptionTest.java @@ -0,0 +1,37 @@ + +package com.jogamp.opencl; + +import java.lang.reflect.InvocationTargetException; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author Michael Bien + */ +public class CLExceptionTest { + + @Test + public void testCLExceptions() throws InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException { + Class[] subTypes = CLException.class.getDeclaredClasses(); + + for (Class type : subTypes) { + + if(type.getName().startsWith(CLException.class.getName()+"$CL")) { + + CLException exception = (CLException) type.getConstructor(String.class).newInstance("foo"); + + assertNotNull("can not resolve "+exception, CLException.resolveErrorCode(exception.errorcode)); + + try{ + CLException.checkForError(exception.errorcode, "foo"); + fail("expected exception for: "+exception.getClass().getName()+" code: "+exception.errorcode); + }catch(CLException ex) { + assertTrue("wrong instance; expected "+exception.getClass()+" but got "+ex.getClass(), + exception.getClass().equals(ex.getClass())); + } + } + } + } + +} -- cgit v1.2.3