diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-03-23 19:48:53 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-03-23 21:47:03 +0530 |
| commit | 346c16b4e2ea26f47e0e370a490b7794492a9ebb (patch) | |
| tree | 277a30ac8b0c82a9c9736985385d0d150a55fcb5 /spec | |
| parent | 9cc72e8ea9f59f9a9627d05528d54a559ebd412c (diff) | |
| download | null-browser-346c16b4e2ea26f47e0e370a490b7794492a9ebb.tar.gz null-browser-346c16b4e2ea26f47e0e370a490b7794492a9ebb.zip | |
Apply clang-tidy suggestions
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/InputMediatorSpec.cpp | 5 | ||||
| -rw-r--r-- | spec/KeySeqParserSpec.cpp | 10 | ||||
| -rw-r--r-- | spec/KeymapEvaluatorSpec.cpp | 74 | ||||
| -rw-r--r-- | spec/LuaRuntimeSpec.cpp | 93 | ||||
| -rw-r--r-- | spec/WebViewStackSpec.cpp | 245 | ||||
| -rw-r--r-- | spec/main.cpp | 2 | ||||
| -rw-r--r-- | spec/testUtils.cpp | 20 | ||||
| -rw-r--r-- | spec/testUtils.h | 12 |
8 files changed, 242 insertions, 219 deletions
diff --git a/spec/InputMediatorSpec.cpp b/spec/InputMediatorSpec.cpp index b48b008..9052cc6 100644 --- a/spec/InputMediatorSpec.cpp +++ b/spec/InputMediatorSpec.cpp @@ -1,8 +1,6 @@ -#include "InputMediator.hpp" -#include "LuaRuntime.hpp" #include "testUtils.h" -#include "widgets/WebViewStack.hpp" +// NOLINTBEGIN class InputMediatorSpec : public QObject { Q_OBJECT @@ -11,3 +9,4 @@ private slots: QTEST_REGISTER(InputMediatorSpec) #include "InputMediatorSpec.moc" +// NOLINTEND diff --git a/spec/KeySeqParserSpec.cpp b/spec/KeySeqParserSpec.cpp index 7ce2a4a..dcf6140 100644 --- a/spec/KeySeqParserSpec.cpp +++ b/spec/KeySeqParserSpec.cpp @@ -4,6 +4,7 @@ #include "keymap/KeySeqParser.hpp" +// NOLINTBEGIN class KeySeqParserSpec : public QObject { Q_OBJECT @@ -15,12 +16,12 @@ private slots: QList<KeyChord> keys = parser.parse("<C-tab><c-tAb><c-Tab>"); - QList<KeyChord> expectedKeys = { + QList<KeyChord> expected_keys = { {.mod = Qt::ControlModifier, .key = Qt::Key_Tab}, {.mod = Qt::ControlModifier, .key = Qt::Key_Tab}, {.mod = Qt::ControlModifier, .key = Qt::Key_Tab}, }; - QCOMPARE(keys, expectedKeys); + QCOMPARE(keys, expected_keys); } context("when input contains individual keys"); @@ -29,7 +30,7 @@ private slots: QList<KeyChord> keys = parser.parse("ab<c><s><sPace><tab><esC>z"); - QList<KeyChord> expectedKeys = { + QList<KeyChord> expected_keys = { {.mod = Qt::NoModifier, .key = Qt::Key_A}, {.mod = Qt::NoModifier, .key = Qt::Key_B}, {.mod = Qt::NoModifier, .key = Qt::Key_C}, @@ -39,10 +40,11 @@ private slots: {.mod = Qt::NoModifier, .key = Qt::Key_Escape}, {.mod = Qt::NoModifier, .key = Qt::Key_Z}, }; - QCOMPARE(keys, expectedKeys); + QCOMPARE(keys, expected_keys); } } }; QTEST_REGISTER(KeySeqParserSpec) #include "KeySeqParserSpec.moc" +// NOLINTEND diff --git a/spec/KeymapEvaluatorSpec.cpp b/spec/KeymapEvaluatorSpec.cpp index 8e8ba87..0483e99 100644 --- a/spec/KeymapEvaluatorSpec.cpp +++ b/spec/KeymapEvaluatorSpec.cpp @@ -3,6 +3,7 @@ #include "keymap/KeymapEvaluator.hpp" +// NOLINTBEGIN class KeymapEvaluatorSpec : public QObject { Q_OBJECT @@ -10,112 +11,121 @@ private slots: void test_evaluate_single_key_chord() { context("when the key sequence is mapped"); it("calls mapping") { - int keymapWasCalled = false; + auto keymap_was_called = false; KeymapEvaluator evaluator; - evaluator.addKeymap(KeyMode::Normal, "<c-t>", - [&keymapWasCalled]() { keymapWasCalled = true; }); + evaluator.add_keymap(KeyMode::Normal, "<c-t>", [&keymap_was_called]() { + keymap_was_called = true; + }); evaluator.evaluate(Qt::ControlModifier, Qt::Key_T); - QVERIFY(keymapWasCalled); + QVERIFY(keymap_was_called); } context("when the key sequence is not mapped"); it("does not call mapping") { - int keymapWasCalled = false; + auto keymap_was_called = false; KeymapEvaluator evaluator; - evaluator.addKeymap(KeyMode::Normal, "<c-t>", - [&keymapWasCalled]() { keymapWasCalled = true; }); + evaluator.add_keymap(KeyMode::Normal, "<c-t>", [&keymap_was_called]() { + keymap_was_called = true; + }); evaluator.evaluate(Qt::ControlModifier, Qt::Key_K); - QVERIFY(NOT keymapWasCalled); + QVERIFY(NOT keymap_was_called); } } void test_evaluate_multi_key_sequence() { context("when the full key sequence is mapped"); it("calls mapping") { - int keymapWasCalled = false; + auto keymap_was_called = false; KeymapEvaluator evaluator; - evaluator.addKeymap(KeyMode::Normal, "<c-t>a", - [&keymapWasCalled]() { keymapWasCalled = true; }); + evaluator.add_keymap(KeyMode::Normal, "<c-t>a", [&keymap_was_called]() { + keymap_was_called = true; + }); evaluator.evaluate(Qt::ControlModifier, Qt::Key_T); evaluator.evaluate(Qt::NoModifier, Qt::Key_A); - QVERIFY(keymapWasCalled); + QVERIFY(keymap_was_called); } context("when only part of a mapped key sequence is entered"); it("does not call mapping") { - int keymapWasCalled = false; + auto keymap_was_called = false; KeymapEvaluator evaluator; - evaluator.addKeymap(KeyMode::Normal, "<c-t>a", - [&keymapWasCalled]() { keymapWasCalled = true; }); + evaluator.add_keymap(KeyMode::Normal, "<c-t>a", [&keymap_was_called]() { + keymap_was_called = true; + }); evaluator.evaluate(Qt::ControlModifier, Qt::Key_T); - QVERIFY(NOT keymapWasCalled); + QVERIFY(NOT keymap_was_called); } context("when the key sequence is not mapped"); it("does not call mapping") { - int keymapWasCalled = false; + auto keymap_was_called = false; KeymapEvaluator evaluator; - evaluator.addKeymap(KeyMode::Normal, "<c-t>a", - [&keymapWasCalled]() { keymapWasCalled = true; }); + evaluator.add_keymap(KeyMode::Normal, "<c-t>a", [&keymap_was_called]() { + keymap_was_called = true; + }); evaluator.evaluate(Qt::ControlModifier, Qt::Key_K); - QVERIFY(NOT keymapWasCalled); + QVERIFY(NOT keymap_was_called); } context("when the key sequence is not mapped"); it("does not call mapping") { - int keymapWasCalled = false; + auto keymap_was_called = false; KeymapEvaluator evaluator; - evaluator.addKeymap(KeyMode::Normal, "<c-t>a", - [&keymapWasCalled]() { keymapWasCalled = true; }); + evaluator.add_keymap(KeyMode::Normal, "<c-t>a", [&keymap_was_called]() { + keymap_was_called = true; + }); evaluator.evaluate(Qt::ControlModifier, Qt::Key_T); evaluator.evaluate(Qt::NoModifier, Qt::Key_B); - QVERIFY(NOT keymapWasCalled); + QVERIFY(NOT keymap_was_called); } context("when an incorrect sequence is entered before the correct one"); it("calls mapping") { - int keymapWasCalled = false; + auto keymap_was_called = false; KeymapEvaluator evaluator; - evaluator.addKeymap(KeyMode::Normal, "<c-t>a", - [&keymapWasCalled]() { keymapWasCalled = true; }); + evaluator.add_keymap(KeyMode::Normal, "<c-t>a", [&keymap_was_called]() { + keymap_was_called = true; + }); evaluator.evaluate(Qt::ControlModifier, Qt::Key_T); evaluator.evaluate(Qt::NoModifier, Qt::Key_B); evaluator.evaluate(Qt::ControlModifier, Qt::Key_T); evaluator.evaluate(Qt::NoModifier, Qt::Key_A); - QVERIFY(keymapWasCalled); + QVERIFY(keymap_was_called); } // TODO: maybe fix this behavior context( "when partial mapped sequence is entered before an entire sequence"); it("does not call mapping") { - int keymapWasCalled = false; + auto keymap_was_called = false; KeymapEvaluator evaluator; - evaluator.addKeymap(KeyMode::Normal, "<c-t>a", - [&keymapWasCalled]() { keymapWasCalled = true; }); + evaluator.add_keymap(KeyMode::Normal, "<c-t>a", [&keymap_was_called]() { + keymap_was_called = true; + }); evaluator.evaluate(Qt::ControlModifier, Qt::Key_T); evaluator.evaluate(Qt::ControlModifier, Qt::Key_T); evaluator.evaluate(Qt::NoModifier, Qt::Key_A); - QVERIFY(NOT keymapWasCalled); + QVERIFY(NOT keymap_was_called); } } }; QTEST_REGISTER(KeymapEvaluatorSpec) #include "KeymapEvaluatorSpec.moc" +// NOLINTEND diff --git a/spec/LuaRuntimeSpec.cpp b/spec/LuaRuntimeSpec.cpp index 3b4be70..4d89f30 100644 --- a/spec/LuaRuntimeSpec.cpp +++ b/spec/LuaRuntimeSpec.cpp @@ -4,67 +4,72 @@ #include "LuaRuntime.hpp" #include "testUtils.h" +// NOLINTBEGIN class LuaRuntimeSpec : public QObject { Q_OBJECT private slots: - void beforeTestCase() { LuaRuntime::instance()->startEventLoop(); } + void beforeTestCase() { LuaRuntime::instance()->start_event_loop(); } void cleanupTestCase() { - LuaRuntime::instance()->stopEventLoop(); + LuaRuntime::instance()->stop_event_loop(); uv_library_shutdown(); } void test_evaluate() { context("when given an expression returning a number"); - it("emits evaluationCompleted with the result") { - auto lua = LuaRuntime::instance(); - QSignalSpy evaluationCompletedSpy(lua, &LuaRuntime::evaluationCompleted); + it("emits evaluation_completed with the result") { + auto *lua = LuaRuntime::instance(); + QSignalSpy evaluation_completed_spy(lua, + &LuaRuntime::evaluation_completed); lua->evaluate("return 20 + 1 * 5"); - evaluationCompletedSpy.wait(); - QCOMPARE(evaluationCompletedSpy.count(), 1); - QVariant result = evaluationCompletedSpy.takeFirst().at(0); + evaluation_completed_spy.wait(); + QCOMPARE(evaluation_completed_spy.count(), 1); + QVariant result = evaluation_completed_spy.takeFirst().at(0); QCOMPARE(result, 25); } context("when given an expression returning a string"); - it("emits evaluationCompleted with the result") { - auto lua = LuaRuntime::instance(); - QSignalSpy evaluationCompletedSpy(lua, &LuaRuntime::evaluationCompleted); + it("emits evaluation_completed with the result") { + auto *lua = LuaRuntime::instance(); + QSignalSpy evaluation_completed_spy(lua, + &LuaRuntime::evaluation_completed); lua->evaluate("local name = 'world'; return 'hello ' .. name"); - evaluationCompletedSpy.wait(); - QCOMPARE(evaluationCompletedSpy.count(), 1); - QVariant result = evaluationCompletedSpy.takeFirst().at(0); + evaluation_completed_spy.wait(); + QCOMPARE(evaluation_completed_spy.count(), 1); + QVariant result = evaluation_completed_spy.takeFirst().at(0); QCOMPARE(result, "hello world"); } context("when given an expression returning a boolean"); - it("emits evaluationCompleted with the result") { - auto lua = LuaRuntime::instance(); - QSignalSpy evaluationCompletedSpy(lua, &LuaRuntime::evaluationCompleted); + it("emits evaluation_completed with the result") { + auto *lua = LuaRuntime::instance(); + QSignalSpy evaluation_completed_spy(lua, + &LuaRuntime::evaluation_completed); lua->evaluate("local num = 5; return 5 == num"); - evaluationCompletedSpy.wait(); - QCOMPARE(evaluationCompletedSpy.count(), 1); - QVariant result = evaluationCompletedSpy.takeFirst().at(0); + evaluation_completed_spy.wait(); + QCOMPARE(evaluation_completed_spy.count(), 1); + QVariant result = evaluation_completed_spy.takeFirst().at(0); QCOMPARE(result, true); } context("when given an expression returning nil"); - it("emits evaluationCompleted with the result") { - auto lua = LuaRuntime::instance(); - QSignalSpy evaluationCompletedSpy(lua, &LuaRuntime::evaluationCompleted); + it("emits evaluation_completed with the result") { + auto *lua = LuaRuntime::instance(); + QSignalSpy evaluation_completed_spy(lua, + &LuaRuntime::evaluation_completed); lua->evaluate("return nil"); - QVERIFY(evaluationCompletedSpy.wait()); - QCOMPARE(evaluationCompletedSpy.count(), 1); - QVariant result = evaluationCompletedSpy.takeFirst().at(0); + QVERIFY(evaluation_completed_spy.wait()); + QCOMPARE(evaluation_completed_spy.count(), 1); + QVariant result = evaluation_completed_spy.takeFirst().at(0); QCOMPARE(result, 0); } } @@ -72,22 +77,24 @@ private slots: void test_queue_task() { context("when task is queued"); it("evaluates task asynchronously") { - auto lua = LuaRuntime::instance(); - bool wasTaskCalled = false; + auto *lua = LuaRuntime::instance(); + bool was_task_called = false; - lua->queueTask([&wasTaskCalled]() { wasTaskCalled = true; }); - QVERIFY(NOT wasTaskCalled); + lua->queue_task([&was_task_called]() { was_task_called = true; }); + QVERIFY(NOT was_task_called); - QVERIFY(QTest::qWaitFor([&wasTaskCalled]() { return wasTaskCalled; })); - QVERIFY(wasTaskCalled); + QVERIFY( + QTest::qWaitFor([&was_task_called]() { return was_task_called; })); + QVERIFY(was_task_called); } } void test_sanity_check_uv_timer() { context("when a 1 second timer is set"); it("calls callback after 1 second") { - auto lua = LuaRuntime::instance(); - QSignalSpy evaluationCompletedSpy(lua, &LuaRuntime::evaluationCompleted); + auto *lua = LuaRuntime::instance(); + QSignalSpy evaluation_completed_spy(lua, + &LuaRuntime::evaluation_completed); lua->evaluate(R"( _G.was_timer_called = false; @@ -97,19 +104,20 @@ private slots: timer:close() end) )"); - QVERIFY(evaluationCompletedSpy.wait()); - QVERIFY(NOT lua->evaluateSync("return _G.was_timer_called").toBool()); + QVERIFY(evaluation_completed_spy.wait()); + QVERIFY(NOT lua->evaluate_sync("return _G.was_timer_called").toBool()); QVERIFY(QTest::qWaitFor([&lua]() { - return lua->evaluateSync("return _G.was_timer_called").toBool(); + return lua->evaluate_sync("return _G.was_timer_called").toBool(); })); } } void test_sanity_check_uv_spawn() { it("calls exit callback when process exists") { - auto lua = LuaRuntime::instance(); - QSignalSpy evaluationCompletedSpy(lua, &LuaRuntime::evaluationCompleted); + auto *lua = LuaRuntime::instance(); + QSignalSpy evaluation_completed_spy(lua, + &LuaRuntime::evaluation_completed); lua->evaluate(R"( _G.spawn_exit_code = -1; @@ -117,11 +125,11 @@ private slots: _G.spawn_exit_code = code; end) )"); - QVERIFY(evaluationCompletedSpy.wait()); - QCOMPARE(lua->evaluateSync("return _G.spawn_exit_code").toInt(), -1); + QVERIFY(evaluation_completed_spy.wait()); + QCOMPARE(lua->evaluate_sync("return _G.spawn_exit_code").toInt(), -1); QVERIFY(QTest::qWaitFor([&lua]() { - return 0 == lua->evaluateSync("return _G.spawn_exit_code").toInt(); + return 0 == lua->evaluate_sync("return _G.spawn_exit_code").toInt(); })); } } @@ -129,3 +137,4 @@ private slots: QTEST_REGISTER(LuaRuntimeSpec) #include "LuaRuntimeSpec.moc" +// NOLINTEND diff --git a/spec/WebViewStackSpec.cpp b/spec/WebViewStackSpec.cpp index 0cd58ed..134c250 100644 --- a/spec/WebViewStackSpec.cpp +++ b/spec/WebViewStackSpec.cpp @@ -7,6 +7,7 @@ #include "widgets/WebView.hpp" #include "widgets/WebViewStack.hpp" +// NOLINTBEGIN class WebViewStackSpec : public QObject { Q_OBJECT @@ -22,11 +23,11 @@ private slots: context("when initialized"); it("opens a single tab") { Configuration configuration; - WebViewStack webViewStack(&configuration); + WebViewStack web_view_stack(&configuration); - QCOMPARE(webViewStack.count(), 1); - QCOMPARE(webViewStack.currentUrl(), configuration.newTabUrl); - webViewStack.deleteLater(); + QCOMPARE(web_view_stack.count(), 1); + QCOMPARE(web_view_stack.current_url(), configuration.new_tab_url); + web_view_stack.deleteLater(); } } @@ -34,48 +35,48 @@ private slots: context("when openUrl is called without an open type"); it("replaces current tab url with newtab url") { Configuration configuration; - WebViewStack webViewStack(&configuration); - webViewStack.openUrl(QUrl("http://a.com"), OpenType::OpenUrl); + WebViewStack web_view_stack(&configuration); + web_view_stack.open_url(QUrl("http://a.com"), OpenType::OpenUrl); - webViewStack.openUrl(QUrl(configuration.newTabUrl)); + web_view_stack.open_url(QUrl(configuration.new_tab_url)); - QCOMPARE(webViewStack.count(), 1); - std::vector<QUrl> urls = {QUrl(configuration.newTabUrl)}; - QCOMPARE(webViewStack.urls(), urls); - QCOMPARE(webViewStack.currentWebViewIndex(), 0); - QCOMPARE(webViewStack.currentUrl(), configuration.newTabUrl); + QCOMPARE(web_view_stack.count(), 1); + std::vector<QUrl> urls = {QUrl(configuration.new_tab_url)}; + QCOMPARE(web_view_stack.urls(), urls); + QCOMPARE(web_view_stack.current_web_view_index(), 0); + QCOMPARE(web_view_stack.current_url(), configuration.new_tab_url); } context("when creating a new webview with a url and focus is false"); it("opens the given url in background") { Configuration configuration; - WebViewStack webViewStack(&configuration); + WebViewStack web_view_stack(&configuration); - webViewStack.openUrl(QUrl("https://duckduckgo.com"), - OpenType::OpenUrlInBgTab); + web_view_stack.open_url(QUrl("https://duckduckgo.com"), + OpenType::OpenUrlInBgTab); - QCOMPARE(webViewStack.count(), 2); - std::vector<QUrl> urls = {QUrl(configuration.newTabUrl), + QCOMPARE(web_view_stack.count(), 2); + std::vector<QUrl> urls = {QUrl(configuration.new_tab_url), QUrl("https://duckduckgo.com")}; - QCOMPARE(webViewStack.urls(), urls); - QCOMPARE(webViewStack.currentWebViewIndex(), 0); - QCOMPARE(webViewStack.currentUrl(), configuration.newTabUrl); + QCOMPARE(web_view_stack.urls(), urls); + QCOMPARE(web_view_stack.current_web_view_index(), 0); + QCOMPARE(web_view_stack.current_url(), configuration.new_tab_url); } context("when creating a new webview with a url and focus is true"); it("opens the given url as current view") { Configuration configuration; - WebViewStack webViewStack(&configuration); + WebViewStack web_view_stack(&configuration); - webViewStack.openUrl(QUrl("https://duckduckgo.com"), - OpenType::OpenUrlInTab); + web_view_stack.open_url(QUrl("https://duckduckgo.com"), + OpenType::OpenUrlInTab); - QCOMPARE(webViewStack.count(), 2); - std::vector<QUrl> urls = {QUrl(configuration.newTabUrl), + QCOMPARE(web_view_stack.count(), 2); + std::vector<QUrl> urls = {QUrl(configuration.new_tab_url), QUrl("https://duckduckgo.com")}; - QCOMPARE(webViewStack.urls(), urls); - QCOMPARE(webViewStack.currentWebViewIndex(), 1); - QCOMPARE(webViewStack.currentUrl(), QUrl("https://duckduckgo.com")); + QCOMPARE(web_view_stack.urls(), urls); + QCOMPARE(web_view_stack.current_web_view_index(), 1); + QCOMPARE(web_view_stack.current_url(), QUrl("https://duckduckgo.com")); } } @@ -84,41 +85,41 @@ private slots: context("- and there is only 1 tab"); it("does nothing") { Configuration configuration; - WebViewStack webViewStack(&configuration); + WebViewStack web_view_stack(&configuration); - webViewStack.next(); + web_view_stack.next(); - QCOMPARE(webViewStack.currentWebViewIndex(), 0); - QCOMPARE(webViewStack.currentUrl(), configuration.newTabUrl); + QCOMPARE(web_view_stack.current_web_view_index(), 0); + QCOMPARE(web_view_stack.current_url(), configuration.new_tab_url); } context("when nextWebView is called"); context("- and there are tabs after the current tab"); it("goes to the next tab") { Configuration configuration; - WebViewStack webViewStack(&configuration); - webViewStack.openUrl(QUrl("http://a1.com"), OpenType::OpenUrlInBgTab); - webViewStack.openUrl(QUrl("http://a2.com"), OpenType::OpenUrlInBgTab); + WebViewStack web_view_stack(&configuration); + web_view_stack.open_url(QUrl("http://a1.com"), OpenType::OpenUrlInBgTab); + web_view_stack.open_url(QUrl("http://a2.com"), OpenType::OpenUrlInBgTab); - webViewStack.next(); + web_view_stack.next(); - QCOMPARE(webViewStack.currentWebViewIndex(), 1); - QCOMPARE(webViewStack.currentUrl(), QUrl("http://a1.com")); + QCOMPARE(web_view_stack.current_web_view_index(), 1); + QCOMPARE(web_view_stack.current_url(), QUrl("http://a1.com")); } context("when nextWebView is called"); context("- and current tab is the last tab"); it("jumps to the first tab") { Configuration configuration; - WebViewStack webViewStack(&configuration); - webViewStack.openUrl(QUrl("http://a1.com"), OpenType::OpenUrlInBgTab); - webViewStack.openUrl(QUrl("http://a2.com"), OpenType::OpenUrlInTab); - QCOMPARE(webViewStack.currentWebViewIndex(), 2); + WebViewStack web_view_stack(&configuration); + web_view_stack.open_url(QUrl("http://a1.com"), OpenType::OpenUrlInBgTab); + web_view_stack.open_url(QUrl("http://a2.com"), OpenType::OpenUrlInTab); + QCOMPARE(web_view_stack.current_web_view_index(), 2); - webViewStack.next(); + web_view_stack.next(); - QCOMPARE(webViewStack.currentWebViewIndex(), 0); - QCOMPARE(webViewStack.currentUrl(), configuration.newTabUrl); + QCOMPARE(web_view_stack.current_web_view_index(), 0); + QCOMPARE(web_view_stack.current_url(), configuration.new_tab_url); } } @@ -127,41 +128,41 @@ private slots: context("- and there is only 1 tab"); it("does nothing") { Configuration configuration; - WebViewStack webViewStack(&configuration); + WebViewStack web_view_stack(&configuration); - webViewStack.previous(); + web_view_stack.previous(); - QCOMPARE(webViewStack.currentWebViewIndex(), 0); - QCOMPARE(webViewStack.currentUrl(), configuration.newTabUrl); + QCOMPARE(web_view_stack.current_web_view_index(), 0); + QCOMPARE(web_view_stack.current_url(), configuration.new_tab_url); } context("when previousWebView is called"); context("- and there are tabs before the current tab"); it("goes to the next tab") { Configuration configuration; - WebViewStack webViewStack(&configuration); - webViewStack.openUrl(QUrl("http://a1.com"), OpenType::OpenUrlInBgTab); - webViewStack.openUrl(QUrl("http://a2.com"), OpenType::OpenUrlInTab); - QCOMPARE(webViewStack.currentWebViewIndex(), 2); + WebViewStack web_view_stack(&configuration); + web_view_stack.open_url(QUrl("http://a1.com"), OpenType::OpenUrlInBgTab); + web_view_stack.open_url(QUrl("http://a2.com"), OpenType::OpenUrlInTab); + QCOMPARE(web_view_stack.current_web_view_index(), 2); - webViewStack.previous(); + web_view_stack.previous(); - QCOMPARE(webViewStack.currentWebViewIndex(), 1); - QCOMPARE(webViewStack.currentUrl(), QUrl("http://a1.com")); + QCOMPARE(web_view_stack.current_web_view_index(), 1); + QCOMPARE(web_view_stack.current_url(), QUrl("http://a1.com")); } context("when previousWebView is called"); context("- and current tab is the last tab"); it("jumps to the last tab") { Configuration configuration; - WebViewStack webViewStack(&configuration); - webViewStack.openUrl(QUrl("http://a1.com"), OpenType::OpenUrlInBgTab); - webViewStack.openUrl(QUrl("http://a2.com"), OpenType::OpenUrlInBgTab); + WebViewStack web_view_stack(&configuration); + web_view_stack.open_url(QUrl("http://a1.com"), OpenType::OpenUrlInBgTab); + web_view_stack.open_url(QUrl("http://a2.com"), OpenType::OpenUrlInBgTab); - webViewStack.previous(); + web_view_stack.previous(); - QCOMPARE(webViewStack.currentWebViewIndex(), 2); - QCOMPARE(webViewStack.currentUrl(), QUrl("http://a2.com")); + QCOMPARE(web_view_stack.current_web_view_index(), 2); + QCOMPARE(web_view_stack.current_url(), QUrl("http://a2.com")); } } @@ -170,32 +171,33 @@ private slots: context("- with out of bounds index"); it("does nothing") { Configuration configuration; - WebViewStack webViewStack(&configuration); - webViewStack.openUrl(QUrl("https://a.com"), OpenType::OpenUrl); + WebViewStack web_view_stack(&configuration); + web_view_stack.open_url(QUrl("https://a.com"), OpenType::OpenUrl); - webViewStack.close(1); + web_view_stack.close(1); - QCOMPARE(webViewStack.count(), 1); - QCOMPARE(webViewStack.urls(), (std::vector<QUrl>{QUrl("https://a.com")})); - QCOMPARE(webViewStack.currentWebViewIndex(), 0); - QCOMPARE(webViewStack.currentUrl(), QUrl("https://a.com")); + QCOMPARE(web_view_stack.count(), 1); + QCOMPARE(web_view_stack.urls(), + (std::vector<QUrl>{QUrl("https://a.com")})); + QCOMPARE(web_view_stack.current_web_view_index(), 0); + QCOMPARE(web_view_stack.current_url(), QUrl("https://a.com")); } context("when closeWebView is called"); context("- and there is only 1 tab"); it("closes the tab and opens empty tab in its place") { Configuration configuration; - WebViewStack webViewStack(&configuration); - webViewStack.openUrl(QUrl("https://a.com"), OpenType::OpenUrl); - QCOMPARE(webViewStack.count(), 1); + WebViewStack web_view_stack(&configuration); + web_view_stack.open_url(QUrl("https://a.com"), OpenType::OpenUrl); + QCOMPARE(web_view_stack.count(), 1); - webViewStack.close(0); + web_view_stack.close(0); - QCOMPARE(webViewStack.count(), 1); - QCOMPARE(webViewStack.urls(), - (std::vector<QUrl>{configuration.newTabUrl})); - QCOMPARE(webViewStack.currentWebViewIndex(), 0); - QCOMPARE(webViewStack.currentUrl(), configuration.newTabUrl); + QCOMPARE(web_view_stack.count(), 1); + QCOMPARE(web_view_stack.urls(), + (std::vector<QUrl>{configuration.new_tab_url})); + QCOMPARE(web_view_stack.current_web_view_index(), 0); + QCOMPARE(web_view_stack.current_url(), configuration.new_tab_url); } context("when closeWebView is called"); @@ -203,20 +205,20 @@ private slots: context("- and there are some tabs after"); it("closes the tab and focuses the next tab") { Configuration configuration; - WebViewStack webViewStack(&configuration); - webViewStack.openUrl(QUrl("https://a1.com"), OpenType::OpenUrlInTab); - webViewStack.openUrl(QUrl("https://a2.com"), OpenType::OpenUrlInBgTab); - QCOMPARE(webViewStack.count(), 3); - QCOMPARE(webViewStack.currentWebViewIndex(), 1); + WebViewStack web_view_stack(&configuration); + web_view_stack.open_url(QUrl("https://a1.com"), OpenType::OpenUrlInTab); + web_view_stack.open_url(QUrl("https://a2.com"), OpenType::OpenUrlInBgTab); + QCOMPARE(web_view_stack.count(), 3); + QCOMPARE(web_view_stack.current_web_view_index(), 1); - webViewStack.close(1); + web_view_stack.close(1); - QCOMPARE(webViewStack.count(), 2); - QCOMPARE( - webViewStack.urls(), - (std::vector<QUrl>{configuration.newTabUrl, QUrl("https://a2.com")})); - QCOMPARE(webViewStack.currentWebViewIndex(), 1); - QCOMPARE(webViewStack.currentUrl(), QUrl("https://a2.com")); + QCOMPARE(web_view_stack.count(), 2); + QCOMPARE(web_view_stack.urls(), + (std::vector<QUrl>{configuration.new_tab_url, + QUrl("https://a2.com")})); + QCOMPARE(web_view_stack.current_web_view_index(), 1); + QCOMPARE(web_view_stack.current_url(), QUrl("https://a2.com")); } context("when closeWebView is called"); @@ -224,20 +226,20 @@ private slots: context("- which is the last tab"); it("closes the tab and focusses previous tab") { Configuration configuration; - WebViewStack webViewStack(&configuration); - webViewStack.openUrl(QUrl("https://a1.com"), OpenType::OpenUrlInBgTab); - webViewStack.openUrl(QUrl("https://a2.com"), OpenType::OpenUrlInTab); - QCOMPARE(webViewStack.count(), 3); - QCOMPARE(webViewStack.currentWebViewIndex(), 2); + WebViewStack web_view_stack(&configuration); + web_view_stack.open_url(QUrl("https://a1.com"), OpenType::OpenUrlInBgTab); + web_view_stack.open_url(QUrl("https://a2.com"), OpenType::OpenUrlInTab); + QCOMPARE(web_view_stack.count(), 3); + QCOMPARE(web_view_stack.current_web_view_index(), 2); - webViewStack.close(2); + web_view_stack.close(2); - QCOMPARE(webViewStack.count(), 2); - QCOMPARE( - webViewStack.urls(), - (std::vector<QUrl>{configuration.newTabUrl, QUrl("https://a1.com")})); - QCOMPARE(webViewStack.currentWebViewIndex(), 1); - QCOMPARE(webViewStack.currentUrl(), QUrl("https://a1.com")); + QCOMPARE(web_view_stack.count(), 2); + QCOMPARE(web_view_stack.urls(), + (std::vector<QUrl>{configuration.new_tab_url, + QUrl("https://a1.com")})); + QCOMPARE(web_view_stack.current_web_view_index(), 1); + QCOMPARE(web_view_stack.current_url(), QUrl("https://a1.com")); } } @@ -246,46 +248,47 @@ private slots: context("- of type new tab"); it("opens a new web view and focusses it") { Configuration configuration; - WebViewStack webViewStack(&configuration); - webViewStack.openUrl(QUrl("https://a.com"), OpenType::OpenUrl); - auto webview = webViewStack.findChild<WebView *>(); - QCOMPARE(webViewStack.count(), 1); + WebViewStack web_view_stack(&configuration); + web_view_stack.open_url(QUrl("https://a.com"), OpenType::OpenUrl); + auto *webview = web_view_stack.findChild<WebView *>(); + QCOMPARE(web_view_stack.count(), 1); - FakeNewWindowRequest windowRequest( + FakeNewWindowRequest window_request( FakeNewWindowRequest::DestinationType::InNewTab, QRect(0, 0, 0, 0), QUrl("https://new.com"), true); - emit webview->page()->newWindowRequested(windowRequest); + emit webview->page()->newWindowRequested(window_request); - QCOMPARE(webViewStack.count(), 2); + QCOMPARE(web_view_stack.count(), 2); QCOMPARE( - webViewStack.urls(), + web_view_stack.urls(), (std::vector<QUrl>{QUrl("https://a.com"), QUrl("https://new.com")})); - QCOMPARE(webViewStack.currentWebViewIndex(), 1); - QCOMPARE(webViewStack.currentUrl(), QUrl("https://new.com")); + QCOMPARE(web_view_stack.current_web_view_index(), 1); + QCOMPARE(web_view_stack.current_url(), QUrl("https://new.com")); } context("when webview emits a newWindowRequested signal"); context("- of type new background tab"); it("opens a new web view in the background") { Configuration configuration; - WebViewStack webViewStack(&configuration); - webViewStack.openUrl(QUrl("https://a.com"), OpenType::OpenUrl); - auto webview = webViewStack.findChild<WebView *>(); + WebViewStack web_view_stack(&configuration); + web_view_stack.open_url(QUrl("https://a.com"), OpenType::OpenUrl); + auto *webview = web_view_stack.findChild<WebView *>(); - FakeNewWindowRequest windowRequest( + FakeNewWindowRequest window_request( FakeNewWindowRequest::DestinationType::InNewBackgroundTab, QRect(0, 0, 0, 0), QUrl("https://new.com"), true); - emit webview->page()->newWindowRequested(windowRequest); + emit webview->page()->newWindowRequested(window_request); - QCOMPARE(webViewStack.count(), 2); + QCOMPARE(web_view_stack.count(), 2); QCOMPARE( - webViewStack.urls(), + web_view_stack.urls(), (std::vector<QUrl>{QUrl("https://a.com"), QUrl("https://new.com")})); - QCOMPARE(webViewStack.currentWebViewIndex(), 0); - QCOMPARE(webViewStack.currentUrl(), QUrl("https://a.com")); + QCOMPARE(web_view_stack.current_web_view_index(), 0); + QCOMPARE(web_view_stack.current_url(), QUrl("https://a.com")); } } }; QTEST_REGISTER(WebViewStackSpec) #include "WebViewStackSpec.moc" +// NOLINTEND diff --git a/spec/main.cpp b/spec/main.cpp index 352ecba..15d0b60 100644 --- a/spec/main.cpp +++ b/spec/main.cpp @@ -4,5 +4,5 @@ int main(int argc, char **argv) { QApplication app(argc, argv); - return runAllTests(); + return run_all_tests(); } diff --git a/spec/testUtils.cpp b/spec/testUtils.cpp index 0fc5e2b..cea7a3d 100644 --- a/spec/testUtils.cpp +++ b/spec/testUtils.cpp @@ -2,23 +2,23 @@ #include <QtTest/qtestcase.h> #include <cstdio> -std::vector<std::function<QObject *()>> &getQTestRegistry() { +std::vector<std::function<QObject *()>> &get_qtest_registry() { static std::vector<std::function<QObject *()>> registry; return registry; } -int runAllTests() { - int exitCode = 0; +int run_all_tests() { + int exit_code = 0; - QString testName = getenv("TEST_NAME"); + QString test_name = getenv("TEST_NAME"); - for (const auto &runTest : getQTestRegistry()) { - auto test = runTest(); - if (testName.isEmpty() || test->objectName().contains(testName)) - exitCode |= QTest::qExec(test); + for (const auto &run_test : get_qtest_registry()) { + auto *test = run_test(); + if (test_name.isEmpty() || test->objectName().contains(test_name)) + exit_code |= QTest::qExec(test); delete test; } - getQTestRegistry().clear(); - return exitCode; + get_qtest_registry().clear(); + return exit_code; } diff --git a/spec/testUtils.h b/spec/testUtils.h index fd0c30b..f6cdebb 100644 --- a/spec/testUtils.h +++ b/spec/testUtils.h @@ -26,16 +26,16 @@ #define STRINGIFY(x) #x -std::vector<std::function<QObject *()>> &getQTestRegistry(); -int runAllTests(); +std::vector<std::function<QObject *()>> &get_qtest_registry(); +int run_all_tests(); #define QTEST_REGISTER(klass) \ namespace { \ const bool registered__##klass = []() { \ - getQTestRegistry().push_back([]() { \ - auto t = new klass; \ - t->setObjectName(#klass); \ - return t; \ + get_qtest_registry().push_back([]() { \ + auto test = new (klass); \ + test->setObjectName(#klass); \ + return test; \ }); \ return true; \ }(); \ |
