1 //=============================================================================
5 * Test the ACE UUID class which generates unique id's
7 * @author Andrew T. Finnel <andrew@activesol.net> and Yamuna Krishnmaurthy <yamuna@oomworks.com>
9 //=============================================================================
11 #include "test_config.h"
27 std::unique_ptr
<ACE_Utils::UUID
> uuid (ACE_Utils::UUID_GENERATOR::instance ()->generate_UUID ());
28 ACE_CString
uuid_str (uuid
->to_string ()->c_str ());
30 ACE_TEXT ("Generated UUID\n %C\n"),
33 #ifndef ACE_LACKS_SSCANF
34 // Construct UUID from string
35 ACE_Utils::UUID
new_uuid (uuid_str
);
38 ACE_TEXT ("UUID Constructed from above Generated UUID\n %C\n"),
39 new_uuid
.to_string ()->c_str ()));
41 // Construct UUID from string by assigning it
42 ACE_Utils::UUID new_uuid_assign
;
43 new_uuid_assign
.from_string (new_uuid
.to_string ()->c_str ());
45 ACE_TEXT ("UUID Constructed from above Generated UUID ")
46 ACE_TEXT ("with assign\n %C\n"),
47 new_uuid_assign
.to_string ()->c_str ()));
49 if (new_uuid
!= new_uuid_assign
)
50 ACE_ERROR_RETURN ((LM_ERROR
,
51 ACE_TEXT ("Error: UUIDs are not the same\n")),
54 // Check the hash value of the 2 UUIDs
56 if (new_uuid
.hash () != new_uuid_assign
.hash ())
57 ACE_ERROR_RETURN ((LM_ERROR
,
58 ACE_TEXT ("Error: hash value of UUIDs are ")
59 ACE_TEXT ("not the same")),
63 const ACE_Utils::UUID
&new_uuid
= *uuid
;
66 // Construct UUID using the copy constructor
67 ACE_Utils::UUID
new_uuid_copy (new_uuid
);
69 ACE_TEXT ("UUID constructed from above Generated UUID")
70 ACE_TEXT (" with copy\n %C\n"),
71 new_uuid_copy
.to_string ()->c_str ()));
73 if (new_uuid
!= new_uuid_copy
)
74 ACE_ERROR_RETURN ((LM_ERROR
,
75 ACE_TEXT ("Error: UUIDs are not the same ")
76 ACE_TEXT ("with copy\n")),
79 #ifndef ACE_LACKS_SSCANF
80 ACE_Utils::UUID
nil_uuid (*ACE_Utils::UUID::NIL_UUID
.to_string ());
82 ACE_TEXT ("UUID Constructed from NIL_UUID with ")
83 ACE_TEXT ("string copy\n %C\n"),
84 nil_uuid
.to_string ()->c_str ()));
86 if (nil_uuid
!= ACE_Utils::UUID::NIL_UUID
)
87 ACE_ERROR_RETURN ((LM_ERROR
,
88 ACE_TEXT ("Error: UUIDs are not the same with ")
89 ACE_TEXT ("NIL_UUID string copy\n")),
93 // Construct UUID using the assignment constructor
94 ACE_Utils::UUID new_uuid_assigment
;
95 new_uuid_assigment
= new_uuid
;
97 ACE_TEXT ("UUID Constructed from above Generated UUID ")
98 ACE_TEXT ("with assignment\n %C\n"),
99 new_uuid_assigment
.to_string ()->c_str ()));
101 if (new_uuid
!= new_uuid_assigment
)
102 ACE_ERROR_RETURN ((LM_ERROR
,
103 ACE_TEXT ("Error: UUIDs are not the same "
104 ACE_TEXT ("with assignment\n"))),
107 // Generate UUID with process and thread ids.
108 std::unique_ptr
<ACE_Utils::UUID
>
109 uuid_with_tp_id (ACE_Utils::UUID_GENERATOR::instance ()->generate_UUID (0x0001, 0xc0));
111 ACE_DEBUG ((LM_DEBUG
,
112 ACE_TEXT ("UUID with Thread and Process ID\n %C\n"),
113 uuid_with_tp_id
->to_string ()->c_str ()));
115 if (new_uuid
== *uuid_with_tp_id
)
116 ACE_ERROR_RETURN ((LM_ERROR
,
117 ACE_TEXT ("Error: UUIDs are the same\n")),
120 #ifndef ACE_LACKS_SSCANF
121 // Construct UUID from string
122 ACE_Utils::UUID
new_uuid_with_tp_id (uuid_with_tp_id
->to_string ()->c_str ());
123 ACE_DEBUG ((LM_DEBUG
,
124 ACE_TEXT ("UUID with Thread and Process ID reconstructed ")
125 ACE_TEXT ("from above UUID \n %C\n"),
126 new_uuid_with_tp_id
.to_string ()->c_str ()));
132 int run_main(int, ACE_TCHAR
* [])
134 ACE_START_TEST (ACE_TEXT ("UUID_Test"));
138 int const result
= tester
.test();
142 ACE_TEXT ("UUID_Test succeeded\n")));
145 ACE_TEXT ("UUID_Test failed\n")));