This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Uncacheable facet testcase
- From: Jerry Quinn <jlquinn at optonline dot net>
- To: libstdc++ at gcc dot gnu dot org
- Date: Wed, 04 Jun 2003 00:28:37 -0400
- Subject: 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;
}