⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 string.c

📁 Wine-20031016
💻 C
📖 第 1 页 / 共 4 页
字号:
/* Unit test suite for string functions and some wcstring functions * * Copyright 2003 Thomas Mertes * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * * NOTES * We use function pointers here as there is no import library for NTDLL on * windows. */#include <stdarg.h>#include <stdlib.h>#include "ntstatus.h"#include "windef.h"#include "winbase.h"#include "wine/test.h"#include "winnt.h"#include "winnls.h"#include "winreg.h"#include "winternl.h"/* Function ptrs for ntdll calls */static HMODULE hntdll = 0;static NTSTATUS (WINAPI *pRtlUnicodeStringToAnsiString)(STRING *, const UNICODE_STRING *, BOOLEAN);static VOID     (WINAPI *pRtlFreeAnsiString)(PSTRING);static BOOLEAN  (WINAPI *pRtlCreateUnicodeStringFromAsciiz)(PUNICODE_STRING,LPCSTR);static VOID     (WINAPI *pRtlFreeUnicodeString)(PUNICODE_STRING);static int      (WINAPIV *patoi)(const char *);static long     (WINAPIV *patol)(const char *);static LONGLONG (WINAPIV *p_atoi64)(const char *);static LPSTR    (WINAPIV *p_itoa)(int, LPSTR, INT);static LPSTR    (WINAPIV *p_ltoa)(long, LPSTR, INT);static LPSTR    (WINAPIV *p_ultoa)(unsigned long, LPSTR, INT);static LPSTR    (WINAPIV *p_i64toa)(LONGLONG, LPSTR, INT);static LPSTR    (WINAPIV *p_ui64toa)(ULONGLONG, LPSTR, INT);static int      (WINAPIV *p_wtoi)(LPWSTR);static long     (WINAPIV *p_wtol)(LPWSTR);static LONGLONG (WINAPIV *p_wtoi64)(LPWSTR);static LPWSTR   (WINAPIV *p_itow)(int, LPWSTR, int);static LPWSTR   (WINAPIV *p_ltow)(long, LPWSTR, INT);static LPWSTR   (WINAPIV *p_ultow)(unsigned long, LPWSTR, INT);static LPWSTR   (WINAPIV *p_i64tow)(LONGLONG, LPWSTR, INT);static LPWSTR   (WINAPIV *p_ui64tow)(ULONGLONG, LPWSTR, INT);static long     (WINAPIV *pwcstol)(LPCWSTR, LPWSTR *, INT);static ULONG    (WINAPIV *pwcstoul)(LPCWSTR, LPWSTR *, INT);static void InitFunctionPtrs(){    hntdll = LoadLibraryA("ntdll.dll");    ok(hntdll != 0, "LoadLibrary failed");    if (hntdll) {	pRtlUnicodeStringToAnsiString = (void *)GetProcAddress(hntdll, "RtlUnicodeStringToAnsiString");	pRtlFreeAnsiString = (void *)GetProcAddress(hntdll, "RtlFreeAnsiString");	pRtlCreateUnicodeStringFromAsciiz = (void *)GetProcAddress(hntdll, "RtlCreateUnicodeStringFromAsciiz");	pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");	patoi = (void *)GetProcAddress(hntdll, "atoi");	patol = (void *)GetProcAddress(hntdll, "atol");	p_atoi64 = (void *)GetProcAddress(hntdll, "_atoi64");	p_itoa = (void *)GetProcAddress(hntdll, "_itoa");	p_ltoa = (void *)GetProcAddress(hntdll, "_ltoa");	p_ultoa = (void *)GetProcAddress(hntdll, "_ultoa");	p_i64toa = (void *)GetProcAddress(hntdll, "_i64toa");	p_ui64toa = (void *)GetProcAddress(hntdll, "_ui64toa");	p_wtoi = (void *)GetProcAddress(hntdll, "_wtoi");	p_wtol = (void *)GetProcAddress(hntdll, "_wtol");	p_wtoi64 = (void *)GetProcAddress(hntdll, "_wtoi64");	p_itow = (void *)GetProcAddress(hntdll, "_itow");	p_ltow = (void *)GetProcAddress(hntdll, "_ltow");	p_ultow = (void *)GetProcAddress(hntdll, "_ultow");	p_i64tow = (void *)GetProcAddress(hntdll, "_i64tow");	p_ui64tow = (void *)GetProcAddress(hntdll, "_ui64tow");	pwcstol = (void *)GetProcAddress(hntdll, "wcstol");	pwcstoul = (void *)GetProcAddress(hntdll, "wcstoul");    } /* if */}#define LARGE_STRI_BUFFER_LENGTH 67typedef struct {    int base;    ULONG value;    const char *Buffer;    int mask; /* ntdll/msvcrt: 0x01=itoa, 0x02=ltoa, 0x04=ultoa */              /*               0x10=itow, 0x20=ltow, 0x40=ultow */} ulong2str_t;static const ulong2str_t ulong2str[] = {    {10,         123, "123\0---------------------------------------------------------------", 0x77},    { 2, 0x80000000U, "10000000000000000000000000000000\0----------------------------------", 0x67},    { 2, -2147483647, "10000000000000000000000000000001\0----------------------------------", 0x67},    { 2,      -65537, "11111111111111101111111111111111\0----------------------------------", 0x67},    { 2,      -65536, "11111111111111110000000000000000\0----------------------------------", 0x67},    { 2,      -65535, "11111111111111110000000000000001\0----------------------------------", 0x67},    { 2,      -32768, "11111111111111111000000000000000\0----------------------------------", 0x67},    { 2,      -32767, "11111111111111111000000000000001\0----------------------------------", 0x67},    { 2,          -2, "11111111111111111111111111111110\0----------------------------------", 0x67},    { 2,          -1, "11111111111111111111111111111111\0----------------------------------", 0x67},    { 2,           0, "0\0-----------------------------------------------------------------", 0x77},    { 2,           1, "1\0-----------------------------------------------------------------", 0x77},    { 2,          10, "1010\0--------------------------------------------------------------", 0x77},    { 2,         100, "1100100\0-----------------------------------------------------------", 0x77},    { 2,        1000, "1111101000\0--------------------------------------------------------", 0x77},    { 2,       10000, "10011100010000\0----------------------------------------------------", 0x77},    { 2,       32767, "111111111111111\0---------------------------------------------------", 0x77},    { 2,       32768, "1000000000000000\0--------------------------------------------------", 0x77},    { 2,       65535, "1111111111111111\0--------------------------------------------------", 0x77},    { 2,      100000, "11000011010100000\0-------------------------------------------------", 0x77},    { 2,      234567, "111001010001000111\0------------------------------------------------", 0x77},    { 2,      300000, "1001001001111100000\0-----------------------------------------------", 0x77},    { 2,      524287, "1111111111111111111\0-----------------------------------------------", 0x77},    { 2,      524288, "10000000000000000000\0----------------------------------------------", 0x67},    { 2,     1000000, "11110100001001000000\0----------------------------------------------", 0x67},    { 2,    10000000, "100110001001011010000000\0------------------------------------------", 0x67},    { 2,   100000000, "101111101011110000100000000\0---------------------------------------", 0x67},    { 2,  1000000000, "111011100110101100101000000000\0------------------------------------", 0x67},    { 2,  1073741823, "111111111111111111111111111111\0------------------------------------", 0x67},    { 2,  2147483646, "1111111111111111111111111111110\0-----------------------------------", 0x67},    { 2,  2147483647, "1111111111111111111111111111111\0-----------------------------------", 0x67},    { 2, 2147483648U, "10000000000000000000000000000000\0----------------------------------", 0x67},    { 2, 2147483649U, "10000000000000000000000000000001\0----------------------------------", 0x67},    { 2, 4294967294U, "11111111111111111111111111111110\0----------------------------------", 0x67},    { 2,  0xFFFFFFFF, "11111111111111111111111111111111\0----------------------------------", 0x67},    { 8, 0x80000000U, "20000000000\0-------------------------------------------------------", 0x77},    { 8, -2147483647, "20000000001\0-------------------------------------------------------", 0x77},    { 8,          -2, "37777777776\0-------------------------------------------------------", 0x77},    { 8,          -1, "37777777777\0-------------------------------------------------------", 0x77},    { 8,           0, "0\0-----------------------------------------------------------------", 0x77},    { 8,           1, "1\0-----------------------------------------------------------------", 0x77},    { 8,  2147483646, "17777777776\0-------------------------------------------------------", 0x77},    { 8,  2147483647, "17777777777\0-------------------------------------------------------", 0x77},    { 8, 2147483648U, "20000000000\0-------------------------------------------------------", 0x77},    { 8, 2147483649U, "20000000001\0-------------------------------------------------------", 0x77},    { 8, 4294967294U, "37777777776\0-------------------------------------------------------", 0x77},    { 8, 4294967295U, "37777777777\0-------------------------------------------------------", 0x77},    {10, 0x80000000U, "-2147483648\0-------------------------------------------------------", 0x33},    {10, 0x80000000U, "2147483648\0--------------------------------------------------------", 0x44},    {10, -2147483647, "-2147483647\0-------------------------------------------------------", 0x33},    {10, -2147483647, "2147483649\0--------------------------------------------------------", 0x44},    {10,          -2, "-2\0----------------------------------------------------------------", 0x33},    {10,          -2, "4294967294\0--------------------------------------------------------", 0x44},    {10,          -1, "-1\0----------------------------------------------------------------", 0x33},    {10,          -1, "4294967295\0--------------------------------------------------------", 0x44},    {10,           0, "0\0-----------------------------------------------------------------", 0x77},    {10,           1, "1\0-----------------------------------------------------------------", 0x77},    {10,          12, "12\0----------------------------------------------------------------", 0x77},    {10,         123, "123\0---------------------------------------------------------------", 0x77},    {10,        1234, "1234\0--------------------------------------------------------------", 0x77},    {10,       12345, "12345\0-------------------------------------------------------------", 0x77},    {10,      123456, "123456\0------------------------------------------------------------", 0x77},    {10,     1234567, "1234567\0-----------------------------------------------------------", 0x77},    {10,    12345678, "12345678\0----------------------------------------------------------", 0x77},    {10,   123456789, "123456789\0---------------------------------------------------------", 0x77},    {10,  2147483646, "2147483646\0--------------------------------------------------------", 0x77},    {10,  2147483647, "2147483647\0--------------------------------------------------------", 0x77},    {10, 2147483648U, "-2147483648\0-------------------------------------------------------", 0x33},    {10, 2147483648U, "2147483648\0--------------------------------------------------------", 0x44},    {10, 2147483649U, "-2147483647\0-------------------------------------------------------", 0x33},    {10, 2147483649U, "2147483649\0--------------------------------------------------------", 0x44},    {10, 4294967294U, "-2\0----------------------------------------------------------------", 0x33},    {10, 4294967294U, "4294967294\0--------------------------------------------------------", 0x44},    {10, 4294967295U, "-1\0----------------------------------------------------------------", 0x33},    {10, 4294967295U, "4294967295\0--------------------------------------------------------", 0x44},    {16,           0, "0\0-----------------------------------------------------------------", 0x77},    {16,           1, "1\0-----------------------------------------------------------------", 0x77},    {16,  2147483646, "7ffffffe\0----------------------------------------------------------", 0x77},    {16,  2147483647, "7fffffff\0----------------------------------------------------------", 0x77},    {16,  0x80000000, "80000000\0----------------------------------------------------------", 0x77},    {16,  0x80000001, "80000001\0----------------------------------------------------------", 0x77},    {16,  0xFFFFFFFE, "fffffffe\0----------------------------------------------------------", 0x77},    {16,  0xFFFFFFFF, "ffffffff\0----------------------------------------------------------", 0x77},    { 2,       32768, "1000000000000000\0--------------------------------------------------", 0x77},    { 2,       65536, "10000000000000000\0-------------------------------------------------", 0x77},    { 2,      131072, "100000000000000000\0------------------------------------------------", 0x77},    {16,  0xffffffff, "ffffffff\0----------------------------------------------------------", 0x77},    {16,         0xa, "a\0-----------------------------------------------------------------", 0x77},    {16,           0, "0\0-----------------------------------------------------------------", 0x77},    {20,     3368421, "111111\0------------------------------------------------------------", 0x77},    {36,    62193781, "111111\0------------------------------------------------------------", 0x77},    {37,    71270178, "111111\0------------------------------------------------------------", 0x77},};#define NB_ULONG2STR (sizeof(ulong2str)/sizeof(*ulong2str))static void one_itoa_test(int test_num, const ulong2str_t *ulong2str){    char dest_str[LARGE_STRI_BUFFER_LENGTH + 1];    int value;    LPSTR result;    memset(dest_str, '-', LARGE_STRI_BUFFER_LENGTH);    dest_str[LARGE_STRI_BUFFER_LENGTH] = '\0';    value = ulong2str->value;    result = p_itoa(value, dest_str, ulong2str->base);    ok(result == dest_str,       "(test %d): _itoa(%d, [out], %d) has result %p, expected: %p",       test_num, value, ulong2str->base, result, dest_str);    ok(memcmp(dest_str, ulong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,       "(test %d): _itoa(%d, [out], %d) assigns string \"%s\", expected: \"%s\"",       test_num, value, ulong2str->base, dest_str, ulong2str->Buffer);}static void one_ltoa_test(int test_num, const ulong2str_t *ulong2str){    char dest_str[LARGE_STRI_BUFFER_LENGTH + 1];    long value;    LPSTR result;    memset(dest_str, '-', LARGE_STRI_BUFFER_LENGTH);    dest_str[LARGE_STRI_BUFFER_LENGTH] = '\0';    value = ulong2str->value;    result = p_ltoa(ulong2str->value, dest_str, ulong2str->base);    ok(result == dest_str,       "(test %d): _ltoa(%ld, [out], %d) has result %p, expected: %p",       test_num, value, ulong2str->base, result, dest_str);    ok(memcmp(dest_str, ulong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,       "(test %d): _ltoa(%ld, [out], %d) assigns string \"%s\", expected: \"%s\"",       test_num, value, ulong2str->base, dest_str, ulong2str->Buffer);}static void one_ultoa_test(int test_num, const ulong2str_t *ulong2str){    char dest_str[LARGE_STRI_BUFFER_LENGTH + 1];    unsigned long value;    LPSTR result;    memset(dest_str, '-', LARGE_STRI_BUFFER_LENGTH);    dest_str[LARGE_STRI_BUFFER_LENGTH] = '\0';    value = ulong2str->value;    result = p_ultoa(ulong2str->value, dest_str, ulong2str->base);    ok(result == dest_str,       "(test %d): _ultoa(%lu, [out], %d) has result %p, expected: %p",       test_num, value, ulong2str->base, result, dest_str);    ok(memcmp(dest_str, ulong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0,       "(test %d): _ultoa(%lu, [out], %d) assigns string \"%s\", expected: \"%s\"",       test_num, value, ulong2str->base, dest_str, ulong2str->Buffer);}static void test_ulongtoa(void){    int test_num;    for (test_num = 0; test_num < NB_ULONG2STR; test_num++) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -