string_streams.cpp
Go to the documentation of this file.
00001 
00008 /*****************************************************************************
00009 ** Includes
00010 *****************************************************************************/
00011 
00012 #include <iostream>
00013 #include <string>
00014 #include <gtest/gtest.h>
00015 #include "../../include/ecl/streams/string_stream.hpp"
00016 
00017 /*****************************************************************************
00018 ** Using
00019 *****************************************************************************/
00020 
00021 using std::string;
00022 using ecl::StringStream;
00023 
00024 /*****************************************************************************
00025 ** Tests
00026 *****************************************************************************/
00027 
00028 TEST(StringStreams,floatTypes) {
00029     StringStream sstream;
00030     float f = 33.33;
00031     double d = -1.0;
00032     sstream << f;
00033     sstream >> d;
00034     EXPECT_FALSE(sstream.fail());
00035     // Give it some room for rounding off
00036     EXPECT_GT(33.34,d);
00037     EXPECT_LT(33.32,d);
00038 }
00039 
00040 TEST(StringStreams,clearStream) {
00041     StringStream sstream;
00042     sstream << "dude";
00043     sstream.clear();
00044     sstream << "aha";
00045     EXPECT_FALSE(sstream.fail());
00046     EXPECT_EQ(string("aha"),sstream.str());
00047 }
00048 
00049 TEST(StringStreams,integralTypes) {
00050     StringStream sstream;
00051     int i = 3;
00052     int j = -1;
00053     sstream << i;
00054     sstream >> j;
00055     EXPECT_FALSE(sstream.fail());
00056     // Give it some room for rounding off
00057     EXPECT_EQ(3,j);
00058 }
00059 
00060 TEST(StringStreams,hexTypes) {
00061     StringStream sstream;
00062     int j = -1;
00063     sstream << "0xA0";
00064     sstream >> j;
00065     EXPECT_FALSE(sstream.fail());
00066     // Give it some room for rounding off
00067     EXPECT_EQ(160,j);
00068 }
00069 TEST(StringStreams,multipleOps) {
00070         StringStream sstream;
00071     string s;
00072     sstream << "Hello";
00073     sstream >> s;
00074     EXPECT_FALSE(sstream.fail());
00075     EXPECT_EQ(string("Hello"),s);
00076     sstream << "Dude";
00077     sstream >> s;
00078     EXPECT_FALSE(sstream.fail());
00079     EXPECT_EQ(string("Dude"),s);
00080 }
00081 
00082 TEST(StringStreams,readEmptyFail) {
00083         StringStream sstream;
00084         int j;
00085     sstream >> j;
00086     EXPECT_TRUE(sstream.fail());
00087 }
00088 
00089 TEST(StringStreams,remaining) {
00090         StringStream sstream;
00091     sstream << "Dude";
00092     EXPECT_EQ(4,sstream.device().remaining());
00093 }
00094 
00095 /*****************************************************************************
00096 ** Main
00097 *****************************************************************************/
00098 
00099 int main(int argc, char** argv) {
00100         testing::InitGoogleTest(&argc,argv);
00101         return RUN_ALL_TESTS();
00102 }
00103 
00104 


ecl_streams
Author(s): Daniel Stonier
autogenerated on Sun Oct 5 2014 23:36:00