Пример #1
0
static void test_UrlUnescape(void)
{
    CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
    WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
    WCHAR *urlW, *expected_urlW;
    DWORD dwEscaped;
    size_t i;
    static char inplace[] = "file:///C:/Program%20Files";
    static WCHAR inplaceW[] = {'f','i','l','e',':','/','/','/','C',':','/',
                               'P','r','o','g','r','a','m','%','2','0','F','i','l','e','s',0};

    for(i=0; i<sizeof(TEST_URL_UNESCAPE)/sizeof(TEST_URL_UNESCAPE[0]); i++) {
        dwEscaped=INTERNET_MAX_URL_LENGTH;
        ok(UrlUnescapeA(TEST_URL_UNESCAPE[i].url, szReturnUrl, &dwEscaped, 0) == S_OK, "UrlUnescapeA didn't return 0x%08x from \"%s\"\n", S_OK, TEST_URL_UNESCAPE[i].url);
        ok(strcmp(szReturnUrl,TEST_URL_UNESCAPE[i].expect)==0, "Expected \"%s\", but got \"%s\" from \"%s\"\n", TEST_URL_UNESCAPE[i].expect, szReturnUrl, TEST_URL_UNESCAPE[i].url);

        dwEscaped = INTERNET_MAX_URL_LENGTH;
        urlW = GetWideString(TEST_URL_UNESCAPE[i].url);
        expected_urlW = GetWideString(TEST_URL_UNESCAPE[i].expect);
        ok(UrlUnescapeW(urlW, ret_urlW, &dwEscaped, 0) == S_OK, "UrlUnescapeW didn't return 0x%08x from \"%s\"\n", S_OK, TEST_URL_UNESCAPE[i].url);
        WideCharToMultiByte(CP_ACP,0,ret_urlW,-1,szReturnUrl,INTERNET_MAX_URL_LENGTH,0,0);
        ok(lstrcmpW(ret_urlW, expected_urlW)==0, "Expected \"%s\", but got \"%s\" from \"%s\" flags %08lx\n", TEST_URL_UNESCAPE[i].expect, szReturnUrl, TEST_URL_UNESCAPE[i].url, 0L);
        FreeWideString(urlW);
        FreeWideString(expected_urlW);
    }

    dwEscaped = sizeof(inplace);
    ok(UrlUnescapeA(inplace, NULL, &dwEscaped, URL_UNESCAPE_INPLACE) == S_OK, "UrlUnescapeA failed unexpectedly\n");

    dwEscaped = sizeof(inplaceW);
    ok(UrlUnescapeW(inplaceW, NULL, &dwEscaped, URL_UNESCAPE_INPLACE) == S_OK, "UrlUnescapeW failed unexpectedly\n");
}
Пример #2
0
static void test_url_part(const char* szUrl, DWORD dwPart, DWORD dwFlags, const char* szExpected)
{
  CHAR szPart[INTERNET_MAX_URL_LENGTH];
  WCHAR wszPart[INTERNET_MAX_URL_LENGTH];
  LPWSTR wszUrl = GetWideString(szUrl);
  LPWSTR wszConvertedPart;

  DWORD dwSize;

  dwSize = INTERNET_MAX_URL_LENGTH;
  ok( UrlGetPartA(szUrl, szPart, &dwSize, dwPart, dwFlags) == S_OK, "UrlGetPartA for \"%s\" part 0x%08x didn't return S_OK but \"%s\"\n", szUrl, dwPart, szPart);
  dwSize = INTERNET_MAX_URL_LENGTH;
  ok( UrlGetPartW(wszUrl, wszPart, &dwSize, dwPart, dwFlags) == S_OK, "UrlGetPartW didn't return S_OK\n" );

  wszConvertedPart = GetWideString(szPart);

  ok(lstrcmpW(wszPart,wszConvertedPart)==0, "Strings didn't match between ascii and unicode UrlGetPart!\n");

  FreeWideString(wszUrl);
  FreeWideString(wszConvertedPart);

  /* Note that v6.0 and later don't return '?' with the query */
  ok(strcmp(szPart,szExpected)==0 ||
     (*szExpected=='?' && !strcmp(szPart,szExpected+1)),
	 "Expected %s, but got %s\n", szExpected, szPart);
}
Пример #3
0
static void test_UrlCreateFromPath(void)
{
    size_t i;
    char ret_url[INTERNET_MAX_URL_LENGTH];
    DWORD len, ret;
    WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
    WCHAR *pathW, *urlW;

    for(i = 0; i < sizeof(TEST_URLFROMPATH) / sizeof(TEST_URLFROMPATH[0]); i++) {
        len = INTERNET_MAX_URL_LENGTH;
        ret = UrlCreateFromPathA(TEST_URLFROMPATH[i].path, ret_url, &len, 0);
        ok(ret == TEST_URLFROMPATH[i].ret, "ret %08x from path %s\n", ret, TEST_URLFROMPATH[i].path);
        ok(!lstrcmpi(ret_url, TEST_URLFROMPATH[i].url), "url %s from path %s\n", ret_url, TEST_URLFROMPATH[i].path);
        ok(len == strlen(ret_url), "ret len %d from path %s\n", len, TEST_URLFROMPATH[i].path);

        len = INTERNET_MAX_URL_LENGTH;
        pathW = GetWideString(TEST_URLFROMPATH[i].path);
        urlW = GetWideString(TEST_URLFROMPATH[i].url);
        ret = UrlCreateFromPathW(pathW, ret_urlW, &len, 0);
        WideCharToMultiByte(CP_ACP, 0, ret_urlW, -1, ret_url, sizeof(ret_url),0,0);
        ok(ret == TEST_URLFROMPATH[i].ret, "ret %08x from path L\"%s\", expected %08x\n",
           ret, TEST_URLFROMPATH[i].path, TEST_URLFROMPATH[i].ret);
        ok(!lstrcmpiW(ret_urlW, urlW), "got %s expected %s from path L\"%s\"\n", ret_url, TEST_URLFROMPATH[i].url, TEST_URLFROMPATH[i].path);
        ok(len == lstrlenW(ret_urlW), "ret len %d from path L\"%s\"\n", len, TEST_URLFROMPATH[i].path);
        FreeWideString(urlW);
        FreeWideString(pathW);
    }
}
Пример #4
0
static void test_url_canonicalize(int index, const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl, BOOL todo)
{
    CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
    WCHAR wszReturnUrl[INTERNET_MAX_URL_LENGTH];
    LPWSTR wszUrl = GetWideString(szUrl);
    LPWSTR wszExpectUrl = GetWideString(szExpectUrl);
    LPWSTR wszConvertedUrl;

    DWORD dwSize;

    dwSize = INTERNET_MAX_URL_LENGTH;
    ok(UrlCanonicalizeA(szUrl, NULL, &dwSize, dwFlags) != dwExpectReturn, "Unexpected return for NULL buffer, index %d\n", index);
    ok(UrlCanonicalizeA(szUrl, szReturnUrl, &dwSize, dwFlags) == dwExpectReturn, "UrlCanonicalizeA didn't return 0x%08x, index %d\n", dwExpectReturn, index);
    if (todo)
        todo_wine
        ok(strcmp(szReturnUrl,szExpectUrl)==0, "UrlCanonicalizeA dwFlags 0x%08x url '%s' Expected \"%s\", but got \"%s\", index %d\n", dwFlags, szUrl, szExpectUrl, szReturnUrl, index);
    else
        ok(strcmp(szReturnUrl,szExpectUrl)==0, "UrlCanonicalizeA dwFlags 0x%08x url '%s' Expected \"%s\", but got \"%s\", index %d\n", dwFlags, szUrl, szExpectUrl, szReturnUrl, index);

    dwSize = INTERNET_MAX_URL_LENGTH;
    ok(UrlCanonicalizeW(wszUrl, NULL, &dwSize, dwFlags) != dwExpectReturn, "Unexpected return for NULL buffer, index %d\n", index);
    ok(UrlCanonicalizeW(wszUrl, wszReturnUrl, &dwSize, dwFlags) == dwExpectReturn, "UrlCanonicalizeW didn't return 0x%08x, index %d\n", dwExpectReturn, index);
    wszConvertedUrl = GetWideString(szReturnUrl);
    ok(lstrcmpW(wszReturnUrl, wszConvertedUrl)==0, "Strings didn't match between ascii and unicode UrlCanonicalize, index %d!\n", index);
    FreeWideString(wszConvertedUrl);


    FreeWideString(wszUrl);
    FreeWideString(wszExpectUrl);
}
Пример #5
0
static void test_url_combine(const char *szUrl1, const char *szUrl2, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl)
{
    HRESULT hr;
    CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
    WCHAR wszReturnUrl[INTERNET_MAX_URL_LENGTH];
    LPWSTR wszUrl1 = GetWideString(szUrl1);
    LPWSTR wszUrl2 = GetWideString(szUrl2);
    LPWSTR wszExpectUrl = GetWideString(szExpectUrl);
    LPWSTR wszConvertedUrl;

    DWORD dwSize;
    DWORD dwExpectLen = lstrlen(szExpectUrl);

    hr = UrlCombineA(szUrl1, szUrl2, NULL, NULL, dwFlags);
    ok(hr == E_INVALIDARG, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_INVALIDARG);

    dwSize = 0;
    hr = UrlCombineA(szUrl1, szUrl2, NULL, &dwSize, dwFlags);
    ok(hr == E_POINTER, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr, E_POINTER);
    ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);

    dwSize--;
    hr = UrlCombineA(szUrl1, szUrl2, szReturnUrl, &dwSize, dwFlags);
    ok(hr == E_POINTER, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_POINTER);
    ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);

    hr = UrlCombineA(szUrl1, szUrl2, szReturnUrl, &dwSize, dwFlags);
    ok(hr == dwExpectReturn, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, dwExpectReturn);
    ok(dwSize == dwExpectLen, "Got length %d, expected %d\n", dwSize, dwExpectLen);
    if(SUCCEEDED(hr)) {
        ok(strcmp(szReturnUrl,szExpectUrl)==0, "Expected %s, but got %s\n", szExpectUrl, szReturnUrl);
    }

    dwSize = 0;
    hr = UrlCombineW(wszUrl1, wszUrl2, NULL, &dwSize, dwFlags);
    ok(hr == E_POINTER, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr, E_POINTER);
    ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);

    dwSize--;
    hr = UrlCombineW(wszUrl1, wszUrl2, wszReturnUrl, &dwSize, dwFlags);
    ok(hr == E_POINTER, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_POINTER);
    ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);

    hr = UrlCombineW(wszUrl1, wszUrl2, wszReturnUrl, &dwSize, dwFlags);
    ok(hr == dwExpectReturn, "UrlCombineW returned 0x%08x, expected 0x%08x\n", hr, dwExpectReturn);
    ok(dwSize == dwExpectLen, "Got length %d, expected %d\n", dwSize, dwExpectLen);
    if(SUCCEEDED(hr)) {
        wszConvertedUrl = GetWideString(szReturnUrl);
        ok(lstrcmpW(wszReturnUrl, wszConvertedUrl)==0, "Strings didn't match between ascii and unicode UrlCombine!\n");
        FreeWideString(wszConvertedUrl);
    }

    FreeWideString(wszUrl1);
    FreeWideString(wszUrl2);
    FreeWideString(wszExpectUrl);
}
Пример #6
0
static void test_url_escape(const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl)
{
    CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
    DWORD dwEscaped;
    WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
    WCHAR *urlW, *expected_urlW;
    dwEscaped=INTERNET_MAX_URL_LENGTH;

    ok(UrlEscapeA(szUrl, szReturnUrl, &dwEscaped, dwFlags) == dwExpectReturn, "UrlEscapeA didn't return 0x%08x from \"%s\"\n", dwExpectReturn, szUrl);
    ok(strcmp(szReturnUrl,szExpectUrl)==0, "Expected \"%s\", but got \"%s\" from \"%s\"\n", szExpectUrl, szReturnUrl, szUrl);

    dwEscaped = INTERNET_MAX_URL_LENGTH;
    urlW = GetWideString(szUrl);
    expected_urlW = GetWideString(szExpectUrl);
    ok(UrlEscapeW(urlW, ret_urlW, &dwEscaped, dwFlags) == dwExpectReturn, "UrlEscapeW didn't return 0x%08x from \"%s\"\n", dwExpectReturn, szUrl);
    WideCharToMultiByte(CP_ACP,0,ret_urlW,-1,szReturnUrl,INTERNET_MAX_URL_LENGTH,0,0);
    ok(lstrcmpW(ret_urlW, expected_urlW)==0, "Expected \"%s\", but got \"%s\" from \"%s\" flags %08x\n", szExpectUrl, szReturnUrl, szUrl, dwFlags);
    FreeWideString(urlW);
    FreeWideString(expected_urlW);

}
Пример #7
0
static void hash_url(const char* szUrl)
{
  LPCSTR szTestUrl = szUrl;
  LPWSTR wszTestUrl = GetWideString(szTestUrl);

  DWORD cbSize = sizeof(DWORD);
  DWORD dwHash1, dwHash2;
  ok(UrlHashA(szTestUrl, (LPBYTE)&dwHash1, cbSize) == S_OK, "UrlHashA didn't return S_OK\n");
  ok(UrlHashW(wszTestUrl, (LPBYTE)&dwHash2, cbSize) == S_OK, "UrlHashW didn't return S_OK\n");

  FreeWideString(wszTestUrl);

  ok(dwHash1 == dwHash2, "Hashes didn't compare\n");
}
Пример #8
0
/******************************************************************************
 * Processes a registry file.
 * Correctly processes comments (in # and ; form), line continuation.
 *
 * Parameters:
 *   in - input stream to read from
 *   first_chars - beginning of stream, read due to Unicode check
 */
static void processRegLinesA(FILE *in, char* first_chars)
{
    LPSTR line           = NULL;  /* line read from input stream */
    ULONG lineSize       = REG_VAL_BUF_SIZE;

    line = HeapAlloc(GetProcessHeap(), 0, lineSize);
    CHECK_ENOUGH_MEMORY(line);
    memcpy(line, first_chars, 2);

    while (!feof(in)) {
        LPSTR s; /* The pointer into line for where the current fgets should read */
        WCHAR* lineW;
        s = line;

        if(first_chars)
        {
            s += 2;
            first_chars = NULL;
        }

        for (;;) {
            size_t size_remaining;
            int size_to_get, i;
            char *s_eol; /* various local uses */

            /* Do we need to expand the buffer ? */
            assert (s >= line && s <= line + lineSize);
            size_remaining = lineSize - (s-line);
            if (size_remaining < 2) /* room for 1 character and the \0 */
            {
                char *new_buffer;
                size_t new_size = lineSize + REG_VAL_BUF_SIZE;
                if (new_size > lineSize) /* no arithmetic overflow */
                    new_buffer = HeapReAlloc (GetProcessHeap(), 0, line, new_size);
                else
                    new_buffer = NULL;
                CHECK_ENOUGH_MEMORY(new_buffer);
                line = new_buffer;
                s = line + lineSize - size_remaining;
                lineSize = new_size;
                size_remaining = lineSize - (s-line);
            }

            /* Get as much as possible into the buffer, terminated either by
             * eof, error, eol or getting the maximum amount.  Abort on error.
             */
            size_to_get = (size_remaining > INT_MAX ? INT_MAX : size_remaining);

            /* get a single line. note that `i' must be one past the last
             * meaningful character in `s' when this loop exits */
            for(i = 0; i < size_to_get-1; ++i){
                int xchar;

                xchar = fgetc(in);
                s[i] = xchar;
                if(xchar == EOF){
                    if(ferror(in)){
                        perror("While reading input");
                        exit(IO_ERROR);
                    }else
                        assert(feof(in));
                    break;
                }
                if(s[i] == '\r'){
                    /* read the next character iff it's \n */
                    if(i+2 >= size_to_get){
                        /* buffer too short, so put back the EOL char to
                         * read next cycle */
                        ungetc('\r', in);
                        break;
                    }
                    s[i+1] = fgetc(in);
                    if(s[i+1] != '\n'){
                        ungetc(s[i+1], in);
                        i = i+1;
                    }else
                        i = i+2;
                    break;
                }
                if(s[i] == '\n'){
                    i = i+1;
                    break;
                }
            }
            s[i] = '\0';

            /* If we didn't read the eol nor the eof go around for the rest */
            s_eol = strpbrk (s, "\r\n");
            if (!feof (in) && !s_eol) {
                s = strchr (s, '\0');
                continue;
            }

            /* If it is a comment line then discard it and go around again */
            if (line [0] == '#' || line [0] == ';') {
                s = line;
                continue;
            }

            /* Remove any line feed.  Leave s_eol on the first \0 */
            if (s_eol) {
               if (*s_eol == '\r' && *(s_eol+1) == '\n')
                   *(s_eol+1) = '\0';
               *s_eol = '\0';
            } else
                s_eol = strchr (s, '\0');

            /* If there is a concatenating \\ then go around again */
            if (s_eol > line && *(s_eol-1) == '\\') {
                int c;
                s = s_eol-1;

                do
                {
                    c = fgetc(in);
                } while(c == ' ' || c == '\t');

                if(c == EOF)
                {
                    fprintf(stderr,"%s: ERROR - invalid continuation.\n",
                            getAppName());
                }
                else
                {
                    *s = c;
                    s++;
                }
                continue;
            }

            lineW = GetWideString(line);

            break; /* That is the full virtual line */
        }

        processRegEntry(lineW, FALSE);
        HeapFree(GetProcessHeap(), 0, lineW);
    }
    processRegEntry(NULL, FALSE);

    HeapFree(GetProcessHeap(), 0, line);
}
Пример #9
0
static BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s)
{
    switch (action) {
    case ACTION_ADD: {
            CHAR filename[MAX_PATH];
            FILE *reg_file;

            get_file_name(&s, filename);
            if (!filename[0]) {
                fprintf(stderr,"%s: No file name was specified\n", getAppName());
                fprintf(stderr,usage);
                exit(1);
            }

            while(filename[0]) {
                char* realname = NULL;

                if (strcmp(filename, "-") == 0)
                {
                    reg_file=stdin;
                }
                else
                {
                    int size;

                    size=SearchPath(NULL, filename, NULL,0, NULL, NULL);
                    if (size>0)
                    {
                        realname=HeapAlloc(GetProcessHeap(), 0, size);
                        size=SearchPath(NULL, filename, NULL, size, realname, NULL);
                    }
                    if (size==0)
                    {
                        fprintf(stderr, "%s: File not found \"%s\" (%d)\n",
                                getAppName(), filename, GetLastError());
                        exit(1);
                    }
                    reg_file = fopen(realname, "r");
                    if (reg_file==NULL)
                    {
                        perror("");
                        fprintf(stderr,"%s: Can't open file \"%s\"\n", getAppName(), filename);
                        exit(1);
                    }
                }
                import_registry_file(reg_file);
                if (realname)
                {
                    HeapFree(GetProcessHeap(),0,realname);
                    fclose(reg_file);
                }
                get_file_name(&s, filename);
            }
            break;
        }
    case ACTION_DELETE: {
            CHAR reg_key_name[KEY_MAX_LEN];

            get_file_name(&s, reg_key_name);
            if (!reg_key_name[0]) {
                fprintf(stderr,"%s: No registry key was specified for removal\n",
                        getAppName());
                fprintf(stderr,usage);
                exit(1);
            } else
            {
                WCHAR* reg_key_nameW = GetWideString(reg_key_name);
                delete_registry_key(reg_key_nameW);
                HeapFree(GetProcessHeap(), 0, reg_key_nameW);
            }
            break;
        }
    case ACTION_EXPORT: {
            CHAR filename[MAX_PATH];
            WCHAR* filenameW;

            filename[0] = '\0';
            get_file_name(&s, filename);
            if (!filename[0]) {
                fprintf(stderr,"%s: No file name was specified\n", getAppName());
                fprintf(stderr,usage);
                exit(1);
            }

            filenameW = GetWideString(filename);
            if (s[0]) {
                CHAR reg_key_name[KEY_MAX_LEN];
                WCHAR* reg_key_nameW;

                get_file_name(&s, reg_key_name);
                reg_key_nameW = GetWideString(reg_key_name);
                export_registry_key(filenameW, reg_key_nameW, REG_FORMAT_4);
                HeapFree(GetProcessHeap(), 0, reg_key_nameW);
            } else {
                export_registry_key(filenameW, NULL, REG_FORMAT_4);
            }
            HeapFree(GetProcessHeap(), 0, filenameW);
            break;
        }
    default:
        fprintf(stderr,"%s: Unhandled action!\n", getAppName());
        exit(1);
        break;
    }
    return TRUE;
}
Пример #10
0
LRESULT
BlobMgmt::ShowImage()
{
#ifndef VC6
	HDC             hdc;
	RECT			rectwin;
	wyInt32         renderwidth, renderheight;
	PAINTSTRUCT     ps;
	LPSTREAM        stream = NULL;
	HGLOBAL         glbmem;
	void            *glbbuffer;
    wyWChar         tempfilename[MAX_PATH+1] = {0}, path[MAX_PATH + 1] = {0};
	wyString		tempstr;
	HANDLE          hfile = INVALID_HANDLE_VALUE;
	DWORD           byteswritten = 0;

	if(!m_piub->m_data || m_piub->m_datasize == 0)
	{
		VERIFY(hdc = BeginPaint(m_hwndimage, &ps));
		VERIFY(EndPaint(m_hwndimage, &ps));
		return 0;
	}
	/* allocate global memory and copy image data in it*/
	VERIFY(glbmem = GlobalAlloc(GMEM_MOVEABLE | GMEM_NODISCARD, m_piub->m_datasize));
	if(!glbmem)
        return 0;

	/* lock the global memory and get a pointer */
	glbbuffer = GlobalLock(glbmem);
	/* copy the memory to buffer */
	CopyMemory(glbbuffer, m_piub->m_data, m_piub->m_datasize);
	/* unlock it */
	VERIFY(GlobalUnlock(glbmem)== NO_ERROR);
	/* create the stream */
	VERIFY(CreateStreamOnHGlobal(glbmem, FALSE, &stream)== S_OK);
	/* prepare window for painting */
	VERIFY(hdc = BeginPaint(m_hwndimage, &ps));
	/* clear the window */
	PrepareScreen(ps.hdc);

    if(pGlobals->m_configdirpath.GetLength() || SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, (LPWSTR)path)))
    {
		if(pGlobals->m_configdirpath.GetLength())
		{
			//wcscpy(path, pGlobals->m_configdirpath.GetAsWideChar());			
			wcsncpy(path, pGlobals->m_configdirpath.GetAsWideChar(), MAX_PATH);			
			path[MAX_PATH] = '\0';
		}
		
		else
		{
			wcscat(path, L"\\");
			wcscat(path, L"SQLyog");
		}
        
        VERIFY(GetTempFileName(path, L"img", 0, tempfilename));
 	    hfile = CreateFile(tempfilename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
								   NULL, NULL);
	    VERIFY(hfile != INVALID_HANDLE_VALUE);
	    VERIFY(WriteFile(hfile, m_piub->m_data, m_piub->m_datasize, &byteswritten, NULL));
	    VERIFY(CloseHandle(hfile));
    }
	tempstr.SetAs(tempfilename);
	
	WCHAR *wpath = GetWideString(tempstr.GetString());
	
	Gdiplus::Graphics	graphics(hdc);
	Gdiplus::Image		*image = new Gdiplus::Image(wpath);

	HeapFree(GetProcessHeap(), 0, wpath);
	/* in win95 image will be null so we exit */
	if(!image)
		goto ExitPara;

	/* the binary data might not be image so image.getlastatus will not return Ok */
	if(image->GetLastStatus()!= Gdiplus::Ok)
    {
		delete image;
		goto ExitPara;
	}

	/* get the window width and calculate the correct render stats */
	VERIFY(GetClientRect(m_hwndimage, &rectwin));

	renderheight =(((LONG)image->GetHeight())> rectwin.bottom)?(rectwin.bottom):(image->GetHeight());
	renderwidth  =(((LONG)image->GetWidth())> rectwin.right)?(rectwin.right):(image->GetWidth());

	graphics.DrawImage(image, 0, 0, renderwidth, renderheight);
	delete image;
	EndPaint(m_hwndimage, &ps);

ExitPara:
	/* free up stuff */
	VERIFY(DeleteFile(tempfilename));
	if(stream)
		stream->Release();

	VERIFY(GlobalFree(glbmem)== NULL);
#endif
	
	return 0;
}
Пример #11
0
void StdStringTest::testStdString()
{
    //GetAnsiString
    std::string strAnsi = GetAnsiString(L"hello");
    CPPUNIT_ASSERT(strAnsi == "hello");
    strAnsi = GetAnsiString(L"");
    CPPUNIT_ASSERT(strAnsi == "");

    //GetWideString
    std::wstring strWide = GetWideString("hello");
    CPPUNIT_ASSERT(strWide == L"hello");
    strWide = GetWideString(L"");
    CPPUNIT_ASSERT(strWide == L"");

    //GetCStyleAnsiString
    char szBuf[64] = {0};
    const char* pTmp = GetCStyleAnsiString("hello", szBuf);
    CPPUNIT_ASSERT_EQUAL(0, lstrcmpA(pTmp, "hello"));
    pTmp = GetCStyleAnsiString("", szBuf);
    CPPUNIT_ASSERT_EQUAL(0, lstrlenA(pTmp));

    //GetCStyleWideString
    wchar_t szBuf2[64] = {0};
    const wchar_t* pTmp2 = GetCStyleWideString(L"hello", szBuf2);
    CPPUNIT_ASSERT_EQUAL(0, lstrcmpW(pTmp2, L"hello"));
    pTmp2 = GetCStyleWideString(L"", szBuf2);
    CPPUNIT_ASSERT_EQUAL(0, lstrlenW(pTmp2));

    //Split
    std::string strDel = " \t";
    strAnsi = " a\t hello                         world         ";
    std::list<std::string> rgpRet;
    int nVal = Split(strAnsi, strDel, rgpRet);
    CPPUNIT_ASSERT(3 == nVal);
    CPPUNIT_ASSERT(3u == rgpRet.size());

    std::list<std::string>::iterator iter = rgpRet.begin();
    CPPUNIT_ASSERT(*iter == "a");
    iter++;
    CPPUNIT_ASSERT(*iter == "hello");
    iter++;
    CPPUNIT_ASSERT(*iter == "world");
    
    //Trim
    strAnsi = "     \t a evil world                     \t               ";
    strAnsi = TrimLeft(strAnsi, strDel);
    CPPUNIT_ASSERT(strAnsi == "a evil world                     \t               ");
    strAnsi = "     \t a evil world                     \t               ";
    strAnsi = TrimRight(strAnsi, strDel);
    CPPUNIT_ASSERT(strAnsi == "     \t a evil world");
    strAnsi = "     \t a evil world                     \t               ";
    strAnsi = Trim(strAnsi, strDel);
    CPPUNIT_ASSERT(strAnsi == "a evil world");

    //StartsWith
    strAnsi = "this is a world";
    strDel = "this";
    CPPUNIT_ASSERT(StartsWith(strAnsi, strDel));
    strDel = "his";
    CPPUNIT_ASSERT(!StartsWith(strAnsi, strDel));

    //EndsWith
    strDel = "world";
    CPPUNIT_ASSERT(EndsWith(strAnsi, strDel));
    strDel = "his";
    CPPUNIT_ASSERT(!EndsWith(strAnsi, strDel));

    //Contains
    strDel = "is";
    CPPUNIT_ASSERT(Contains(strAnsi, strDel));
    strDel = "his name";
    CPPUNIT_ASSERT(!Contains(strAnsi, strDel));

}
Пример #12
0
/******************************************************************************
 * Processes a registry file.
 * Correctly processes comments (in # and ; form), line continuation.
 *
 * Parameters:
 *   in - input stream to read from
 *   first_chars - beginning of stream, read due to Unicode check
 */
static void processRegLinesA(FILE *in, char* first_chars)
{
    char *buf = NULL;  /* the line read from the input stream */
    unsigned long line_size = REG_VAL_BUF_SIZE;
    size_t chars_in_buf = -1;
    char *s; /* A pointer to buf for fread */
    char *line; /* The start of the current line */
    WCHAR *lineW;

    buf = HeapAlloc(GetProcessHeap(), 0, line_size);
    CHECK_ENOUGH_MEMORY(buf);
    s = buf;
    line = buf;

    memcpy(line, first_chars, 2);

    if (first_chars)
        s += 2;

    while (!feof(in)) {
        size_t size_remaining;
        int size_to_get;
        char *s_eol = NULL; /* various local uses */

        /* Do we need to expand the buffer? */
        assert(s >= buf && s <= buf + line_size);
        size_remaining = line_size - (s - buf);
        if (size_remaining < 3) /* we need at least 3 bytes of room for \r\n\0 */
        {
            char *new_buffer;
            size_t new_size = line_size + REG_VAL_BUF_SIZE;
            if (new_size > line_size) /* no arithmetic overflow */
                new_buffer = HeapReAlloc(GetProcessHeap(), 0, buf, new_size);
            else
                new_buffer = NULL;
            CHECK_ENOUGH_MEMORY(new_buffer);
            buf = new_buffer;
            line = buf;
            s = buf + line_size - size_remaining;
            line_size = new_size;
            size_remaining = line_size - (s - buf);
        }

        /* Get as much as possible into the buffer, terminating on EOF,
         * error or once we have read the maximum amount. Abort on error.
         */
        size_to_get = (size_remaining > INT_MAX ? INT_MAX : size_remaining);

        chars_in_buf = fread(s, 1, size_to_get - 1, in);
        s[chars_in_buf] = 0;

        if (chars_in_buf == 0) {
            if (ferror(in)) {
                perror("While reading input");
                exit(IO_ERROR);
            } else {
                assert(feof(in));
                *s = '\0';
            }
        }

        /* If we didn't read the end-of-line sequence or EOF, go around again */
        while (1)
        {
            s_eol = strpbrk(line, "\r\n");
            if (!s_eol) {
                /* Move the stub of the line to the start of the buffer so
                 * we get the maximum space to read into, and so we don't
                 * have to recalculate 'line' if the buffer expands */
                MoveMemory(buf, line, strlen(line) + 1);
                line = buf;
                s = strchr(line, '\0');
                break;
            }

            /* If we find a comment line, discard it and go around again */
            if (line [0] == '#' || line [0] == ';') {
                if (*s_eol == '\r' && *(s_eol + 1) == '\n')
                    line = s_eol + 2;
                else
                    line = s_eol + 1;
                continue;
            }

            /* If there is a concatenating '\\', go around again */
            if (*(s_eol - 1) == '\\') {
                char *next_line = s_eol + 1;

                if (*s_eol == '\r' && *(s_eol + 1) == '\n')
                    next_line++;

                while (*(next_line + 1) == ' ' || *(next_line + 1) == '\t')
                    next_line++;

                MoveMemory(s_eol - 1, next_line, chars_in_buf - (next_line - s) + 1);
                chars_in_buf -= next_line - s_eol + 1;
                s_eol = 0;
                continue;
            }

            /* Remove any line feed. Leave s_eol on the last \0 */
            if (*s_eol == '\r' && *(s_eol + 1) == '\n')
                *s_eol++ = '\0';
            *s_eol = '\0';

            lineW = GetWideString(line);
            processRegEntry(lineW, FALSE);
            HeapFree(GetProcessHeap(), 0, lineW);
            line = s_eol + 1;
            s_eol = 0;
            continue; /* That is the full virtual line */
        }
    }
    processRegEntry(NULL, FALSE);

    HeapFree(GetProcessHeap(), 0, buf);
}