This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[PATCH] Fix collate_members_char[wchar_t].cc
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: libstdc++ at gcc dot gnu dot org
- Cc: bkoz at redhat dot com, ncm at cantrip dot org
- Date: Wed, 13 Mar 2002 22:24:31 +0100
- Subject: [PATCH] Fix collate_members_char[wchar_t].cc
Hi,
I think most probably I know what is wrong with collate_members_wchar_t.cc (if
I'm right the char version passes only by chance and must be fixed in the same
way).
Currently we are carrying out this kind of comparison:
wstring str3 = coll_de.transform(strlit3, strlit3 + size3);
wstring str4 = coll_de.transform(strlit4, strlit4 + size4);
i1 = coll_de.compare(str3.c_str(), str3.c_str() + size3,
str4.c_str(), str4.c_str() + size4);
i2 = coll_de.compare(strlit3, strlit3 + size3, strlit4, strlit4 + size4);
VERIFY(i1 == i2);
Therefore, schematically, we compare the effect of:
collate::transform -> collate::compare
with that of:
collate::compare
IMHO, those are not at all guaranteed to give the same results, for the very
simple reason that collate::tranform exist in order to compare strings using the
usual string::compare /not/ with collate::compare!
Otherwise, what collate::transform is for?
Therefore, I propose to change those tests to:
collate::transform -> string::compare
and
collate::compare
We must only be a little careful that the output of string::compare is not
normalized, as is that of collate::compare.
Thus the following patch, tested i686-pc-linux-gnu. 1 unexpected, 0 expected
(yo!)
Ok?
Ciao, Paolo.
///////////////////
2002-03-13 Paolo Carlini <pcarlini@unitus.it>
* testsuite/22_locale/collate_members_wchar_t.cc
(test01): compare the result of collate::compare with
that of collate::transform + string::compare, not with
that of collate::transform + collate::compare.
* testsuite/22_locale/collate_members_char.cc: Ditto.
diff -urN libstdc++-v3-orig/testsuite/22_locale/collate_members_char.cc
libstdc++-v3/testsuite/22_locale/collate_members_char.cc
--- libstdc++-v3-orig/testsuite/22_locale/collate_members_char.cc Mon Feb 11
19:56:24 2002
+++ libstdc++-v3/testsuite/22_locale/collate_members_char.cc Wed Mar 13 21:51:36
2002
@@ -86,10 +86,10 @@
string str1 = coll_c.transform(strlit1, strlit1 + size1);
string str2 = coll_c.transform(strlit2, strlit2 + size2);
- i1 = coll_c.compare(str1.c_str(), str1.c_str() + size1,
- str2.c_str(), str2.c_str() + size2);
+ i1 = str1.compare(str2);
i2 = coll_c.compare(strlit1, strlit1 + size1, strlit2, strlit2 + size2);
- VERIFY(i1 == i2);
+ VERIFY(i2 == 1)
+ VERIFY(i1 * i2 > 0);
// Check German "de_DE" locale.
const char* strlit3 = "Äuglein Augment"; // "C" == "Augment Äuglein"
@@ -123,10 +123,10 @@
string str3 = coll_de.transform(strlit3, strlit3 + size3);
string str4 = coll_de.transform(strlit4, strlit4 + size4);
- i1 = coll_de.compare(str3.c_str(), str3.c_str() + size3,
- str4.c_str(), str4.c_str() + size4);
+ i1 = str3.compare(str4);
i2 = coll_de.compare(strlit3, strlit3 + size3, strlit4, strlit4 + size4);
- VERIFY(i1 == i2);
+ VERIFY(i2 == -1);
+ VERIFY(i1 * i2 > 0);
}
// libstdc++/5280
diff -urN libstdc++-v3-orig/testsuite/22_locale/collate_members_wchar_t.cc
libstdc++-v3/testsuite/22_locale/collate_members_wchar_t.cc
--- libstdc++-v3-orig/testsuite/22_locale/collate_members_wchar_t.cc Mon Feb 11
19:56:24 2002
+++ libstdc++-v3/testsuite/22_locale/collate_members_wchar_t.cc Wed Mar 13
21:57:47 2002
@@ -86,10 +86,10 @@
wstring str1 = coll_c.transform(strlit1, strlit1 + size1);
wstring str2 = coll_c.transform(strlit2, strlit2 + size2);
- i1 = coll_c.compare(str1.c_str(), str1.c_str() + size1,
- str2.c_str(), str2.c_str() + size2);
+ i1 = str1.compare(str2);
i2 = coll_c.compare(strlit1, strlit1 + size1, strlit2, strlit2 + size2);
- VERIFY(i1 == i2);
+ VERIFY(i2 == 1);
+ VERIFY(i1 * i2 > 0);
// Check German "de_DE" locale.
const wchar_t* strlit3 = L"Äuglein Augment"; // "C" == "Augment Äuglein"
@@ -123,10 +123,10 @@
wstring str3 = coll_de.transform(strlit3, strlit3 + size3);
wstring str4 = coll_de.transform(strlit4, strlit4 + size4);
- i1 = coll_de.compare(str3.c_str(), str3.c_str() + size3,
- str4.c_str(), str4.c_str() + size4);
+ i1 = str3.compare(str4);
i2 = coll_de.compare(strlit3, strlit3 + size3, strlit4, strlit4 + size4);
- VERIFY(i1 == i2);
+ VERIFY(i2 == -1);
+ VERIFY(i1 * i2 > 0);
}
// libstdc++/5280