summaryrefslogtreecommitdiff
path: root/tests/lib/test_frrscript.c
diff options
context:
space:
mode:
authorDonald Lee <dlqs@gmx.com>2021-07-08 03:07:06 +0800
committerDonald Lee <dlqs@gmx.com>2021-07-18 06:32:03 +0800
commit8a04c1e74e0a21d34a626c378a80c3d5b6302971 (patch)
tree34304327fc1716b6863ddb7f8263ff7d64efccbf /tests/lib/test_frrscript.c
parentb664092990bddc95562626847396e067d50fae85 (diff)
tests: Add more examples to get_result
Signed-off-by: Donald Lee <dlqs@gmx.com>
Diffstat (limited to 'tests/lib/test_frrscript.c')
-rw-r--r--tests/lib/test_frrscript.c38
1 files changed, 32 insertions, 6 deletions
diff --git a/tests/lib/test_frrscript.c b/tests/lib/test_frrscript.c
index 399b950799..e01807f193 100644
--- a/tests/lib/test_frrscript.c
+++ b/tests/lib/test_frrscript.c
@@ -28,14 +28,30 @@ int main(int argc, char **argv)
struct frrscript *fs = frrscript_new("script1");
int result;
+ /* Positive testing */
+
long long a = 100, b = 200;
result = frrscript_load(fs, "foo", NULL);
assert(result == 0);
result = frrscript_call(fs, "foo", ("a", &a), ("b", &b));
assert(result == 0);
- assert(a == 300);
- assert(b == 200);
+ assert(a == 101);
+ assert(b == 202);
+
+ a = 100, b = 200;
+
+ result = frrscript_load(fs, "bar", NULL);
+ assert(result == 0);
+ result = frrscript_call(fs, "bar", ("a", &a), ("b", &b));
+ assert(result == 0);
+ long long *cptr = frrscript_get_result(fs, "bar", "c", lua_tointegerp);
+
+ /* a should not occur in the returned table in script */
+ assert(a == 100);
+ assert(b == 202);
+ assert(*cptr == 303);
+ XFREE(MTYPE_TMP, cptr);
long long n = 5;
@@ -48,9 +64,7 @@ int main(int argc, char **argv)
assert(*ansptr == 120);
XFREE(MTYPE_TMP, ansptr);
- /* Function does not exist in script file*/
- result = frrscript_load(fs, "does_not_exist", NULL);
- assert(result == 1);
+ /* Negative testing */
/* Function does not exist in script file*/
result = frrscript_load(fs, "does_not_exist", NULL);
@@ -60,6 +74,11 @@ int main(int argc, char **argv)
result = frrscript_call(fs, "does_not_exist", ("a", &a), ("b", &b));
assert(result == 1);
+ /* Get result from a function that was not loaded */
+ long long *llptr =
+ frrscript_get_result(fs, "does_not_exist", "c", lua_tointegerp);
+ assert(llptr == NULL);
+
/* Function returns void */
result = frrscript_call(fs, "bad_return1");
assert(result == 1);
@@ -68,9 +87,16 @@ int main(int argc, char **argv)
result = frrscript_call(fs, "bad_return2");
assert(result == 1);
- /* Function throws exception */
+ /* Get non-existent result from a function */
result = frrscript_call(fs, "bad_return3");
assert(result == 1);
+ long long *cllptr =
+ frrscript_get_result(fs, "bad_return3", "c", lua_tointegerp);
+ assert(cllptr == NULL);
+
+ /* Function throws exception */
+ result = frrscript_call(fs, "bad_return4");
+ assert(result == 1);
frrscript_unload(fs);