// Copyright 2002 - 2008, 2010, 2011 National Technology Engineering // Solutions of Sandia, LLC (NTESS). Under the terms of Contract // DE-NA0003525 with NTESS, the U.S. Government retains certain rights // in this software. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of NTESS nor the names of its contributors // may be used to endorse or promote products derived from this // software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // #include "gtest/gtest.h" #include "stk_util/diag/SlibDiagWriter.hpp" #include "stk_util/diag/WriterExt.hpp" // for operator<< #include "stk_util/diag/WriterOStream.hpp" // for operator<< #include "stk_util/environment/EnvData.hpp" #include "stk_util/environment/OutputLog.hpp" #include "stk_util/util/IndentStreambuf.hpp" // for indent_streambuf #include "stk_util/util/Writer.hpp" // for Writer, operator<<, dendl, push, pop, dflush #include "stk_util/util/WriterManip.hpp" // for operator<<, resetiosflags, setw, setfill #include "stk_util/util/Writer_fwd.hpp" // for LOG_ALWAYS, LOG_MEMBERS, LOG_TRACE, LOG_TRA... #include // for bitset, bitset<>::reference #include // for list, _List_iterator, list<>::iterator #include // for multimap<>::value_type, multimap, map, _Rb_... #include // for set #include // for ostringstream, operator<<, ostream, operator& #include // for operator==, string #include // for pair #include // for vector, vector<>::iterator using namespace stk::diag; enum LogMask { LOG_ALWAYS = stk::LOG_ALWAYS, LOG_TRACE = stk::LOG_TRACE, LOG_TRACE_STATS = stk::LOG_TRACE_STATS, LOG_TRACE_SUB_CALLS = stk::LOG_TRACE_SUB_CALLS, LOG_MEMBERS = stk::LOG_MEMBERS, LOG_TEST1 = 0x0000010, LOG_TEST2 = 0x0000020 }; TEST(UnitTestWriter, diag_writer_with_output_stream_specified) { stk::EnvData::instance(); stk::bind_output_streams("dout>null"); EXPECT_NO_THROW(slibout << "pass"); } TEST(UnitTestWriter, diag_writer_with_default_output_stream) { stk::EnvData::instance(); EXPECT_NO_THROW(slibout << "pass"); } TEST(UnitTestWriter, diagWriter_NoBlankLines) { std::cout.flush(); std::ostringstream mystream; std::streambuf* oldbuf = std::cout.rdbuf(mystream.rdbuf()); sierra::configure_dwout(); sierra::dwout()<<"a\n\n\n\nb"< v = { 1, 2, 3}; std::vector vl; for (int i = 0; i < 20; ++i) vl.push_back(i); std::vector vp; vp.push_back(new int(1)); vp.push_back(new int(2)); vp.push_back(new int(3)); vp.push_back(nullptr); std::list l = { 1, 2, 3 }; std::list lp; lp.push_back(new int(1)); lp.push_back(new int(2)); lp.push_back(new int(3)); std::map m; m[1] = 2; m[2] = 3; m[3] = 4; std::map mp; mp[1] = new int(2); mp[2] = new int(3); mp[3] = new int(4); std::multimap mm; mm.insert(std::multimap::value_type(1, 2)); mm.insert(std::multimap::value_type(1, 3)); mm.insert(std::multimap::value_type(2, 4)); std::multimap mmp; mmp.insert(std::multimap::value_type(1, new int(2))); mmp.insert(std::multimap::value_type(1, new int(3))); mmp.insert(std::multimap::value_type(2, new int(4))); std::set s = { 2, 3, 4}; std::bitset<8> b; b[1] = 1; b[3] = 1; dw() << typeid(int) << dendl; dw() << std::pair(5, 7) << dendl; dw() << v << dendl; dw() << vl << dendl; dw() << vp << dendl; dw() << l << dendl; dw() << lp << dendl; dw() << m << dendl; dw() << mp << dendl; dw() << mm << dendl; dw() << mmp << dendl; dw() << s << dendl; dw() << b << dendl; for(std::vector::iterator it=vp.begin(); it!=vp.end(); ++it) delete *it; for ( std::multimap::iterator curmmp = mmp.begin() ; curmmp != mmp.end() ; curmmp++ ) delete curmmp->second; for ( std::map::iterator curmp = mp.begin() ; curmp != mp.end() ; curmp++ ) delete curmp->second; for ( std::list::iterator curp = lp.begin() ; curp != lp.end() ; curp++ ) delete *curp; } }