diff options
author | George Joseph <george.joseph@fairview5.com> | 2015-05-09 15:58:46 -0600 |
---|---|---|
committer | George Joseph <george.joseph@fairview5.com> | 2015-05-11 15:49:06 -0500 |
commit | 87d8b36755805a2eaec54aa71ee088f365695817 (patch) | |
tree | 8023552d60354ffe3a8eda0d94d089416ec40e57 /tests | |
parent | 4da293459297ed66fbb85aa53e328bd560e73d17 (diff) |
vector: Add REMOVE, ADD_SORTED and RESET macros
Based on feedback from Corey Farrell and Y Ateya, a few new
macros have been added...
AST_VECTOR_REMOVE which takes a parameter to indicate if
order should be preserved.
AST_VECTOR_ADD_SORTED which adds an element to
a sorted vector.
AST_VECTOR_RESET which cleans all elements from the vector
leaving the storage intact.
Change-Id: I41d32dbdf7137e0557134efeff9f9f1064b58d14
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_vector.c | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/tests/test_vector.c b/tests/test_vector.c index bd45b0c2b..ff305b5d7 100644 --- a/tests/test_vector.c +++ b/tests/test_vector.c @@ -63,7 +63,9 @@ AST_TEST_DEFINE(basic_ops) char *CCC = "CCC"; char *YYY = "YYY"; char *ZZZ = "ZZZ"; + char CCC2[4]; + strcpy(CCC2, "CCC"); switch (cmd) { case TEST_INIT: info->name = "basic"; @@ -202,6 +204,29 @@ AST_TEST_DEFINE(basic_ops) ast_test_validate_cleanup(test, AST_VECTOR_GET(&sv1, 0) == CCC, rc, cleanup); ast_test_validate_cleanup(test, cleanup_count == 1, rc, cleanup); + /* Test INSERT_SORTED */ + AST_VECTOR_FREE(&sv1); + ast_test_validate(test, AST_VECTOR_INIT(&sv1, 0) == 0); + + ast_test_validate_cleanup(test, AST_VECTOR_ADD_SORTED(&sv1, BBB, strcmp) == 0, rc, cleanup); + ast_test_validate_cleanup(test, AST_VECTOR_ADD_SORTED(&sv1, ZZZ, strcmp) == 0, rc, cleanup); + ast_test_validate_cleanup(test, AST_VECTOR_ADD_SORTED(&sv1, CCC, strcmp) == 0, rc, cleanup); + ast_test_validate_cleanup(test, AST_VECTOR_ADD_SORTED(&sv1, AAA, strcmp) == 0, rc, cleanup); + ast_test_validate_cleanup(test, AST_VECTOR_ADD_SORTED(&sv1, CCC2, strcmp) == 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) == BBB, rc, cleanup); + ast_test_validate_cleanup(test, AST_VECTOR_GET(&sv1, 2) == CCC, rc, cleanup); + ast_test_validate_cleanup(test, AST_VECTOR_GET(&sv1, 3) == CCC2, rc, cleanup); + ast_test_validate_cleanup(test, AST_VECTOR_GET(&sv1, 4) == ZZZ, rc, cleanup); + + cleanup_count = 0; + AST_VECTOR_RESET(&sv1, cleanup); + ast_test_validate_cleanup(test, AST_VECTOR_SIZE(&sv1) == 0, rc, cleanup); + ast_test_validate_cleanup(test, sv1.max >= 5, rc, cleanup); + ast_test_validate_cleanup(test, sv1.elems != NULL, rc, cleanup); + ast_test_validate_cleanup(test, cleanup_count == 5, rc, cleanup); + cleanup: AST_VECTOR_FREE(&sv1); return rc; @@ -218,13 +243,13 @@ AST_TEST_DEFINE(basic_ops_integer) int rc = AST_TEST_PASS; int AAA = 1; - int BBB = 2; - int CCC = 3; + int BBB = 3; + int CCC = 5; int ZZZ = 26; switch (cmd) { case TEST_INIT: - info->name = "basic integer"; + info->name = "basic_integer"; info->category = "/main/vector/"; info->summary = "Test integer vector basic ops"; info->description = "Test integer vector basic ops"; |