From a434b3c5fbaeefe3fcb4dc9cce19421ac4879f0a Mon Sep 17 00:00:00 2001 From: Hiroshi Inoue Date: Sat, 22 Jul 2017 12:06:00 +0900 Subject: [PATCH] Modify wchar-char test so that it handles parameters which are not properly null-terminated. --- test/expected/wchar-char_2.out | 7 ++++++- test/src/wchar-char-test-eucjp.c | 18 +++++++++++++----- test/src/wchar-char-test-sjis.c | 22 +++++++++++++++------- test/src/wchar-char-test-utf8.c | 18 +++++++++++++----- test/src/wchar-char-test.c | 7 ++++++- 5 files changed, 53 insertions(+), 19 deletions(-) diff --git a/test/expected/wchar-char_2.out b/test/expected/wchar-char_2.out index 5917145..a4b50ca 100755 --- a/test/expected/wchar-char_2.out +++ b/test/expected/wchar-char_2.out @@ -1 +1,6 @@ -Unfortunately can't handle this locale +Unfortunately this program can't handle this locale +Or you are testing an ansi driver +Anyway bypass this program +abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz +abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz +abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz diff --git a/test/src/wchar-char-test-eucjp.c b/test/src/wchar-char-test-eucjp.c index 17c9bbf..38c974c 100644 --- a/test/src/wchar-char-test-eucjp.c +++ b/test/src/wchar-char-test-eucjp.c @@ -4,7 +4,9 @@ static int eucjp_test(HSTMT hstmt) int rc; SQLLEN ind, cbParam, cbParam2; + SQLINTEGER cbQueryLen; unsigned char lovedt[100] = {0x95, 0x4e, 0x0a, 0x4e, 0x5a, 0x53, 0xf2, 0x53, 0x0, 0x0}; + unsigned char lovedt2[100] = {0xf2, 0x53, 0x5a, 0x53, 0x0a, 0x4e, 0x95, 0x4e, 0x0, 0x0}; SQLWCHAR wchar[100]; SQLCHAR str[100]; SQLCHAR chardt[100]; @@ -13,7 +15,9 @@ static int eucjp_test(HSTMT hstmt) rc = SQLBindCol(hstmt, 1, SQL_C_CHAR, (SQLPOINTER) chardt, sizeof(chardt), &ind); CHECK_STMT_RESULT(rc, "SQLBindCol to SQL_C_CHAR failed", hstmt); - cbParam = SQL_NTS; + // cbParam = SQL_NTS; + cbParam = strlen(lovedt); + strcat(lovedt, lovedt2); rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_WCHAR, /* value type */ SQL_WCHAR, /* param type */ @@ -23,11 +27,15 @@ static int eucjp_test(HSTMT hstmt) sizeof(lovedt), /* buffer len */ &cbParam /* StrLen_or_IndPtr */); CHECK_STMT_RESULT(rc, "SQLBindParameter 1 failed", hstmt); - cbParam2 = SQL_NTS; + // cbParam2 = SQL_NTS; + strncpy((char *) str, "ÀÆÆ£¹À", sizeof(str)); + cbParam2 = strlen(str); + strcat((char *) str, "¿®¸¼"); rc = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(str), 0, str, sizeof(str), &cbParam2); CHECK_STMT_RESULT(rc, "SQLBindParameter 2 failed", hstmt); - strncpy((char *) str, "ÀÆÆ£¹À", sizeof(str)); - rc = SQLExecDirect(hstmt, query, SQL_NTS); + cbQueryLen = (SQLINTEGER) strlen(query); + strcat((char *) query, "¿®¸¼"); + rc = SQLExecDirect(hstmt, query, cbQueryLen); CHECK_STMT_RESULT(rc, "SQLExecDirect failed to return SQL_C_CHAR", hstmt); while (SQL_SUCCEEDED(SQLFetch(hstmt))) printf("ANSI=%s\n", chardt); @@ -38,7 +46,7 @@ static int eucjp_test(HSTMT hstmt) CHECK_STMT_RESULT(rc, "SQLBindCol to SQL_C_WCHAR failed", hstmt); - rc = SQLExecDirect(hstmt, query, SQL_NTS); + rc = SQLExecDirect(hstmt, query, cbQueryLen); CHECK_STMT_RESULT(rc, "SQLExecDirect failed to return SQL_C_WCHAR", hstmt); while (SQL_SUCCEEDED(rc = SQLFetch(hstmt))) { diff --git a/test/src/wchar-char-test-sjis.c b/test/src/wchar-char-test-sjis.c index 0078aed..34ea0d7 100644 --- a/test/src/wchar-char-test-sjis.c +++ b/test/src/wchar-char-test-sjis.c @@ -4,16 +4,20 @@ static int sjis_test(HSTMT hstmt) int rc; SQLLEN ind, cbParam, cbParam2; + SQLINTEGER cbQueryLen; unsigned char lovedt[100] = {0x95, 0x4e, 0x0a, 0x4e, 0x5a, 0x53, 0xf2, 0x53, 0x0, 0x0}; + unsigned char lovedt2[100] = {0xf2, 0x53, 0x5a, 0x53, 0x0a, 0x4e, 0x95, 0x4e, 0x0, 0x0}; SQLWCHAR wchar[100]; SQLCHAR str[100]; SQLCHAR chardt[100]; - SQLTCHAR query[] = _T("select 'Ž„‚Í' || ?::text || '‚Å‚·B‹M•û‚Í' || ?::text || '‚³‚ñ‚Å‚·‚ˁH'"); + SQLTCHAR query[200] = _T("select 'Ž„‚Í' || ?::text || '‚Å‚·B‹M•û‚Í' || ?::text || '‚³‚ñ‚Å‚·‚ˁH'"); rc = SQLBindCol(hstmt, 1, SQL_C_CHAR, (SQLPOINTER) chardt, sizeof(chardt), &ind); CHECK_STMT_RESULT(rc, "SQLBindCol to SQL_C_CHAR failed", hstmt); - cbParam = SQL_NTS; + // cbParam = SQL_NTS; + cbParam = strlen(lovedt); + strcat(lovedt, lovedt2); rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_WCHAR, /* value type */ SQL_WCHAR, /* param type */ @@ -22,12 +26,16 @@ static int sjis_test(HSTMT hstmt) lovedt, // param1, /* param value ptr */ sizeof(lovedt), /* buffer len */ &cbParam /* StrLen_or_IndPtr */); - CHECK_STMT_RESULT(rc, "SQLBindParameter 1 failed", hstmt); - cbParam2 = SQL_NTS; + CHECK_STMT_RESULT(rc, "SQLBindParameter 1 failed", hstmt); + // cbParam2 = SQL_NTS; + strncpy((char *) str, "Ä“¡_", sizeof(str)); + cbParam2 = strlen(str); + strcat((char *) str, "M’·"); rc = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(str), 0, str, sizeof(str), &cbParam2); CHECK_STMT_RESULT(rc, "SQLBindParameter 2 failed", hstmt); - strncpy((char *) str, "Ä“¡_", sizeof(str)); - rc = SQLExecDirect(hstmt, query, SQL_NTS); + cbQueryLen = (SQLINTEGER) strlen(query); + strcat((char *) query, "‚¾‚æ[‚ñ"); + rc = SQLExecDirect(hstmt, query, cbQueryLen); CHECK_STMT_RESULT(rc, "SQLExecDirect failed to return SQL_C_CHAR", hstmt); while (SQL_SUCCEEDED(SQLFetch(hstmt))) printf("ANSI=%s\n", chardt); @@ -38,7 +46,7 @@ static int sjis_test(HSTMT hstmt) CHECK_STMT_RESULT(rc, "SQLBindCol to SQL_C_WCHAR failed", hstmt); - rc = SQLExecDirect(hstmt, query, SQL_NTS); + rc = SQLExecDirect(hstmt, query, cbQueryLen); CHECK_STMT_RESULT(rc, "SQLExecDirect failed to return SQL_C_WCHAR", hstmt); while (SQL_SUCCEEDED(rc = SQLFetch(hstmt))) { diff --git a/test/src/wchar-char-test-utf8.c b/test/src/wchar-char-test-utf8.c index 88c531f..de6af04 100644 --- a/test/src/wchar-char-test-utf8.c +++ b/test/src/wchar-char-test-utf8.c @@ -4,7 +4,9 @@ static int utf8_test_one(HSTMT hstmt) int rc; SQLLEN ind, cbParam, cbParam2; + SQLINTEGER cbQueryLen; unsigned char lovedt[100] = {0x95, 0x4e, 0x0a, 0x4e, 0x5a, 0x53, 0xf2, 0x53, 0x0, 0x0}; + unsigned char lovedt2[100] = {0xf2, 0x53, 0x5a, 0x53, 0x0a, 0x4e, 0x95, 0x4e, 0x0, 0x0}; SQLWCHAR wchar[100]; SQLCHAR str[100]; SQLCHAR chardt[100]; @@ -14,7 +16,9 @@ static int utf8_test_one(HSTMT hstmt) rc = SQLBindCol(hstmt, 1, SQL_C_CHAR, (SQLPOINTER) chardt, sizeof(chardt), &ind); CHECK_STMT_RESULT(rc, "SQLBindCol to SQL_C_CHAR failed", hstmt); - cbParam = SQL_NTS; + // cbParam = SQL_NTS; + cbParam = strlen(lovedt); + strcat(lovedt, lovedt2); rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_WCHAR, /* value type */ SQL_WCHAR, /* param type */ @@ -24,11 +28,15 @@ static int utf8_test_one(HSTMT hstmt) sizeof(lovedt), /* buffer len */ &cbParam /* StrLen_or_IndPtr */); CHECK_STMT_RESULT(rc, "SQLBindParameter 1 failed", hstmt); - cbParam2 = SQL_NTS; + // cbParam2 = SQL_NTS; + strncpy((char *) str, "斉藤浩", sizeof(str)); + cbParam2 = strlen(str); + strcat((char *) str, "斉藤浩"); rc = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(str), 0, str, sizeof(str), &cbParam2); CHECK_STMT_RESULT(rc, "SQLBindParameter 2 failed", hstmt); - strncpy((char *) str, "斉藤浩", sizeof(str)); - rc = SQLExecDirect(hstmt, query, SQL_NTS); + cbQueryLen = (SQLINTEGER) strlen(query); + strcat((char *) query, "斉藤浩"); + rc = SQLExecDirect(hstmt, query, cbQueryLen); CHECK_STMT_RESULT(rc, "SQLExecDirect failed to return SQL_C_CHAR", hstmt); while (SQL_SUCCEEDED(SQLFetch(hstmt))) printf("ANSI=%s\n", chardt); @@ -39,7 +47,7 @@ static int utf8_test_one(HSTMT hstmt) CHECK_STMT_RESULT(rc, "SQLBindCol to SQL_C_WCHAR failed", hstmt); - rc = SQLExecDirect(hstmt, query, SQL_NTS); + rc = SQLExecDirect(hstmt, query, cbQueryLen); CHECK_STMT_RESULT(rc, "SQLExecDirect failed to return SQL_C_WCHAR", hstmt); while (SQL_SUCCEEDED(rc = SQLFetch(hstmt))) { diff --git a/test/src/wchar-char-test.c b/test/src/wchar-char-test.c index 32f37b5..9553edf 100644 --- a/test/src/wchar-char-test.c +++ b/test/src/wchar-char-test.c @@ -81,7 +81,12 @@ int main(int argc, char **argv) } if (testsw < 0) { - printf("Unfortunately can't handle this locale\n"); + printf("Unfortunately this program can't handle this locale\n"); + printf("Or you are testing an ansi driver\n"); + printf("Anyway bypass this program\n"); + printf("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n"); + printf("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n"); + printf("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n"); exit(0); } test_connect_ext(""); -- 2.39.5