Exemplo n.º 1
0
// Helper of test_new_file_and_save() which tests creating a new file of
// the type corresponding to the key argument, used to select this type in
// the "New" popup menu.
//
// The last argument indicates whether a dialog is shown when creating a
// new file of this type (e.g. true for illustrations, false for census).
// It affects this function behaviour in two ways: first, it needs to be
// ready for this dialog appearing and, second, "File|Save" menu command is
// disabled for the files created in this way and "File|Save as" needs to
// be used instead.
void do_test_create_open
        (wx_base_test_case& test
        ,int key
        ,char const* basename
        ,bool uses_dialog)
{
    test.skip_if_not_supported(basename);

    wxString const file = test.get_test_file_path_for(basename);
    LMI_ASSERT(!wxFileExists(file));

    wxUIActionSimulator z;
    z.Char('n', wxMOD_CONTROL); // new file
    z.Char(key               ); // choose document type
    if (uses_dialog)
        {
        wxTEST_DIALOG
            (wxYield()
            ,wxExpectDismissableModal<MvcController>(wxID_OK).
                Describe("new file properties")
            );
        }
    wxYield();

    z.Char(uses_dialog ? 'a' : 's', wxMOD_CONTROL); // save or save as
    wxTEST_DIALOG
        (wxYield()
        ,wxExpectModal<wxFileDialog>(file).Describe("save file dialog")
        );
    wxYield();

    LMI_ASSERT(wxFileExists(file));
    wxON_BLOCK_EXIT1(wxRemoveFile, file);

    z.Char('l', wxMOD_CONTROL); // close document
    wxYield();

    z.Char('o', wxMOD_CONTROL); // and open it again

    if (uses_dialog)
        {
        wxTEST_DIALOG
            (wxYield()
            ,wxExpectModal<wxFileDialog>(file).Describe("open file dialog")
            ,wxExpectDismissableModal<MvcController>(wxID_OK).
                Describe("existing file properties")
            );
        }
    else
        {
        wxTEST_DIALOG
            (wxYield()
            ,wxExpectModal<wxFileDialog>(file).Describe("open file dialog")
            );
        }
    wxYield();

    z.Char('l', wxMOD_CONTROL); // close it finally
    wxYield();
}
Exemplo n.º 2
0
    // Common part of both constructors.
    void do_new_illustration(wxModalExpectation const& e)
    {
        wxUIActionSimulator ui;
        ui.Char('n', wxMOD_CONTROL);    // "File|New"
        ui.Char('i');                   // "Illustration"

        wxTEST_DIALOG(wxYield(), e);

        set_opened();
    }
Exemplo n.º 3
0
void ModalDialogsTestCase::CustomDialog()
{
    MyDialog dlg(NULL);

    wxTEST_DIALOG
    (
        dlg.ShowModal(),
        wxExpectModal<MyDialog>(42)
    );

    CPPUNIT_ASSERT_EQUAL( 42, dlg.m_value );
}
Exemplo n.º 4
0
void ModalDialogsTestCase::MessageDialog()
{
    int rc;

    wxTEST_DIALOG
    (
        rc = wxMessageBox("Should I fail?", "Question", wxYES|wxNO),
        wxExpectModal<wxMessageDialog>(wxNO),
        wxExpectModal<wxFileDialog>(wxGetCwd() + "/test.txt").Optional()
    );

    CPPUNIT_ASSERT_EQUAL(wxNO, rc);
}
Exemplo n.º 5
0
void ModalDialogsTestCase::FileDialog()
{
    wxFileDialog dlg(NULL);
    int rc;

    wxTEST_DIALOG
    (
        rc = dlg.ShowModal(),
        wxExpectModal<wxFileDialog>(wxGetCwd() + "/test.txt")
    );

    CPPUNIT_ASSERT_EQUAL((int)wxID_OK, rc);

    CPPUNIT_ASSERT_EQUAL("test.txt", dlg.GetFilename());
}
Exemplo n.º 6
0
void ModalDialogsTestCase::FileDialog()
{
    wxFileDialog dlg(NULL);
    int rc;

    wxTEST_DIALOG
    (
        rc = dlg.ShowModal(),
        wxExpectModal<wxFileDialog>(wxGetCwd() + "/test.txt")
    );

    CPPUNIT_ASSERT_EQUAL((int)wxID_OK, rc);

    CPPUNIT_ASSERT_EQUAL("test.txt", dlg.GetFilename());

#ifdef __WXGTK3__
    // The native file dialog in GTK+ 3 launches an async operation which tries
    // to dereference the already deleted dialog object if we don't let it to
    // complete before leaving this function.
    wxYield();
#endif
}