Browse Source

Fixed usage cache count, simplified Gtk::Main::iteration calls, and added info message about background processes if any when quitting juCi++

merge-requests/399/head
eidheim 6 years ago
parent
commit
d52d84e16c
  1. 2
      src/dialogs.cc
  2. 2
      src/juci.cc
  3. 2
      src/notebook.cc
  4. 2
      src/selection_dialog.cc
  5. 8
      src/source_clang.cc
  6. 16
      src/usages_clang.cc
  7. 1
      src/usages_clang.h
  8. 14
      src/window.cc
  9. 2
      tests/source_clang_test.cc
  10. 80
      tests/source_key_test.cc
  11. 11
      tests/usages_clang_test.cc

2
src/dialogs.cc

@ -23,7 +23,7 @@ Dialog::Message::Message(const std::string &text) : Gtk::Window(Gtk::WindowType:
show_now(); show_now();
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
} }
bool Dialog::Message::on_delete_event(GdkEventAny *event) { bool Dialog::Message::on_delete_event(GdkEventAny *event) {

2
src/juci.cc

@ -105,7 +105,7 @@ void Application::on_activate() {
} }
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
for(auto view : Notebook::get().get_views()) for(auto view : Notebook::get().get_views())
view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5); view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5);
} }

2
src/notebook.cc

@ -168,7 +168,7 @@ void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_i
if(!show_tooltips) if(!show_tooltips)
view->hide_tooltips(); view->hide_tooltips();
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
if(get_current_view() == view) { if(get_current_view() == view) {
if(center) if(center)
view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5); view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5);

2
src/selection_dialog.cc

@ -166,7 +166,7 @@ void SelectionDialogBase::show() {
} }
else if(list_view_text.get_model()->children().begin() != list_view_text.get_selection()->get_selected()) { else if(list_view_text.get_model()->children().begin() != list_view_text.get_selection()->get_selected()) {
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
if(is_visible()) if(is_visible())
list_view_text.scroll_to_row(list_view_text.get_model()->get_path(list_view_text.get_selection()->get_selected()), 0.5); list_view_text.scroll_to_row(list_view_text.get_model()->get_path(list_view_text.get_selection()->get_selected()), 0.5);
} }

8
src/source_clang.cc

@ -1793,7 +1793,7 @@ void Source::ClangViewRefactor::wait_parsing() {
if(message) { if(message) {
for(;;) { for(;;) {
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
bool all_parsed = true; bool all_parsed = true;
for(auto &clang_view : clang_views) { for(auto &clang_view : clang_views) {
if(!clang_view->parsed) { if(!clang_view->parsed) {
@ -1927,7 +1927,7 @@ void Source::ClangView::async_delete() {
} }
auto before_parse_time = std::time(nullptr); auto before_parse_time = std::time(nullptr);
delete_thread = std::thread([this, before_parse_time, project_paths_in_use = std::move(project_paths_in_use)] { delete_thread = std::thread([this, before_parse_time, project_paths_in_use = std::move(project_paths_in_use), buffer_modified = get_buffer()->get_modified()] {
while(!parsed) while(!parsed)
std::this_thread::sleep_for(std::chrono::milliseconds(10)); std::this_thread::sleep_for(std::chrono::milliseconds(10));
@ -1935,7 +1935,7 @@ void Source::ClangView::async_delete() {
parse_state = ParseState::STOP; parse_state = ParseState::STOP;
dispatcher.disconnect(); dispatcher.disconnect();
if(get_buffer()->get_modified()) { if(buffer_modified) {
std::ifstream stream(file_path.string(), std::ios::binary); std::ifstream stream(file_path.string(), std::ios::binary);
if(stream) { if(stream) {
std::string buffer; std::string buffer;
@ -1953,6 +1953,8 @@ void Source::ClangView::async_delete() {
auto build = Project::Build::create(file_path); auto build = Project::Build::create(file_path);
Usages::Clang::cache(build->project_path, build->get_default_path(), file_path, before_parse_time, project_paths_in_use, clang_tu.get(), clang_tokens.get()); Usages::Clang::cache(build->project_path, build->get_default_path(), file_path, before_parse_time, project_paths_in_use, clang_tu.get(), clang_tokens.get());
} }
else
Usages::Clang::cancel_cache_in_progress();
if(full_reparse_thread.joinable()) if(full_reparse_thread.joinable())
full_reparse_thread.join(); full_reparse_thread.join();

16
src/usages_clang.cc

@ -165,7 +165,7 @@ std::vector<Usages::Clang::Usages> Usages::Clang::get_usages(const boost::filesy
message = std::make_unique<Dialog::Message>(message_string); message = std::make_unique<Dialog::Message>(message_string);
while(cache_in_progress_count != 0) { while(cache_in_progress_count != 0) {
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
} }
} }
@ -359,8 +359,14 @@ void Usages::Clang::erase_all_caches_for_project(const boost::filesystem::path &
if(project_path.empty()) if(project_path.empty())
return; return;
if(cache_in_progress_count != 0) if(cache_in_progress_count != 0) {
std::this_thread::sleep_for(std::chrono::milliseconds(10)); Dialog::Message message("Please wait while clearing project parse cache");
while(cache_in_progress_count != 0) {
while(Gtk::Main::events_pending())
Gtk::Main::iteration();
}
message.hide();
}
LockGuard lock(caches_mutex); LockGuard lock(caches_mutex);
boost::system::error_code ec; boost::system::error_code ec;
@ -384,6 +390,10 @@ void Usages::Clang::cache_in_progress() {
++cache_in_progress_count; ++cache_in_progress_count;
} }
void Usages::Clang::cancel_cache_in_progress() {
--cache_in_progress_count;
}
void Usages::Clang::add_usages(const boost::filesystem::path &project_path, const boost::filesystem::path &build_path, const boost::filesystem::path &path_, void Usages::Clang::add_usages(const boost::filesystem::path &project_path, const boost::filesystem::path &build_path, const boost::filesystem::path &path_,
std::vector<Usages> &usages, PathSet &visited, const std::string &spelling, clangmm::Cursor cursor, std::vector<Usages> &usages, PathSet &visited, const std::string &spelling, clangmm::Cursor cursor,
clangmm::TranslationUnit *translation_unit, bool store_in_cache) { clangmm::TranslationUnit *translation_unit, bool store_in_cache) {

1
src/usages_clang.h

@ -117,6 +117,7 @@ namespace Usages {
static void erase_cache(const boost::filesystem::path &path); static void erase_cache(const boost::filesystem::path &path);
static void erase_all_caches_for_project(const boost::filesystem::path &project_path, const boost::filesystem::path &build_path); static void erase_all_caches_for_project(const boost::filesystem::path &project_path, const boost::filesystem::path &build_path);
static void cache_in_progress(); static void cache_in_progress();
static void cancel_cache_in_progress();
private: private:
static void add_usages(const boost::filesystem::path &project_path, const boost::filesystem::path &build_path, const boost::filesystem::path &path_, static void add_usages(const boost::filesystem::path &project_path, const boost::filesystem::path &build_path, const boost::filesystem::path &path_,

14
src/window.cc

@ -105,13 +105,19 @@ Window::Window() {
return false; return false;
}); });
signal_hide().connect([] { signal_delete_event().connect([](GdkEventAny *) {
while(!Source::View::non_deleted_views.empty()) { if(!Source::View::non_deleted_views.empty()) {
while(Gtk::Main::events_pending()) Dialog::Message message("Please wait while completing background processes");
Gtk::Main::iteration(false); while(!Source::View::non_deleted_views.empty()) {
while(Gtk::Main::events_pending())
Gtk::Main::iteration();
}
message.hide();
} }
// TODO 2022 (after Debian Stretch LTS has ended, see issue #354): remove: // TODO 2022 (after Debian Stretch LTS has ended, see issue #354): remove:
Project::current = nullptr; Project::current = nullptr;
return false;
}); });
Gtk::Settings::get_default()->connect_property_changed("gtk-theme-name", [] { Gtk::Settings::get_default()->connect_property_changed("gtk-theme-name", [] {

2
tests/source_clang_test.cc

@ -16,7 +16,7 @@ std::string main_error = R"(int main() {
void flush_events() { void flush_events() {
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
} }
int main() { int main() {

80
tests/source_key_test.cc

@ -27,7 +27,7 @@ int main() {
{ {
buffer->set_text(" ''\n"); buffer->set_text(" ''\n");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
auto iter = buffer->get_iter_at_line(0); auto iter = buffer->get_iter_at_line(0);
iter.forward_chars(3); iter.forward_chars(3);
assert(view.is_spellcheck_iter(iter)); assert(view.is_spellcheck_iter(iter));
@ -36,7 +36,7 @@ int main() {
{ {
buffer->set_text(" \"\"\n"); buffer->set_text(" \"\"\n");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
auto iter = buffer->get_iter_at_line(0); auto iter = buffer->get_iter_at_line(0);
iter.forward_chars(3); iter.forward_chars(3);
assert(view.is_spellcheck_iter(iter)); assert(view.is_spellcheck_iter(iter));
@ -45,7 +45,7 @@ int main() {
{ {
buffer->set_text(" 'test\n"); buffer->set_text(" 'test\n");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
auto iter = buffer->get_iter_at_line(0); auto iter = buffer->get_iter_at_line(0);
iter.forward_to_line_end(); iter.forward_to_line_end();
assert(view.is_spellcheck_iter(iter)); assert(view.is_spellcheck_iter(iter));
@ -54,7 +54,7 @@ int main() {
{ {
buffer->set_text(" \"test'\n"); buffer->set_text(" \"test'\n");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
auto iter = buffer->get_iter_at_line(0); auto iter = buffer->get_iter_at_line(0);
iter.forward_to_line_end(); iter.forward_to_line_end();
iter.backward_char(); iter.backward_char();
@ -67,7 +67,7 @@ int main() {
{ {
buffer->set_text(" 'test'\n"); buffer->set_text(" 'test'\n");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
auto iter = buffer->get_iter_at_line(0); auto iter = buffer->get_iter_at_line(0);
iter.forward_chars(2); iter.forward_chars(2);
assert(!view.is_spellcheck_iter(iter)); assert(!view.is_spellcheck_iter(iter));
@ -85,7 +85,7 @@ int main() {
{ {
buffer->set_text(" \"test\"\n"); buffer->set_text(" \"test\"\n");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
auto iter = buffer->get_iter_at_line(0); auto iter = buffer->get_iter_at_line(0);
iter.forward_chars(2); iter.forward_chars(2);
assert(!view.is_spellcheck_iter(iter)); assert(!view.is_spellcheck_iter(iter));
@ -103,7 +103,7 @@ int main() {
{ {
buffer->set_text(" '\\''\n"); buffer->set_text(" '\\''\n");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
auto iter = buffer->get_iter_at_line(0); auto iter = buffer->get_iter_at_line(0);
iter.forward_chars(2); iter.forward_chars(2);
assert(!view.is_spellcheck_iter(iter)); assert(!view.is_spellcheck_iter(iter));
@ -124,7 +124,7 @@ int main() {
{ {
buffer->set_text(" /**/\n"); buffer->set_text(" /**/\n");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
auto iter = buffer->get_iter_at_line(0); auto iter = buffer->get_iter_at_line(0);
iter.forward_chars(2); iter.forward_chars(2);
assert(!view.is_spellcheck_iter(iter)); assert(!view.is_spellcheck_iter(iter));
@ -145,7 +145,7 @@ int main() {
{ {
buffer->set_text(" //t\n"); buffer->set_text(" //t\n");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
auto iter = buffer->get_iter_at_line(0); auto iter = buffer->get_iter_at_line(0);
iter.forward_chars(2); iter.forward_chars(2);
assert(!view.is_spellcheck_iter(iter)); assert(!view.is_spellcheck_iter(iter));
@ -474,7 +474,7 @@ int main() {
{ {
buffer->set_text(" int main() {//comment"); buffer->set_text(" int main() {//comment");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
view.on_key_press_event(&event); view.on_key_press_event(&event);
g_assert(buffer->get_text() == " int main() {//comment\n" g_assert(buffer->get_text() == " int main() {//comment\n"
" \n" " \n"
@ -511,7 +511,7 @@ int main() {
iter.backward_chars(4); iter.backward_chars(4);
buffer->place_cursor(iter); buffer->place_cursor(iter);
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
view.on_key_press_event(&event); view.on_key_press_event(&event);
g_assert(buffer->get_text() == " int main() {//comment\n" g_assert(buffer->get_text() == " int main() {//comment\n"
" \n" " \n"
@ -578,7 +578,7 @@ int main() {
iter.backward_chars(1); iter.backward_chars(1);
buffer->place_cursor(iter); buffer->place_cursor(iter);
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
view.on_key_press_event(&event); view.on_key_press_event(&event);
g_assert(buffer->get_text() == " int main()\n" g_assert(buffer->get_text() == " int main()\n"
" {/*comment*/\n" " {/*comment*/\n"
@ -598,7 +598,7 @@ int main() {
{ {
buffer->set_text(" else // comment"); buffer->set_text(" else // comment");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
view.on_key_press_event(&event); view.on_key_press_event(&event);
g_assert(buffer->get_text() == " else // comment\n" g_assert(buffer->get_text() == " else // comment\n"
" "); " ");
@ -614,7 +614,7 @@ int main() {
{ {
buffer->set_text(" else;//comment"); buffer->set_text(" else;//comment");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
view.on_key_press_event(&event); view.on_key_press_event(&event);
g_assert(buffer->get_text() == " else;//comment\n" g_assert(buffer->get_text() == " else;//comment\n"
" "); " ");
@ -630,7 +630,7 @@ int main() {
{ {
buffer->set_text(" else {}//comment"); buffer->set_text(" else {}//comment");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
view.on_key_press_event(&event); view.on_key_press_event(&event);
g_assert(buffer->get_text() == " else {}//comment\n" g_assert(buffer->get_text() == " else {}//comment\n"
" "); " ");
@ -654,7 +654,7 @@ int main() {
{ {
buffer->set_text(" } else if(true)//comment"); buffer->set_text(" } else if(true)//comment");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
view.on_key_press_event(&event); view.on_key_press_event(&event);
g_assert(buffer->get_text() == " } else if(true)//comment\n" g_assert(buffer->get_text() == " } else if(true)//comment\n"
" "); " ");
@ -673,7 +673,7 @@ int main() {
buffer->set_text(" } else if(true)//comment\n" buffer->set_text(" } else if(true)//comment\n"
" ;//comment"); " ;//comment");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
view.on_key_press_event(&event); view.on_key_press_event(&event);
g_assert(buffer->get_text() == " } else if(true)//comment\n" g_assert(buffer->get_text() == " } else if(true)//comment\n"
" ;//comment\n" " ;//comment\n"
@ -694,7 +694,7 @@ int main() {
buffer->set_text(" if(true) { /*comment*/\n" buffer->set_text(" if(true) { /*comment*/\n"
" ;"); " ;");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
view.on_key_press_event(&event); view.on_key_press_event(&event);
g_assert(buffer->get_text() == " if(true) { /*comment*/\n" g_assert(buffer->get_text() == " if(true) { /*comment*/\n"
" ;\n" " ;\n"
@ -745,7 +745,7 @@ int main() {
buffer->set_text(" if(true && // comment\n" buffer->set_text(" if(true && // comment\n"
" false) { // comment"); " false) { // comment");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
view.on_key_press_event(&event); view.on_key_press_event(&event);
g_assert(buffer->get_text() == " if(true && // comment\n" g_assert(buffer->get_text() == " if(true && // comment\n"
" false) { // comment\n" " false) { // comment\n"
@ -771,7 +771,7 @@ int main() {
" false)//comment\n" " false)//comment\n"
" ;//comment"); " ;//comment");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
view.on_key_press_event(&event); view.on_key_press_event(&event);
g_assert(buffer->get_text() == " if(true &&\n" g_assert(buffer->get_text() == " if(true &&\n"
" false)//comment\n" " false)//comment\n"
@ -828,7 +828,7 @@ int main() {
buffer->set_text(" int a = 2 + // test\n" buffer->set_text(" int a = 2 + // test\n"
" 2;"); " 2;");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
view.on_key_press_event(&event); view.on_key_press_event(&event);
g_assert(buffer->get_text() == " int a = 2 + // test\n" g_assert(buffer->get_text() == " int a = 2 + // test\n"
" 2;\n" " 2;\n"
@ -1085,7 +1085,7 @@ int main() {
{ {
buffer->set_text(" auto func=[] {//comment"); buffer->set_text(" auto func=[] {//comment");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
view.on_key_press_event(&event); view.on_key_press_event(&event);
g_assert(buffer->get_text() == " auto func=[] {//comment\n" g_assert(buffer->get_text() == " auto func=[] {//comment\n"
" \n" " \n"
@ -1193,7 +1193,7 @@ int main() {
buffer->set_text(" class Class : BaseClass {\n" buffer->set_text(" class Class : BaseClass {\n"
" public://comment"); " public://comment");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
view.on_key_press_event(&event); view.on_key_press_event(&event);
g_assert(buffer->get_text() == " class Class : BaseClass {\n" g_assert(buffer->get_text() == " class Class : BaseClass {\n"
" public://comment\n" " public://comment\n"
@ -1285,7 +1285,7 @@ int main() {
{ {
buffer->set_text(" /*"); buffer->set_text(" /*");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
view.on_key_press_event(&event); view.on_key_press_event(&event);
g_assert(buffer->get_text() == " /*\n" g_assert(buffer->get_text() == " /*\n"
" * "); " * ");
@ -1295,7 +1295,7 @@ int main() {
buffer->set_text(" /*\n" buffer->set_text(" /*\n"
" */"); " */");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
view.on_key_press_event(&event); view.on_key_press_event(&event);
g_assert(buffer->get_text() == " /*\n" g_assert(buffer->get_text() == " /*\n"
" */\n" " */\n"
@ -1305,7 +1305,7 @@ int main() {
{ {
buffer->set_text(" //comment"); buffer->set_text(" //comment");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
view.on_key_press_event(&event); view.on_key_press_event(&event);
g_assert(buffer->get_text() == " //comment\n" g_assert(buffer->get_text() == " //comment\n"
" "); " ");
@ -1315,7 +1315,7 @@ int main() {
buffer->set_text(" //comment\n" buffer->set_text(" //comment\n"
" //comment"); " //comment");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
view.on_key_press_event(&event); view.on_key_press_event(&event);
g_assert(buffer->get_text() == " //comment\n" g_assert(buffer->get_text() == " //comment\n"
" //comment\n" " //comment\n"
@ -1326,7 +1326,7 @@ int main() {
buffer->set_text("#test\n" buffer->set_text("#test\n"
" test();"); " test();");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
auto iter = buffer->get_iter_at_line(0); auto iter = buffer->get_iter_at_line(0);
iter.forward_to_line_end(); iter.forward_to_line_end();
buffer->place_cursor(iter); buffer->place_cursor(iter);
@ -1342,7 +1342,7 @@ int main() {
buffer->set_text(" #test\n" buffer->set_text(" #test\n"
" test();"); " test();");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
auto iter = buffer->get_iter_at_line(0); auto iter = buffer->get_iter_at_line(0);
iter.forward_to_line_end(); iter.forward_to_line_end();
buffer->place_cursor(iter); buffer->place_cursor(iter);
@ -1361,7 +1361,7 @@ int main() {
iter.backward_char(); iter.backward_char();
buffer->place_cursor(iter); buffer->place_cursor(iter);
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
view.on_key_press_event(&event); view.on_key_press_event(&event);
g_assert(buffer->get_text() == "if('a'=='a'\n" g_assert(buffer->get_text() == "if('a'=='a'\n"
" )"); " )");
@ -1392,7 +1392,7 @@ int main() {
buffer->set_text(" else if(true)//comment\n" buffer->set_text(" else if(true)//comment\n"
" "); " ");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
view.on_key_press_event(&event); view.on_key_press_event(&event);
g_assert(buffer->get_text() == " else if(true)//comment\n" g_assert(buffer->get_text() == " else if(true)//comment\n"
" {"); " {");
@ -1516,7 +1516,7 @@ int main() {
{ {
buffer->set_text(" {} //}"); buffer->set_text(" {} //}");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
auto iter = buffer->begin(); auto iter = buffer->begin();
iter.forward_chars(3); iter.forward_chars(3);
buffer->place_cursor(iter); buffer->place_cursor(iter);
@ -1624,7 +1624,7 @@ int main() {
buffer->set_text(" else if(true)//comment\n" buffer->set_text(" else if(true)//comment\n"
" "); " ");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
view.on_key_press_event(&event); view.on_key_press_event(&event);
g_assert(buffer->get_text() == " else if(true)//comment\n" g_assert(buffer->get_text() == " else if(true)//comment\n"
" {}"); " {}");
@ -1704,7 +1704,7 @@ int main() {
buffer->set_text(" if(true) // test\n" buffer->set_text(" if(true) // test\n"
" ;"); " ;");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
auto iter = buffer->get_iter_at_line(0); auto iter = buffer->get_iter_at_line(0);
iter.forward_chars(11); iter.forward_chars(11);
buffer->place_cursor(iter); buffer->place_cursor(iter);
@ -1719,7 +1719,7 @@ int main() {
buffer->set_text(" if(true) // test\n" buffer->set_text(" if(true) // test\n"
" ;"); " ;");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
auto iter = buffer->get_iter_at_line(0); auto iter = buffer->get_iter_at_line(0);
iter.forward_chars(11); iter.forward_chars(11);
buffer->place_cursor(iter); buffer->place_cursor(iter);
@ -1847,7 +1847,7 @@ int main() {
buffer->set_text(" int main() {//comment\n" buffer->set_text(" int main() {//comment\n"
" "); " ");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
view.on_key_press_event(&event); view.on_key_press_event(&event);
g_assert(buffer->get_text() == " int main() {//comment\n" g_assert(buffer->get_text() == " int main() {//comment\n"
" }"); " }");
@ -2076,7 +2076,7 @@ int main() {
"\n" "\n"
" test"); " test");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
auto iter = buffer->get_iter_at_line(2); auto iter = buffer->get_iter_at_line(2);
buffer->place_cursor(iter); buffer->place_cursor(iter);
view.on_key_press_event(&event); view.on_key_press_event(&event);
@ -2110,7 +2110,7 @@ int main() {
"\n" "\n"
" test"); " test");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
auto iter = buffer->get_iter_at_line(2); auto iter = buffer->get_iter_at_line(2);
buffer->place_cursor(iter); buffer->place_cursor(iter);
view.on_key_press_event(&event); view.on_key_press_event(&event);
@ -2489,7 +2489,7 @@ int main() {
buffer->set_text("\n" buffer->set_text("\n"
" * [test](https://test.org)\n"); " * [test](https://test.org)\n");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
auto iter = buffer->get_iter_at_line(1); auto iter = buffer->get_iter_at_line(1);
iter.forward_to_line_end(); iter.forward_to_line_end();
buffer->place_cursor(iter); buffer->place_cursor(iter);
@ -2505,7 +2505,7 @@ int main() {
buffer->set_text("\n" buffer->set_text("\n"
" * [test](https://test.org)"); " * [test](https://test.org)");
while(Gtk::Main::events_pending()) while(Gtk::Main::events_pending())
Gtk::Main::iteration(false); Gtk::Main::iteration();
view.on_key_press_event(&event); view.on_key_press_event(&event);
g_assert(buffer->get_text() == "\n" g_assert(buffer->get_text() == "\n"
" * [test](https://test.org)\n" " * [test](https://test.org)\n"

11
tests/usages_clang_test.cc

@ -5,10 +5,17 @@
#include "usages_clang.h" #include "usages_clang.h"
#include <cassert> #include <cassert>
#include <fstream> #include <fstream>
#include <gtksourceviewmm.h>
#include <iostream> //Requires display server to work
//However, it is possible to use the Broadway backend if the test is run in a pure terminal environment:
//broadwayd&
//make test
int main() { int main() {
auto app = Gtk::Application::create();
Gsv::init();
auto tests_path = boost::filesystem::canonical(JUCI_TESTS_PATH); auto tests_path = boost::filesystem::canonical(JUCI_TESTS_PATH);
auto project_path = boost::filesystem::canonical(tests_path / "usages_clang_test_files"); auto project_path = boost::filesystem::canonical(tests_path / "usages_clang_test_files");
auto build_path = project_path / "build"; auto build_path = project_path / "build";
@ -148,6 +155,7 @@ int main() {
} }
Usages::Clang::erase_unused_caches({project_path}); Usages::Clang::erase_unused_caches({project_path});
Usages::Clang::cache_in_progress();
Usages::Clang::cache(project_path, build_path, path, time(nullptr), {project_path}, &translation_unit, tokens.get()); Usages::Clang::cache(project_path, build_path, path, time(nullptr), {project_path}, &translation_unit, tokens.get());
assert(Usages::Clang::caches.size() == 3); assert(Usages::Clang::caches.size() == 3);
assert(Usages::Clang::caches.find(project_path / "main.cpp") != Usages::Clang::caches.end()); assert(Usages::Clang::caches.find(project_path / "main.cpp") != Usages::Clang::caches.end());
@ -155,6 +163,7 @@ int main() {
assert(Usages::Clang::caches.find(project_path / "test2.hpp") != Usages::Clang::caches.end()); assert(Usages::Clang::caches.find(project_path / "test2.hpp") != Usages::Clang::caches.end());
Usages::Clang::erase_unused_caches({}); Usages::Clang::erase_unused_caches({});
Usages::Clang::cache_in_progress();
Usages::Clang::cache(project_path, build_path, path, time(nullptr), {}, &translation_unit, tokens.get()); Usages::Clang::cache(project_path, build_path, path, time(nullptr), {}, &translation_unit, tokens.get());
assert(Usages::Clang::caches.size() == 0); assert(Usages::Clang::caches.size() == 0);

Loading…
Cancel
Save