Changeset 143


Ignore:
Timestamp:
08/01/11 18:59:05 (13 years ago)
Author:
jhall
Message:

added assertion handling for "fileEquals" and "textEquals", should work properly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MFCtooling/replay/LogParser.cpp

    r105 r143  
    7878                } 
    7979                currentParent = winData; 
    80         }  
     80        } 
     81        else if( localName.compare(L"textEquals")==0 ) { 
     82                expectedValue = GetAttributeValue(pAttributes, L"expectedValue", L""); 
     83        } 
     84        else if( localName.compare(L"fileEquals")==0) { 
     85                actualFile = GetAttributeValue(pAttributes, L"actualFile", L""); 
     86                expectedFile = GetAttributeValue(pAttributes, L"expectedFile", L""); 
     87        } 
     88 
    8189        return S_OK; 
    8290} 
     
    130138                currentWindow = NULL; 
    131139        } 
     140        else if( localName.compare(L"textEquals")==0 ) { 
     141                WindowFinder finder; 
     142                HWND hwnd = finder.find(currentWindow); 
     143 
     144                wchar_t* wstr = new wchar_t[256]; 
     145                wstr[0] = '\0'; 
     146                 
     147                //GetWindowText is not working properly for EditControls in other applications -> send WM_GETTEXT instead 
     148                SendMessage(hwnd, WM_GETTEXT, 255, (LPARAM)wstr); 
     149                std::wstring windowText = wstr; 
     150 
     151                if(expectedValue == windowText) std::wcout << std::endl << L"textEquals passed (expected value: " << expectedValue.c_str() << ")" << std::endl << std::endl; 
     152                else std::wcout << std::endl << L"textEquals failed (expected value: " << expectedValue.c_str() << ", windowText: " << windowText << ")" << std::endl << std::endl; 
     153                deleteWindowData(currentWindow); 
     154                currentWindow = NULL; 
     155        } 
     156        else if( localName.compare(L"fileEquals")==0) { 
     157                std::ifstream f1(actualFile.c_str(), std::ios_base::in | std::ios_base::binary); 
     158                if(f1 == NULL) { 
     159 
     160                        std::wcout << std::endl << L"fileEquals failed because " << actualFile << " is not available!"<< std::endl << std::endl; 
     161                        return S_OK; 
     162                } 
     163 
     164                std::ifstream f2(expectedFile.c_str(), std::ios_base::in | std::ios_base::binary); 
     165                if(f2 == NULL) { 
     166                        std::wcout << std::endl << L"fileEquals failed because " << expectedFile << " is not available!" << std::endl << std::endl; 
     167                        return S_OK; 
     168                } 
     169 
     170                f1.seekg(0, std::ios_base::end); 
     171                f2.seekg(0, std::ios_base::end); 
     172                std::streamsize length1 = f1.tellg(); 
     173                std::streamsize length2 = f2.tellg(); 
     174 
     175                bool passed = true; 
     176 
     177                if (length1 != length2) { // Non equal length -> files differ 
     178                        passed = false; 
     179                } 
     180                else { 
     181                        f1.seekg(0); 
     182                        f2.seekg(0); 
     183 
     184                        const std::streamsize blocksize = 4096; 
     185                        char block1[blocksize], block2[blocksize]; 
     186 
     187                        for (std::streamsize counter=length1; counter > 0; counter -= blocksize) 
     188                        {                                
     189                                f1.read(block1, blocksize); 
     190                                f2.read(block2, blocksize); 
     191 
     192                                if(memcmp(block1, block2, blocksize) != 0) { //block are non equal -> files differ 
     193                                        passed = false; 
     194                                        break; 
     195                                } 
     196                        } 
     197                } 
     198 
     199                if(passed) { 
     200                        std::wcout << std::endl << L"FileEquals passed" << std::endl << std::endl; 
     201                } 
     202                else { 
     203                        std::wcout << std::endl << L"fileEquals failed (expectedFile: " << expectedFile.c_str() << ", actualFile: " << actualFile << ")" << std::endl << std::endl; 
     204                } 
     205                 
     206                f1.close(); 
     207                f2.close(); 
     208        } 
     209 
    132210        return S_OK; 
    133211} 
Note: See TracChangeset for help on using the changeset viewer.