Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / tests / Capabilities_Test.cpp
blob75951f39bbdc31f4bd73d1109e9850da8a845ae3
2 //=============================================================================
3 /**
4 * @file Capabilities_Test.cpp
6 * This is a test that makes sure the <ACE_Capabililties> class
7 * works correctly.
9 * @author Arturo Montes <mitosys@colomsat.net.co>
11 //=============================================================================
14 #include "test_config.h"
15 #include "ace/OS_NS_fcntl.h"
16 #include "ace/OS_NS_unistd.h"
17 #include "ace/Capabilities.h"
19 static const ACE_TCHAR config[] = ACE_TEXT ("Capabilities_Test.cfg");
21 static int
22 load_config ()
24 ACE_Capabilities caps;
25 if (caps.getent (config, ACE_TEXT ("Config")) == -1)
26 ACE_ERROR_RETURN ((LM_ERROR,
27 ACE_TEXT ("Can't read %s\n"),
28 config),
29 1);
31 int b = 0;
32 caps.getval (ACE_TEXT ("bool"), b);
33 ACE_DEBUG ((LM_DEBUG,
34 ACE_TEXT ("bool = %d\n"),
35 b));
37 int n = 0;
38 caps.getval (ACE_TEXT ("integer"), n);
40 ACE_DEBUG ((LM_DEBUG,
41 ACE_TEXT ("integer = %d\n"),
42 n));
44 ACE_TString s;
45 caps.getval (ACE_TEXT ("string"), s);
47 ACE_DEBUG ((LM_DEBUG,
48 ACE_TEXT ("string = %s\n"),
49 s.c_str ()));
50 return 0;
53 int
54 run_main (int, ACE_TCHAR *[])
56 ACE_START_TEST (ACE_TEXT ("Capabilities_Test"));
59 // --------------------------------------------------------
60 // Create config file
61 // --------------------------------------------------------
63 // A config file is created within the test so that the test is
64 // completely self contained.
66 const char file_contents[] =
67 "Config|Esta entrada reservada para la configuracion,\n"
68 " bool,\n"
69 " integer#2,\n"
70 " string=000030,\n\n";
72 ACE_HANDLE fd = ACE_OS::open (config,
73 O_RDWR | O_CREAT | O_TRUNC,
74 ACE_DEFAULT_FILE_PERMS);
76 if (fd == ACE_INVALID_HANDLE)
77 ACE_ERROR_RETURN ((LM_ERROR,
78 ACE_TEXT ("%p\n"),
79 ACE_TEXT ("ACE_OS::open")),
80 -1);
83 if (ACE_OS::write (fd, file_contents, sizeof(file_contents)) !=
84 (ssize_t) sizeof(file_contents))
86 ACE_OS::unlink (config);
87 ACE_OS::close (fd);
88 ACE_ERROR_RETURN ((LM_ERROR,
89 ACE_TEXT ("%p\n"),
90 ACE_TEXT ("ACE_OS::write")),
91 -1);
94 if (ACE_OS::close (fd) != 0)
96 ACE_OS::unlink (config);
97 ACE_ERROR_RETURN ((LM_ERROR,
98 ACE_TEXT ("%p\n"),
99 ACE_TEXT ("ACE_OS::close")),
100 -1);
102 // --------------------------------------------------------
105 int const result = load_config ();
107 ACE_OS::unlink (config);
109 ACE_END_TEST;
110 return result;