X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=libstdc%2B%2B-v3%2Ftestsuite%2F22_locale%2Fnum_get%2Fget%2Fchar%2F37958.cc;fp=libstdc%2B%2B-v3%2Ftestsuite%2F22_locale%2Fnum_get%2Fget%2Fchar%2F37958.cc;h=f0ed3efc60d09c7152ac083492a59bb16050bb83;hb=6fed43773c9b0ce596dca5686f37ac3fc0fa11c0;hp=0000000000000000000000000000000000000000;hpb=27b11d56b743098deb193d510b337ba22dc52e5c;p=msp430-gcc.git diff --git a/libstdc++-v3/testsuite/22_locale/num_get/get/char/37958.cc b/libstdc++-v3/testsuite/22_locale/num_get/get/char/37958.cc new file mode 100644 index 00000000..f0ed3efc --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/num_get/get/char/37958.cc @@ -0,0 +1,196 @@ +// 2008-10-31 Paolo Carlini + +// Copyright (C) 2008, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 22.2.2.1.1 num_get members + +#include +#include +#include + +struct Punct1: std::numpunct +{ + std::string do_truename() const { return "a"; } + std::string do_falsename() const { return "abb"; } +}; + +struct Punct2: std::numpunct +{ + std::string do_truename() const { return "1"; } + std::string do_falsename() const { return "0"; } +}; + +struct Punct3: std::numpunct +{ + std::string do_truename() const { return ""; } + std::string do_falsename() const { return ""; } +}; + +struct Punct4: std::numpunct +{ + std::string do_truename() const { return "one"; } + std::string do_falsename() const { return "two"; } +}; + +// libstdc++/37958 +void test01() +{ + using namespace std; + typedef istreambuf_iterator iterator_type; + + bool test __attribute__((unused)) = true; + + istringstream iss0, iss1, iss2, iss3, iss4; + iss1.imbue(locale(iss1.getloc(), new Punct1)); + iss2.imbue(locale(iss2.getloc(), new Punct2)); + iss3.imbue(locale(iss3.getloc(), new Punct3)); + iss4.imbue(locale(iss4.getloc(), new Punct4)); + const num_get& ng0 = use_facet >(iss0.getloc()); + const num_get& ng1 = use_facet >(iss1.getloc()); + const num_get& ng2 = use_facet >(iss2.getloc()); + const num_get& ng3 = use_facet >(iss3.getloc()); + const num_get& ng4 = use_facet >(iss4.getloc()); + + ios_base::iostate err = ios_base::goodbit; + iterator_type end; + bool b0 = false; + bool b1 = false; + bool b2 = false; + bool b3 = true; + bool b4 = false; + + iss0.str("true"); + iss0.setf(ios_base::boolalpha); + err = ios_base::goodbit; + end = ng0.get(iss0.rdbuf(), 0, iss0, err, b0); + VERIFY( err == ios_base::goodbit ); + VERIFY( b0 == true ); + + iss0.str("false"); + iss0.clear(); + err = ios_base::goodbit; + end = ng0.get(iss0.rdbuf(), 0, iss0, err, b0); + VERIFY( err == ios_base::goodbit ); + VERIFY( b0 == false ); + + iss1.str("a"); + iss1.setf(ios_base::boolalpha); + err = ios_base::goodbit; + end = ng1.get(iss1.rdbuf(), 0, iss1, err, b1); + VERIFY( err == ios_base::eofbit ); + VERIFY( b1 == true ); + + iss1.str("abb"); + iss1.clear(); + err = ios_base::goodbit; + end = ng1.get(iss1.rdbuf(), 0, iss1, err, b1); + VERIFY( err == ios_base::goodbit ); + VERIFY( b1 == false ); + + iss1.str("abc"); + iss1.clear(); + err = ios_base::goodbit; + end = ng1.get(iss1.rdbuf(), 0, iss1, err, b1); + VERIFY( err == ios_base::failbit ); + VERIFY( b1 == false ); + VERIFY( *end == 'c' ); + + iss1.str("ab"); + iss1.clear(); + b1 = true; + err = ios_base::goodbit; + end = ng1.get(iss1.rdbuf(), 0, iss1, err, b1); + VERIFY( err == (ios_base::failbit | ios_base::eofbit) ); + VERIFY( b1 == false ); + + iss2.str("1"); + iss2.setf(ios_base::boolalpha); + err = ios_base::goodbit; + end = ng2.get(iss2.rdbuf(), 0, iss2, err, b2); + VERIFY( err == ios_base::goodbit ); + VERIFY( b2 == true ); + + iss2.str("0"); + iss2.clear(); + err = ios_base::goodbit; + end = ng2.get(iss2.rdbuf(), 0, iss2, err, b2); + VERIFY( err == ios_base::goodbit ); + VERIFY( b2 == false ); + + iss2.str("2"); + iss2.clear(); + b2 = true; + err = ios_base::goodbit; + end = ng2.get(iss2.rdbuf(), 0, iss2, err, b2); + VERIFY( err == ios_base::failbit ); + VERIFY( b2 == false ); + VERIFY( *end == '2' ); + + iss3.str("blah"); + iss3.setf(ios_base::boolalpha); + err = ios_base::goodbit; + end = ng3.get(iss3.rdbuf(), 0, iss3, err, b3); + VERIFY( err == ios_base::failbit ); + VERIFY( b3 == false ); + VERIFY( *end == 'b' ); + + iss3.str(""); + iss3.clear(); + b3 = true; + err = ios_base::goodbit; + end = ng3.get(iss3.rdbuf(), 0, iss3, err, b3); + VERIFY( err == ios_base::failbit ); + VERIFY( b3 == false ); + + iss4.str("one"); + iss4.setf(ios_base::boolalpha); + err = ios_base::goodbit; + end = ng4.get(iss4.rdbuf(), 0, iss4, err, b4); + VERIFY( err == ios_base::goodbit ); + VERIFY( b4 == true ); + + iss4.str("two"); + iss4.clear(); + err = ios_base::goodbit; + end = ng4.get(iss4.rdbuf(), 0, iss4, err, b4); + VERIFY( err == ios_base::goodbit ); + VERIFY( b4 == false ); + + iss4.str("three"); + iss4.clear(); + b4 = true; + err = ios_base::goodbit; + end = ng4.get(iss4.rdbuf(), 0, iss4, err, b4); + VERIFY( err == ios_base::failbit ); + VERIFY( b4 == false ); + VERIFY( *end == 'h' ); + + iss4.str("on"); + iss4.clear(); + b4 = true; + err = ios_base::goodbit; + end = ng4.get(iss4.rdbuf(), 0, iss4, err, b4); + VERIFY( err == (ios_base::failbit | ios_base::eofbit) ); + VERIFY( b4 == false ); +} + +int main() +{ + test01(); + return 0; +}