summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGeorge Joseph <george.joseph@fairview5.com>2015-05-09 15:58:46 -0600
committerGeorge Joseph <george.joseph@fairview5.com>2015-05-11 14:47:46 -0600
commitea917fefafd878f4021e5e7a929b848d8032f28e (patch)
tree217505d90610a21738eed9c29cb29dafc66a1b98 /tests
parent4dbd4021c91a6a612746ed5e116021e270bc6ff5 (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.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/tests/test_vector.c b/tests/test_vector.c
index 6badd75af..8ca4efa1a 100644
--- a/tests/test_vector.c
+++ b/tests/test_vector.c
@@ -61,7 +61,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";
@@ -200,6 +202,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;
@@ -216,13 +241,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";