summaryrefslogtreecommitdiff
path: root/tests/Capabilities_Test.cpp
blob: 35c7f4875c7d46a8354e0accf55013368066ae37 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// $Id$

// ============================================================================
//
// = LIBRARY
//    tests
//
// = FILENAME
//    Capabilities_Test.cpp
//
// = DESCRIPTION
//      This is a test that makes sure the <ACE_Capabililties> class
//      works correctly.
//
// = AUTHOR
//    Arturo Montes <mitosys@colomsat.net.co>
//
// ============================================================================

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

ACE_RCSID(tests, Capabilities_Test, "$Id$")

static const ACE_TCHAR config[] = ACE_TEXT ("Capabilities_Test.cfg");

static int
load_config (void)
{
  ACE_Capabilities caps;
  if (caps.getent (config, ACE_TEXT ("Config")) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("Can't read %s\n"),
                       config),
                      1);

  int b = 0;
  caps.getval (ACE_TEXT ("bool"), b);
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("bool = %d\n"),
              b));

  int n = 0;
  caps.getval (ACE_TEXT ("integer"), n);

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("integer = %d\n"),
              n));

  ACE_TString s;
  caps.getval (ACE_TEXT ("string"), s);

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("string = %s\n"),
              s.c_str ()));
  return 0;
}

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


  // --------------------------------------------------------
  // Create config file
  // --------------------------------------------------------

  // A config file is created within the test so that the test is
  // completely self contained.

  const char file_contents[] =
    "Config|Esta entrada reservada para la configuracion,\n"
    "   bool,\n"
    "   integer#2,\n"
    "   string=000030,\n\n";

  ACE_HANDLE fd = ACE_OS::open (config,
                                O_RDWR | O_CREAT | O_TRUNC,
                                ACE_DEFAULT_FILE_PERMS);

  if (fd == ACE_INVALID_HANDLE)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("ACE_OS::open")),
                      -1);


  if (ACE_OS::write (fd, file_contents, sizeof(file_contents)) !=
      sizeof(file_contents))
    {
      ACE_OS::unlink (config);
      ACE_OS::close (fd);
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("%p\n"),
                         ACE_TEXT ("ACE_OS::write")),
                        -1);
    }

  if (ACE_OS::close (fd) != 0)
    {
      ACE_OS::unlink (config);
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("%p\n"),
                         ACE_TEXT ("ACE_OS::close")),
                        -1);
    }
  // --------------------------------------------------------


  int result = load_config ();

  ACE_OS::unlink (config);

  ACE_END_TEST;
  return result;
}