Add tests for function pointers.

This commit is contained in:
Matt Pharr
2011-11-03 15:59:06 -07:00
parent afcd42028f
commit ba9bb3338f
25 changed files with 628 additions and 0 deletions

23
tests/funcptr-null-1.ispc Normal file
View File

@@ -0,0 +1,23 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
return min(a, b);
}
export void f_f(uniform float RET[], uniform float aFOO[]) {
float a = aFOO[programIndex];
float b = aFOO[0]-1;
uniform FuncType func = foo;
RET[programIndex] = (func ? func : bar)(a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = 1 + 1*programIndex;
}

26
tests/funcptr-null-2.ispc Normal file
View File

@@ -0,0 +1,26 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
return min(a, b);
}
export void f_f(uniform float RET[], uniform float aFOO[]) {
float a = aFOO[programIndex];
float b = aFOO[0]-1;
FuncType func = foo;
if (a == 2)
func = NULL;
RET[programIndex] = (func ? func : bar)(a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = 1 + 1*programIndex;
RET[1] = 0;
}

29
tests/funcptr-null-3.ispc Normal file
View File

@@ -0,0 +1,29 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
return min(a, b);
}
export void f_f(uniform float RET[], uniform float aFOO[]) {
float a = aFOO[programIndex];
float b = aFOO[0]-1;
FuncType func = foo;
if (a == 2)
func = NULL;
if (func != NULL)
RET[programIndex] = func(a, b);
else
RET[programIndex] = -1;
}
export void result(uniform float RET[]) {
RET[programIndex] = 1 + 1*programIndex;
RET[1] = -1;
}

29
tests/funcptr-null-4.ispc Normal file
View File

@@ -0,0 +1,29 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
return min(a, b);
}
export void f_f(uniform float RET[], uniform float aFOO[]) {
float a = aFOO[programIndex];
float b = aFOO[0]-1;
FuncType func = NULL;
if (a == 2)
func = foo;
if (func != NULL)
RET[programIndex] = func(a, b);
else
RET[programIndex] = -1;
}
export void result(uniform float RET[]) {
RET[programIndex] = -1;
RET[1] = 2;
}

29
tests/funcptr-null-5.ispc Normal file
View File

@@ -0,0 +1,29 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
return min(a, b);
}
export void f_f(uniform float RET[], uniform float aFOO[]) {
float a = aFOO[programIndex];
float b = aFOO[0]-1;
FuncType func = NULL;
if (a == 2)
func = foo;
if (func)
RET[programIndex] = func(a, b);
else
RET[programIndex] = -1;
}
export void result(uniform float RET[]) {
RET[programIndex] = -1;
RET[1] = 2;
}

29
tests/funcptr-null-6.ispc Normal file
View File

@@ -0,0 +1,29 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
return min(a, b);
}
export void f_f(uniform float RET[], uniform float aFOO[]) {
float a = aFOO[programIndex];
float b = aFOO[0]-1;
FuncType func = NULL;
if (a == 2)
func = foo;
if (!func)
RET[programIndex] = -1;
else
RET[programIndex] = func(a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = -1;
RET[1] = 2;
}

View File

@@ -0,0 +1,23 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
return min(a, b);
}
export void f_f(uniform float RET[], uniform float aFOO[]) {
float a = aFOO[programIndex];
float b = aFOO[0]-1;
uniform FuncType func = foo;
RET[programIndex] = func(a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = 1 + 1*programIndex;
}

View File

@@ -0,0 +1,25 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
return min(a, b);
}
export void f_f(uniform float RET[], uniform float aFOO[]) {
uniform FuncType func[] = { bar, foo };
float a = aFOO[programIndex];
float b = aFOO[0]-1; // == 0
func[min(a, 0)] = foo;
RET[programIndex] = func[0](a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = programIndex+1;
}

View File

@@ -0,0 +1,25 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
return min(a, b);
}
export void f_f(uniform float RET[], uniform float aFOO[]) {
float a = aFOO[programIndex];
float b = aFOO[0]-1;
uniform FuncType func = bar;
if (aFOO[0] == 1)
func = foo;
RET[programIndex] = func(a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = 1 + 1*programIndex;
}

View File

@@ -0,0 +1,23 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
return min(a, b);
}
export void f_f(uniform float RET[], uniform float aFOO[]) {
float a = aFOO[programIndex];
float b = aFOO[0]-1;
uniform FuncType func = (aFOO[0] == 1) ? foo : bar;
RET[programIndex] = func(a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = 1 + 1*programIndex;
}

View File

@@ -0,0 +1,23 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
return min(a, b);
}
export void f_f(uniform float RET[], uniform float aFOO[]) {
float a = aFOO[programIndex];
float b = aFOO[0]-1;
uniform FuncType func = min;
RET[programIndex] = func(a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = 0;
}

View File

@@ -0,0 +1,24 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
return min(a, b);
}
static uniform FuncType func = foo;
export void f_f(uniform float RET[], uniform float aFOO[]) {
float a = aFOO[programIndex];
float b = aFOO[0]-1;
RET[programIndex] = func(a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = 1 + 1*programIndex;
}

View File

@@ -0,0 +1,24 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
return min(a, b);
}
export void f_f(uniform float RET[], uniform float aFOO[]) {
static uniform FuncType func = foo;
float a = aFOO[programIndex];
float b = aFOO[0]-1;
RET[programIndex] = func(a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = 1 + 1*programIndex;
}

View File

@@ -0,0 +1,24 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
return min(a, b);
}
export void f_f(uniform float RET[], uniform float aFOO[]) {
uniform FuncType func[] = { foo, bar };
float a = aFOO[programIndex];
float b = aFOO[0]-1; // == 0
RET[programIndex] = func[(int)b](a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = programIndex+1;
}

View File

@@ -0,0 +1,24 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
return min(a, b);
}
export void f_f(uniform float RET[], uniform float aFOO[]) {
uniform FuncType func[] = { foo, bar };
float a = aFOO[programIndex];
float b = aFOO[0]-1; // == 0
RET[programIndex] = func[(int)b](a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = programIndex+1;
}

View File

@@ -0,0 +1,28 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
if (a < b)
return a;
else
return b;
}
export void f_f(uniform float RET[], uniform float aFOO[]) {
uniform FuncType func[] = { foo, bar };
float a = aFOO[programIndex];
float b = aFOO[0]-1; // == 0
RET[programIndex] = ((a == 1) ? bar : foo)(a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = programIndex+1;
RET[0] = 0;
}

View File

@@ -0,0 +1,23 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
return min(a, b);
}
export void f_f(uniform float RET[], uniform float aFOO[]) {
float a = aFOO[programIndex];
float b = aFOO[0]-1;
FuncType func = foo;
RET[programIndex] = func(a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = 1 + 1*programIndex;
}

View File

@@ -0,0 +1,24 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
return min(a, b);
}
export void f_f(uniform float RET[], uniform float aFOO[]) {
float a = aFOO[programIndex];
float b = aFOO[0]-1;
FuncType func = bar;
func = foo;
RET[programIndex] = func(a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = 1 + 1*programIndex;
}

View File

@@ -0,0 +1,25 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
return min(a, b);
}
FuncType func = bar;
export void f_f(uniform float RET[], uniform float aFOO[]) {
float a = aFOO[programIndex];
float b = aFOO[0]-1;
func = foo;
RET[programIndex] = func(a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = 1 + 1*programIndex;
}

View File

@@ -0,0 +1,25 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
return min(a, b);
}
export void f_f(uniform float RET[], uniform float aFOO[]) {
static FuncType func = bar;
float a = aFOO[programIndex];
float b = aFOO[0]-1;
func = foo;
RET[programIndex] = func(a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = 1 + 1*programIndex;
}

View File

@@ -0,0 +1,26 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
return min(a, b);
}
export void f_f(uniform float RET[], uniform float aFOO[]) {
FuncType func;
float a = aFOO[programIndex];
float b = aFOO[0]-1;
func = (a == 2) ? foo : bar;
RET[programIndex] = func(a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = 0;
RET[1] = 2;
}

View File

@@ -0,0 +1,24 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
return min(a, b);
}
export void f_f(uniform float RET[], uniform float aFOO[]) {
static FuncType func = bar;
float a = aFOO[programIndex];
float b = aFOO[0]-1;
RET[programIndex] = func(a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = 0;
}

View File

@@ -0,0 +1,24 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
return min(a, b);
}
export void f_f(uniform float RET[], uniform float aFOO[]) {
FuncType func[] = { foo, bar };
float a = aFOO[programIndex];
float b = aFOO[0]-1; // == 0
RET[programIndex] = func[(int)b](a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = programIndex+1;
}

View File

@@ -0,0 +1,24 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
return min(a, b);
}
export void f_f(uniform float RET[], uniform float aFOO[]) {
FuncType func[] = { foo, bar };
float a = aFOO[programIndex];
float b = aFOO[0]-1; // == 0
RET[programIndex] = func[(int)b](a, b);
}
export void result(uniform float RET[]) {
RET[programIndex] = programIndex+1;
}

View File

@@ -0,0 +1,25 @@
export uniform int width() { return programCount; }
typedef float (*FuncType)(float, float);
float foo(float a, float b) {
return a+b;
}
static float bar(float a, float b) {
return a<b?a:b;
}
export void f_f(uniform float RET[], uniform float aFOO[]) {
float a = aFOO[programIndex];
float b = aFOO[0]-1; // == 0
FuncType func[] = { (a == 1) ? foo : bar, (a == 1) ? bar : foo };
FuncType f = func[(a == 1) ? 0 : 1];
RET[programIndex] = f(a,b);
}
export void result(uniform float RET[]) {
RET[programIndex] = programIndex+1;
}