TEST_F(CmMessageBlockTest, ChainedReserveTest) { char szData[] = "0123456789"; const DWORD dwLen = static_cast<DWORD>(strlen(szData)); CCmMessageBlock mb1(dwLen, szData, 0, dwLen); CCmMessageBlock mb2(dwLen, szData, 0, dwLen); mb1.Append(mb2.DuplicateChained()); CmResult rv = mb1.ReserveCapacity(dwLen + 4); ASSERT_TRUE(CM_SUCCEEDED(rv)); rv = mb1.Write("abcd", 4); ASSERT_TRUE(CM_SUCCEEDED(rv)); CCmMessageBlock* mbNext = mb1.GetNext(); rv = mbNext->ReserveCapacity(dwLen + 6); ASSERT_TRUE(CM_SUCCEEDED(rv)); rv = mbNext->Write("abcdef", 6); ASSERT_TRUE(CM_SUCCEEDED(rv)); char szBuffer[31] = {0}; rv = mb1.Read(szBuffer, 30); CM_ASSERTE(CM_SUCCEEDED(rv)); ASSERT_EQ(0, memcmp(szBuffer, "0123456789abcd0123456789abcdef", 30)); }
int run_main (int, ACE_TCHAR *[]) { ACE_START_TEST (ACE_TEXT ("Simple_Message_Block_Test")); { // Checks normal stack deletes. ACE_Message_Block mb; } { // Checks normal heap deletes. ACE_Message_Block *mb = 0; ACE_NEW_RETURN (mb, ACE_Message_Block, -1); mb->release (); } { // Checks continuation of message blocks on the stack. ACE_Message_Block mb1 (1024); ACE_Message_Block mb2 (1024); mb1.cont (&mb2); } { // Checks continuation of message blocks on the heap. ACE_Message_Block *mb1; ACE_Message_Block *mb2; ACE_NEW_RETURN (mb1, ACE_Message_Block (1024), -1); ACE_NEW_RETURN (mb2, ACE_Message_Block (1024), -1); mb1->cont (mb2); mb1->release (); } // Same set of tests but with locking_strategy set. { ACE_Lock_Adapter <ACE_SYNCH_MUTEX> mutex; ACE_Lock *lock = &mutex; { // Checks normal stack deletes. ACE_Message_Block mb; mb.locking_strategy (lock); } { // Checks normal heap deletes. ACE_Message_Block *mb = 0; ACE_NEW_RETURN (mb, ACE_Message_Block, -1); mb->locking_strategy (lock); mb->release (); } { // Checks continuation of message blocks on the stack with one // lock strategy. ACE_Message_Block mb1 (1024); ACE_Message_Block mb2 (1024); mb1.locking_strategy (lock); mb1.cont (&mb2); } { // Checks continuation of message blocks on the heap with one // lock strategy. ACE_Message_Block *mb1; ACE_Message_Block *mb2; ACE_NEW_RETURN (mb1, ACE_Message_Block (1024), -1); ACE_NEW_RETURN (mb2, ACE_Message_Block (1024), -1); mb1->locking_strategy (lock); mb1->cont (mb2); mb1->release (); } { // Checks continuation of message blocks on the stack with two // lock strategy. ACE_Message_Block mb1 (1024); ACE_Message_Block mb2 (1024); mb1.locking_strategy (lock); mb2.locking_strategy (lock); mb1.cont (&mb2); } { // Checks continuation of message blocks on the heap with two // lock strategy ACE_Message_Block *mb1; ACE_Message_Block *mb2; ACE_NEW_RETURN (mb1, ACE_Message_Block (1024), -1); ACE_NEW_RETURN (mb2, ACE_Message_Block (1024), -1); mb1->locking_strategy (lock); mb2->locking_strategy (lock); mb1->cont (mb2); mb1->release (); } { // Checks continuation of message blocks on the heap with two // lock strategy where the second one is a duplicate of the // first ACE_Message_Block *mb1; ACE_NEW_RETURN (mb1, ACE_Message_Block (1024), -1); mb1->locking_strategy (lock); ACE_Message_Block *mb2 = mb1->duplicate (); mb1->cont (mb2); mb1->release (); } } { // Checks continuation of message blocks on the heap with two // different lock strategies ACE_Lock_Adapter <ACE_SYNCH_MUTEX> lock1; ACE_Lock_Adapter <ACE_SYNCH_MUTEX> lock2; ACE_Message_Block *mb1; ACE_Message_Block *mb2; ACE_NEW_RETURN (mb1, ACE_Message_Block (1024), -1); ACE_NEW_RETURN (mb2, ACE_Message_Block (1024), -1); mb1->locking_strategy (&lock1); mb2->locking_strategy (&lock2); mb1->cont (mb2); mb1->release (); } { // Checks failure of copy when "virtual" allocation (using mark) // is too small char message[]="abcdefghijklmnop"; ACE_Message_Block mb1 (ACE_OS::strlen (message) + 1); ACE_Message_Block mb2 (ACE_OS::strlen (message) + 1); // Resize mb2 so that we mark for use less than the allocated buffer if (mb2.size (ACE_OS::strlen (message) + 1 - 10) == -1) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) Resize test failed ..\n"))); } // We expect this to succeed if (mb1.copy (message, ACE_OS::strlen (message) + 1) == -1) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) Copy test failed ..\n"))); } // We expect this to fail if (mb2.copy (message, ACE_OS::strlen (message) + 1) != -1) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) Copy test succeeded when it should have failed ..\n"))); } // We also expect this to fail if (mb2.copy (message) != -1) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) Copy test succeeded when it should have failed ..\n"))); } } ACE_END_TEST; return 0; }
void checkModel(rbdyn_urdf::Urdf urdf1, rbdyn_urdf::Urdf urdf2) { rbd::MultiBody mb1(urdf1.mbg.makeMultiBody(0, true)); rbd::MultiBody mb2(urdf2.mbg.makeMultiBody(0, true)); // basic check BOOST_CHECK_EQUAL(mb1.nrBodies(), mb2.nrBodies()); BOOST_CHECK_EQUAL(mb1.nrJoints(), mb2.nrJoints()); BOOST_CHECK_EQUAL(mb1.nrParams(), mb2.nrParams()); BOOST_CHECK_EQUAL(mb1.nrDof(), mb2.nrDof()); // mb structure check BOOST_CHECK(std::equal(mb1.predecessors().begin(), mb1.predecessors().end(), mb2.predecessors().begin())); BOOST_CHECK(std::equal(mb1.successors().begin(), mb1.successors().end(), mb2.successors().begin())); BOOST_CHECK(std::equal(mb1.parents().begin(), mb1.parents().end(), mb2.parents().begin())); BOOST_CHECK(std::equal(mb1.transforms().begin(), mb1.transforms().end(), mb2.transforms().begin())); // check limits // position BOOST_CHECK(std::equal(urdf1.limits.ql.begin(), urdf1.limits.ql.end(), urdf2.limits.ql.begin())); BOOST_CHECK(std::equal(urdf1.limits.qu.begin(), urdf1.limits.qu.end(), urdf2.limits.qu.begin())); // velocity BOOST_CHECK(std::equal(urdf1.limits.vl.begin(), urdf1.limits.vl.end(), urdf2.limits.vl.begin())); BOOST_CHECK(std::equal(urdf1.limits.vu.begin(), urdf1.limits.vu.end(), urdf2.limits.vu.begin())); // torque BOOST_CHECK(std::equal(urdf1.limits.tl.begin(), urdf1.limits.tl.end(), urdf2.limits.tl.begin())); BOOST_CHECK(std::equal(urdf1.limits.tu.begin(), urdf1.limits.tu.end(), urdf2.limits.tu.begin())); // check bodies for(int i = 0; i < mb1.nrBodies(); ++i) { const rbd::Body& b1 = mb1.body(i); const rbd::Body& b2 = mb2.body(i); BOOST_CHECK_EQUAL(b1.id(), b2.id()); BOOST_CHECK_EQUAL(b1.name(), b2.name()); BOOST_CHECK_EQUAL(b1.inertia().mass(), b2.inertia().mass()); BOOST_CHECK_EQUAL(b1.inertia().momentum(), b2.inertia().momentum()); BOOST_CHECK_SMALL((b1.inertia().inertia() - b2.inertia().inertia()).norm(), TOL); } // check joints for(int i = 0; i < mb1.nrJoints(); ++i) { const rbd::Joint& j1 = mb1.joint(i); const rbd::Joint& j2 = mb2.joint(i); BOOST_CHECK_EQUAL(j1.id(), j2.id()); BOOST_CHECK_EQUAL(j1.name(), j2.name()); BOOST_CHECK_EQUAL(j1.type(), j2.type()); BOOST_CHECK_EQUAL(j1.direction(), j2.direction()); BOOST_CHECK_EQUAL(j1.motionSubspace(), j2.motionSubspace()); } }