From c42df2435d7c41c45f36f9da9f61442eb1326100 Mon Sep 17 00:00:00 2001 From: "Pawel.Paprocki" Date: Thu, 29 Apr 2021 07:34:13 +0200 Subject: [PATCH] [EGD-6646] Fix Contact Record db tests Clean WAL file after db init --- module-db/tests/CMakeLists.txt | 1 + module-db/tests/ContactsRecord_tests.cpp | 9 +++------ module-db/tests/common.cpp | 16 ++++++++++++++++ module-db/tests/common.hpp | 8 ++++++++ 4 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 module-db/tests/common.cpp create mode 100644 module-db/tests/common.hpp diff --git a/module-db/tests/CMakeLists.txt b/module-db/tests/CMakeLists.txt index 9fd555eda86848db9a3fac12f0187ee4a03a0b5c..1a3ba5c3ea52a8beecb6f029bcb41b8710a1ef0a 100644 --- a/module-db/tests/CMakeLists.txt +++ b/module-db/tests/CMakeLists.txt @@ -32,6 +32,7 @@ add_catch2_executable( ThreadRecord_tests.cpp ThreadsTable_tests.cpp tests-main.cpp + common.cpp LIBS module-db diff --git a/module-db/tests/ContactsRecord_tests.cpp b/module-db/tests/ContactsRecord_tests.cpp index 7ed02e6b8412f089f1a47a7a88d391b05ac2054d..5daf8cea0f18fdd333020c2c94bf64c45959360d 100644 --- a/module-db/tests/ContactsRecord_tests.cpp +++ b/module-db/tests/ContactsRecord_tests.cpp @@ -1,6 +1,7 @@ // Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md +#include "common.hpp" #include #include "Interface/ContactRecord.hpp" @@ -12,9 +13,7 @@ TEST_CASE("Contact Record db tests") Database::initialize(); const auto contactsPath = (std::filesystem::path{"sys/user"} / "contacts.db"); - if (std::filesystem::exists(contactsPath)) { - REQUIRE(std::filesystem::remove(contactsPath)); - } + RemoveDbFiles(contactsPath.stem()); ContactsDB contactDB(contactsPath.c_str()); REQUIRE(contactDB.isInitialized()); @@ -263,9 +262,7 @@ TEST_CASE("Contact record numbers update") { Database::initialize(); const auto contactsPath = (std::filesystem::path{"sys/user"} / "contacts.db"); - if (std::filesystem::exists(contactsPath)) { - REQUIRE(std::filesystem::remove(contactsPath)); - } + RemoveDbFiles(contactsPath.stem()); ContactsDB contactDB(contactsPath.c_str()); REQUIRE(contactDB.isInitialized()); diff --git a/module-db/tests/common.cpp b/module-db/tests/common.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2ffdc316a3592e595227a442504343f82a6a6c5c --- /dev/null +++ b/module-db/tests/common.cpp @@ -0,0 +1,16 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md +#include "common.hpp" +#include +#include + +void RemoveDbFiles(const std::string &dbName) +{ + std::vector dbFileExt = {".db", ".db-journal", ".db-wal"}; + for (const auto &ext : dbFileExt) { + const auto dbPath = (std::filesystem::path{"sys/user"} / std::filesystem::path{dbName + ext}); + if (std::filesystem::exists(dbPath)) { + std::filesystem::remove(dbPath.c_str()); + } + } +} diff --git a/module-db/tests/common.hpp b/module-db/tests/common.hpp new file mode 100644 index 0000000000000000000000000000000000000000..dfe82a8fd6d82e08afb56b0f677af8d00ab77bb2 --- /dev/null +++ b/module-db/tests/common.hpp @@ -0,0 +1,8 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include + +void RemoveDbFiles(const std::string &dbName);