--- var_test.c 2002/02/27 13:44:16 1.33
+++ var_test.c 2002/02/28 08:08:16 1.34
@@ -205,26 +205,38 @@
var_rc_t rc;
size_t i;
char buffer[1024];
+ var_t *var;
+ char *err;
- for (i = 0; i < sizeof(tests) / sizeof(struct test_case); ++i) {
+ if ((rc = var_create(&var)) != VAR_OK) {
+ var_strerror(NULL, rc, &err);
+ printf("unable to create variable expansion context: %s (%d)\n", err, rc);
+ return 1;
+ }
+ if ((rc = var_config(var, VAR_CONFIG_CB_VALUE, var_lookup, vars)) != VAR_OK) {
+ var_strerror(NULL, rc, &err);
+ printf("unable to configure variable expansion context: %s (%d)\n", err, rc);
+ return 1;
+ }
+
+ for (i = 0; i < sizeof(tests)/sizeof(struct test_case); ++i) {
#ifdef DEBUG
printf("Test case #%02d: Original input is '%s'.\n", i,
tests[i].input);
#endif
- rc = var_unescape(tests[i].input, strlen(tests[i].input), buffer, 0);
+ rc = var_unescape(var, tests[i].input, strlen(tests[i].input), buffer, sizeof(buffer), 0);
if (rc != VAR_OK) {
- printf ("Test case #%d: First var_unescape() failed with return code %d ('%s').\n",
- i, rc, var_strerror(rc));
+ var_strerror(var, rc, &err);
+ printf("Test case #%d: var_unescape() failed: %s (%d)\n", i, err, rc);
return 1;
}
#ifdef DEBUG
printf("Test case #%02d: Unescaped input is '%s'.\n", i, buffer);
#endif
- rc = var_expand(buffer, strlen(buffer), &tmp, &tmp_len,
- &var_lookup, (void *)vars, NULL, 0);
+ rc = var_expand(var, buffer, strlen(buffer), &tmp, &tmp_len, 0);
if (rc != VAR_OK) {
- printf ("Test case #%d: var_expand() failed with return code %d ('%s').\n",
- i, rc, var_strerror(rc));
+ var_strerror(var, rc, &err);
+ printf("Test case #%d: var_expand() failed: %s (%d).\n", i, err, rc);
return 1;
}
#ifdef DEBUG
@@ -234,11 +246,12 @@
|| tmp == NULL
|| memcmp(tests[i].expected, tmp, tmp_len) != 0) {
printf("Test case #%d: Expected result '%s' but got '%s'.\n",
- i, tests[i].expected, tmp);
+ i, tests[i].expected, tmp);
return 1;
}
free(tmp);
}
+ var_destroy(var);
return 0;
}
|