Also use Objects as part of an operation but as a result don't generate Any operation...
[ACE_TAO.git] / ACE / tests / Compiler_Features_09_Test.cpp
blobeb38413cd6ec5d26f4d53b6783fd1c0cdf849643
1 /**
2 * @file
4 * This program checks if the compiler / platform supports the
5 * std::auto_ptr<> correctly. The motivation for this test was a discussion
6 * on the development mailing list, and the documentation was captured
7 * in:
9 * http://bugzilla.dre.vanderbilt.edu/show_bug.cgi?id=3715
12 #include "test_config.h"
14 // The first part of the test is to compile this line. If the program
15 // does not compile the platform is just too broken.
16 #include <memory>
18 // For extra challenge, we use the anonymous namespace
19 namespace
21 /**
22 * @class Base
24 class Base
26 public:
27 Base()
29 constructors++;
31 Base(Base const & )
33 constructors++;
35 ~Base()
37 destructors++;
40 static int constructors;
41 static int destructors;
44 int Base::constructors = 0;
45 int Base::destructors = 0;
47 class Derived : public Base
49 public:
50 Derived()
51 : Base()
56 int
57 run_main (int, ACE_TCHAR *[])
59 ACE_START_TEST (ACE_TEXT("Compiler_Features_09_Test"));
61 // As usual, the exit status from the test is 0 on success, 1 on
62 // failure
63 int status = 0;
65 // ... this works with the ACE version of auto_ptr (well, the
66 // namespace is broken, but you get the idea) ...
67 std::auto_ptr<Base> x(new Base);
68 std::auto_ptr<Derived> y(new Derived);
70 // ... with a compliant implementation of std::auto_ptr<> you should be
71 // able to write:
72 // x = y;
73 // but the Solaris compiler was broken as of August, 2009!! So you have
74 // to work around in the following way. This compiler is important
75 // enough for the ACE community, so we have to support this broken
76 // configuration ...
77 x.reset(y.release());
79 // ... there should be just one destruction so far ...
80 if (Base::destructors != 1)
82 status = 1;
83 ACE_ERROR((LM_ERROR,
84 ACE_TEXT("Destructor count off, expected 1, found %d\n"),
85 Base::destructors));
88 std::auto_ptr<Base> z;
89 z = x;
90 if (Base::destructors != 1)
92 status = 1;
93 ACE_ERROR((LM_ERROR,
94 ACE_TEXT("Destructor count off, expected 1, found %d\n"),
95 Base::destructors));
97 if (x.get())
99 status = 1;
100 ACE_ERROR((LM_ERROR,
101 ACE_TEXT("x contents should have been transferred\n")
105 ACE_END_TEST;
106 return status;