diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b81a0f..eee5b55 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,8 +46,8 @@ jobs: # build canvas-sync - run: make build - # - name: Run tests - # run: ./build/test/CanvasSyncTest + - name: Run tests + run: ./build/test/CanvasSyncTest # package app - run: | @@ -90,7 +90,9 @@ jobs: with: arch: win64_msvc2019_64 version: ${{ matrix.version }} + setup-python: false tools: tools_ifw + archives: qtbase qttools - name: Install MSVC 2022 uses: ilammy/msvc-dev-cmd@v1 @@ -109,10 +111,8 @@ jobs: -DCMAKE_PREFIX_PATH=${{ env.Qt6_DIR }} cmake --build build --parallel - # - name: Run tests - # run: | - # ls build/test - # ./build/test/CanvasSyncTest.exe + - name: Run tests + run: ./build/test/CanvasSyncTest.exe -tap - name: Use windeployqt to load libraries shell: bash diff --git a/Makefile b/Makefile index b159f7f..28384ea 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ QT_SRC_DIR ?= $(MAKEFILE_DIR)/Qt/src QT_CFG_ARGS := -opensource -release -static -nomake examples -nomake tests -skip qt3d -skip qttranslations -skip qt5compat -skip qtactiveqt -skip qtcharts -skip qtcoap -skip qtconnectivity -skip qtdatavis3d -skip qtdeclarative -skip qtdoc -skip qthttpserver -skip qtlanguageserver -skip qtlottie -skip qtmqtt -skip qtmultimedia -skip qtnetworkauth -skip qtopcua -skip qtpositioning -skip qtquick3d -skip qtquick3dphysics -skip qtquicktimeline -skip qtremoteobjects -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtshadertools -skip qtspeech -skip qtsvg -skip qttools -skip qtwebsockets QT_INIT_ARGS := --module-subset=qtbase -QT_VERSION ?= 6.2.0 +QT_VERSION ?= 6.2.4 main: @make --no-print-directory build diff --git a/app/clickable_tree_view.cc b/app/clickable_tree_view.cc index 64c385a..a10a691 100644 --- a/app/clickable_tree_view.cc +++ b/app/clickable_tree_view.cc @@ -32,6 +32,7 @@ ClickableTreeView::ClickableTreeView(QWidget *parent) : QTreeView(parent) setContextMenuPolicy(Qt::CustomContextMenu); connect(this, &QTreeView::customContextMenuRequested, this, [&](const QPoint &pos) { this->context_menu(pos); }); + this->hideColumn(TreeIndex::FOLDER_ID); } TreeModel *ClickableTreeView::model() const @@ -42,6 +43,7 @@ TreeModel *ClickableTreeView::model() const void ClickableTreeView::setModel(TreeModel *model) { QTreeView::setModel(model); + this->hideColumn(TreeIndex::FOLDER_ID); this->expand_tracked(); }; diff --git a/app/include/csync/tree_model.h b/app/include/csync/tree_model.h index 373ac26..08c87bb 100644 --- a/app/include/csync/tree_model.h +++ b/app/include/csync/tree_model.h @@ -16,16 +16,16 @@ class TreeIndex : public QModelIndex { - QString data(int i) const { return siblingAtColumn(i).data().toString(); } + QString data_at(int i) const { return siblingAtColumn(i).data().toString(); } public: enum TreeCol { REMOTE_DIR, LOCAL_DIR, FOLDER_ID }; TreeIndex(const QModelIndex i) : QModelIndex(i){}; - const QModelIndex index() { return this->index(); } - QString id() const { return data(TreeCol::FOLDER_ID); } - QString local_dir() const { return data(TreeCol::LOCAL_DIR); } - QString remote_dir() const { return data(TreeCol::REMOTE_DIR); } + const QModelIndex index() { return *this; } + QString id() const { return this->data_at(TreeCol::FOLDER_ID); } + QString local_dir() const { return this->data_at(TreeCol::LOCAL_DIR); } + QString remote_dir() const { return this->data_at(TreeCol::REMOTE_DIR); } QString course() const { @@ -61,8 +61,10 @@ class TreeIndex : public QModelIndex { int i = 0; const QAbstractItemModel *m = this->model(); - while (m->index(i, 0, this->index()).isValid()) + while (m->index(i, 0, this->index()).isValid()) { + qDebug() << m->index(i + 1, 0, this->index()); i++; + } return i; } }; @@ -107,9 +109,9 @@ class TreeItem public: std::vector resolve_folders(); - QString get_id() const { return str_data(TreeIndex::FOLDER_ID); }; - QString get_local_dir() const { return str_data(TreeIndex::LOCAL_DIR); }; - QString get_remote_dir() const { return str_data(TreeIndex::REMOTE_DIR); }; + QString id() const { return str_data(TreeIndex::FOLDER_ID); }; + QString local_dir() const { return str_data(TreeIndex::LOCAL_DIR); }; + QString remote_dir() const { return str_data(TreeIndex::REMOTE_DIR); }; private: QVector itemData; diff --git a/app/include/csync/ui_mainwindow.h b/app/include/csync/ui_mainwindow.h index 9824e2f..7602f7a 100644 --- a/app/include/csync/ui_mainwindow.h +++ b/app/include/csync/ui_mainwindow.h @@ -1,7 +1,7 @@ /******************************************************************************** ** Form generated from reading UI file 'mainwindow.ui' ** -** Created by: Qt User Interface Compiler version 6.2.0 +** Created by: Qt User Interface Compiler version 6.2.4 ** ** WARNING! All changes made in this file will be lost when recompiling UI file! ********************************************************************************/ diff --git a/app/include/csync/ui_updates.h b/app/include/csync/ui_updates.h index 3532951..27b3b02 100644 --- a/app/include/csync/ui_updates.h +++ b/app/include/csync/ui_updates.h @@ -1,7 +1,7 @@ /******************************************************************************** ** Form generated from reading UI file 'updates.ui' ** -** Created by: Qt User Interface Compiler version 6.2.0 +** Created by: Qt User Interface Compiler version 6.2.4 ** ** WARNING! All changes made in this file will be lost when recompiling UI file! ********************************************************************************/ diff --git a/app/mainwindow.cc b/app/mainwindow.cc index 9ecbfc0..a3f3e76 100644 --- a/app/mainwindow.cc +++ b/app/mainwindow.cc @@ -15,9 +15,9 @@ void MainWindow::setup_ui() ui->pushButton_changeToken->hide(); ui->pushButton_changeToken->setEnabled(false); ui->progressBar->hide(); - ui->treeView->setModel(newTreeModel()); ui->guideText->hide(); ui->label_accessTokenHelp->hide(); + ui->treeView->setModel(newTreeModel()); } void MainWindow::connect_ui() @@ -370,7 +370,7 @@ std::vector MainWindow::gather_tracked() TreeModel *MainWindow::newTreeModel() { - return new TreeModel({"canvas folder", "local folder"}); + return new TreeModel({"canvas folder", "local folder", ""}); }; const QString MainWindow::settings_path = diff --git a/app/tree_model.cc b/app/tree_model.cc index 57eb52d..4d823d7 100644 --- a/app/tree_model.cc +++ b/app/tree_model.cc @@ -148,14 +148,14 @@ void TreeItem::track_folder(const TreeIndex &ti, const QString &dir, // clear children maps on_all_children([&](TreeItem &child) { child.setData(TreeIndex::LOCAL_DIR, ""); - QString folder_id = child.get_id(); + QString folder_id = child.id(); if (!folder_id.isEmpty()) settings.remove(folder_id); }); // clear parent maps on_all_parents([&](TreeItem &parent) { parent.setData(TreeIndex::LOCAL_DIR, ""); - QString folder_id = parent.get_id(); + QString folder_id = parent.id(); if (!folder_id.isEmpty()) settings.remove(folder_id); }); @@ -168,13 +168,13 @@ void TreeItem::track_folder(const TreeIndex &ti, const QString &dir, void resolve_all_folders(TreeItem *item, std::filesystem::path *local_base_dir, std::filesystem::path *cwd, std::vector *list) { - std::string local_dir = item->get_local_dir().toStdString(); + std::string local_dir = item->local_dir().toStdString(); std::filesystem::path new_cwd; std::filesystem::path new_base = *local_base_dir; if (!local_base_dir->empty()) { - new_cwd = *cwd / item->get_remote_dir().toStdString(); + new_cwd = *cwd / item->remote_dir().toStdString(); } // one-time thing. on any path downwards it is guaranteed to only have @@ -184,7 +184,7 @@ void resolve_all_folders(TreeItem *item, std::filesystem::path *local_base_dir, } if (!new_base.empty()) { - list->push_back(Folder(item->get_id().toInt(), new_base / new_cwd)); + list->push_back(Folder(item->id().toInt(), new_base / new_cwd)); } auto children = item->childrenItems(); @@ -205,7 +205,7 @@ std::vector TreeItem::resolve_folders() std::filesystem::path base = ""; resolve_all_folders(child, &base, &p, &fl); } - int id = this->get_id().toInt(); + int id = this->id().toInt(); for (size_t i = 0; i < fl.size(); i++) { fl[i].course_id = id; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d317d95..2463c85 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -8,7 +8,6 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -enable_testing(TRUE) find_package(Qt6 REQUIRED COMPONENTS Widgets Network Gui Test) @@ -27,10 +26,6 @@ target_link_libraries(${TEST_NAME} PRIVATE csync ) -install(TARGETS ${TEST_NAME} - BUNDLE DESTINATION . - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) - qt_finalize_target(${TEST_NAME}) add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME}) diff --git a/test/main.cc b/test/main.cc index c114bb1..3bc84fb 100644 --- a/test/main.cc +++ b/test/main.cc @@ -2,19 +2,18 @@ QTEST_MAIN(TestGui) -void TestGui::authenticate(MainWindow *app) +void TestGui::authenticate() { - QPushButton *change_token = app->ui->pushButton_changeToken; + QPushButton *change_token = app.ui->pushButton_changeToken; QTest::mouseClick(change_token, Qt::MouseButton::LeftButton); - QTest::keyClicks(app->ui->lineEdit_accessToken, "valid"); + QTest::keyClicks(app.ui->lineEdit_accessToken, "valid"); } void TestGui::access_token_entry_test() { - MainWindow *app = create_app(); - QSignalSpy auth_tries(app->canvas, &ICanvas::authenticate_done); + QSignalSpy auth_tries(app.canvas, &ICanvas::authenticate_done); - QPushButton *change_token = app->ui->pushButton_changeToken; + QPushButton *change_token = app.ui->pushButton_changeToken; // click on "Change Token" QTest::mouseClick(change_token, Qt::MouseButton::LeftButton); @@ -24,19 +23,18 @@ void TestGui::access_token_entry_test() QVERIFY(change_token->isHidden()); // enter a valid token - QTest::keyClicks(app->ui->lineEdit_accessToken, "valid"); + QTest::keyClicks(app.ui->lineEdit_accessToken, "valid"); QCOMPARE(auth_tries.count(), 5); - QCOMPARE(app->ui->label_authenticationStatus->text(), "authenticated!"); + QCOMPARE(app.ui->label_authenticationStatus->text(), "authenticated!"); QVERIFY(change_token->isEnabled()); QVERIFY(!change_token->isHidden()); } void TestGui::fetch_courses_test() { - MainWindow *app = create_app(); - authenticate(app); + authenticate(); std::string expected[] = { "#0|Linear Algebra: {\n" " #20010|course files: {\n" @@ -58,38 +56,27 @@ void TestGui::fetch_courses_test() " }\n" "}", }; - for (auto t : app->course_trees) + for (auto t : app.course_trees) QCOMPARE(QString(t.to_string().c_str()), QString(expected[t.id].c_str())); } void TestGui::fetch_courses_ui_test() { - MainWindow *app = create_app(); - authenticate(app); + authenticate(); + TreeModel *model = app.ui->treeView->model(); + TreeIndex ptr(model->index(0, 0)); - TreeModel *model = app->ui->treeView->model(); - QCOMPARE(model->childrenCount(), 3); - - TreeIndex ptr = model->index(0, 0); - // QCOMPARE(1, 2); - - qDebug() << "!!!!!!!!!!!!!!!!!!! COUNT" << ptr.children_count(); QCOMPARE(ptr.course(), "Calculus"); - QCOMPARE(ptr.children_count(), 1); ptr = ptr.child(0); QCOMPARE(ptr.remote_dir(), "course files"); QCOMPARE(ptr.child(0).remote_dir(), "Admin"); QCOMPARE(ptr.child(1).remote_dir(), "Tutorials"); - qDebug() << "!!!!!!!!!!!!!!!!!!! COUNT" << ptr.children_count(); ptr = model->index(1, 0); QCOMPARE(ptr.course(), "Geometry"); - qDebug() << "!!!!!!!!!!!!!!!!!!! COUNT" << ptr.children_count(); - QCOMPARE(ptr.children_count(), 10); - QCOMPARE(ptr.children_count(), 11); ptr = ptr.child(0); QCOMPARE(ptr.remote_dir(), "course files"); - QCOMPARE(ptr.child(0).remote_dir(), "Course ntoes"); + QCOMPARE(ptr.child(0).remote_dir(), "Course notes"); QCOMPARE(ptr.child(1).remote_dir(), "Lectures"); QCOMPARE(ptr.child(2).remote_dir(), "Tutorials"); diff --git a/test/main.h b/test/main.h index 1a66075..6edb34f 100644 --- a/test/main.h +++ b/test/main.h @@ -22,20 +22,11 @@ class TestGui : public QObject std::vector tmp_settings; public: + TestGui() : app(new FakeCanvas(), "canvas-sync-test.ini"){}; + MainWindow app; + // convenience routines - void authenticate(MainWindow *app); - MainWindow *create_app() - { - return new MainWindow(new FakeCanvas(), settings_file()); - } - QString settings_file() - { - this->id_mtx.lock(); - QString result = QString("canvas-sync-test-%1.ini").arg(this->id++); - tmp_settings.push_back(MainWindow::settings_path + '/' + result); - this->id_mtx.unlock(); - return result; - } + void authenticate(); private slots: // tests void access_token_entry_test();