This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Uncacheable facet testcase


I discovered the following (unfortunate) testcase of a facet that
cannot be cached for later use.  The implication is that in general,
the facets canot be cached safely.  As best as I can interpret the
spec, this program is valid.

Anyway, I'd like to add it into the test suite.  Where is the best
place for this to go?  It doesn't really seem to fit in well with any
of the existing subdirs in 27_io.

Jerry Quinn

// Test a non-cacheable facet

#include <sstream>
#include <locale>
#include <cassert>

using namespace std;

bool flip = false;

class badfacet : public numpunct<char>
{
public:
  string_type do_truename() const
  { if (flip) return "false"; else return "true"; }
};


void test01()
{
  bool blah = true;
  ostringstream os;

  locale loc(locale::classic(), new badfacet);
  os.imbue(loc);
  os.setf(ios::boolalpha);

  os << blah << " ";
  flip = !flip;
  os << blah;
  VERIFY( os.str() == "true false" );
}


int main ()
{
  test01();
  return 0;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]