mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-03-14 06:48:16 +08:00
tests: added check for function-based str replacements
This commit is contained in:
@@ -18,9 +18,15 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <talloc.h>
|
||||||
|
|
||||||
#include "../src/str.h"
|
#include "../src/str.h"
|
||||||
|
|
||||||
|
static char *myfunc(void *pool, const char *str)
|
||||||
|
{
|
||||||
|
return talloc_strdup(pool, str);
|
||||||
|
}
|
||||||
|
|
||||||
#define STR1 "hi there people. How are you?"
|
#define STR1 "hi there people. How are you?"
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
@@ -52,7 +58,8 @@ int main()
|
|||||||
STR_TAB_SET(3, "%{D}", "dev1");
|
STR_TAB_SET(3, "%{D}", "dev1");
|
||||||
STR_TAB_SET(4, "%D", "dev2");
|
STR_TAB_SET(4, "%D", "dev2");
|
||||||
STR_TAB_SET(5, "%U", "u1");
|
STR_TAB_SET(5, "%U", "u1");
|
||||||
STR_TAB_TERM(6);
|
STR_TAB_SET_FUNC(6, "%{FUNC}", myfunc, "function-output");
|
||||||
|
STR_TAB_TERM(7);
|
||||||
|
|
||||||
/* check proper operation */
|
/* check proper operation */
|
||||||
#define STR2 "This is one route1, and one route2, while a route3 was replaced by dev1 and dev2 and dev1. That's all u1."
|
#define STR2 "This is one route1, and one route2, while a route3 was replaced by dev1 and dev2 and dev1. That's all u1."
|
||||||
@@ -85,5 +92,27 @@ int main()
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define STR3 "%U: Testing %{FUNC}."
|
||||||
|
#define STR3_OUT "u1: Testing function-output."
|
||||||
|
str_reset(&str);
|
||||||
|
str_append_str(&str, STR3);
|
||||||
|
|
||||||
|
if (str_replace_str(&str, tab) != 0) {
|
||||||
|
fprintf(stderr, "error in %d\n", __LINE__);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str.length != sizeof(STR3_OUT)-1) {
|
||||||
|
fprintf(stderr, "error in %d\n", __LINE__);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strncmp((char*)str.data, STR3_OUT, sizeof(STR3_OUT)-1) != 0) {
|
||||||
|
fprintf(stderr, "error in %d\n", __LINE__);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
str_clear(&str);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user