-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1309 from uklotzde/cratestorage_tests
Initial DB tests for CrateStorage
- Loading branch information
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include "test/librarytest.h" | ||
|
||
#include "library/crate/cratestorage.h" | ||
|
||
|
||
class CrateStorageTest : public LibraryTest { | ||
protected: | ||
CrateStorageTest() { | ||
m_crateStorage.connectDatabase(dbConnection()); | ||
} | ||
|
||
CrateStorage m_crateStorage; | ||
}; | ||
|
||
TEST_F(CrateStorageTest, persistentLifecycle) { | ||
const uint kNumCrates = 10; | ||
|
||
// Insert some crates | ||
for (auto i = kNumCrates; i > 0; --i) { | ||
Crate crate; | ||
crate.setName(QString("Crate %1").arg(i)); | ||
ASSERT_TRUE(m_crateStorage.onInsertingCrate(crate)); | ||
} | ||
EXPECT_EQ(kNumCrates, m_crateStorage.countCrates()); | ||
|
||
// Identify one of the "middle" crates by name | ||
const auto kCrateIndex = (kNumCrates + 1) / 2; | ||
const auto kCrateName = QString("Crate %1").arg(kCrateIndex); | ||
CrateId crateId; | ||
|
||
// Find this crate by name | ||
{ | ||
Crate crate; | ||
ASSERT_TRUE(m_crateStorage.readCrateByName(kCrateName, &crate)); | ||
EXPECT_EQ(kCrateName, crate.getName()); | ||
crateId = crate.getId(); | ||
ASSERT_TRUE(crateId.isValid()); | ||
} | ||
|
||
// Find this crate crate again, but now by id | ||
Crate crate; | ||
{ | ||
ASSERT_TRUE(m_crateStorage.readCrateById(crateId, &crate)); | ||
EXPECT_EQ(crateId, crate.getId()); | ||
EXPECT_EQ(kCrateName, crate.getName()); | ||
} | ||
|
||
// Update the crate's name | ||
const auto kNewCrateName = QString("New%1").arg(kCrateName); | ||
crate.setName(kNewCrateName); | ||
ASSERT_TRUE(m_crateStorage.onUpdatingCrate(crate)); | ||
// Reading the crate by its old name should fail | ||
EXPECT_FALSE(m_crateStorage.readCrateByName(kCrateName)); | ||
// Reading by id should reflect the updated name | ||
{ | ||
Crate updatedCrate; | ||
EXPECT_TRUE(m_crateStorage.readCrateById(crateId, &updatedCrate)); | ||
EXPECT_EQ(kNewCrateName, updatedCrate.getName()); | ||
} | ||
|
||
// Finally delete this crate | ||
ASSERT_TRUE(m_crateStorage.onDeletingCrate(crateId)); | ||
EXPECT_FALSE(m_crateStorage.readCrateById(crateId)); | ||
EXPECT_FALSE(m_crateStorage.readCrateByName(kCrateName)); | ||
EXPECT_FALSE(m_crateStorage.readCrateByName(kNewCrateName)); | ||
EXPECT_EQ(kNumCrates - 1, m_crateStorage.countCrates()); | ||
} |