示例#1
0
void FileNameTestCase::TestIsSame()
{
    wxFileName fn1( wxFileName::CreateTempFileName( "filenametest1" ) );
    CPPUNIT_ASSERT( fn1.IsOk() );
    wxON_BLOCK_EXIT1( wxRemoveFile, fn1.GetFullPath() );

    wxFileName fn2( wxFileName::CreateTempFileName( "filenametest2" ) );
    CPPUNIT_ASSERT( fn2.IsOk() );
    wxON_BLOCK_EXIT1( wxRemoveFile, fn2.GetFullPath() );

    CPPUNIT_ASSERT( fn1.SameAs( fn1 ) );
    CPPUNIT_ASSERT( !fn1.SameAs( fn2 ) );

#if defined(__UNIX__)
    // We need to create a temporary directory and a temporary link.
    // Unfortunately we can't use wxFileName::CreateTempFileName() for neither
    // as it creates plain files, so use tempnam() explicitly instead.
    char* tn = tempnam(NULL, "wxfn1");
    const wxString tempdir1 = wxString::From8BitData(tn);
    free(tn);

    CPPUNIT_ASSERT( wxFileName::Mkdir(tempdir1) );
    // Unfortunately the casts are needed to select the overload we need here.
    wxON_BLOCK_EXIT2( static_cast<bool (*)(const wxString&, int)>(wxFileName::Rmdir),
                      tempdir1, static_cast<int>(wxPATH_RMDIR_RECURSIVE) );

    tn = tempnam(NULL, "wxfn2");
    const wxString tempdir2 = wxString::From8BitData(tn);
    free(tn);
    CPPUNIT_ASSERT_EQUAL( 0, symlink(tempdir1.c_str(), tempdir2.c_str()) );
    wxON_BLOCK_EXIT1( wxRemoveFile, tempdir2 );


    wxFileName fn3(tempdir1, "foo");
    wxFileName fn4(tempdir2, "foo");

    // These files have different paths, hence are different.
    CPPUNIT_ASSERT( !fn3.SameAs(fn4) );

    // Create and close a file to trigger creating it.
    wxFile(fn3.GetFullPath(), wxFile::write);

    // Now that both files do exist we should be able to detect that they are
    // actually the same file.
    CPPUNIT_ASSERT( fn3.SameAs(fn4) );
#endif // __UNIX__
}
示例#2
0
void ScopeGuardTestCase::BlockExit()
{
    int n = 1,
        m = 2;

    {
        gs_count = 1;

        wxON_BLOCK_EXIT0(IncGlobal);
        wxON_BLOCK_EXIT1(Inc, &n);
        wxON_BLOCK_EXIT2(IncBy, &m, 15);

        CPPUNIT_ASSERT_EQUAL( 1, gs_count );
        CPPUNIT_ASSERT_EQUAL( 1, n );
        CPPUNIT_ASSERT_EQUAL( 2, m );
    }

    CPPUNIT_ASSERT_EQUAL( 2, gs_count );
    CPPUNIT_ASSERT_EQUAL( 2, n );
    CPPUNIT_ASSERT_EQUAL( 17, m );
}
示例#3
0
void TextCtrlTestCase::StreamInput()
{
#ifndef __WXOSX__
    {
        // Ensure we use decimal point and not a comma.
        char * const locOld = setlocale(LC_NUMERIC, "C");
        wxON_BLOCK_EXIT2( setlocale, (int)LC_NUMERIC, locOld );

        *m_text << "stringinput"
                << 10
                << 1000L
                << 3.14f
                << 2.71
                << 'a'
                << L'b';
    }

    CPPUNIT_ASSERT_EQUAL("stringinput1010003.142.71ab", m_text->GetValue());

    m_text->SetValue("");

#if wxHAS_TEXT_WINDOW_STREAM

    std::ostream stream(m_text);

    // We don't test a wide character as this is not a wide stream
    stream << "stringinput"
           << 10
           << 1000L
           << 3.14f
           << 2.71
           << 'a';

    stream.flush();

    CPPUNIT_ASSERT_EQUAL("stringinput1010003.142.71a", m_text->GetValue());

#endif // wxHAS_TEXT_WINDOW_STREAM
#endif // !__WXOSX__
}