[asterisk-commits] dvossel: branch dvossel/fixtheworld_phase1_step1 r298831 - in /team/dvossel/f...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Dec 17 21:19:11 UTC 2010
Author: dvossel
Date: Fri Dec 17 15:19:07 2010
New Revision: 298831
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=298831
Log:
ast_cap iterator unit test
Modified:
team/dvossel/fixtheworld_phase1_step1/include/asterisk/format_cap.h
team/dvossel/fixtheworld_phase1_step1/main/format_cap.c
team/dvossel/fixtheworld_phase1_step1/tests/test_format_api.c
Modified: team/dvossel/fixtheworld_phase1_step1/include/asterisk/format_cap.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step1/include/asterisk/format_cap.h?view=diff&rev=298831&r1=298830&r2=298831
==============================================================================
--- team/dvossel/fixtheworld_phase1_step1/include/asterisk/format_cap.h (original)
+++ team/dvossel/fixtheworld_phase1_step1/include/asterisk/format_cap.h Fri Dec 17 15:19:07 2010
@@ -87,6 +87,37 @@
*/
struct ast_cap *ast_cap_get_type(struct ast_cap *cap, enum ast_format_type ftype);
+
+/*! \brief Start iterating formats */
+void ast_cap_iter_start(struct ast_cap *cap);
+
+/*! \brief Next format in interation
+ *
+ * \details
+ * Here is how to use the ast_cap iterator.
+ *
+ * 1. call ast_cap_iter_start
+ * 2. call ast_cap_iter_next in a loop until it returns -1
+ * 3. call ast_cap_iter_end to terminate the iterator.
+ *
+ * example:
+ *
+ * ast_cap_iter_start(cap);
+ * while (!ast_cap_iter_next(cap, &format)) {
+ *
+ * }
+ * ast_cap_iter_end(Cap);
+ *
+ * \retval 0 on success, new format is copied into input format struct
+ * \retval -1, no more formats are present.
+ */
+int ast_cap_iter_next(struct ast_cap *cap, struct ast_format *format);
+
+/*! \brief Ends ast_cap iteration.
+ * \note this must be call after every ast_cap_iter_start
+ */
+void ast_cap_iter_end(struct ast_cap *cap);
+
/*!
* \brief ast_cap to iax2 bitfield format represenatation
*
Modified: team/dvossel/fixtheworld_phase1_step1/main/format_cap.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step1/main/format_cap.c?view=diff&rev=298831&r1=298830&r2=298831
==============================================================================
--- team/dvossel/fixtheworld_phase1_step1/main/format_cap.c (original)
+++ team/dvossel/fixtheworld_phase1_step1/main/format_cap.c Fri Dec 17 15:19:07 2010
@@ -38,6 +38,7 @@
struct ast_cap {
/* The capabilities structure is just an ao2 container of ast_formats */
struct ao2_container *formats;
+ struct ao2_iterator it;
};
/*! format exists within capabilities structure if it is identical to
@@ -247,6 +248,29 @@
return NULL;
}
+void ast_cap_iter_start(struct ast_cap *cap)
+{
+ cap->it = ao2_iterator_init(cap->formats, 0);
+}
+
+void ast_cap_iter_end(struct ast_cap *cap)
+{
+ ao2_iterator_destroy(&cap->it);
+}
+
+int ast_cap_iter_next(struct ast_cap *cap, struct ast_format *format)
+{
+ struct ast_format *tmp = ao2_iterator_next(&cap->it);
+
+ if (!tmp) {
+ return -1;
+ }
+ ast_format_copy(tmp, format);
+ ao2_ref(tmp, -1);
+
+ return 0;
+}
+
uint64_t ast_cap_to_iax2(struct ast_cap *cap)
{
uint64_t res = 0;
@@ -274,6 +298,4 @@
ast_cap_add(dst, ast_format_from_iax2(tmp, &tmp_format));
}
}
-
-
-}
+}
Modified: team/dvossel/fixtheworld_phase1_step1/tests/test_format_api.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step1/tests/test_format_api.c?view=diff&rev=298831&r1=298830&r2=298831
==============================================================================
--- team/dvossel/fixtheworld_phase1_step1/tests/test_format_api.c (original)
+++ team/dvossel/fixtheworld_phase1_step1/tests/test_format_api.c Fri Dec 17 15:19:07 2010
@@ -519,11 +519,59 @@
return res;
}
+/*!
+ * \internal
+ */
+AST_TEST_DEFINE(format_test4)
+{
+ int num = 0;
+ struct ast_format tmpformat = { 0, };
+ struct ast_cap *cap;
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "ast_format_test4";
+ info->category = "/main/format/";
+ info->summary = "Test ast_cap iterator";
+ info->description =
+ "This test exercises the Ast Capability API iterators.";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ cap = ast_cap_alloc();
+ if (!cap) {
+ ast_test_status_update(test, "alloc failed\n");
+ return AST_TEST_FAIL;
+ }
+
+ ast_cap_add(cap, ast_format_set(&tmpformat, AST_FORMATNEW_GSM, 0));
+ ast_cap_add(cap, ast_format_set(&tmpformat, AST_FORMATNEW_ULAW, 0));
+ ast_cap_add(cap, ast_format_set(&tmpformat, AST_FORMATNEW_G722, 0));
+
+ ast_cap_iter_start(cap);
+ while (!ast_cap_iter_next(cap, &tmpformat)) {
+ num++;
+ }
+ ast_cap_iter_end(cap);
+
+ ast_cap_iter_start(cap);
+ while (!ast_cap_iter_next(cap, &tmpformat)) {
+ num++;
+ }
+ ast_cap_iter_end(cap);
+
+ ast_cap_destroy(cap);
+ ast_test_status_update(test, "%d items iterated over\n", num);
+ return (num == 6) ? AST_TEST_PASS : AST_TEST_FAIL;
+}
static int unload_module(void)
{
AST_TEST_UNREGISTER(format_test1);
AST_TEST_UNREGISTER(format_test2);
AST_TEST_UNREGISTER(format_test3);
+ AST_TEST_UNREGISTER(format_test4);
return 0;
}
@@ -533,6 +581,7 @@
AST_TEST_REGISTER(format_test1);
AST_TEST_REGISTER(format_test2);
AST_TEST_REGISTER(format_test3);
+ AST_TEST_REGISTER(format_test4);
return AST_MODULE_LOAD_SUCCESS;
}
More information about the asterisk-commits
mailing list