| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
#include "asterisk.h" |
| 29 |
#include "asterisk/test.h" |
| 30 |
#include "asterisk/uuid.h" |
| 31 |
#include "asterisk/module.h" |
| 32 |
|
| 33 |
AST_TEST_DEFINE(uuid) |
| 34 |
{ |
| 35 |
struct ast_uuid *uuid1 = NULL; |
| 36 |
struct ast_uuid *uuid2 = NULL; |
| 37 |
struct ast_uuid *uuid3 = NULL; |
| 38 |
char uuid_str[AST_UUID_STR_LEN]; |
| 39 |
enum ast_test_result_state res = AST_TEST_FAIL; |
| 40 |
|
| 41 |
switch (cmd) { |
| 42 |
case TEST_INIT: |
| 43 |
info->name = "uuid"; |
| 44 |
info->category = "/main/uuid/"; |
| 45 |
info->summary = "UUID unit test"; |
| 46 |
info->description = |
| 47 |
"This tests basic UUID operations to ensure they work properly"; |
| 48 |
return AST_TEST_NOT_RUN; |
| 49 |
case TEST_EXECUTE: |
| 50 |
break; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
ast_uuid_generate_str(uuid_str, sizeof(uuid_str)); |
| 55 |
if (strlen(uuid_str) != (AST_UUID_STR_LEN - 1)) { |
| 56 |
ast_test_status_update(test, "Failed to directly generate UUID string\n"); |
| 57 |
goto end; |
| 58 |
} |
| 59 |
ast_test_status_update(test, "Generate UUID direct to string, got %s\n", uuid_str); |
| 60 |
|
| 61 |
|
| 62 |
uuid1 = ast_str_to_uuid(uuid_str); |
| 63 |
if (!uuid1) { |
| 64 |
ast_test_status_update(test, "Unable to convert direct UUID string %s to UUID\n", uuid_str); |
| 65 |
goto end; |
| 66 |
} |
| 67 |
ast_free(uuid1); |
| 68 |
|
| 69 |
|
| 70 |
uuid1 = ast_uuid_generate(); |
| 71 |
if (!uuid1) { |
| 72 |
ast_test_status_update(test, "Unable to generate a UUID\n"); |
| 73 |
goto end; |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
if (ast_uuid_is_nil(uuid1)) { |
| 78 |
ast_test_status_update(test, "We generated a nil UUID. Something is wrong\n"); |
| 79 |
goto end; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
ast_uuid_to_str(uuid1, uuid_str, sizeof(uuid_str)); |
| 84 |
|
| 85 |
if (strlen(uuid_str) != (AST_UUID_STR_LEN - 1)) { |
| 86 |
ast_test_status_update(test, "Failed to convert the UUID to a string\n"); |
| 87 |
goto end; |
| 88 |
} |
| 89 |
|
| 90 |
ast_test_status_update(test, "Second generated UUID converted to string, got %s\n", uuid_str); |
| 91 |
|
| 92 |
|
| 93 |
uuid2 = ast_str_to_uuid(uuid_str); |
| 94 |
if (!uuid2) { |
| 95 |
ast_test_status_update(test, "Unable to convert string %s to UUID\n", uuid_str); |
| 96 |
goto end; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
if (ast_uuid_compare(uuid1, uuid2) != 0) { |
| 101 |
ast_test_status_update(test, "UUIDs that should be identical are different\n"); |
| 102 |
goto end; |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
uuid3 = ast_uuid_copy(uuid1); |
| 107 |
if (!uuid3) { |
| 108 |
ast_test_status_update(test, "Unable to copy UUID\n"); |
| 109 |
goto end; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
if (ast_uuid_compare(uuid1, uuid3) != 0) { |
| 114 |
ast_test_status_update(test, "UUIDs that should be identical are different\n"); |
| 115 |
goto end; |
| 116 |
} |
| 117 |
|
| 118 |
if (ast_uuid_compare(uuid2, uuid3) != 0) { |
| 119 |
ast_test_status_update(test, "UUIDs that should be identical are different\n"); |
| 120 |
goto end; |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
ast_uuid_clear(uuid1); |
| 125 |
|
| 126 |
if (!ast_uuid_is_nil(uuid1)) { |
| 127 |
ast_test_status_update(test, "UUID that was cleared does not appear to be nil\n"); |
| 128 |
goto end; |
| 129 |
} |
| 130 |
|
| 131 |
res = AST_TEST_PASS; |
| 132 |
|
| 133 |
end: |
| 134 |
ast_free(uuid1); |
| 135 |
ast_free(uuid2); |
| 136 |
ast_free(uuid3); |
| 137 |
return res; |
| 138 |
} |
| 139 |
|
| 140 |
static int unload_module(void) |
| 141 |
{ |
| 142 |
AST_TEST_UNREGISTER(uuid); |
| 143 |
return 0; |
| 144 |
} |
| 145 |
|
| 146 |
static int load_module(void) |
| 147 |
{ |
| 148 |
AST_TEST_REGISTER(uuid); |
| 149 |
return AST_MODULE_LOAD_SUCCESS; |
| 150 |
} |
| 151 |
|
| 152 |
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "UUID test module"); |