summaryrefslogtreecommitdiff
path: root/tests/UUIDTest.cpp
blob: 3174aeeaae50ac31c05bd355f61bf9fcfed3bea9 (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//$Id$
// UUIDTest.cpp
// $Revision$ $Date$

#include "test_config.h"
#include "ace/UUID.h"

class Tester
{
public:
  int init (void);
  int test (void);
};


int
Tester::init (void)
{
  ///Initialise the UUID Generator
  ACE_Utils::UUID_GENERATOR::instance ()->init ();
  return 0;
}

int
Tester::test (void)
{
  // Generate UUID
  ACE_Utils::UUID* uuid = ACE_Utils::UUID_GENERATOR::instance ()->generateUUID ();
  ACE_CString uuid_str (uuid->to_string ()->c_str ());
  ACE_DEBUG ((LM_DEBUG,
              "Generated UUID\n %s\n",
              uuid_str.c_str ()));
  delete uuid;

  // Construct UUID from string
  ACE_Utils::UUID new_uuid (uuid_str);
  ACE_DEBUG ((LM_DEBUG,
              "UUID Constructed from above Generated UUID\n %s\n",
              new_uuid.to_string ()->c_str ()));

  // Generate UUID with process and thread ids.
  ACE_Utils::UUID* uuid_with_tp_id =
    ACE_Utils::UUID_GENERATOR::instance ()->generateUUID (0x0001, 0xc0);
  ACE_DEBUG ((LM_DEBUG,
              "UUID with Thread and Process ID\n %s\n",
              uuid_with_tp_id->to_string ()->c_str ()));

  // Construct UUID from string
  ACE_Utils::UUID new_uuid_with_tp_id (uuid_with_tp_id->to_string ()->c_str ());
  ACE_DEBUG ((LM_DEBUG,
              "UUID with Thread and Process ID reconstructed from above UUID \n %s\n",
              new_uuid_with_tp_id.to_string ()->c_str ()));
  delete uuid_with_tp_id;

  return 0;
}

int run_main(int, ACE_TCHAR* [])
{
  ACE_START_TEST (ACE_TEXT ("UUIDTest"));

  Tester tester;

  if (tester.init () == -1)
    {

      ACE_DEBUG((LM_DEBUG,
                 "UUIDTest: Tester::init failed\n"));
      return -1;
    }

  int testRetValue = tester.test();

  if (testRetValue == 0)
    {
      ACE_DEBUG((LM_DEBUG,
                 "UUIDTest succeeded\n"));
    }
  else
    {
      ACE_DEBUG((LM_DEBUG,
                 "UUIDTest failed\n"));
    }

  ACE_END_TEST;

  return testRetValue;
}