2020-06-05 14:57:20 -07:00
|
|
|
#include "./api_tests.h"
|
|
|
|
|
|
|
|
|
|
static const char* testName = NULL;
|
|
|
|
|
|
|
|
|
|
WrenForeignMethodFn APITest_bindForeignMethod(
|
2015-05-24 09:23:30 -07:00
|
|
|
WrenVM* vm, const char* module, const char* className,
|
|
|
|
|
bool isStatic, const char* signature)
|
2018-03-24 11:10:36 -07:00
|
|
|
{
|
2018-07-15 20:09:41 -07:00
|
|
|
if (strncmp(module, "./test/", 7) != 0) return NULL;
|
2015-05-24 09:23:30 -07:00
|
|
|
|
|
|
|
|
// For convenience, concatenate all of the method qualifiers into a single
|
|
|
|
|
// signature string.
|
|
|
|
|
char fullName[256];
|
|
|
|
|
fullName[0] = '\0';
|
|
|
|
|
if (isStatic) strcat(fullName, "static ");
|
|
|
|
|
strcat(fullName, className);
|
|
|
|
|
strcat(fullName, ".");
|
|
|
|
|
strcat(fullName, signature);
|
2020-06-05 14:57:20 -07:00
|
|
|
|
2015-12-15 16:02:13 -08:00
|
|
|
WrenForeignMethodFn method = NULL;
|
2020-06-05 14:57:20 -07:00
|
|
|
|
2015-12-15 16:02:13 -08:00
|
|
|
method = benchmarkBindMethod(fullName);
|
|
|
|
|
if (method != NULL) return method;
|
2020-06-05 14:57:20 -07:00
|
|
|
|
2019-02-08 17:09:39 -08:00
|
|
|
method = callCallsForeignBindMethod(fullName);
|
|
|
|
|
if (method != NULL) return method;
|
2020-06-05 14:57:20 -07:00
|
|
|
|
2016-06-09 19:14:21 -07:00
|
|
|
method = errorBindMethod(fullName);
|
|
|
|
|
if (method != NULL) return method;
|
2015-12-26 10:53:14 -08:00
|
|
|
|
|
|
|
|
method = getVariableBindMethod(fullName);
|
|
|
|
|
if (method != NULL) return method;
|
|
|
|
|
|
2015-12-15 16:02:13 -08:00
|
|
|
method = foreignClassBindMethod(fullName);
|
|
|
|
|
if (method != NULL) return method;
|
2020-06-05 14:57:20 -07:00
|
|
|
|
2016-05-20 20:55:28 -07:00
|
|
|
method = handleBindMethod(fullName);
|
|
|
|
|
if (method != NULL) return method;
|
|
|
|
|
|
2015-12-16 16:28:26 -08:00
|
|
|
method = listsBindMethod(fullName);
|
|
|
|
|
if (method != NULL) return method;
|
2020-06-05 14:57:20 -07:00
|
|
|
|
2020-06-14 22:45:23 +01:00
|
|
|
method = mapsBindMethod(fullName);
|
|
|
|
|
if (method != NULL) return method;
|
|
|
|
|
|
2016-03-03 14:31:47 -08:00
|
|
|
method = newVMBindMethod(fullName);
|
|
|
|
|
if (method != NULL) return method;
|
2020-06-05 14:57:20 -07:00
|
|
|
|
2018-03-23 07:54:09 -07:00
|
|
|
method = resolutionBindMethod(fullName);
|
|
|
|
|
if (method != NULL) return method;
|
|
|
|
|
|
2015-12-16 13:00:13 -08:00
|
|
|
method = slotsBindMethod(fullName);
|
2015-12-15 16:02:13 -08:00
|
|
|
if (method != NULL) return method;
|
2020-06-05 14:57:20 -07:00
|
|
|
|
2017-03-22 07:26:19 -07:00
|
|
|
method = userDataBindMethod(fullName);
|
|
|
|
|
if (method != NULL) return method;
|
2015-05-24 09:23:30 -07:00
|
|
|
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Unknown foreign method '%s' for test '%s'\n", fullName, testName);
|
2015-05-24 10:04:24 -07:00
|
|
|
exit(1);
|
2015-05-24 09:23:30 -07:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-05 14:57:20 -07:00
|
|
|
WrenForeignClassMethods APITest_bindForeignClass(
|
2015-08-15 12:07:53 -07:00
|
|
|
WrenVM* vm, const char* module, const char* className)
|
|
|
|
|
{
|
|
|
|
|
WrenForeignClassMethods methods = { NULL, NULL };
|
2020-06-05 14:57:20 -07:00
|
|
|
if (strncmp(module, "./test/api", 7) != 0) return methods;
|
2015-08-15 12:07:53 -07:00
|
|
|
|
2015-12-15 16:02:13 -08:00
|
|
|
foreignClassBindClass(className, &methods);
|
2016-02-19 07:18:00 -08:00
|
|
|
if (methods.allocate != NULL) return methods;
|
2020-06-05 14:57:20 -07:00
|
|
|
|
2016-08-28 08:23:27 -07:00
|
|
|
resetStackAfterForeignConstructBindClass(className, &methods);
|
2016-02-19 07:18:00 -08:00
|
|
|
if (methods.allocate != NULL) return methods;
|
2020-06-05 14:57:20 -07:00
|
|
|
|
2016-08-28 08:23:27 -07:00
|
|
|
slotsBindClass(className, &methods);
|
|
|
|
|
if (methods.allocate != NULL) return methods;
|
2020-06-05 14:57:20 -07:00
|
|
|
|
2016-02-19 07:18:00 -08:00
|
|
|
fprintf(stderr,
|
|
|
|
|
"Unknown foreign class '%s' for test '%s'\n", className, testName);
|
|
|
|
|
exit(1);
|
2015-08-15 12:07:53 -07:00
|
|
|
return methods;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-05 14:57:20 -07:00
|
|
|
int APITest_Run(WrenVM* vm, const char* inTestName)
|
2018-03-20 06:54:51 -07:00
|
|
|
{
|
2020-06-05 14:57:20 -07:00
|
|
|
testName = inTestName;
|
|
|
|
|
if (strstr(inTestName, "/call.wren") != NULL)
|
2016-11-01 08:40:16 -07:00
|
|
|
{
|
2020-06-05 14:57:20 -07:00
|
|
|
return callRunTests(vm);
|
2016-11-01 08:40:16 -07:00
|
|
|
}
|
2020-06-05 14:57:20 -07:00
|
|
|
else if (strstr(inTestName, "/call_calls_foreign.wren") != NULL)
|
2019-02-08 17:09:39 -08:00
|
|
|
{
|
2020-06-05 14:57:20 -07:00
|
|
|
return callCallsForeignRunTests(vm);
|
2019-02-08 17:09:39 -08:00
|
|
|
}
|
2020-06-05 14:57:20 -07:00
|
|
|
else if (strstr(inTestName, "/call_wren_call_root.wren") != NULL)
|
2018-07-21 10:02:29 -07:00
|
|
|
{
|
2020-06-05 14:57:20 -07:00
|
|
|
return callWrenCallRootRunTests(vm);
|
2018-07-21 10:02:29 -07:00
|
|
|
}
|
2020-06-05 14:57:20 -07:00
|
|
|
else if (strstr(inTestName, "/reset_stack_after_call_abort.wren") != NULL)
|
2016-11-01 08:40:16 -07:00
|
|
|
{
|
2020-06-05 14:57:20 -07:00
|
|
|
return resetStackAfterCallAbortRunTests(vm);
|
2016-11-01 08:40:16 -07:00
|
|
|
}
|
2020-06-05 14:57:20 -07:00
|
|
|
else if (strstr(inTestName, "/reset_stack_after_foreign_construct.wren") != NULL)
|
2015-05-24 09:23:30 -07:00
|
|
|
{
|
2020-06-05 14:57:20 -07:00
|
|
|
return resetStackAfterForeignConstructRunTests(vm);
|
2015-05-24 09:23:30 -07:00
|
|
|
}
|
|
|
|
|
|
2020-06-05 14:57:20 -07:00
|
|
|
return 0;
|
2015-05-24 09:23:30 -07:00
|
|
|
}
|