Asterisk - The Open Source Telephony Project  18.5.0
Functions | Variables
test_uuid.c File Reference

Universally unique identifier tests. More...

#include "asterisk.h"
#include "asterisk/test.h"
#include "asterisk/uuid.h"
#include "asterisk/module.h"
Include dependency graph for test_uuid.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
 AST_TEST_DEFINE (uuid)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "UUID test module" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 

Detailed Description

Universally unique identifier tests.

Definition in file test_uuid.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 152 of file test_uuid.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 152 of file test_uuid.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 152 of file test_uuid.c.

◆ AST_TEST_DEFINE()

AST_TEST_DEFINE ( uuid  )

Definition at line 33 of file test_uuid.c.

References ast_free, ast_str_to_uuid(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, ast_uuid_clear(), ast_uuid_compare(), ast_uuid_copy(), ast_uuid_generate(), ast_uuid_generate_str(), ast_uuid_is_nil(), AST_UUID_STR_LEN, ast_uuid_to_str(), end, sip_to_pjsip::info(), NULL, TEST_EXECUTE, and TEST_INIT.

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];
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  /* Use method of generating UUID directly as a string. */
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  /* Now convert the direct UUID string to a UUID */
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  /* Make sure that we can generate a UUID */
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  /* Make sure we're not generating nil UUIDs */
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  /* Convert it to a string */
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  /* Now convert the string back to a UUID */
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  /* Make sure the UUIDs are identical */
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  /* Try copying a UUID */
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  /* Make sure copied UUIDs are identical */
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  /* Clear a UUID and ensure that it registers as nil */
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 }
#define AST_UUID_STR_LEN
Definition: uuid.h:27
struct ast_uuid * ast_uuid_copy(struct ast_uuid *src)
Make a copy of a UUID.
Definition: uuid.c:168
int ast_uuid_is_nil(struct ast_uuid *uuid)
Check if a UUID is a nil UUID (all 0s)
Definition: uuid.c:189
#define NULL
Definition: resample.c:96
char * end
Definition: eagi_proxy.c:73
Definition: uuid.c:39
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
void ast_uuid_clear(struct ast_uuid *uuid)
Clear a UUID by setting it to be a nil UUID (all 0s)
Definition: uuid.c:184
struct ast_uuid * ast_str_to_uuid(char *str)
Convert a string to a UUID.
Definition: uuid.c:151
def info(msg)
struct ast_uuid * ast_uuid_generate(void)
Generate a UUID.
Definition: uuid.c:125
#define ast_free(a)
Definition: astmm.h:182
char * ast_uuid_generate_str(char *buf, size_t size)
Generate a UUID string.
Definition: uuid.c:143
int ast_uuid_compare(struct ast_uuid *left, struct ast_uuid *right)
Compare two UUIDs.
Definition: uuid.c:179
char * ast_uuid_to_str(struct ast_uuid *uuid, char *buf, size_t size)
Convert a UUID to a string.
Definition: uuid.c:136
ast_test_result_state
Definition: test.h:200

◆ load_module()

static int load_module ( void  )
static

Definition at line 146 of file test_uuid.c.

References AST_MODULE_LOAD_SUCCESS, and AST_TEST_REGISTER.

147 {
148  AST_TEST_REGISTER(uuid);
150 }
#define AST_TEST_REGISTER(cb)
Definition: test.h:127

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 140 of file test_uuid.c.

References AST_TEST_UNREGISTER.

141 {
142  AST_TEST_UNREGISTER(uuid);
143  return 0;
144 }
#define AST_TEST_UNREGISTER(cb)
Definition: test.h:128

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "UUID test module" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 152 of file test_uuid.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 152 of file test_uuid.c.