This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[v3] money_put iterator fixups



Testing output with non-streambuf iterators, non-required iterators,
checking iterator position, value inserted, error state.

tested x86/linux

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

	* include/bits/locale_facets.tcc (money_put::do_put(string):
	Correct output iterator value.
	* testsuite/22_locale/money_put_members_char.cc (test03): Add.
	* testsuite/22_locale/money_put_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.50
diff -c -p -r1.50 locale_facets.tcc
*** locale_facets.tcc	2002/01/11 20:12:02	1.50
--- locale_facets.tcc	2002/01/13 04:24:52
*************** namespace std
*** 1415,1422 ****
  	    }
  
  	  // Write resulting, fully-formatted string to output iterator.
! 	  for (size_type __j = 0; __j < __len; ++__j)
! 	    __s = __res[__j];
  	}
        __io.width(0);
        return __s; 
--- 1415,1422 ----
  	    }
  
  	  // Write resulting, fully-formatted string to output iterator.
! 	  for (size_type __j = 0; __j < __len; ++__j, ++__s)
! 	    *__s = __res[__j];
  	}
        __io.width(0);
        return __s; 
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.4
diff -c -p -r1.4 money_get_members_char.cc
*** money_get_members_char.cc	2002/01/11 20:12:02	1.4
--- money_get_members_char.cc	2002/01/13 04:24:54
*************** void test03()
*** 255,261 ****
    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;
--- 255,261 ----
    bool test = true;
  
    // Check money_get works with other iterators besides streambuf
!   // input iterators.
    typedef string::const_iterator iter_type;
    typedef money_get<char, iter_type> mon_get_type;
    const ios_base::iostate goodbit = ios_base::goodbit;
Index: testsuite/22_locale/money_put_members_char.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/22_locale/money_put_members_char.cc,v
retrieving revision 1.4
diff -c -p -r1.4 money_put_members_char.cc
*** money_put_members_char.cc	2001/09/20 09:07:37	1.4
--- money_put_members_char.cc	2002/01/13 04:24:55
***************
*** 1,6 ****
  // 2001-08-27 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-08-27 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()
*** 161,167 ****
    VERIFY( result11 == "-,01****************");
  }
  
! // test double/string versions
  void test02()
  {
    using namespace std;
--- 161,167 ----
    VERIFY( result11 == "-,01****************");
  }
  
! // test double version
  void test02()
  {
    using namespace std;
*************** void test02()
*** 241,249 ****
--- 241,293 ----
    VERIFY( result4 != result2 );
  }
  
+ void test03()
+ {
+   using namespace std;
+   bool test = true;
+ 
+   // Check money_put works with other iterators besides streambuf
+   // output iterators. (As long as output_iterator requirements are met.)
+   typedef string::iterator iter_type;
+   typedef money_put<char, iter_type> mon_put_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();
+   // woman, art, thief (stole the blues)
+   const string str("1943 Janis Joplin");
+   const long double ld = 1943;
+   const string x(str.size(), 'x'); // have to have allocated string!
+   string res;
+ 
+   ostringstream oss; 
+   oss.imbue(locale(loc_c, new mon_put_type));
+ 
+   // Iterator advanced, state, output.
+   const mon_put_type& mp = use_facet<mon_put_type>(oss.getloc());
+ 
+   // 01 string
+   res = x;
+   iter_type ret1 = mp.put(res.begin(), false, oss, ' ', str);
+   string sanity1(res.begin(), ret1);
+   VERIFY( err == goodbit );
+   VERIFY( res == "1943xxxxxxxxxxxxx" );
+   VERIFY( sanity1 == "1943" );
+ 
+   // 02 long double
+   res = x;
+   iter_type ret2 = mp.put(res.begin(), false, oss, ' ', ld);
+   string sanity2(res.begin(), ret2);
+   VERIFY( err == goodbit );
+   VERIFY( res == "1943xxxxxxxxxxxxx" );
+   VERIFY( sanity2 == "1943" );
+ }
+ 
  int main()
  {
    test01();
    test02();
+   test03();
    return 0;
  }
+ 
Index: testsuite/22_locale/money_put_members_wchar_t.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/22_locale/money_put_members_wchar_t.cc,v
retrieving revision 1.4
diff -c -p -r1.4 money_put_members_wchar_t.cc
*** money_put_members_wchar_t.cc	2001/09/20 09:07:37	1.4
--- money_put_members_wchar_t.cc	2002/01/13 04:24:56
***************
*** 1,6 ****
  // 2001-09-09 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-09 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 test02()
*** 240,245 ****
--- 240,287 ----
    VERIFY( result3 != result1 );
    VERIFY( result4 != result2 );
  }
+ 
+ void test03()
+ {
+   using namespace std;
+   bool test = true;
+ 
+   // Check money_put works with other iterators besides streambuf
+   // output iterators. (As long as output_iterator requirements are met.)
+   typedef wstring::iterator iter_type;
+   typedef money_put<wchar_t, iter_type> mon_put_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();
+   // woman, art, thief (stole the blues)
+   const wstring str(L"1943 Janis Joplin");
+   const long double ld = 1943;
+   const wstring x(str.size(), 'x'); // have to have allocated string!
+   wstring res;
+ 
+   wostringstream oss; 
+   oss.imbue(locale(loc_c, new mon_put_type));
+ 
+   // Iterator advanced, state, output.
+   const mon_put_type& mp = use_facet<mon_put_type>(oss.getloc());
+ 
+   // 01 string
+   res = x;
+   iter_type ret1 = mp.put(res.begin(), false, oss, ' ', str);
+   wstring sanity1(res.begin(), ret1);
+   VERIFY( err == goodbit );
+   VERIFY( res == L"1943xxxxxxxxxxxxx" );
+   VERIFY( sanity1 == L"1943" );
+ 
+   // 02 long double
+   res = x;
+   iter_type ret2 = mp.put(res.begin(), false, oss, ' ', ld);
+   wstring sanity2(res.begin(), ret2);
+   VERIFY( err == goodbit );
+   VERIFY( res == L"1943xxxxxxxxxxxxx" );
+   VERIFY( sanity2 == L"1943" );
+ }
  #endif
  
  int main()
*************** int main()
*** 247,252 ****
--- 289,295 ----
  #ifdef _GLIBCPP_USE_WCHAR_T
    test01();
    test02();
+   test03();
  #endif
    return 0;
  }


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