generated_messages.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2009, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 /* Author: Josh Faust */
00031 
00032 /*
00033  * Test generated messages
00034  */
00035 
00036 #include <gtest/gtest.h>
00037 #include "helpers.h"
00038 #include "test_roscpp/ArrayOfFixedLength.h"
00039 #include "test_roscpp/ArrayOfVariableLength.h"
00040 #include "test_roscpp/EmbeddedFixedLength.h"
00041 #include "test_roscpp/EmbeddedVariableLength.h"
00042 #include "test_roscpp/FixedLength.h"
00043 #include "test_roscpp/VariableLength.h"
00044 #include "test_roscpp/WithHeader.h"
00045 #include "test_roscpp/EmbeddedExternal.h"
00046 #include "test_roscpp/WithTime.h"
00047 #include "test_roscpp/WithDuration.h"
00048 #include "test_roscpp/WithMemberNamedHeaderThatIsNotAHeader.h"
00049 #include "test_roscpp/FixedLengthArrayOfExternal.h"
00050 #include "test_roscpp/VariableLengthArrayOfExternal.h"
00051 #include "test_roscpp/Constants.h"
00052 #include "test_roscpp/VariableLengthStringArray.h"
00053 #include "test_roscpp/FixedLengthStringArray.h"
00054 #include "test_roscpp/HeaderNotFirstMember.h"
00055 
00056 using namespace test_roscpp;
00057 
00058 namespace test_roscpp
00059 {
00060   ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(ArrayOfFixedLength, MyArrayOfFixedLength, Allocator);
00061   ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(ArrayOfVariableLength, MyArrayOfVariableLength, Allocator);
00062   ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(EmbeddedFixedLength, MyEmbeddedFixedLength, Allocator);
00063   ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(EmbeddedVariableLength, MyEmbeddedVariableLength, Allocator);
00064   ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(FixedLength, MyFixedLength, Allocator);
00065   ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(VariableLength, MyVariableLength, Allocator);
00066   ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(WithHeader, MyWithHeader, Allocator);
00067   ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(EmbeddedExternal, MyEmbeddedExternal, Allocator);
00068   ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(WithTime, MyWithTime, Allocator);
00069   ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(WithDuration, MyWithDuration, Allocator);
00070   ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(WithMemberNamedHeaderThatIsNotAHeader, MyWithMemberNamedHeaderThatIsNotAHeader, Allocator);
00071   ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(FixedLengthArrayOfExternal, MyFixedLengthArrayOfExternal, Allocator);
00072   ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(VariableLengthArrayOfExternal, MyVariableLengthArrayOfExternal, Allocator);
00073   ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(FixedLengthStringArray, MyFixedLengthStringArray, Allocator);
00074   ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(VariableLengthStringArray, MyVariableLengthStringArray, Allocator);
00075 }
00076 
00077 TEST(GeneratedMessages, traitsWithStandardMessages)
00078 {
00079   EXPECT_TRUE(mt::isFixedSize<ArrayOfFixedLength>());
00080   EXPECT_FALSE(mt::isFixedSize<ArrayOfVariableLength>());
00081   EXPECT_TRUE(mt::isFixedSize<EmbeddedFixedLength>());
00082   EXPECT_FALSE(mt::isFixedSize<EmbeddedVariableLength>());
00083   EXPECT_TRUE(mt::isFixedSize<FixedLength>());
00084   EXPECT_FALSE(mt::isFixedSize<VariableLength>());
00085   EXPECT_FALSE(mt::isFixedSize<WithHeader>());
00086   EXPECT_TRUE(mt::isFixedSize<EmbeddedExternal>());
00087   EXPECT_TRUE(mt::isFixedSize<WithTime>());
00088   EXPECT_TRUE(mt::isFixedSize<WithDuration>());
00089   EXPECT_TRUE(mt::isFixedSize<WithMemberNamedHeaderThatIsNotAHeader>());
00090   EXPECT_FALSE(mt::isFixedSize<FixedLengthArrayOfExternal>());
00091   EXPECT_FALSE(mt::isFixedSize<VariableLengthArrayOfExternal>());
00092   EXPECT_FALSE(mt::isFixedSize<FixedLengthStringArray>());
00093   EXPECT_FALSE(mt::isFixedSize<VariableLengthStringArray>());
00094 
00095   EXPECT_FALSE(mt::hasHeader<ArrayOfFixedLength>());
00096   EXPECT_FALSE(mt::hasHeader<ArrayOfVariableLength>());
00097   EXPECT_FALSE(mt::hasHeader<EmbeddedFixedLength>());
00098   EXPECT_FALSE(mt::hasHeader<EmbeddedVariableLength>());
00099   EXPECT_FALSE(mt::hasHeader<FixedLength>());
00100   EXPECT_FALSE(mt::hasHeader<VariableLength>());
00101   EXPECT_TRUE(mt::hasHeader<WithHeader>());
00102   EXPECT_FALSE(mt::hasHeader<EmbeddedExternal>());
00103   EXPECT_FALSE(mt::hasHeader<WithTime>());
00104   EXPECT_FALSE(mt::hasHeader<WithDuration>());
00105   EXPECT_FALSE(mt::hasHeader<WithMemberNamedHeaderThatIsNotAHeader>());
00106   EXPECT_FALSE(mt::hasHeader<FixedLengthArrayOfExternal>());
00107   EXPECT_FALSE(mt::hasHeader<VariableLengthArrayOfExternal>());
00108   EXPECT_FALSE(mt::hasHeader<FixedLengthStringArray>());
00109   EXPECT_FALSE(mt::hasHeader<VariableLengthStringArray>());
00110   EXPECT_FALSE(mt::hasHeader<HeaderNotFirstMember>());
00111 
00112   EXPECT_FALSE(mt::isSimple<ArrayOfFixedLength>());
00113   EXPECT_FALSE(mt::isSimple<ArrayOfVariableLength>());
00114   EXPECT_FALSE(mt::isSimple<EmbeddedFixedLength>());
00115   EXPECT_FALSE(mt::isSimple<EmbeddedVariableLength>());
00116   EXPECT_FALSE(mt::isSimple<FixedLength>());
00117   EXPECT_FALSE(mt::isSimple<VariableLength>());
00118   EXPECT_FALSE(mt::isSimple<WithHeader>());
00119   EXPECT_FALSE(mt::isSimple<EmbeddedExternal>());
00120   EXPECT_FALSE(mt::isSimple<WithTime>());
00121   EXPECT_FALSE(mt::isSimple<WithDuration>());
00122   EXPECT_FALSE(mt::isSimple<WithMemberNamedHeaderThatIsNotAHeader>());
00123   EXPECT_FALSE(mt::isSimple<FixedLengthArrayOfExternal>());
00124   EXPECT_FALSE(mt::isSimple<VariableLengthArrayOfExternal>());
00125   EXPECT_FALSE(mt::isSimple<FixedLengthStringArray>());
00126   EXPECT_FALSE(mt::isSimple<VariableLengthStringArray>());
00127 }
00128 
00129 TEST(GeneratedMessages, traitsWithCustomAllocator)
00130 {
00131   EXPECT_TRUE(mt::isFixedSize<MyArrayOfFixedLength>());
00132   EXPECT_FALSE(mt::isFixedSize<MyArrayOfVariableLength>());
00133   EXPECT_TRUE(mt::isFixedSize<MyEmbeddedFixedLength>());
00134   EXPECT_FALSE(mt::isFixedSize<MyEmbeddedVariableLength>());
00135   EXPECT_TRUE(mt::isFixedSize<MyFixedLength>());
00136   EXPECT_FALSE(mt::isFixedSize<MyVariableLength>());
00137   EXPECT_FALSE(mt::isFixedSize<MyWithHeader>());
00138   EXPECT_TRUE(mt::isFixedSize<MyEmbeddedExternal>());
00139   EXPECT_TRUE(mt::isFixedSize<MyWithTime>());
00140   EXPECT_TRUE(mt::isFixedSize<MyWithDuration>());
00141   EXPECT_TRUE(mt::isFixedSize<MyWithMemberNamedHeaderThatIsNotAHeader>());
00142   EXPECT_FALSE(mt::isFixedSize<MyFixedLengthArrayOfExternal>());
00143   EXPECT_FALSE(mt::isFixedSize<MyVariableLengthArrayOfExternal>());
00144   EXPECT_FALSE(mt::isFixedSize<MyFixedLengthStringArray>());
00145   EXPECT_FALSE(mt::isFixedSize<MyVariableLengthStringArray>());
00146 
00147   EXPECT_FALSE(mt::hasHeader<MyArrayOfFixedLength>());
00148   EXPECT_FALSE(mt::hasHeader<MyArrayOfVariableLength>());
00149   EXPECT_FALSE(mt::hasHeader<MyEmbeddedFixedLength>());
00150   EXPECT_FALSE(mt::hasHeader<MyEmbeddedVariableLength>());
00151   EXPECT_FALSE(mt::hasHeader<MyFixedLength>());
00152   EXPECT_FALSE(mt::hasHeader<MyVariableLength>());
00153   EXPECT_TRUE(mt::hasHeader<MyWithHeader>());
00154   EXPECT_FALSE(mt::hasHeader<MyEmbeddedExternal>());
00155   EXPECT_FALSE(mt::hasHeader<MyWithTime>());
00156   EXPECT_FALSE(mt::hasHeader<MyWithDuration>());
00157   EXPECT_FALSE(mt::hasHeader<MyWithMemberNamedHeaderThatIsNotAHeader>());
00158   EXPECT_FALSE(mt::hasHeader<MyFixedLengthArrayOfExternal>());
00159   EXPECT_FALSE(mt::hasHeader<MyVariableLengthArrayOfExternal>());
00160   EXPECT_FALSE(mt::hasHeader<MyFixedLengthStringArray>());
00161   EXPECT_FALSE(mt::hasHeader<MyVariableLengthStringArray>());
00162 
00163   EXPECT_FALSE(mt::isSimple<MyArrayOfFixedLength>());
00164   EXPECT_FALSE(mt::isSimple<MyArrayOfVariableLength>());
00165   EXPECT_FALSE(mt::isSimple<MyEmbeddedFixedLength>());
00166   EXPECT_FALSE(mt::isSimple<MyEmbeddedVariableLength>());
00167   EXPECT_FALSE(mt::isSimple<MyFixedLength>());
00168   EXPECT_FALSE(mt::isSimple<MyVariableLength>());
00169   EXPECT_FALSE(mt::isSimple<MyWithHeader>());
00170   EXPECT_FALSE(mt::isSimple<MyEmbeddedExternal>());
00171   EXPECT_FALSE(mt::isSimple<MyWithTime>());
00172   EXPECT_FALSE(mt::isSimple<MyWithDuration>());
00173   EXPECT_FALSE(mt::isSimple<MyWithMemberNamedHeaderThatIsNotAHeader>());
00174   EXPECT_FALSE(mt::isSimple<MyFixedLengthArrayOfExternal>());
00175   EXPECT_FALSE(mt::isSimple<MyVariableLengthArrayOfExternal>());
00176   EXPECT_FALSE(mt::isSimple<MyFixedLengthStringArray>());
00177   EXPECT_FALSE(mt::isSimple<MyVariableLengthStringArray>());
00178 }
00179 
00180 #define SERIALIZATION_COMPILATION_TEST(Type) \
00181   TEST(GeneratedMessages, serialization_##Type) \
00182   { \
00183     Type ser_val, deser_val; \
00184     serializeAndDeserialize(ser_val, deser_val); \
00185   }
00186 
00187 SERIALIZATION_COMPILATION_TEST(ArrayOfFixedLength);
00188 SERIALIZATION_COMPILATION_TEST(ArrayOfVariableLength);
00189 SERIALIZATION_COMPILATION_TEST(EmbeddedFixedLength);
00190 SERIALIZATION_COMPILATION_TEST(EmbeddedVariableLength);
00191 SERIALIZATION_COMPILATION_TEST(FixedLength);
00192 SERIALIZATION_COMPILATION_TEST(VariableLength);
00193 SERIALIZATION_COMPILATION_TEST(WithHeader);
00194 SERIALIZATION_COMPILATION_TEST(EmbeddedExternal);
00195 SERIALIZATION_COMPILATION_TEST(WithTime);
00196 SERIALIZATION_COMPILATION_TEST(WithDuration);
00197 SERIALIZATION_COMPILATION_TEST(WithMemberNamedHeaderThatIsNotAHeader);
00198 SERIALIZATION_COMPILATION_TEST(FixedLengthArrayOfExternal);
00199 SERIALIZATION_COMPILATION_TEST(VariableLengthArrayOfExternal);
00200 SERIALIZATION_COMPILATION_TEST(FixedLengthStringArray);
00201 SERIALIZATION_COMPILATION_TEST(VariableLengthStringArray);
00202 
00203 SERIALIZATION_COMPILATION_TEST(MyArrayOfFixedLength);
00204 SERIALIZATION_COMPILATION_TEST(MyArrayOfVariableLength);
00205 SERIALIZATION_COMPILATION_TEST(MyEmbeddedFixedLength);
00206 SERIALIZATION_COMPILATION_TEST(MyEmbeddedVariableLength);
00207 SERIALIZATION_COMPILATION_TEST(MyFixedLength);
00208 SERIALIZATION_COMPILATION_TEST(MyVariableLength);
00209 SERIALIZATION_COMPILATION_TEST(MyWithHeader);
00210 SERIALIZATION_COMPILATION_TEST(MyEmbeddedExternal);
00211 SERIALIZATION_COMPILATION_TEST(MyWithTime);
00212 SERIALIZATION_COMPILATION_TEST(MyWithDuration);
00213 SERIALIZATION_COMPILATION_TEST(MyWithMemberNamedHeaderThatIsNotAHeader);
00214 SERIALIZATION_COMPILATION_TEST(MyFixedLengthArrayOfExternal);
00215 SERIALIZATION_COMPILATION_TEST(MyVariableLengthArrayOfExternal);
00216 SERIALIZATION_COMPILATION_TEST(MyFixedLengthStringArray);
00217 SERIALIZATION_COMPILATION_TEST(MyVariableLengthStringArray);
00218 
00219 #define ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(Type, Allocator) \
00220   TEST(GeneratedMessages, allocationConstructor_##Type) \
00221   { \
00222     Allocator a; \
00223     Type val(a); \
00224   }
00225 
00226 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(ArrayOfFixedLength, std::allocator<void>);
00227 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(ArrayOfVariableLength, std::allocator<void>);
00228 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(EmbeddedFixedLength, std::allocator<void>);
00229 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(EmbeddedVariableLength, std::allocator<void>);
00230 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(FixedLength, std::allocator<void>);
00231 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(VariableLength, std::allocator<void>);
00232 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(WithHeader, std::allocator<void>);
00233 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(EmbeddedExternal, std::allocator<void>);
00234 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(WithTime, std::allocator<void>);
00235 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(WithDuration, std::allocator<void>);
00236 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(WithMemberNamedHeaderThatIsNotAHeader, std::allocator<void>);
00237 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(FixedLengthArrayOfExternal, std::allocator<void>);
00238 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(VariableLengthArrayOfExternal, std::allocator<void>);
00239 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(FixedLengthStringArray, std::allocator<void>);
00240 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(VariableLengthStringArray, std::allocator<void>);
00241 
00242 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(MyArrayOfFixedLength, Allocator<void>);
00243 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(MyArrayOfVariableLength, Allocator<void>);
00244 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(MyEmbeddedFixedLength, Allocator<void>);
00245 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(MyEmbeddedVariableLength, Allocator<void>);
00246 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(MyFixedLength, Allocator<void>);
00247 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(MyVariableLength, Allocator<void>);
00248 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(MyWithHeader, Allocator<void>);
00249 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(MyEmbeddedExternal, Allocator<void>);
00250 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(MyWithTime, Allocator<void>);
00251 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(MyWithDuration, Allocator<void>);
00252 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(MyWithMemberNamedHeaderThatIsNotAHeader, Allocator<void>);
00253 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(MyFixedLengthArrayOfExternal, Allocator<void>);
00254 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(MyVariableLengthArrayOfExternal, Allocator<void>);
00255 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(MyFixedLengthStringArray, Allocator<void>);
00256 ALLOCATOR_CONSTRUCTOR_COMPILATION_TEST(MyVariableLengthStringArray, Allocator<void>);
00257 
00258 TEST(Generated, serializationOStreamOperator)
00259 {
00260   using namespace ros::serialization;
00261   Array b(new uint8_t[8]);
00262   OStream ostream(b.get(), 8);
00263   FixedLength m;
00264   ostream << m;
00265   ASSERT_EQ(ostream.getLength(), 0UL);
00266 }
00267 
00268 TEST(Generated, constants)
00269 {
00270   EXPECT_EQ(Constants::a, 1U);
00271   EXPECT_EQ(Constants::b, 2);
00272   EXPECT_EQ(Constants::c, 3U);
00273   EXPECT_EQ(Constants::d, 4);
00274   EXPECT_EQ(Constants::e, 5U);
00275   EXPECT_EQ(Constants::f, 6);
00276   EXPECT_EQ(Constants::g, 7U);
00277   EXPECT_EQ(Constants::h, 8);
00278   EXPECT_FLOAT_EQ(Constants::fa, 1.5);
00279   EXPECT_FLOAT_EQ(Constants::fb, 40.9);
00280   EXPECT_STREQ(Constants::str.c_str(), "hello there");
00281   EXPECT_STREQ(Constants::str2.c_str(), "this string has \"quotes\" and \\slashes\\ in it");
00282 }
00283 
00284 int main(int argc, char** argv)
00285 {
00286   testing::InitGoogleTest(&argc, argv);
00287   return RUN_ALL_TESTS();
00288 }
00289 
00290 
00291 


test_roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim
autogenerated on Thu Jun 6 2019 21:10:42