[v3] Improve some tests

Paolo Carlini pcarlini@unitus.it
Sat Mar 2 13:37:00 GMT 2002


Hi,

the subject says it all: improved coverage, clean up, better consistency. Tested
x86-linux, approved by Benjamin Kosnik, committed to head, shortly to 3_1 too.

Ciao, Paolo.

//////////////

2002-03-02  Paolo Carlini  <pcarlini@unitus.it>

        * testsuite/22_locale/num_get_members_char.cc (test04):
        Use a named locale expecting grouping (de_DE).
        * testsuite/22_locale/num_get_members_wchar_t.cc (test04): Ditto.
        * testsuite/27_io/ios_manip_basefield.cc (test01):
        Extend coverage, uniform treatment of hexs and octs.

===================================================================
RCS file:
/cvs/gcc/gcc/libstdc++-v3/testsuite/22_locale/num_get_members_char.cc,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- gcc/libstdc++-v3/testsuite/22_locale/num_get_members_char.cc
2002/02/28 21:16:45     1.8
+++ gcc/libstdc++-v3/testsuite/22_locale/num_get_members_char.cc
2002/03/02 21:32:55     1.9
@@ -332,15 +332,6 @@
 #endif
 }

-struct MyNP : std::numpunct<char>
-{
-  std::string do_grouping() const;
-  char   do_thousands_sep() const;
-};
-
-std::string MyNP::do_grouping() const { std::string s("\3"); return s; }
-char   MyNP::do_thousands_sep() const { return ' '; }
-
 // Testing the correct parsing of grouped hexadecimals and octals.
 void test04()
 {
@@ -351,49 +342,52 @@
   unsigned long ul;

   istringstream iss;
-  iss.imbue(locale(locale(), new MyNP));
+
+  // A locale that expects grouping
+  locale loc_de("de_DE");
+  iss.imbue(loc_de);

   const num_get<char>& ng = use_facet<num_get<char> >(iss.getloc());
   const ios_base::iostate goodbit = ios_base::goodbit;
   ios_base::iostate err = ios_base::goodbit;

   iss.setf(ios::hex, ios::basefield);
-  iss.str("0xbf fff 74c.");
+  iss.str("0xbf.fff.74c ");
   err = goodbit;
   ng.get(iss.rdbuf(), 0, iss, err, ul);
   VERIFY( err == goodbit );
   VERIFY( ul == 0xbffff74c );

-  iss.str("0Xf fff.");
+  iss.str("0Xf.fff ");
   err = goodbit;
   ng.get(iss.rdbuf(), 0, iss, err, ul);
   VERIFY( err == goodbit );
   VERIFY( ul == 0xffff );

-  iss.str("f ffe.");
+  iss.str("ffe ");
   err = goodbit;
   ng.get(iss.rdbuf(), 0, iss, err, ul);
   VERIFY( err == goodbit );
-  VERIFY( ul == 0xfffe );
+  VERIFY( ul == 0xffe );

   iss.setf(ios::oct, ios::basefield);
-  iss.str("07 654 321.");
+  iss.str("07.654.321 ");
   err = goodbit;
   ng.get(iss.rdbuf(), 0, iss, err, ul);
   VERIFY( err == goodbit );
   VERIFY( ul == 07654321 );

-  iss.str("07 777.");
+  iss.str("07.777 ");
   err = goodbit;
   ng.get(iss.rdbuf(), 0, iss, err, ul);
   VERIFY( err == goodbit );
   VERIFY( ul == 07777 );

-  iss.str("7 776.");
+  iss.str("776 ");
   err = goodbit;
   ng.get(iss.rdbuf(), 0, iss, err, ul);
   VERIFY( err == goodbit );
-  VERIFY( ul == 07776 );
+  VERIFY( ul == 0776 );
 }

 int main()

===================================================================
RCS file:
/cvs/gcc/gcc/libstdc++-v3/testsuite/22_locale/num_get_members_wchar_t.cc,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- gcc/libstdc++-v3/testsuite/22_locale/num_get_members_wchar_t.cc
2002/02/28 21:16:45     1.6
+++ gcc/libstdc++-v3/testsuite/22_locale/num_get_members_wchar_t.cc
2002/03/02 21:32:55     1.7
@@ -334,15 +334,6 @@
 #endif
 }

-struct MyNP : std::numpunct<wchar_t>
-{
-  std::string do_grouping() const;
-  wchar_t   do_thousands_sep() const;
-};
-
-std::string MyNP::do_grouping() const { std::string s("\3"); return s; }
-wchar_t   MyNP::do_thousands_sep() const { return L' '; }
-
 // Testing the correct parsing of grouped hexadecimals and octals.
 void test04()
 {
@@ -353,49 +344,52 @@
   unsigned long ul;

   wistringstream iss;
-  iss.imbue(locale(locale(), new MyNP));
+
+  // A locale that expects grouping
+  locale loc_de("de_DE");
+  iss.imbue(loc_de);

   const num_get<wchar_t>& ng = use_facet<num_get<wchar_t> >(iss.getloc());
   const ios_base::iostate goodbit = ios_base::goodbit;
   ios_base::iostate err = ios_base::goodbit;

   iss.setf(ios::hex, ios::basefield);
-  iss.str(L"0xbf fff 74c.");
+  iss.str(L"0xbf.fff.74c ");
   err = goodbit;
   ng.get(iss.rdbuf(), 0, iss, err, ul);
   VERIFY( err == goodbit );
   VERIFY( ul == 0xbffff74c );

-  iss.str(L"0Xf fff.");
+  iss.str(L"0Xf.fff ");
   err = goodbit;
   ng.get(iss.rdbuf(), 0, iss, err, ul);
   VERIFY( err == goodbit );
   VERIFY( ul == 0xffff );

-  iss.str(L"f ffe.");
+  iss.str(L"ffe ");
   err = goodbit;
   ng.get(iss.rdbuf(), 0, iss, err, ul);
   VERIFY( err == goodbit );
-  VERIFY( ul == 0xfffe );
+  VERIFY( ul == 0xffe );

   iss.setf(ios::oct, ios::basefield);
-  iss.str(L"07 654 321.");
+  iss.str(L"07.654.321 ");
   err = goodbit;
   ng.get(iss.rdbuf(), 0, iss, err, ul);
   VERIFY( err == goodbit );
   VERIFY( ul == 07654321 );

-  iss.str(L"07 777.");
+  iss.str(L"07.777 ");
   err = goodbit;
   ng.get(iss.rdbuf(), 0, iss, err, ul);
   VERIFY( err == goodbit );
   VERIFY( ul == 07777 );

-  iss.str(L"7 776.");
+  iss.str(L"776 ");
   err = goodbit;
   ng.get(iss.rdbuf(), 0, iss, err, ul);
   VERIFY( err == goodbit );
-  VERIFY( ul == 07776 );
+  VERIFY( ul == 0776 );
 }
 #endif

===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/ios_manip_basefield.cc,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- gcc/libstdc++-v3/testsuite/27_io/ios_manip_basefield.cc     2002/02/28
21:16:43     1.9
+++ gcc/libstdc++-v3/testsuite/27_io/ios_manip_basefield.cc     2002/03/02
21:32:56     1.10
@@ -47,12 +47,15 @@
   bool test = true;

   const char lit[] = "0123 456\n: 01 234 567:\n:0123 456   :\n"
-                     ":    012 345:\n:     01 234:\n: 04 553 207:\n"
-                     ":0361 100   :\n:    030 071:\n:     02 322:\n"
-                     "0x000012 345 678\n";
+                     ":    012 345:\n:     01 234:\n:0726 746 425:\n"
+                     ":04 553 207 :\n:   0361 100:\n:       0173:\n"
+                     "0x12 345 678\n|0x000012 345 678|\n|0x12 345 6780000|\n"
+                     "|00000x12 345 678|\n|0x000012 345 678|\n";

   std::ostringstream oss;
   oss.imbue(std::locale(std::locale(), new MyNP));
+
+  // Octals
   oss << std::oct << std::showbase;
   oss << 0123456l << std::endl;

@@ -69,24 +72,33 @@
   oss << 01234l << ":" << std::endl;

   oss << ":" << std::setw(11);
-  oss << 1234567l << ":" << std::endl;
+  oss << 123456789l << ":" << std::endl;

   oss << ":" << std::setw(11) << std::left;
-  oss << 123456l << ":" << std::endl;
+  oss << 1234567l << ":" << std::endl;

   oss << ":" << std::setw(11) << std::right;
-  oss << 12345l << ":" << std::endl;
+  oss << 123456l << ":" << std::endl;

   oss << ":" << std::setw(11) << std::internal;
-  oss << 1234l << ":" << std::endl;
+  oss << 123l << ":" << std::endl;

-  oss << std::hex;
-  oss << std::setfill('0');
-  oss << std::internal;
-  oss << std::showbase;
-  oss << std::setw(16);
+  // Hexadecimals
+  oss << std::hex << std::setfill('0');
   oss << 0x12345678l << std::endl;

+  oss << "|" << std::setw(16);
+  oss << 0x12345678l << "|" << std::endl;
+
+  oss << "|" << std::setw(16) << std::left;
+  oss << 0x12345678l << "|" << std::endl;
+
+  oss << "|" << std::setw(16) << std::right;
+  oss << 0x12345678l << "|" << std::endl;
+
+  oss << "|" << std::setw(16) << std::internal;
+  oss << 0x12345678l << "|" << std::endl;
+
   VERIFY( oss.good() );
   VERIFY( oss.str() == lit );

@@ -133,9 +145,13 @@
 :0123 456   :
 :    012 345:
 :     01 234:
-: 04 553 207:
-:0361 100   :
-:    030 071:
-:     02 322:
-0x000012 345 678
+:0726 746 425:
+:04 553 207 :
+:   0361 100:
+:       0173:
+0x12 345 678
+|0x000012 345 678|
+|0x12 345 6780000|
+|00000x12 345 678|
+|0x000012 345 678|
 */




More information about the Gcc-patches mailing list