From 1443b08e50359d980a816c68ca6159b012f248bf Mon Sep 17 00:00:00 2001 From: eidheim Date: Wed, 25 May 2016 12:42:08 +0200 Subject: [PATCH] Added some more tests to source_clang_test, and fixed test error on OS X --- tests/clang_project/CMakeLists.txt | 2 +- tests/clang_project/main.cpp | 14 ++++++--- tests/source_clang_test.cc | 50 ++++++++++++++++++------------ 3 files changed, 42 insertions(+), 24 deletions(-) diff --git a/tests/clang_project/CMakeLists.txt b/tests/clang_project/CMakeLists.txt index dade4ec..d64d309 100644 --- a/tests/clang_project/CMakeLists.txt +++ b/tests/clang_project/CMakeLists.txt @@ -1 +1 @@ -project(hello) +project(test) diff --git a/tests/clang_project/main.cpp b/tests/clang_project/main.cpp index 811f08b..d1c3ab6 100644 --- a/tests/clang_project/main.cpp +++ b/tests/clang_project/main.cpp @@ -1,5 +1,11 @@ -#include - -int main() { - std::cout << "hello world\n"; +class Test { +public: + void function(); +}; + +void Test::function() {} + +int main() { + Test test; + test.function(); } diff --git a/tests/source_clang_test.cc b/tests/source_clang_test.cc index 64c4222..f85197a 100644 --- a/tests/source_clang_test.cc +++ b/tests/source_clang_test.cc @@ -3,10 +3,9 @@ #include "config.h" #include "filesystem.h" -std::string hello_world_error=R"(#include - -int main() { - std::cout << "hello world\n" +std::string main_error=R"(int main() { + int number=2; + number=3 } )"; @@ -15,6 +14,11 @@ int main() { //broadwayd& //make test +void flush_events() { + while(Gtk::Main::events_pending()) + Gtk::Main::iteration(false); +} + int main() { auto app=Gtk::Application::create(); Gsv::init(); @@ -22,22 +26,30 @@ int main() { Config::get().project.default_build_path="./build"; Source::ClangView *clang_view=new Source::ClangView(boost::filesystem::canonical(std::string(JUCI_TESTS_PATH)+"/clang_project/main.cpp"), Gsv::LanguageManager::get_default()->get_language("cpp")); - while(!clang_view->parsed) { - while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); - } - g_assert(clang_view->diagnostics.size()==0); - clang_view->get_buffer()->set_text(hello_world_error); - while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); - while(!clang_view->parsed) { - while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); - } - g_assert(clang_view->diagnostics.size()>0); + while(!clang_view->parsed) + flush_events(); + g_assert_cmpuint(clang_view->diagnostics.size(), ==, 0); + + clang_view->place_cursor_at_line_index(10-1, 8-1); + flush_events(); + auto location=clang_view->get_declaration_location({clang_view}); + g_assert_cmpuint(location.line, ==, 3); + clang_view->place_cursor_at_line_index(location.line-1, location.index-1); + flush_events(); + location=clang_view->get_implementation_location({clang_view}); + g_assert_cmpuint(location.line, ==, 6); + clang_view->place_cursor_at_line_index(location.line-1, location.index-1); + flush_events(); + location=clang_view->get_declaration_location({clang_view}); + g_assert_cmpuint(location.line, ==, 3); + + clang_view->get_buffer()->set_text(main_error); + flush_events(); + while(!clang_view->parsed) + flush_events(); + g_assert_cmpuint(clang_view->diagnostics.size(), >, 0); clang_view->async_delete(); clang_view->delete_thread.join(); - while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + flush_events(); }