summaryrefslogtreecommitdiffstats
path: root/test/com/jogamp/opencl/CLExceptionTest.java
blob: f6d7ca7b341a3bc14f017bdb126241345a206415 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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()));
                }
            }
        }
    }

}