[v3] money_get iterator fixups

Benjamin Kosnik bkoz@redhat.com
Fri Jan 11 13:27:00 GMT 2002


This takes the iterator tests from libstdc++/5331 and applies them to
money_get. In the process, more bugs were found, which are now fixed.
It looks like this type of test, like the facet typedef tests and
non-required facet compilation tests, should be done universally. So
I'll go through the testsuite and add them in an effort to pro-actively
fix bugs...

tested x86/linux

2002-01-11  Benjamin Kosnik  <bkoz@redhat.com>

	* include/bits/locale_facets.tcc (money_get::do_get(string)):
	Check for zero-length negative sign before adding it to output
	string.
	(money_get::do_get(long double)): Return beg.
	* testsuite/22_locale/money_get_members_char.cc (test02): Add
	iterator checks.
	* testsuite/22_locale/money_get_members_wchar_t.cc: Same.


Index: include/bits/locale_facets.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/locale_facets.tcc,v
retrieving revision 1.49
diff -c -p -r1.49 locale_facets.tcc
*** locale_facets.tcc	2002/01/11 05:07:22	1.49
--- locale_facets.tcc	2002/01/11 20:03:51
*************** namespace std
*** 1035,1041 ****
  	   ios_base::iostate& __err, long double& __units) const
      { 
        string_type __str;
!       this->do_get(__beg, __end, __intl, __io, __err, __str); 
  
        const int __n = numeric_limits<long double>::digits10;
        char* __cs = static_cast<char*>(__builtin_alloca(sizeof(char) * __n));
--- 1035,1041 ----
  	   ios_base::iostate& __err, long double& __units) const
      { 
        string_type __str;
!       __beg = this->do_get(__beg, __end, __intl, __io, __err, __str); 
  
        const int __n = numeric_limits<long double>::digits10;
        char* __cs = static_cast<char*>(__builtin_alloca(sizeof(char) * __n));
*************** namespace std
*** 1222,1228 ****
        while (__units[0] == __ctype.widen('0'))
  	__units.erase(__units.begin());
  
!       if (__sign == __neg_sign)
  	__units.insert(__units.begin(), __ctype.widen('-'));
  
        // Test for grouping fidelity.
--- 1222,1228 ----
        while (__units[0] == __ctype.widen('0'))
  	__units.erase(__units.begin());
  
!       if (__sign.size() && __sign == __neg_sign)
  	__units.insert(__units.begin(), __ctype.widen('-'));
  
        // Test for grouping fidelity.
Index: testsuite/22_locale/money_get_members_char.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/22_locale/money_get_members_char.cc,v
retrieving revision 1.3
diff -c -p -r1.3 money_get_members_char.cc
*** money_get_members_char.cc	2001/09/20 09:07:37	1.3
--- money_get_members_char.cc	2002/01/11 20:03:53
***************
*** 1,6 ****
  // 2001-09-12 Benjamin Kosnik  <bkoz@redhat.com>
  
! // Copyright (C) 2001 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
--- 1,6 ----
  // 2001-09-12 Benjamin Kosnik  <bkoz@redhat.com>
  
! // Copyright (C) 2001-2002 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
*************** void test01()
*** 172,178 ****
    VERIFY( err11 == ios_base::goodbit );
  }
  
! // test double/string versions
  void test02()
  {
    using namespace std;
--- 172,178 ----
    VERIFY( err11 == ios_base::goodbit );
  }
  
! // test double version
  void test02()
  {
    using namespace std;
*************** void test02()
*** 249,257 ****
--- 249,298 ----
    VERIFY( err03 == ios_base::goodbit );
  }
  
+ void test03()
+ {
+   using namespace std;
+   bool test = true;
+ 
+   // Check money_get works with other iterators besides streambuf
+   // output iterators.
+   typedef string::const_iterator iter_type;
+   typedef money_get<char, iter_type> mon_get_type;
+   const ios_base::iostate goodbit = ios_base::goodbit;
+   const ios_base::iostate eofbit = ios_base::eofbit;
+   ios_base::iostate err = goodbit;
+   const locale loc_c = locale::classic();
+   const string str = "0.01Eleanor Roosevelt";
+ 
+   istringstream iss; 
+   iss.imbue(locale(loc_c, new mon_get_type));
+ 
+   // Iterator advanced, state, output.
+   const mon_get_type& mg = use_facet<mon_get_type>(iss.getloc());
+ 
+   // 01 string
+   string res1;
+   iter_type end1 = mg.get(str.begin(), str.end(), false, iss, err, res1);
+   string rem1(end1, str.end());
+   VERIFY( err == goodbit );
+   VERIFY( res1 == "1" );
+   VERIFY( rem1 == "Eleanor Roosevelt" );
+ 
+   // 02 long double
+   iss.clear();
+   err = goodbit;
+   long double res2;
+   iter_type end2 = mg.get(str.begin(), str.end(), false, iss, err, res2);
+   string rem2(end2, str.end());
+   VERIFY( err == goodbit );
+   VERIFY( res2 == 1 );
+   VERIFY( rem2 == "Eleanor Roosevelt" );
+ }
+ 
  int main()
  {
    test01();
    test02();
+   test03();
    return 0;
  }
Index: testsuite/22_locale/money_get_members_wchar_t.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/22_locale/money_get_members_wchar_t.cc,v
retrieving revision 1.3
diff -c -p -r1.3 money_get_members_wchar_t.cc
*** money_get_members_wchar_t.cc	2001/09/20 09:07:37	1.3
--- money_get_members_wchar_t.cc	2002/01/11 20:03:54
*************** void test02()
*** 250,262 ****
--- 250,304 ----
    VERIFY( result3 == digits4 );
    VERIFY( err03 == ios_base::goodbit );
  }
+ 
+ void test03()
+ {
+   using namespace std;
+   bool test = true;
+ 
+   // Check money_get works with other iterators besides streambuf
+   // output iterators.
+   typedef wstring::const_iterator iter_type;
+   typedef money_get<wchar_t, iter_type> mon_get_type;
+   const ios_base::iostate goodbit = ios_base::goodbit;
+   const ios_base::iostate eofbit = ios_base::eofbit;
+   ios_base::iostate err = goodbit;
+   const locale loc_c = locale::classic();
+   const wstring str = L"0.01Eleanor Roosevelt";
+ 
+   wistringstream iss; 
+   iss.imbue(locale(loc_c, new mon_get_type));
+ 
+   // Iterator advanced, state, output.
+   const mon_get_type& mg = use_facet<mon_get_type>(iss.getloc());
+ 
+   // 01 string
+   wstring res1;
+   iter_type end1 = mg.get(str.begin(), str.end(), false, iss, err, res1);
+   wstring rem1(end1, str.end());
+   VERIFY( err == goodbit );
+   VERIFY( res1 == L"1" );
+   VERIFY( rem1 == L"Eleanor Roosevelt" );
+ 
+   // 02 long double
+   iss.clear();
+   err = goodbit;
+   long double res2;
+   iter_type end2 = mg.get(str.begin(), str.end(), false, iss, err, res2);
+   wstring rem2(end2, str.end());
+   VERIFY( err == goodbit );
+   VERIFY( res2 == 1 );
+   VERIFY( rem2 == L"Eleanor Roosevelt" );
+ }
  #endif
  
+ 
  int main()
  {
  #ifdef _GLIBCPP_USE_WCHAR_T
    test01();
    test02();
+   test03();
  #endif
    return 0;
  }















More information about the Gcc-patches mailing list