gtest-message_test.cc
Go to the documentation of this file.
00001 // Copyright 2005, Google Inc.
00002 // All rights reserved.
00003 //
00004 // Redistribution and use in source and binary forms, with or without
00005 // modification, are permitted provided that the following conditions are
00006 // 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
00011 // copyright notice, this list of conditions and the following disclaimer
00012 // in the documentation and/or other materials provided with the
00013 // distribution.
00014 //     * Neither the name of Google Inc. nor the names of its
00015 // contributors may be used to endorse or promote products derived from
00016 // this software without specific prior written permission.
00017 //
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // Author: wan@google.com (Zhanyong Wan)
00031 //
00032 // Tests for the Message class.
00033 
00034 #include "gtest/gtest-message.h"
00035 
00036 #include "gtest/gtest.h"
00037 
00038 namespace {
00039 
00040 using ::testing::Message;
00041 
00042 // Tests the testing::Message class
00043 
00044 // Tests the default constructor.
00045 TEST(MessageTest, DefaultConstructor) {
00046   const Message msg;
00047   EXPECT_EQ("", msg.GetString());
00048 }
00049 
00050 // Tests the copy constructor.
00051 TEST(MessageTest, CopyConstructor) {
00052   const Message msg1("Hello");
00053   const Message msg2(msg1);
00054   EXPECT_EQ("Hello", msg2.GetString());
00055 }
00056 
00057 // Tests constructing a Message from a C-string.
00058 TEST(MessageTest, ConstructsFromCString) {
00059   Message msg("Hello");
00060   EXPECT_EQ("Hello", msg.GetString());
00061 }
00062 
00063 // Tests streaming a float.
00064 TEST(MessageTest, StreamsFloat) {
00065   const std::string s = (Message() << 1.23456F << " " << 2.34567F).GetString();
00066   // Both numbers should be printed with enough precision.
00067   EXPECT_PRED_FORMAT2(testing::IsSubstring, "1.234560", s.c_str());
00068   EXPECT_PRED_FORMAT2(testing::IsSubstring, " 2.345669", s.c_str());
00069 }
00070 
00071 // Tests streaming a double.
00072 TEST(MessageTest, StreamsDouble) {
00073   const std::string s = (Message() << 1260570880.4555497 << " "
00074                                   << 1260572265.1954534).GetString();
00075   // Both numbers should be printed with enough precision.
00076   EXPECT_PRED_FORMAT2(testing::IsSubstring, "1260570880.45", s.c_str());
00077   EXPECT_PRED_FORMAT2(testing::IsSubstring, " 1260572265.19", s.c_str());
00078 }
00079 
00080 // Tests streaming a non-char pointer.
00081 TEST(MessageTest, StreamsPointer) {
00082   int n = 0;
00083   int* p = &n;
00084   EXPECT_NE("(null)", (Message() << p).GetString());
00085 }
00086 
00087 // Tests streaming a NULL non-char pointer.
00088 TEST(MessageTest, StreamsNullPointer) {
00089   int* p = NULL;
00090   EXPECT_EQ("(null)", (Message() << p).GetString());
00091 }
00092 
00093 // Tests streaming a C string.
00094 TEST(MessageTest, StreamsCString) {
00095   EXPECT_EQ("Foo", (Message() << "Foo").GetString());
00096 }
00097 
00098 // Tests streaming a NULL C string.
00099 TEST(MessageTest, StreamsNullCString) {
00100   char* p = NULL;
00101   EXPECT_EQ("(null)", (Message() << p).GetString());
00102 }
00103 
00104 // Tests streaming std::string.
00105 TEST(MessageTest, StreamsString) {
00106   const ::std::string str("Hello");
00107   EXPECT_EQ("Hello", (Message() << str).GetString());
00108 }
00109 
00110 // Tests that we can output strings containing embedded NULs.
00111 TEST(MessageTest, StreamsStringWithEmbeddedNUL) {
00112   const char char_array_with_nul[] =
00113       "Here's a NUL\0 and some more string";
00114   const ::std::string string_with_nul(char_array_with_nul,
00115                                       sizeof(char_array_with_nul) - 1);
00116   EXPECT_EQ("Here's a NUL\\0 and some more string",
00117             (Message() << string_with_nul).GetString());
00118 }
00119 
00120 // Tests streaming a NUL char.
00121 TEST(MessageTest, StreamsNULChar) {
00122   EXPECT_EQ("\\0", (Message() << '\0').GetString());
00123 }
00124 
00125 // Tests streaming int.
00126 TEST(MessageTest, StreamsInt) {
00127   EXPECT_EQ("123", (Message() << 123).GetString());
00128 }
00129 
00130 // Tests that basic IO manipulators (endl, ends, and flush) can be
00131 // streamed to Message.
00132 TEST(MessageTest, StreamsBasicIoManip) {
00133   EXPECT_EQ("Line 1.\nA NUL char \\0 in line 2.",
00134                (Message() << "Line 1." << std::endl
00135                          << "A NUL char " << std::ends << std::flush
00136                          << " in line 2.").GetString());
00137 }
00138 
00139 // Tests Message::GetString()
00140 TEST(MessageTest, GetString) {
00141   Message msg;
00142   msg << 1 << " lamb";
00143   EXPECT_EQ("1 lamb", msg.GetString());
00144 }
00145 
00146 // Tests streaming a Message object to an ostream.
00147 TEST(MessageTest, StreamsToOStream) {
00148   Message msg("Hello");
00149   ::std::stringstream ss;
00150   ss << msg;
00151   EXPECT_EQ("Hello", testing::internal::StringStreamToString(&ss));
00152 }
00153 
00154 // Tests that a Message object doesn't take up too much stack space.
00155 TEST(MessageTest, DoesNotTakeUpMuchStackSpace) {
00156   EXPECT_LE(sizeof(Message), 16U);
00157 }
00158 
00159 }  // namespace


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Sat Jun 8 2019 18:24:44