From f5e9cf5975cf8a58774579f126952be61beb0e54 Mon Sep 17 00:00:00 2001 From: Mark Michelson Date: Tue, 11 Dec 2012 21:52:09 +0000 Subject: Add automerge property back after conflict. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377879 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- tests/test_uuid.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 tests/test_uuid.c (limited to 'tests') diff --git a/tests/test_uuid.c b/tests/test_uuid.c new file mode 100644 index 000000000..a76ec8b39 --- /dev/null +++ b/tests/test_uuid.c @@ -0,0 +1,136 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012, Digium, Inc. + * + * Mark Michelson + * + * See http://www.asterisk.org for more information about + * the Asterisk project. Please do not directly contact + * any of the maintainers of this project for assistance; + * the project provides a web site, mailing lists and IRC + * channels for your use. + * + * This program is free software, distributed under the terms of + * the GNU General Public License Version 2. See the LICENSE file + * at the top of the source tree. + */ + +/*! \file + * \brief Universally unique identifier tests + */ + +/*** MODULEINFO + TEST_FRAMEWORK + core + ***/ + +#include "asterisk.h" +#include "asterisk/test.h" +#include "asterisk/uuid.h" +#include "asterisk/module.h" + +AST_TEST_DEFINE(uuid) +{ + struct ast_uuid *uuid1 = NULL; + struct ast_uuid *uuid2 = NULL; + struct ast_uuid *uuid3 = NULL; + char uuid_str[AST_UUID_STR_LEN]; + enum ast_test_result_state res = AST_TEST_FAIL; + + switch (cmd) { + case TEST_INIT: + info->name = "uuid"; + info->category = "/main/uuid/"; + info->summary = "UUID unit test"; + info->description = + "This tests basic UUID operations to ensure they work properly"; + return AST_TEST_NOT_RUN; + case TEST_EXECUTE: + break; + } + + /* First, make sure that we can generate a UUID */ + uuid1 = ast_uuid_generate(); + if (!uuid1) { + ast_test_status_update(test, "Unable to generate a UUID\n"); + goto end; + } + + /* Make sure we're not generating nil UUIDs */ + if (ast_uuid_is_nil(uuid1)) { + ast_test_status_update(test, "We generated a nil UUID. Something is wrong\n"); + goto end; + } + + /* Convert it to a string */ + ast_uuid_to_str(uuid1, uuid_str, sizeof(uuid_str)); + + if (strlen(uuid_str) != (AST_UUID_STR_LEN - 1)) { + ast_test_status_update(test, "Failed to convert the UUID to a string\n"); + goto end; + } + + ast_test_status_update(test, "Converted uuid to string, got %s\n", uuid_str); + + /* Now convert the string back to a UUID */ + uuid2 = ast_str_to_uuid(uuid_str); + if (!uuid2) { + ast_test_status_update(test, "Unable to convert string %s to UUID\n", uuid_str); + goto end; + } + + /* Make sure the UUIDs are identical */ + if (ast_uuid_compare(uuid1, uuid2) != 0) { + ast_test_status_update(test, "UUIDs that should be identical are different\n"); + goto end; + } + + /* Try copying a UUID */ + uuid3 = ast_uuid_copy(uuid1); + if (!uuid3) { + ast_test_status_update(test, "Unable to copy UUID\n"); + goto end; + } + + /* Make sure copied UUIDs are identical */ + if (ast_uuid_compare(uuid1, uuid3) != 0) { + ast_test_status_update(test, "UUIDs that should be identical are different\n"); + goto end; + } + + if (ast_uuid_compare(uuid2, uuid3) != 0) { + ast_test_status_update(test, "UUIDs that should be identical are different\n"); + goto end; + } + + /* Clear a UUID and ensure that it registers as nil */ + ast_uuid_clear(uuid1); + + if (!ast_uuid_is_nil(uuid1)) { + ast_test_status_update(test, "UUID that was cleared does not appear to be nil\n"); + goto end; + } + + res = AST_TEST_PASS; + +end: + ast_free(uuid1); + ast_free(uuid2); + ast_free(uuid3); + return res; +} + +static int unload_module(void) +{ + AST_TEST_UNREGISTER(uuid); + return 0; +} + +static int load_module(void) +{ + AST_TEST_REGISTER(uuid); + return AST_MODULE_LOAD_SUCCESS; +} + +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "UUID test module"); -- cgit v1.2.3