[asterisk-commits] eliel: branch group/data_api_gsoc2009 r204404 - in /team/group/data_api_gsoc2...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jun 30 10:37:56 CDT 2009
Author: eliel
Date: Tue Jun 30 10:37:53 2009
New Revision: 204404
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=204404
Log:
Move the test code to a module (not finish yet, just the skel).
Added:
team/group/data_api_gsoc2009/tests/test_data.c (with props)
Modified:
team/group/data_api_gsoc2009/include/asterisk/data.h
team/group/data_api_gsoc2009/main/data.c
Modified: team/group/data_api_gsoc2009/include/asterisk/data.h
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/data_api_gsoc2009/include/asterisk/data.h?view=diff&rev=204404&r1=204403&r2=204404
==============================================================================
--- team/group/data_api_gsoc2009/include/asterisk/data.h (original)
+++ team/group/data_api_gsoc2009/include/asterisk/data.h Tue Jun 30 10:37:53 2009
@@ -244,7 +244,14 @@
* \param[in] path A path to the node to get the type.
* \return The type of the requested node type.
*/
-enum ast_data_type ast_data_get_type(struct ast_data *res, const char *path);
+enum ast_data_type ast_data_retrieve_type(struct ast_data *res, const char *path);
+
+/*!
+ * \brief Get the node name.
+ * \param[in] node The node pointer.
+ * \returns The node name.
+ */
+char *ast_data_retrieve_name(struct ast_data *node);
/*!
* \brief Add a container child.
Modified: team/group/data_api_gsoc2009/main/data.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/data_api_gsoc2009/main/data.c?view=diff&rev=204404&r1=204403&r2=204404
==============================================================================
--- team/group/data_api_gsoc2009/main/data.c (original)
+++ team/group/data_api_gsoc2009/main/data.c Tue Jun 30 10:37:53 2009
@@ -486,8 +486,9 @@
*/
static void data_result_destructor(void *obj)
{
- struct ast_data *child, *root = obj;
- struct ao2_iterator i;
+ struct ast_data *root = obj;
+
+ ast_log(LOG_ERROR, "Destroying node: %s\n", root->name);
switch (root->type) {
case AST_DATA_POINTER:
@@ -790,7 +791,7 @@
case AST_DATA_POINTER:
case AST_DATA_IPADDR:
snprintf(node_content, sizeof(node_content), "%s", ast_inet_ntoa(node->payload.ipaddr));
- ast_xml_set_Text(child_xml, node_content);
+ ast_xml_set_text(child_xml, node_content);
break;
}
ast_xml_add_child(parent_xml, child_xml);
@@ -829,7 +830,7 @@
return doc;
}
-enum ast_data_type ast_data_get_type(struct ast_data *node, const char *path)
+enum ast_data_type ast_data_retrieve_type(struct ast_data *node, const char *path)
{
struct ast_data *internal;
@@ -839,6 +840,11 @@
}
return internal->type;
+}
+
+char *ast_data_retrieve_name(struct ast_data *node)
+{
+ return node->name;
}
/*!
@@ -1016,85 +1022,6 @@
return res;
}
-/* XXX: test callback */
-static struct ast_data *test_data_provider(void)
-{
- struct ast_data *res, *internal;
-
- res = ast_data_create("root_test");
- if (!res) {
- return NULL;
- }
-
- ast_data_add_int(res, "data1", 10);
- ast_data_add_dbl(res, "data2", 20);
- ast_data_add_bool(res, "data3", 1);
-
- internal = ast_data_add_node(res, "internal");
- if (!internal) {
- return res;
- }
-
- ast_data_add_str(internal, "name", "eliel");
-
- return res;
-}
-
-/* XXX: test */
-static const struct ast_data_handler test_provider = {
- .get = test_data_provider
-};
-
-/* XXX: test */
-static const struct ast_data_entry test_providers[] = {
- AST_DATA_ENTRY("asterisk/node1/node11/node111", &test_provider),
- AST_DATA_ENTRY("asterisk/node1/node12/node121", &test_provider),
- AST_DATA_ENTRY("asterisk/node1/node13/node131", &test_provider),
- AST_DATA_ENTRY("asterisk/node1/node14/node141", &test_provider),
- AST_DATA_ENTRY("asterisk/node1/node14/node142", &test_provider),
- AST_DATA_ENTRY("asterisk/node1/node15/node151", &test_provider),
- AST_DATA_ENTRY("asterisk/node1/node15/node152", &test_provider),
-};
-
-/* XXX: test */
-static void runtest(void)
-{
- struct ast_data *res, *node;
- struct ast_data_query query = {
- .path = "asterisk/node1",
- };
- struct ast_data_iterator *i;
- struct ast_xml_doc *doc;
- FILE *outfile;
-
- /* some tests */
- ast_data_register_multiple(test_providers, ARRAY_LEN(test_providers));
-
- res = ast_data_get(&query);
-
- /* test the iterators */
- i = ast_data_iterator_init(res, NULL);
- while ((node = ast_data_iterator_next(i))) {
- ast_log(LOG_ERROR, "TESTING ITERATOR: %s\n", node->name);
- }
- ast_data_iterator_end(i);
-
- if (res) {
- ast_data_free(res);
- }
-
- /* and now get it in xml form. */
- doc = ast_data_get_xml(&query);
- if (doc) {
- outfile = fopen("/tmp/ast_data_xml_output", "w+");
- if (outfile) {
- ast_xml_doc_dump_file(outfile, doc);
- }
- ast_xml_close(doc);
- }
-
- ast_data_unregister(NULL);
-}
int ast_data_init(void)
{
@@ -1105,8 +1032,5 @@
return -1;
}
- /* XXX: test */
- runtest();
-
return 0;
}
Added: team/group/data_api_gsoc2009/tests/test_data.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/data_api_gsoc2009/tests/test_data.c?view=auto&rev=204404
==============================================================================
--- team/group/data_api_gsoc2009/tests/test_data.c (added)
+++ team/group/data_api_gsoc2009/tests/test_data.c Tue Jun 30 10:37:53 2009
@@ -1,0 +1,211 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2009, Eliel C. Sardanons (LU1ALY) <eliels at gmail.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief DATA API Test
+ *
+ * \author\verbatim Eliel C. Sardanons <eliels at gmail.com> \endverbatim
+ *
+ * \ingroup tests
+ */
+
+/*** MODULEINFO
+ <defaultenabled>no</defaultenabled>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/file.h"
+#include "asterisk/pbx.h"
+#include "asterisk/module.h"
+#include "asterisk/lock.h"
+#include "asterisk/app.h"
+#include "asterisk/cli.h"
+#include "asterisk/data.h"
+
+static struct ast_data *test_data_provider(void)
+{
+ struct ast_data *res, *internal;
+
+ res = ast_data_create("root_test");
+ if (!res) {
+ return NULL;
+ }
+
+ ast_data_add_int(res, "data1", 10);
+ ast_data_add_dbl(res, "data2", 20);
+ ast_data_add_bool(res, "data3", 1);
+
+ internal = ast_data_add_node(res, "internal");
+ if (!internal) {
+ return res;
+ }
+
+ ast_data_add_str(internal, "name", "eliel");
+
+ return res;
+}
+
+static const struct ast_data_handler test_provider = {
+ .get = test_data_provider
+};
+
+static const struct ast_data_entry test_providers[] = {
+ AST_DATA_ENTRY("test/node1/node11/node111", &test_provider),
+/*
+ AST_DATA_ENTRY("test/node1/node12/node121", &test_provider),
+ AST_DATA_ENTRY("test/node1/node13/node131", &test_provider),
+ AST_DATA_ENTRY("test/node2/node14/node141", &test_provider),
+ AST_DATA_ENTRY("test/node2/node14/node142", &test_provider),
+ AST_DATA_ENTRY("test/node2/node15/node151", &test_provider),
+ AST_DATA_ENTRY("test/node2/node15/node152", &test_provider),
+*/
+};
+
+static char *handle_cli_data_get_bench(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "data test get benchmark";
+ e->usage = ""
+ "Usage: data test get benchmark\n"
+ " Benchmark ast_data get performance.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ return CLI_SUCCESS;
+}
+
+static char *handle_cli_data_get_automatic(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ struct ast_data *res, *node;
+ struct ast_data_iterator *i;
+ struct ast_data_query query = {
+ .path = "test",
+ };
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "data test get automatic";
+ e->usage = "Usage: data test get automatic\n"
+ " Automatic ast_data get test.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ /* get the tree and check for errors. */
+ ast_cli(a->fd, "Getting tree... ");
+ res = ast_data_get(&query);
+ if (res) {
+ ast_cli(a->fd, "OK\n");
+ } else {
+ ast_cli(a->fd, "ERROR\n");
+ return CLI_FAILURE;
+ }
+
+ /* initiate the iterator and check for errors. */
+ i = ast_data_iterator_init(res, NULL);
+ ast_cli(a->fd, "Starting iterator... ");
+ if (i) {
+ ast_cli(a->fd, " OK\n");
+ } else {
+ ast_cli(a->fd, " ERROR\n");
+ return CLI_FAILURE;
+ }
+
+ /* walk the returned nodes. */
+ while ((node = ast_data_iterator_next(i))) {
+ ast_cli(a->fd, "TESTING ITERATOR: %s\n", ast_data_retrieve_name(node));
+ }
+
+ /* finish the iterator. */
+ ast_cli(a->fd, "Finish iterating...\n");
+ ast_data_iterator_end(i);
+
+ ast_data_free(res);
+
+ return CLI_SUCCESS;
+}
+
+static char *handle_cli_data_get_dump(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ struct ast_xml_doc *doc;
+ FILE *outfile;
+ struct ast_data_query query = {
+ .path = "test",
+ };
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "data test get dump";
+ e->usage = "Usage: data test get dump <output-filename>\n"
+ " Dump ast_data test to a file in XML format.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ /* and now get it in xml form. */
+ doc = ast_data_get_xml(&query);
+ if (doc) {
+ outfile = fopen("/tmp/ast_data_xml_output", "w+");
+ if (outfile) {
+ ast_xml_doc_dump_file(outfile, doc);
+ }
+ ast_xml_close(doc);
+ } else {
+ return CLI_FAILURE;
+ }
+
+ return CLI_SUCCESS;
+}
+
+static struct ast_cli_entry cli_data[] = {
+ AST_CLI_DEFINE(handle_cli_data_get_bench, "Benchmark ast_data get performance"),
+ AST_CLI_DEFINE(handle_cli_data_get_automatic, "Test data get"),
+ AST_CLI_DEFINE(handle_cli_data_get_dump, "Dump test data to xml")
+};
+
+static int unload_module(void)
+{
+ ast_cli_unregister_multiple(cli_data, ARRAY_LEN(cli_data));
+
+ ast_data_unregister(NULL);
+
+ return 0;
+}
+
+static int load_module(void)
+{
+ int res;
+
+ res = ast_data_register_multiple(test_providers, ARRAY_LEN(test_providers));
+ if (res) {
+ return AST_MODULE_LOAD_FAILURE;
+ }
+
+ ast_cli_register_multiple(cli_data, ARRAY_LEN(cli_data));
+
+ return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Data API Test");
Propchange: team/group/data_api_gsoc2009/tests/test_data.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/group/data_api_gsoc2009/tests/test_data.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/group/data_api_gsoc2009/tests/test_data.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the asterisk-commits
mailing list