Daniel Lehman : msvcp90: Return last index in string:: find_last_not_of_cstr_substr if input is empty.
Alexandre Julliard
julliard at winehq.org
Thu Nov 14 13:57:10 CST 2013
Module: wine
Branch: master
Commit: 90cb553e5eaec08187e325a5eb7ec8f3c393ac5b
URL: http://source.winehq.org/git/wine.git/?a=commit;h=90cb553e5eaec08187e325a5eb7ec8f3c393ac5b
Author: Daniel Lehman <dlehman at esri.com>
Date: Wed Sep 12 16:13:47 2012 -0700
msvcp90: Return last index in string::find_last_not_of_cstr_substr if input is empty.
---
dlls/msvcp90/string.c | 4 +-
dlls/msvcp90/tests/string.c | 59 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+), 2 deletions(-)
diff --git a/dlls/msvcp90/string.c b/dlls/msvcp90/string.c
index 23322fe..f412ddb 100644
--- a/dlls/msvcp90/string.c
+++ b/dlls/msvcp90/string.c
@@ -1837,7 +1837,7 @@ MSVCP_size_t __thiscall MSVCP_basic_string_char_find_last_not_of_cstr_substr(
TRACE("%p %p %lu %lu\n", this, find, off, len);
- if(len>0 && this->size>0) {
+ if(this->size>0) {
if(off >= this->size)
off = this->size-1;
@@ -3861,7 +3861,7 @@ MSVCP_size_t __thiscall MSVCP_basic_string_wchar_find_last_not_of_cstr_substr(
TRACE("%p %p %lu %lu\n", this, find, off, len);
- if(len>0 && this->size>0) {
+ if(this->size>0) {
if(off >= this->size)
off = this->size-1;
diff --git a/dlls/msvcp90/tests/string.c b/dlls/msvcp90/tests/string.c
index 511d846..6cc06ce 100644
--- a/dlls/msvcp90/tests/string.c
+++ b/dlls/msvcp90/tests/string.c
@@ -78,6 +78,7 @@ static int (__thiscall *p_basic_string_char_compare_substr_cstr_len)(basic_strin
static size_t (__thiscall *p_basic_string_char_find_cstr_substr)(basic_string_char*, const char*, size_t, size_t);
static size_t (__thiscall *p_basic_string_char_rfind_cstr_substr)(basic_string_char*, const char*, size_t, size_t);
static basic_string_char* (__thiscall *p_basic_string_char_replace_cstr)(basic_string_char*, size_t, size_t, const char*);
+static size_t (__thiscall *p_basic_string_char_find_last_not_of_cstr_substr)(const basic_string_char*, const char*, size_t, size_t);
static size_t *p_basic_string_char_npos;
@@ -229,6 +230,8 @@ static BOOL init(void)
"?rfind@?$basic_string at DU?$char_traits at D@std@@V?$allocator at D@2@@std@@QEBA_KPEBD_K1 at Z");
SET(p_basic_string_char_replace_cstr,
"?replace@?$basic_string at DU?$char_traits at D@std@@V?$allocator at D@2@@std@@QEAAAEAV12 at _K0PEBD@Z");
+ SET(p_basic_string_char_find_last_not_of_cstr_substr,
+ "?find_last_not_of@?$basic_string at DU?$char_traits at D@std@@V?$allocator at D@2@@std@@QEBA_KPEBD_K1 at Z");
SET(p_basic_string_char_npos,
"?npos@?$basic_string at DU?$char_traits at D@std@@V?$allocator at D@2@@std@@2_KB");
@@ -295,6 +298,8 @@ static BOOL init(void)
"?rfind@?$basic_string at DU?$char_traits at D@std@@V?$allocator at D@2@@std@@QBEIPBDII at Z");
SET(p_basic_string_char_replace_cstr,
"?replace@?$basic_string at DU?$char_traits at D@std@@V?$allocator at D@2@@std@@QAEAAV12 at IIPBD@Z");
+ SET(p_basic_string_char_find_last_not_of_cstr_substr,
+ "?find_last_not_of@?$basic_string at DU?$char_traits at D@std@@V?$allocator at D@2@@std@@QBEIPBDII at Z");
SET(p_basic_string_char_npos,
"?npos@?$basic_string at DU?$char_traits at D@std@@V?$allocator at D@2@@std@@2IB");
@@ -708,6 +713,59 @@ static void test_basic_string_wchar_swap(void) {
call_func1(p_basic_string_wchar_dtor, &str2);
}
+static void test_basic_string_char_find_last_not_of(void) {
+ struct find_last_not_of_test {
+ const char *str;
+ const char *find;
+ size_t off;
+ size_t len;
+ size_t ret;
+ };
+
+ int i;
+ size_t ret;
+ basic_string_char str;
+ struct find_last_not_of_test tests[] = {
+ /* simple cases where find is not in string */
+ { "AAAAA", "B", 0, 1, 0 },
+ { "AAAAA", "B", 5, 1, 4 },
+ { "AAAAA", "BCDE", 0, 4, 0 },
+ { "AAAAA", "BCDE", 5, 4, 4 },
+
+ /* simple cases where find is in string */
+ { "AAAAA", "A", 5, 1, -1 },
+ { "AAAAB", "A", 5, 1, 4 },
+ { "AAAAB", "A", 4, 1, 4 },
+ { "AAAAB", "A", 3, 1, -1 },
+ { "ABCDE", "ABCDE", 0, 5, -1 },
+ { "ABCDE", "ABCDE", 5, 5, -1 },
+ { "ABCDE", "AB DE", 5, 5, 2 },
+
+ /* cases where find appears in multiple spots */
+ { "ABABA", "A", 0, 1, -1 },
+ { "ABABA", "A", 1, 1, 1 },
+ { "ABABA", "A", 2, 1, 1 },
+ { "ABABA", "A", 3, 1, 3 },
+
+ /* using empty strings */
+ { "", "", 0, 0, -1 },
+ { "", "A", 0, 1, -1 },
+ { "ABCDE", "", 0, 0, 0 },
+ { "ABCDE", "", 3, 0, 3 },
+ { "ABCDE", "", 5, 0, 4 },
+ };
+
+ for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
+ call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
+
+ ret = (size_t)call_func4(p_basic_string_char_find_last_not_of_cstr_substr,
+ &str, tests[i].find, tests[i].off, tests[i].len);
+ ok(ret == tests[i].ret, "ret = %li tests[%i].ret = %li\n", (long)ret, i, (long)tests[i].ret);
+
+ call_func1(p_basic_string_char_dtor, &str);
+ }
+}
+
START_TEST(string)
{
if(!init())
@@ -723,6 +781,7 @@ START_TEST(string)
test_basic_string_char_replace();
test_basic_string_wchar();
test_basic_string_wchar_swap();
+ test_basic_string_char_find_last_not_of();
ok(!invalid_parameter, "invalid_parameter_handler was invoked too many times\n");
}
More information about the wine-cvs
mailing list