summaryrefslogtreecommitdiff
path: root/test/dns_decoder_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/dns_decoder_test.cpp')
-rw-r--r--test/dns_decoder_test.cpp84
1 files changed, 83 insertions, 1 deletions
diff --git a/test/dns_decoder_test.cpp b/test/dns_decoder_test.cpp
index 87ff3d3..aec2e21 100644
--- a/test/dns_decoder_test.cpp
+++ b/test/dns_decoder_test.cpp
@@ -13,6 +13,7 @@ extern "C"
#include "cJSON.h"
#include "dns_decoder.h"
+#include "toml/toml.h"
#include "stellar/stellar.h"
#include "stellar/session.h"
@@ -22,11 +23,14 @@ extern "C"
}
#endif
+#define DNS_DECODER_TEST_TOML_PATH "./etc/dns/dns_decoder.toml"
+
struct dns_decoder_test_plugin_env
{
int plugin_id;
int topic_id;
int result_index;
+ int commit_result_enable;
};
extern "C" int commit_test_result_json(cJSON *node, const char *name);
@@ -327,7 +331,14 @@ void dns_decoder_test_message_cb(struct session *ss, int topic_id, const void *m
dns_real_result_write_file(real_result_str);
free(real_result_str);
- commit_test_result_json(real_result, result_name);
+ if(plugin_env->commit_result_enable==1)
+ {
+ commit_test_result_json(real_result, result_name);
+ }
+ else
+ {
+ cJSON_Delete(real_result);
+ }
}
void *dns_decoder_test_per_session_context_new(struct session *sess, void *plugin_env)
@@ -340,10 +351,81 @@ void dns_decoder_test_per_session_context_free(struct session *sess, void *sessi
}
+
+int32_t dns_decoder_test_config_load(const char *cfg_path, struct dns_decoder_test_plugin_env *plugin_env)
+{
+ FILE *fp=fopen(cfg_path, "r");
+ if (NULL==fp)
+ {
+ fprintf(stderr, "[%s:%d] Can't open config file: %s", __FUNCTION__, __LINE__, cfg_path);
+ return -1;
+ }
+
+ int32_t ret=0;
+ char errbuf[256]={0};
+
+ toml_table_t *root=toml_parse_file(fp, errbuf, sizeof(errbuf));
+ fclose(fp);
+
+ toml_table_t *decoder_tbl=toml_table_in(root, "decoder");
+ if(NULL==decoder_tbl)
+ {
+ fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder]", __FUNCTION__, __LINE__, cfg_path);
+ toml_free(root);
+ return -1;
+ }
+
+ toml_table_t *dns_tbl=toml_table_in(decoder_tbl, "dns");
+ if(NULL==dns_tbl)
+ {
+ fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder.dns]", __FUNCTION__, __LINE__, cfg_path);
+ toml_free(root);
+ return -1;
+ }
+
+ toml_table_t *test_tbl=toml_table_in(dns_tbl, "test");
+ if(NULL==test_tbl)
+ {
+ fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder.dns.test]", __FUNCTION__, __LINE__, cfg_path);
+ toml_free(root);
+ return -1;
+ }
+
+ toml_datum_t commit_result_enable_val=toml_string_in(test_tbl, "commit_result_enable");
+ if(commit_result_enable_val.ok==0)
+ {
+ plugin_env->commit_result_enable=0;
+ fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder.dns.test.commit_result_enable]", __FUNCTION__, __LINE__, cfg_path);
+ }
+ else
+ {
+ if(memcmp("no", commit_result_enable_val.u.s, strlen("no"))==0)
+ {
+ plugin_env->commit_result_enable=0;
+ }
+ else if(memcmp("yes", commit_result_enable_val.u.s, strlen("yes"))==0)
+ {
+ plugin_env->commit_result_enable=1;
+ }
+ else
+ {
+ plugin_env->commit_result_enable=1;
+ fprintf(stderr, "[%s:%d] config file: %s key: [decoder.dns.test.commit_result_enable] value is not yes or no", __FUNCTION__, __LINE__, cfg_path);
+ }
+
+ }
+
+ toml_free(root);
+
+ return ret;
+}
+
extern "C" void *dns_decoder_test_init(struct stellar *st)
{
struct dns_decoder_test_plugin_env *plugin_env=(struct dns_decoder_test_plugin_env *)calloc(1, sizeof(struct dns_decoder_test_plugin_env));
+
plugin_env->result_index=1;
+ dns_decoder_test_config_load(DNS_DECODER_TEST_TOML_PATH, plugin_env);
plugin_env->plugin_id=stellar_session_plugin_register(st, dns_decoder_test_per_session_context_new, dns_decoder_test_per_session_context_free, plugin_env);
if(plugin_env->plugin_id<0)