summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKevin Harwell <kharwell@digium.com>2017-04-25 11:43:26 -0500
committerKevin Harwell <kharwell@digium.com>2017-04-26 13:23:39 -0500
commitcf3429b93444293d131cd0c90df285e7644907d9 (patch)
treeaae8e86088609305e1d0c8bf97af8c72844035a0 /tests
parent59203c51cc6a9676ef1ab42aebe070a55f55ead2 (diff)
vector: defaults and indexes
Added an pre-defined integer vector declaration. This makes integer vectors easier to declare and pass around. Also, added the ability to default a vector up to a given size with a default value. Lastly, added functionality that returns the "nth" index of a matching value. Also, updated a unit test to test these changes. Change-Id: Iaf4b51b2540eda57cb43f67aa59cf1d96cdbcaa5
Diffstat (limited to 'tests')
-rw-r--r--tests/test_vector.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/test_vector.c b/tests/test_vector.c
index 8ca4efa1a..8e0d121dd 100644
--- a/tests/test_vector.c
+++ b/tests/test_vector.c
@@ -282,6 +282,25 @@ AST_TEST_DEFINE(basic_ops_integer)
ast_test_validate_cleanup(test, *(int *)AST_VECTOR_GET_CMP(&sv1, AAA, AST_VECTOR_ELEM_DEFAULT_CMP) == AAA, rc, cleanup);
ast_test_validate_cleanup(test, *(int *)AST_VECTOR_GET_CMP(&sv1, ZZZ, AST_VECTOR_ELEM_DEFAULT_CMP) == ZZZ, rc, cleanup);
+ /* Default first value */
+ ast_test_validate_cleanup(test, AST_VECTOR_DEFAULT(&sv1, 1, CCC) == 0, rc, cleanup);
+ ast_test_validate_cleanup(test, AST_VECTOR_GET(&sv1, 0) == CCC, rc, cleanup);
+ ast_test_validate_cleanup(test, AST_VECTOR_GET(&sv1, 1) == ZZZ, rc, cleanup);
+ /* Default all values */
+ ast_test_validate_cleanup(test, AST_VECTOR_DEFAULT(&sv1, 0, AAA) == 0, rc, cleanup);
+ ast_test_validate_cleanup(test, AST_VECTOR_GET(&sv1, 0) == AAA, rc, cleanup);
+ ast_test_validate_cleanup(test, AST_VECTOR_GET(&sv1, 1) == AAA, rc, cleanup);
+ ast_test_validate_cleanup(test, AST_VECTOR_GET(&sv1, 2) == AAA, rc, cleanup);
+ ast_test_validate_cleanup(test, AST_VECTOR_GET(&sv1, 3) == AAA, rc, cleanup);
+ /* Default more values than are currently in the vector */
+ ast_test_validate_cleanup(test, AST_VECTOR_DEFAULT(&sv1, 5, BBB) == 0, rc, cleanup);
+ ast_test_validate_cleanup(test, AST_VECTOR_GET(&sv1, 4) == BBB, rc, cleanup);
+
+ /* Check getting index(es) */
+ ast_test_validate_cleanup(test, AST_VECTOR_GET_INDEX(&sv1, BBB, AST_VECTOR_ELEM_DEFAULT_CMP) == 0, rc, cleanup);
+ ast_test_validate_cleanup(test, AST_VECTOR_GET_INDEX_NTH(&sv1, 2, BBB, AST_VECTOR_ELEM_DEFAULT_CMP) == 1, rc, cleanup);
+ ast_test_validate_cleanup(test, AST_VECTOR_GET_INDEX_NTH(&sv1, 4, BBB, AST_VECTOR_ELEM_DEFAULT_CMP) == 3, rc, cleanup);
+
AST_VECTOR_FREE(&sv1);
ast_test_validate(test, sv1.elems == NULL);
ast_test_validate(test, sv1.current == 0);