示例#1
0
void LogTestCase::Trace()
{
    // we use wxLogTrace() or wxVLogTrace() from inside TraceTest()
    // interchangeably here, it shouldn't make any difference

    wxLogTrace(TEST_MASK, "Not shown");
    CPPUNIT_ASSERT_EQUAL( "", m_log->GetLog(wxLOG_Trace) );

    wxLog::AddTraceMask(TEST_MASK);
    TraceTest("Shown");
    CPPUNIT_ASSERT_EQUAL( wxString::Format("(%s) Shown", TEST_MASK),
                          m_log->GetLog(wxLOG_Trace) );

    wxLog::RemoveTraceMask(TEST_MASK);
    m_log->Clear();

    TraceTest("Not shown again");
    CPPUNIT_ASSERT_EQUAL( "", m_log->GetLog(wxLOG_Trace) );
}
bool DeleteFileOrCheck(TestLog& log, const std::wstring& lpFileName)
{
    SetFileAttributesW(lpFileName.c_str(), FILE_ATTRIBUTE_NORMAL);
    BOOL result = DeleteFileW(lpFileName.c_str());

    if(result)
    {
        log.GetStream(TestLog::MT_MESSAGE) << L"Deletion success." << endl;
        return true;
    }

    if(GetLastError() == ERROR_FILE_NOT_FOUND)
    {
        log.GetStream(TestLog::MT_MESSAGE) << L"Deletion success(file not found)." << endl;
        return true;
    }

    log.GetStream(TestLog::MT_ERROR) << L"<" << lpFileName << L"> file deletion." << endl;
    return false;
}
示例#3
0
void ListFiles(TestLog& log, const wstring& dirpath)
{
    HANDLE hFind = INVALID_HANDLE_VALUE;
    DWORD dwError;

    WIN32_FIND_DATA wfd;

    // Find the first file in the directory.
    hFind = apiFindFirstFile(dirpath.c_str(), &wfd);

    if(hFind == INVALID_HANDLE_VALUE)
    {
        log.GetStream(TestLog::MT_ERROR) << L"Invalid file handle. Error is " << GetLastErrorStr() << std::endl;
        return;
    }
    else 
    {
        log.GetStream(TestLog::MT_ERROR) << L"First file name is " << wfd.cFileName << std::endl;

        // List all the other files in the directory.

        for(;;)
        {
            if(apiFindNextFile(hFind, &wfd) == 0)
            {
                break;
            }

            log.GetStream(TestLog::MT_ERROR) << L"Next file name is " << wfd.cFileName << std::endl;
        }

        dwError = GetLastError();
        uFindClose(hFind);
        if(dwError != ERROR_NO_MORE_FILES)
        {
            log.GetStream(TestLog::MT_ERROR) << L"FindNextFile error. Error is " << GetLastErrorStr() << std::endl;
        }
    }
}
BOOL CreateDirectoryWithAttributes(TestLog& log, const std::wstring& path, DWORD dwAttribute)
{
    BOOL fOk = uCreateDirectory(path.c_str(), 0);

    log.GetStream(TestLog::MT_MESSAGE) << GetString_dwFileAttributes(dwAttribute) << std::endl;

    if(!fOk)
    {
        log.GetStream(TestLog::MT_ERROR) << L"Directory creation failed." << endl;
        return FALSE;
    }

    fOk = uSetFileAttributes(path.c_str(), dwAttribute);
    DWORD dwError = GetLastError();
    if(!fOk)
    {
        log.GetStream(TestLog::MT_ERROR) << L"Cannot apply the attributes to the directory. " << GetErrorDefineString(dwError) << endl;
        return FALSE;
    }

    return TRUE;
}
示例#5
0
void LogTestCase::SysError()
{
    wxString s;

    wxLogSysError(17, "Error");
    CPPUNIT_ASSERT( m_log->GetLog(wxLOG_Error).StartsWith("Error (", &s) );
    WX_ASSERT_MESSAGE( ("Error message is \"(%s\"", s), s.StartsWith("error 17") );

    // The last error code seems to be set somewhere in MinGW CRT as its value
    // is just not what we expect (ERROR_INVALID_PARAMETER instead of 0 and 0
    // instead of ERROR_FILE_NOT_FOUND) so exclude the tests which rely on last
    // error being preserved for this compiler.
#ifndef __MINGW32__
    wxLogSysError("Success");
    CPPUNIT_ASSERT( m_log->GetLog(wxLOG_Error).StartsWith("Success (", &s) );
    WX_ASSERT_MESSAGE( ("Error message is \"(%s\"", s), s.StartsWith("error 0") );

    wxOpen("no-such-file", 0, 0);
    wxLogSysError("Not found");
    CPPUNIT_ASSERT( m_log->GetLog(wxLOG_Error).StartsWith("Not found (", &s) );
    WX_ASSERT_MESSAGE( ("Error message is \"(%s\"", s), s.StartsWith("error 2") );
#endif // __MINGW32__
}
void CopyFileEx_ExistingDst(TestLog& log, BOOL bFailIfExists)
{
    const wstring pSrcFileName = GetSrcFileName();
    const wstring pDstFileName = GetDstFileName();

    if(!MakeFile(log, pSrcFileName))
    {
        log.GetStream(TestLog::MT_ERROR) << L"Cannot create a file." << endl;
        return;
    }

    if(!TouchFile(log, pDstFileName))
    {
        log.GetStream(TestLog::MT_ERROR) << L"Cannot create a file." << endl;
        return;
    }

    BOOL result = apiCopyFileEx(pSrcFileName.c_str(), pDstFileName.c_str(), 0, 0, 0, bFailIfExists ? COPY_FILE_FAIL_IF_EXISTS : 0);

    if(result)
    {
        CheckFileData(log, pDstFileName);
    }

    if(!DeleteFileOrCheck(log, pSrcFileName))
    {
        log.GetStream(TestLog::MT_ERROR) << L"Cannot delete the file created before." << endl;
    }
    if(!DeleteFileOrCheck(log, pDstFileName))
    {
        log.GetStream(TestLog::MT_ERROR) << L"Cannot delete the file created before." << endl;
        return;
    }

    log.Ok();
}
示例#7
0
void LogTestCase::SysError()
{
    wxString s;

    wxLogSysError(17, "Error");
    CPPUNIT_ASSERT( m_log->GetLog(wxLOG_Error).StartsWith("Error (", &s) );
    WX_ASSERT_MESSAGE( ("Error message is \"(%s\"", s), s.StartsWith("error 17") );

    // Try to ensure that the system error is 0.
#ifdef __WINDOWS__
    ::SetLastError(0);
#else
    errno = 0;
#endif

    wxLogSysError("Success");
    CPPUNIT_ASSERT( m_log->GetLog(wxLOG_Error).StartsWith("Success (", &s) );
    WX_ASSERT_MESSAGE( ("Error message is \"(%s\"", s), s.StartsWith("error 0") );

    wxOpen("no-such-file", 0, 0);
    wxLogSysError("Not found");
    CPPUNIT_ASSERT( m_log->GetLog(wxLOG_Error).StartsWith("Not found (", &s) );
    WX_ASSERT_MESSAGE( ("Error message is \"(%s\"", s), s.StartsWith("error 2") );
}
示例#8
0
void LogTestCase::NoWarnings()
{
    // Check that "else" branch is [not] taken as expected and that this code
    // compiles without warnings (which used to not be the case).

    bool b = wxFalse;
    if ( b )
        wxLogError("Not logged");
    else
        b = !b;

    CPPUNIT_ASSERT( b );

    if ( b )
        wxLogError("If");
    else
        CPPUNIT_FAIL("Should not be taken");

    CPPUNIT_ASSERT_EQUAL( "If", m_log->GetLog(wxLOG_Error) );
}
RBTestDataModule::RBTestDataModule(const char* name, TestLog& log, UErrorCode& status) 
: TestDataModule(name, log, status),
  fModuleBundle(NULL),
  fTestData(NULL),
  fInfoRB(NULL),
  tdpath(NULL)
{
  fNumberOfTests = 0;
  fDataTestValid = TRUE;
  fModuleBundle = getTestBundle(name, status);
  if(fDataTestValid) {
    fTestData = ures_getByKey(fModuleBundle, "TestData", NULL, &status);
    fNumberOfTests = ures_getSize(fTestData);
    fInfoRB = ures_getByKey(fModuleBundle, "Info", NULL, &status);
    if(status != U_ZERO_ERROR) {
      log.errln(UNICODE_STRING_SIMPLE("Unable to initalize test data - missing mandatory description resources!"));
      fDataTestValid = FALSE;
    } else {
      fInfo = new RBDataMap(fInfoRB, status);
    }
  }
}
示例#10
0
BOOL MakeManyFiles(TestLog& log, size_t iFileNum, INT32 iFileSize, const std::wstring& basePath, std::vector<std::wstring>& vCreatedFiles)
{
    wstring predirectorypath;

    if(basePath.size() > 0)
    {
        predirectorypath = GetWidTestBasePath();

        if(!IsFileExist(basePath.c_str()))
        {
            CreateSubDir(basePath.c_str());
        }

        log.GetStream(TestLog::MT_MESSAGE) << L"Set Base path to : " << basePath << endl;
        BOOL fOk = uSetCurrentDirectory(basePath.c_str());
        if(!fOk)
        {
            log.GetStream(TestLog::MT_ERROR) << L"Current Directory Setting Failed. : " << GetLastErrorStr() << endl;
            return FALSE;
        }
    }

    if(vCreatedFiles.capacity() < iFileNum)
    {
        vCreatedFiles.reserve(iFileNum);
    }

    TestFileName t;

    wstring fileName = t.GetFirstFileName();
    if(!MakeFile(log, fileName, iFileSize))
    {
        log.GetStream(TestLog::MT_ERROR) << L"TouchFile Failed. : " << GetLastErrorStr() << endl;
        return FALSE;
    }

    vCreatedFiles.push_back(fileName);

    for(size_t i = 0; i < iFileNum; ++i)
    {
        fileName = t.GetNextFileName();
        if(!MakeFile(log, fileName, iFileSize))
        {
            log.GetStream(TestLog::MT_ERROR) << L"TouchFile Failed. : " << GetLastErrorStr() << endl;
            return FALSE;
        }

        vCreatedFiles.push_back(fileName);
    }

    if(basePath.size() > 0 && predirectorypath.size() > 0)
    {
        BOOL fOk = uSetCurrentDirectory(predirectorypath.c_str());
        if(!fOk)
        {
            log.GetStream(TestLog::MT_ERROR) << L"Current Directory Setting Failed. : " << GetLastErrorStr() << endl;
            return FALSE;
        }
    }

    return TRUE;
}
示例#11
0
bool CheckFileData(TestLog& log, const std::wstring& lpFileName, INT32 iFileSizeKB, size_t buffersizeKB)
{
    File f(lpFileName, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING);

    if(!f.IsValidHandle())
    {
        log.GetStream(TestLog::MT_ERROR) << L"CreateFile" << endl;
        return false;
    }

    if(buffersizeKB == 0)
    {
        buffersizeKB = 1;
    }

    char* buffer = new char[buffersizeKB * 1024];

    for(size_t i = 0; i < buffersizeKB; i++)
    {
        memcpy_s(buffer + (1024 * i), 1024, "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
            "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
            "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
            "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
            "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
            "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
            "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
            "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
            "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
            "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
            "ABCDEFGHIJKLMNOPQRSTUV\r\n", 1024 );
    }

    char* readBuffer = new char[buffersizeKB * 1024];
    DWORD readBytes = 0;

    for(int x = 0; x < iFileSizeKB; x += buffersizeKB)
    {
        if(uReadFile(f, readBuffer, buffersizeKB * 1024, &readBytes, 0) == FALSE)
        {
            log.GetStream(TestLog::MT_ERROR) << L"ReadFile" << endl;
            delete[] readBuffer;
            delete[] buffer;
            return false;
        }
        if(readBytes != buffersizeKB * 1024)
        {
            log.GetStream(TestLog::MT_ERROR) << L"ReadFile: readBytes Error." << endl;
            delete[] readBuffer;
            delete[] buffer;
            return false;
        }
        if(memcmp(readBuffer, buffer, buffersizeKB * 1024) != 0)
        {
            log.GetStream(TestLog::MT_ERROR) << L"memcmp" << endl;
            delete[] readBuffer;
            delete[] buffer;
            return false;
        }
    }

    delete[] readBuffer;
    delete[] buffer;

    log.GetStream(TestLog::MT_MESSAGE) << L"CheckFileData success." << endl;
    return true;
}
示例#12
0
void TestVSQt::testLogClicked()
{
	TestLog *t = new TestLog(this);
	t->show();
}