diff options
author | Kevin Harwell <kharwell@digium.com> | 2017-04-25 11:43:26 -0500 |
---|---|---|
committer | Kevin Harwell <kharwell@digium.com> | 2017-04-26 13:24:49 -0500 |
commit | 00001443dc7400803aa73b9056856138ec12d709 (patch) | |
tree | d58211f7c021ef717f0cb9cf60594253aa7115c2 /tests | |
parent | 7b7d0571f7267e373eca6222760ea08c1d5dbfe9 (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.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/test_vector.c b/tests/test_vector.c index ff305b5d7..03d092fef 100644 --- a/tests/test_vector.c +++ b/tests/test_vector.c @@ -284,6 +284,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); |