void fixture::testTextFile() { // Test find. wxExTextFile textFile(GetTestFile(), ID_TOOL_REPORT_FIND); CPPUNIT_ASSERT( textFile.GetFileName() == GetTestFile()); CPPUNIT_ASSERT( textFile.GetTool().GetId() == ID_TOOL_REPORT_FIND); wxExFindReplaceData::Get()->SetFindString("test"); wxExFindReplaceData::Get()->SetMatchCase(true); wxExFindReplaceData::Get()->SetMatchWord(true); wxExFindReplaceData::Get()->SetUseRegEx(false); wxStopWatch sw; sw.Start(); CPPUNIT_ASSERT( textFile.RunTool()); const long elapsed = sw.Time(); CPPUNIT_ASSERT(elapsed < 20); Report(wxString::Format( "wxExTextFile::matching %d items in %ld ms", textFile.GetStatistics().Get(_("Actions Completed")), elapsed).ToStdString()); CPPUNIT_ASSERT(!textFile.GetStatistics().GetElements().GetItems().empty()); CPPUNIT_ASSERT( textFile.GetStatistics().Get(_("Actions Completed")) == 193); // Test replace. wxExTextFile textFile2(GetTestFile(), ID_TOOL_REPORT_REPLACE); wxExFindReplaceData::Get()->SetReplaceString("test"); wxStopWatch sw2; sw2.Start(); CPPUNIT_ASSERT( textFile2.RunTool()); const long elapsed2 = sw2.Time(); CPPUNIT_ASSERT(elapsed2 < 100); Report(wxString::Format( "wxExTextFile::replacing %d items in %ld ms", textFile2.GetStatistics().Get(_("Actions Completed")), elapsed2).ToStdString()); CPPUNIT_ASSERT(!textFile2.GetStatistics().GetElements().GetItems().empty()); CPPUNIT_ASSERT( textFile2.GetStatistics().Get(_("Actions Completed")) == 194); }
void JournalDM_TestModel::test_loading_file() { JournalDM_Model aModel; QString aFile = GetTestFile( "test1.txt" ); JournalDM_ExerciseData e; CPPUNIT_ASSERT_EQUAL( true, aModel.Load( aFile ) ); CPPUNIT_ASSERT_EQUAL( 1, aModel.GetNbCategories() ); CPPUNIT_ASSERT_EQUAL( QString( "test1" ), aModel.GetCategory( 0 )->GetName() ); CPPUNIT_ASSERT_EQUAL( 8, aModel.GetCategory( 0 )->GetNbLines() ); CPPUNIT_ASSERT_EQUAL( 6, aModel.GetCategory( 0 )->GetNbLines( true ) ); CPPUNIT_ASSERT_EQUAL( 11, aModel.GetCategory( 0 )->GetNbExercises() ); e = aModel.GetCategory( 0 )->GetExercise( 0 ); CPPUNIT_ASSERT_EQUAL( QString( "couper ... pomme en deux parties" ), e.Question ); CPPUNIT_ASSERT_EQUAL( QString( "une" ), e.Answer ); e = aModel.GetCategory( 0 )->GetExercise( 3 ); CPPUNIT_ASSERT_EQUAL( QString( "un poste = ..." ), e.Question ); CPPUNIT_ASSERT_EQUAL( QString::fromUtf8( "должность" ), e.Answer ); e = aModel.GetCategory( 0 )->GetExercise( 6 ); CPPUNIT_ASSERT_EQUAL( QString( "aider ... qn" ), e.Question ); CPPUNIT_ASSERT_EQUAL( QString( "" ), e.Answer ); e = aModel.GetCategory( 0 )->GetExercise( 9 ); CPPUNIT_ASSERT_EQUAL( QString::fromUtf8( "... = яблоко" ), e.Question ); CPPUNIT_ASSERT_EQUAL( QString( "une pomme" ), e.Answer ); e = aModel.GetCategory( 0 )->GetExercise( 10 ); CPPUNIT_ASSERT_EQUAL( QString( "une pomme = ..." ), e.Question ); CPPUNIT_ASSERT_EQUAL( QString::fromUtf8( "яблоко" ), e.Answer ); }
void JournalDM_TestModel::test_loading_folder() { JournalDM_Model aModel; QString aPath = GetTestFile( "" ); CPPUNIT_ASSERT_EQUAL( true, aModel.Load( aPath ) ); CPPUNIT_ASSERT_EQUAL( 2, aModel.GetNbCategories() ); CPPUNIT_ASSERT_EQUAL( QString( "test1" ), aModel.GetCategory( 0 )->GetName() ); CPPUNIT_ASSERT_EQUAL( 8, aModel.GetCategory( 0 )->GetNbLines() ); CPPUNIT_ASSERT_EQUAL( 6, aModel.GetCategory( 0 )->GetNbLines( true ) ); CPPUNIT_ASSERT_EQUAL( 11, aModel.GetCategory( 0 )->GetNbExercises() ); CPPUNIT_ASSERT_EQUAL( QString( "test2" ), aModel.GetCategory( 1 )->GetName() ); CPPUNIT_ASSERT_EQUAL( 0, aModel.GetCategory( 1 )->GetNbLines() ); CPPUNIT_ASSERT_EQUAL( 0, aModel.GetCategory( 1 )->GetNbLines( true ) ); CPPUNIT_ASSERT_EQUAL( 0, aModel.GetCategory( 1 )->GetNbExercises() ); }
void fixture::testSTC() { // Some methods do not return values, just call them to // prevent cores, and improve test coverage. wxExSTC::ConfigDialog(m_Frame, "test stc", wxExSTC::STC_CONFIG_MODELESS); wxExSTC* stc = new wxExSTC(m_Frame, "hello stc"); CPPUNIT_ASSERT( stc->GetText() == "hello stc"); CPPUNIT_ASSERT( stc->FindNext(wxString("hello"))); CPPUNIT_ASSERT(!stc->FindNext(wxString("%d"))); CPPUNIT_ASSERT(!stc->FindNext(wxString("%ld"))); CPPUNIT_ASSERT(!stc->FindNext(wxString("%q"))); CPPUNIT_ASSERT( stc->FindNext(wxString("hello"), wxSTC_FIND_WHOLEWORD)); CPPUNIT_ASSERT(!stc->FindNext(wxString("HELLO"), wxSTC_FIND_MATCHCASE)); CPPUNIT_ASSERT( stc->GetSearchFlags() & wxSTC_FIND_MATCHCASE); wxExFindReplaceData::Get()->SetMatchCase(false); CPPUNIT_ASSERT( stc->FindNext(wxString("HELLO"))); // uses flags from frd CPPUNIT_ASSERT( stc->AllowChangeIndicator()); stc->AppendText("more text"); CPPUNIT_ASSERT( stc->GetText() != "hello stc"); CPPUNIT_ASSERT( stc->CanCut()); CPPUNIT_ASSERT( stc->CanPaste()); stc->DocumentStart(); wxExFindReplaceData::Get()->SetMatchWord(false); CPPUNIT_ASSERT( stc->FindNext(wxString("more text"))); CPPUNIT_ASSERT( stc->GetFindString() == "more text"); CPPUNIT_ASSERT( stc->ReplaceAll("more", "less") == 1); CPPUNIT_ASSERT( stc->ReplaceAll("more", "less") == 0); CPPUNIT_ASSERT(!stc->FindNext(wxString("more text"))); stc->SelectNone(); CPPUNIT_ASSERT(!stc->FindNext()); CPPUNIT_ASSERT( stc->FindNext(wxString("less text"))); CPPUNIT_ASSERT( stc->ReplaceNext("less text", "")); CPPUNIT_ASSERT(!stc->ReplaceNext()); CPPUNIT_ASSERT(!stc->FindNext(wxString("less text"))); CPPUNIT_ASSERT( stc->GetFindString() != "less text"); CPPUNIT_ASSERT( stc->ReplaceAll("%", "percent") == 0); stc->GotoLineAndSelect(1); CPPUNIT_ASSERT(stc->GetCurrentLine() == 0); CPPUNIT_ASSERT(stc->GetCurrentPos() == 0); stc->GotoLineAndSelect(1, wxEmptyString, 5); CPPUNIT_ASSERT(stc->GetCurrentLine() == 0); CPPUNIT_ASSERT(stc->GetCurrentPos() == 4); stc->SetText("new text"); CPPUNIT_ASSERT(stc->GetText() == "new text"); CPPUNIT_ASSERT(stc->SetLexer("cpp")); wxExLexer lexer; CPPUNIT_ASSERT( lexer.Reset(stc)); CPPUNIT_ASSERT( lexer.Set("cpp", stc, false)); CPPUNIT_ASSERT(!lexer.Set("xyz", stc, false)); CPPUNIT_ASSERT( stc->SetLexer(lexer)); // do the same test as with wxExFile in base for a binary file CPPUNIT_ASSERT(stc->Open(wxExFileName(GetTestDir() + "test.bin"))); CPPUNIT_ASSERT(stc->GetFlags() == 0); const wxCharBuffer& buffer = stc->GetTextRaw(); CPPUNIT_ASSERT(buffer.length() == 40); stc->AddText("hello"); CPPUNIT_ASSERT( stc->GetFile().GetContentsChanged()); stc->GetFile().ResetContentsChanged(); CPPUNIT_ASSERT(!stc->GetFile().GetContentsChanged()); stc->ConfigGet(); stc->Cut(); // stc->FileTypeMenu(); stc->Fold(); stc->Fold(true); // FoldAll CPPUNIT_ASSERT(!stc->GetEOL().empty()); stc->GuessType(); CPPUNIT_ASSERT(stc->MarkerDeleteAllChange()); stc->Paste(); CPPUNIT_ASSERT(!stc->PositionRestore()); stc->PositionSave(); CPPUNIT_ASSERT( stc->PositionRestore()); // stc->Print(); stc->PrintPreview(); stc->ProcessChar(5); stc->PropertiesMessage(); stc->Reload(); stc->ResetMargins(); stc->SelectNone(); CPPUNIT_ASSERT(!stc->SetIndicator(wxExIndicator(4,5), 100, 200)); stc->SetLexerProperty("xx", "yy"); CPPUNIT_ASSERT(!(stc->GetSearchFlags() & wxSTC_FIND_MATCHCASE)); wxExFindReplaceData::Get()->SetMatchCase(false); stc->SetSearchFlags(-1); CPPUNIT_ASSERT(!(stc->GetSearchFlags() & wxSTC_FIND_MATCHCASE)); // Test AutoIndentation // first test auto indentation on next line stc->SetText(" \n line with indentation"); stc->DocumentEnd(); CPPUNIT_ASSERT(!stc->AutoIndentation('x')); CPPUNIT_ASSERT( stc->GetText() == " \n line with indentation"); CPPUNIT_ASSERT( stc->GetLineCount() == 2); CPPUNIT_ASSERT( stc->AutoIndentation('\n')); // the \n is not added, but indentation does CPPUNIT_ASSERT( stc->GetText() == " \n line with indentation"); CPPUNIT_ASSERT( stc->GetLineCount() == 2); // test auto indentation for level change CPPUNIT_ASSERT(stc->SetLexer("cpp")); stc->SetText("if ()"); stc->NewLine(); stc->AddText("{"); // TODO: Fix. CPPUNIT_ASSERT(!stc->AutoIndentation('\n')); stc->Sync(false); stc->Sync(true); stc->Undo(); stc->UseModificationMarkers(true); stc->UseModificationMarkers(false); stc->ClearDocument(); stc->Reload(wxExSTC::STC_WIN_HEX); CPPUNIT_ASSERT(stc->HexMode()); stc->GetHexMode().AppendText("in hex mode"); // Test stc with file (not yet done ???). wxExSTC stc2(m_Frame, GetTestFile()); CPPUNIT_ASSERT( stc2.GetFileName().GetFullPath().Contains("test.h")); CPPUNIT_ASSERT( stc2.Open(GetTestFile())); CPPUNIT_ASSERT(!stc2.Open(wxExFileName("XXX"))); stc2.PropertiesMessage(); // Test events. wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED); event.SetInt(ID_EDIT_HEX_DEC_CALLTIP); wxPostEvent(stc, event); event.SetInt(ID_EDIT_MARKER_NEXT); wxPostEvent(stc, event); event.SetInt(ID_EDIT_MARKER_PREVIOUS); wxPostEvent(stc, event); event.SetInt(ID_EDIT_OPEN_LINK); wxPostEvent(stc, event); event.SetInt(ID_EDIT_SHOW_PROPERTIES); wxPostEvent(stc, event); event.SetInt(ID_EDIT_ZOOM_IN); wxPostEvent(stc, event); event.SetInt(ID_EDIT_ZOOM_OUT); wxPostEvent(stc, event); wxYield(); }