Fix font preference settings, workaround missing preferences include for travis, new tests

This commit is contained in:
Tim Warren 2015-06-18 13:34:54 -04:00
parent 1ddcde45d5
commit 6f053f84ed
20 changed files with 182 additions and 9531 deletions

View File

@ -5,6 +5,9 @@ before_install:
- export DISPLAY=:99.0 - export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start - sh -e /etc/init.d/xvfb start
# Define TRAVIS variable for workarounds
- export CXXFLAGS="$CXXFLAGS -DTRAVIS"
# Upgrade gcc # Upgrade gcc
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
- sudo apt-get -qq update - sudo apt-get -qq update
@ -12,11 +15,11 @@ before_install:
- if [ "$CXX" = "g++" ]; then sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 98; fi - if [ "$CXX" = "g++" ]; then sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 98; fi
# Install dependencies # Install dependencies
- sudo apt-get -qq install libwxgtk3.0-dev libwxgtk3.0-0 libssh2-1-dev - sudo apt-get -qq install libwxgtk3.0-dev libwxgtk3.0-0 libssh2-1-dev cpputest
# Build with both gcc and clang # Build with both gcc and clang
compiler: compiler:
- gcc - gcc
- clang - clang
script: make clean dev script: make clean run-tests

View File

@ -20,10 +20,10 @@ WX_CXXFLAGS = $(shell wx-config --cxxflags)
INC_FLAGS = -Iinclude -I. -I/usr/local/include INC_FLAGS = -Iinclude -I. -I/usr/local/include
DEV_CXXFLAGS = -O0 -g -Wall -Wextra -pipe -DDEBUG $(INC_FLAGS) DEV_CXXFLAGS = -O0 -g -Wall -Wextra -pipe -DDEBUG $(INC_FLAGS)
CXXFLAGS = -Os -pipe -DNDEBUG $(INC_FLAGS) CXXFLAGS += -Os -pipe -DNDEBUG $(INC_FLAGS)
TEST_SRC = $(wildcard tests/*.cpp) TEST_SRC = $(wildcard tests/*Test.cpp)
TESTS = $(patsubst %.cpp,%,$(TEST_SRC)) TESTS = $(patsubst %.cpp,%.o,$(TEST_SRC))
LDLIBS = LDLIBS =
@ -38,7 +38,7 @@ endif
# Platform compiler flags # Platform compiler flags
ifeq ($(OS),Darwin) ifeq ($(OS),Darwin)
CXX = $(shell wx-config --cxx) -D__WXMAC__ -std=c++11 CXX = $(shell wx-config --cxx) -D__WXMAC__ -std=gnu++11
LDLIBS += /usr/local/lib/libssh2.a LDLIBS += /usr/local/lib/libssh2.a
else else
LDLIBS += -lssh2 LDLIBS += -lssh2
@ -63,7 +63,7 @@ all: Tyro.app
endif endif
dev: DEV = true dev: DEV = true
dev: CXXFLAGS = $(DEV_CXXFLAGS) dev: CXXFLAGS += $(DEV_CXXFLAGS)
dev: all dev: all
json_wrapper: json_wrapper_build json_wrapper: json_wrapper_build
@ -152,12 +152,18 @@ endif
cp build/Tyro build/Tyro.app/Contents/MacOS/Tyro cp build/Tyro build/Tyro.app/Contents/MacOS/Tyro
cp resources/platform/osx/tyro.icns build/Tyro.app/Contents/Resources/ cp resources/platform/osx/tyro.icns build/Tyro.app/Contents/Resources/
$(TESTS): $(BASE_LIB)
$(foreach var, $(TEST_SRC), $(CXX) $(CXXFLAGS) $(var) $(BASE_LIB) $(WX_LDLIBS) $(LDLIBS) -o $(patsubst %.cpp,%, $(var));)
.PHONY: tests $(TESTS):
tests: $(TESTS) $(foreach var, $(TEST_SRC), $(CXX) $(CXXFLAGS) $(WX_CXXFLAGS) -c -o $(patsubst %.cpp,%.o,$(var)) $(var);)
sh ./tests/runtests.sh
.PHONY: tests
tests: LDLIBS += -lstdc++ -lCppUTestExt -lCppUTest
tests: $(TESTS) json_wrapper $(BASE_LIB) $(WIDGET_LIB)
$(patsubst g++,clang++, $(CXX)) $(CXXFLAGS) $(WX_CXXFLAGS) tests/main.cpp $(TESTS) $(WIDGET_LIB) $(BASE_LIB) $(WX_LDLIBS) $(LDLIBS) -o tests/runner
run-tests: tests
./tests/runner -v
clean: clean:
rm -f *.res rm -f *.res
@ -166,6 +172,7 @@ clean:
rm -f config/*_json.h rm -f config/*_json.h
rm -rf *.o rm -rf *.o
rm -rf build rm -rf build
rm -rf build $(OBJECTS) $(PROGRAM) $(BASE_LIB) $(CONFIG_LIB) $(WIDGET_LIB) $(TESTS) rm -rf $(OBJECTS) $(TESTS)
rm -f tests/runner
find . -name "*.gc*" -exec rm {} \; find . -name "*.gc*" -exec rm {} \;
rm -rf `find . -name "*.dSYM" -print` rm -rf `find . -name "*.dSYM" -print`

View File

@ -7,6 +7,8 @@
#include <wx/app.h> #include <wx/app.h>
#include <wx/sysopt.h> #include <wx/sysopt.h>
#include <wx/vidmode.h>
#include <wx/display.h>
// Some global stuff // Some global stuff
@ -14,9 +16,12 @@ wxConfigBase *Glob_config = nullptr;
TyroMenu *Glob_menu_bar = nullptr; TyroMenu *Glob_menu_bar = nullptr;
wxStatusBar *Glob_status_bar = nullptr; wxStatusBar *Glob_status_bar = nullptr;
MainFrame *Glob_main_frame = nullptr; MainFrame *Glob_main_frame = nullptr;
PrefPane *Glob_pref_pane = nullptr;
StringConstMap Glob_lexer_map; StringConstMap Glob_lexer_map;
#ifndef TRAVIS
PrefPane *Glob_pref_pane = nullptr;
#endif
// Static app loading variables // Static app loading variables
static wxArrayString files; static wxArrayString files;
static int param_count; static int param_count;
@ -44,8 +49,10 @@ public:
this->InitLexerMap(); this->InitLexerMap();
Glob_config = wxConfigBase::Get(); Glob_config = wxConfigBase::Get();
Glob_menu_bar = new TyroMenu(); Glob_menu_bar = new TyroMenu();
Glob_main_frame = new MainFrame(0L, APP_NAME); Glob_main_frame = new MainFrame(0L, APP_NAME, this->CalculateWindowSize());
#ifndef TRAVIS
Glob_pref_pane = new PrefPane(); Glob_pref_pane = new PrefPane();
#endif
// Setup Main Window // Setup Main Window
Glob_main_frame->Layout(); Glob_main_frame->Layout();
@ -144,6 +151,21 @@ private:
Glob_lexer_map["yaml"] = wxSTC_LEX_YAML; Glob_lexer_map["yaml"] = wxSTC_LEX_YAML;
} }
/**
* Calculate original window size based on size of the current monitor
*/
wxSize CalculateWindowSize()
{
wxDisplay display;
wxVideoMode mode = display.GetCurrentMode();
wxLogDebug("Current display: %ix%i", mode.w, mode.h);
wxSize base((int)((float)mode.w * 0.8), (int)((float)mode.h * 0.8));
return base;
}
/** /**
* Toolkit-specific settings * Toolkit-specific settings
*/ */

View File

@ -26,10 +26,7 @@ LangConfig::LangConfig()
/** /**
* Destructor * Destructor
*/ */
LangConfig::~LangConfig() LangConfig::~LangConfig() {}
{
wxLogDebug("Called LangConfig Destructor");
}
/** /**
* Determine the format of the current file by * Determine the format of the current file by

View File

@ -17,10 +17,7 @@ ThemeConfig::ThemeConfig()
/** /**
* Destructor * Destructor
*/ */
ThemeConfig::~ThemeConfig() ThemeConfig::~ThemeConfig() {}
{
wxLogDebug("Called ThemeConfig Destructor");
}
/** /**
* Set the current theme * Set the current theme

View File

@ -333,19 +333,16 @@ void EditPane::_ApplyTheme(JsonValue &lexer_map)
if ( ! HAS_FONT_BUG()) if ( ! HAS_FONT_BUG())
{ {
wxFont globalFont;
wxString fontFace; wxString fontFace;
int fontFamily = TYRO_DEFAULT_FONT_FAMILY; if ( ! Glob_config->Read("global_font", &globalFont))
int pointSize = TYRO_DEFAULT_FONT_SIZE; {
Glob_config->Read("global_font_face_name", fontFace); this->StyleSetFont(i, *defaultFont);
Glob_config->Read("global_font_family", fontFamily); }
Glob_config->Read("global_font_point_size", pointSize); else
{
wxFontInfo fInfo(pointSize); this->StyleSetFont(i, globalFont);
fInfo.Family((wxFontFamily) fontFamily).FaceName(fontFace); }
wxFont *font = new wxFont(fInfo);
this->StyleSetFont(i, *font);
} }
else else
{ {

View File

@ -31,8 +31,10 @@ FilePane::FilePane(
this->CreateContextMenu(); this->CreateContextMenu();
this->BindEvents(); this->BindEvents();
//this->SetDefaultPath(wxStandardPaths::Get().GetDocumentsDir()); this->CollapseTree();
//this->SetPath(this->GetDefaultPath());
this->SetDefaultPath(wxStandardPaths::Get().GetDocumentsDir() + "../");
this->SetPath(this->GetDefaultPath());
} }
/** /**
@ -40,6 +42,7 @@ FilePane::FilePane(
*/ */
FilePane::~FilePane() FilePane::~FilePane()
{ {
wxLogDebug("File Pane Destructor Called.");
delete this->contextMenu; delete this->contextMenu;
} }

View File

@ -9,7 +9,8 @@ public:
const wxString &dir = wxDirDialogDefaultFolderStr, const wxString &dir = wxDirDialogDefaultFolderStr,
const wxPoint &pos = wxDefaultPosition, const wxPoint &pos = wxDefaultPosition,
const wxSize &size = wxDefaultSize, const wxSize &size = wxDefaultSize,
long style = wxDIRCTRL_EDIT_LABELS | wxDIRCTRL_MULTIPLE, long style = wxDIRCTRL_3D_INTERNAL | wxDIRCTRL_EDIT_LABELS |
wxDIRCTRL_SHOW_FILTERS | wxDIRCTRL_MULTIPLE,
const wxString &filter = wxEmptyString const wxString &filter = wxEmptyString
); );
~FilePane(); ~FilePane();

View File

@ -5,24 +5,28 @@
// Nasty globals // Nasty globals
extern TyroMenu *Glob_menu_bar; extern TyroMenu *Glob_menu_bar;
extern PrefPane *Glob_pref_pane;
extern wxStatusBar *Glob_status_bar; extern wxStatusBar *Glob_status_bar;
static TabContainer *notebook = nullptr; static TabContainer *notebook = nullptr;
static FilePane *filePane = nullptr; static FilePane *filePane = nullptr;
#ifndef TRAVIS
extern PrefPane *Glob_pref_pane;
#endif
// Frame icon // Frame icon
#include "../../resources/xpm/tyro.xpm" #include "../../resources/xpm/tyro.xpm"
/** /**
* Constructor * Constructor
*/ */
MainFrame::MainFrame(wxFrame *frame, const wxString &title) MainFrame::MainFrame(wxFrame *frame, const wxString &title, const wxSize &size)
: wxFrame(frame, -1, title, wxDefaultPosition, wxSize(800,600)) : wxFrame(frame, -1, title, wxDefaultPosition, size)
{ {
// Create the tab container // Create the tab container
notebook = new TabContainer(this); notebook = new TabContainer(this);
filePane = new FilePane(this, wxID_ANY, wxStandardPaths::Get().GetDocumentsDir()); filePane = new FilePane(this);
// Set the frame icon // Set the frame icon
wxIcon app_icon(tyro_icon); wxIcon app_icon(tyro_icon);
@ -46,9 +50,9 @@ MainFrame::MainFrame(wxFrame *frame, const wxString &title)
MainFrame::~MainFrame() MainFrame::~MainFrame()
{ {
wxLogDebug("Main Frame Destructor Called."); wxLogDebug("Main Frame Destructor Called.");
delete notebook; //delete notebook;
delete toolBar; //delete toolBar;
delete filePane; //delete filePane;
wxDELETE(this->findDlg); wxDELETE(this->findDlg);
wxDELETE(this->findData); wxDELETE(this->findData);
@ -207,10 +211,11 @@ void MainFrame::BindEvents()
case wxID_REDO: case wxID_REDO:
if (editor->CanRedo()) editor->Redo(); if (editor->CanRedo()) editor->Redo();
break; break;
#ifndef TRAVIS
case wxID_PREFERENCES: case wxID_PREFERENCES:
Glob_pref_pane->Show(this); Glob_pref_pane->Show(this);
break; break;
#endif
case wxID_FIND: case wxID_FIND:
this->OnEditFind(event); this->OnEditFind(event);

View File

@ -10,7 +10,7 @@
class MainFrame: public wxFrame class MainFrame: public wxFrame
{ {
public: public:
MainFrame(wxFrame *frame, const wxString &title); MainFrame(wxFrame *frame, const wxString &title, const wxSize &size);
~MainFrame(); ~MainFrame();
void EnableEditControls(bool enable=true); void EnableEditControls(bool enable=true);
void OpenFiles(wxArrayString filelist); void OpenFiles(wxArrayString filelist);

View File

@ -2,6 +2,7 @@
extern wxConfigBase *Glob_config; extern wxConfigBase *Glob_config;
#ifndef TRAVIS
class GeneralPrefPanePage : public wxPanel { class GeneralPrefPanePage : public wxPanel {
public: public:
GeneralPrefPanePage(wxWindow *parent) GeneralPrefPanePage(wxWindow *parent)
@ -25,7 +26,7 @@ public:
wxNullFont, wxNullFont,
wxDefaultPosition, wxDefaultPosition,
wxDefaultSize, wxDefaultSize,
wxFNTP_USE_TEXTCTRL | wxFNTP_USEFONT_FOR_LABEL wxFNTP_USE_TEXTCTRL ^ wxFNTP_USEFONT_FOR_LABEL
); );
wxSizer *fontSizer = new wxBoxSizer(wxHORIZONTAL); wxSizer *fontSizer = new wxBoxSizer(wxHORIZONTAL);
fontSizer->Add(this->fontPicker, wxSizerFlags().Border()); fontSizer->Add(this->fontPicker, wxSizerFlags().Border());
@ -45,11 +46,7 @@ public:
if ( ! HAS_FONT_BUG()) if ( ! HAS_FONT_BUG())
{ {
this->fontPicker->Bind(wxEVT_FONTPICKER_CHANGED, [=] (wxFontPickerEvent &event) { this->fontPicker->Bind(wxEVT_FONTPICKER_CHANGED, [=] (wxFontPickerEvent &event) {
wxFont font = event.GetFont(); Glob_config->Write("global_font", event.GetFont());
Glob_config->Write("global_font_family", (int)font.GetFamily());
Glob_config->Write("global_font_face_name", font.GetFaceName());
Glob_config->Write("global_font_point_size", font.GetPointSize());
this->frame->OnPrefsChanged(event); this->frame->OnPrefsChanged(event);
Glob_config->Flush(); Glob_config->Flush();
}, myID_PREFS_FONT); }, myID_PREFS_FONT);
@ -92,18 +89,10 @@ public:
if ( ! HAS_FONT_BUG()) if ( ! HAS_FONT_BUG())
{ {
wxString fontFace; wxFont globalFont;
int fontFamily = TYRO_DEFAULT_FONT_FAMILY; Glob_config->Read("global_font", &globalFont);
int pointSize = TYRO_DEFAULT_FONT_SIZE;
Glob_config->Read("global_font_face_name", fontFace);
Glob_config->Read("global_font_family", fontFamily);
Glob_config->Read("global_font_point_size", pointSize);
wxFontInfo fInfo(pointSize); this->fontPicker->SetSelectedFont(globalFont);
fInfo.Family((wxFontFamily) fontFamily).FaceName(fontFace);
this->fontPicker->SetSelectedFont(wxFont(fInfo));
} }
return true; return true;
@ -123,10 +112,7 @@ public:
if ( ! HAS_FONT_BUG()) if ( ! HAS_FONT_BUG())
{ {
wxFont font = this->fontPicker->GetSelectedFont(); Glob_config->Write("global_font", this->fontPicker->GetSelectedFont());
Glob_config->Write("global_font_family", (int)font.GetFamily());
Glob_config->Write("global_font_face_name", font.GetFaceName());
Glob_config->Write("global_font_point_size", font.GetPointSize());
} }
wxCommandEvent evt = wxCommandEvent(); wxCommandEvent evt = wxCommandEvent();
@ -166,7 +152,7 @@ PrefPane::PrefPane()
PrefPane::~PrefPane() PrefPane::~PrefPane()
{ {
delete this->pref_window; //delete this->pref_window;
} }
void PrefPane::Show(wxWindow *parent) void PrefPane::Show(wxWindow *parent)
@ -174,6 +160,5 @@ void PrefPane::Show(wxWindow *parent)
this->pref_window->Show(parent); this->pref_window->Show(parent);
} }
#endif // ifndef TRAVIS

View File

@ -67,8 +67,10 @@ void TyroMenu::SetupMainMenus()
editMenu->AppendSeparator(); editMenu->AppendSeparator();
editMenu->Append(wxID_SELECTALL, "Select All\tCtrl+A", "Select all the text in the current document"); editMenu->Append(wxID_SELECTALL, "Select All\tCtrl+A", "Select all the text in the current document");
#ifndef TRAVIS
editMenu->AppendSeparator(); editMenu->AppendSeparator();
editMenu->Append(wxID_PREFERENCES, "&Preferences\tCtrl+P"); editMenu->Append(wxID_PREFERENCES, "&Preferences\tCtrl+P");
#endif
viewMenu->AppendCheckItem(myID_VIEW_WHITESPACE, "Show Invisible Characters\tCtrl+Shift+I", "Toggle visibility of white space characters"); viewMenu->AppendCheckItem(myID_VIEW_WHITESPACE, "Show Invisible Characters\tCtrl+Shift+I", "Toggle visibility of white space characters");
viewMenu->AppendCheckItem(myID_VIEW_LINE_ENDINGS, "Show line endings", "Toggle visibility of line ending characters"); viewMenu->AppendCheckItem(myID_VIEW_LINE_ENDINGS, "Show line endings", "Toggle visibility of line ending characters");

View File

@ -12,16 +12,23 @@
#include <wx/fdrepdlg.h> #include <wx/fdrepdlg.h>
#include <wx/aui/aui.h> #include <wx/aui/aui.h>
#include <wx/stc/stc.h> #include <wx/stc/stc.h>
#include <wx/preferences.h> #include <wx/treectrl.h>
#include <wx/dir.h>
#include <wx/dirctrl.h> #include <wx/dirctrl.h>
#include <wx/fontpicker.h> #include <wx/fontpicker.h>
#ifndef TRAVIS
#include <wx/preferences.h>
#endif
// Tyro includes // Tyro includes
#include "TyroMenu.h" #include "TyroMenu.h"
#include "EditPane.h" #include "EditPane.h"
#include "TabContainer.h" #include "TabContainer.h"
#include "MainFrame.h" #include "MainFrame.h"
#ifndef TRAVIS
#include "PrefPane.h" #include "PrefPane.h"
#endif
#include "FilePane.h" #include "FilePane.h"
#endif /* TYRO_WIDGET_H */ #endif /* TYRO_WIDGET_H */

View File

@ -29,7 +29,6 @@
#include <wx/font.h> #include <wx/font.h>
#include <wx/stdpaths.h> #include <wx/stdpaths.h>
#include <wx/platinfo.h> #include <wx/platinfo.h>
#include <wx/vidmode.h>
#include <wx/filename.h> #include <wx/filename.h>
#include <wx/artprov.h> #include <wx/artprov.h>

23
tests/ConfigTest.cpp Normal file
View File

@ -0,0 +1,23 @@
#include <CppUTest/TestHarness.h>
#include "../src/base/settings/Config.h"
TEST_GROUP(Config)
{
TyroConfig *config;
void setup()
{
config = new TyroConfig();
}
void teardown()
{
delete config;
}
};
TEST(Config, Create)
{
config->LoadJson("{\"foo\":\"bar\"}");
CHECK(config->GetRoot().isObject());
}

51
tests/LangConfigTest.cpp Normal file
View File

@ -0,0 +1,51 @@
#include <CppUTest/TestHarness.h>
#include "../src/settings/LangConfig.h"
TEST_GROUP(LangConfig)
{
LangConfig *config;
void setup()
{
config = new LangConfig();
}
void teardown()
{
delete config;
}
};
TEST(LangConfig, GetLangList)
{
StringMap list = config->GetLangList();
CHECK(list.size() > 0);
}
TEST(LangConfig, GetLang)
{
string lang;
lang = config->GetLang();
CHECK_EQUAL(lang, "");
}
TEST(LangConfig, SetLang)
{
string lang="cpp";
config->SetLang(lang);
CHECK_EQUAL(lang, config->GetLang());
}
TEST(LangConfig, GetLangByFile)
{
wxFileName file("foo.cpp");
string lang = config->GetLangByFile(file);
CHECK_EQUAL("cpp", lang);
}
TEST(LangConfig, GetLangByName)
{
string lang = config->GetLangByName("C / C++");
CHECK_EQUAL("cpp", lang);
}

View File

@ -1,22 +0,0 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "../src/base/network/SFTP.h"
TEST_CASE("ssh connections work", "[SFTP]") {
SFTP *sftp = new SFTP("shell.xshellz.com", "twarren", "of0fmk2dsj");
sftp->getFingerprint();
SECTION("sftp object is not null") {
REQUIRE(sftp != NULL);
}
SECTION("can retreive a file") {
string file;
file = sftp->getFile("test.txt");
REQUIRE(file != "");
REQUIRE(file == "SFTP works!\n");
}
}

File diff suppressed because it is too large Load Diff

10
tests/main.cpp Normal file
View File

@ -0,0 +1,10 @@
#include <CppUTest/CommandLineTestRunner.h>
int main(int argc, char *argv[])
{
MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
return CommandLineTestRunner::RunAllTests(argc, argv);
}
IMPORT_TEST_GROUP(Config);
IMPORT_TEST_GROUP(LangConfig);

View File

@ -1,9 +0,0 @@
for i in tests/*Test
do
if test -f $i
then
./$i
fi
done
echo ""