data: bookmark refactoring
* implemented handling of aggregations in bookmarks * split index Storage and bookmark storage * each sqlite database has its own version now * added bookmark tests * fixed creating bookmark tables when project can be loaded but bookmark db does not exist * fixed font size for bookmarkview tooltips * using bookmark cache now * using default category name when none specified by the user * raising bookmark windows when they should be shown * clearing a bookmark or category in the editor will now update the star icon accordingly * non-persistent bookmarks use ids of nodes and edges now (instead of names) * git ignore .srctrlbm files
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
#include "cxxtest/TestSuite.h"
|
||||
|
||||
#include "boost/filesystem.hpp"
|
||||
|
||||
#include "data/bookmark/EdgeBookmark.h"
|
||||
#include "data/bookmark/NodeBookmark.h"
|
||||
#include "data/SqliteBookmarkStorage.h"
|
||||
|
||||
class SqliteBookmarkStorageTestSuite: public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void test_add_bookmarks()
|
||||
{
|
||||
std::string databasePath = "data/SQLiteTestSuite/bookmarkTest.sqlite";
|
||||
int bookmarkCount = 4;
|
||||
int result = -1;
|
||||
{
|
||||
boost::filesystem::remove(databasePath);
|
||||
SqliteBookmarkStorage storage(databasePath);
|
||||
storage.setup();
|
||||
|
||||
for (unsigned int i = 0; i < bookmarkCount; i++)
|
||||
{
|
||||
const Id categoryId = storage.addBookmarkCategory("test category");
|
||||
storage.addBookmark("test bookmark", "test comment", TimePoint::now().toString(), categoryId);
|
||||
}
|
||||
|
||||
result = storage.getAllBookmarks().size();
|
||||
}
|
||||
|
||||
boost::filesystem::remove(databasePath);
|
||||
|
||||
TS_ASSERT_EQUALS(result, bookmarkCount);
|
||||
}
|
||||
|
||||
void test_add_bookmarked_node()
|
||||
{
|
||||
std::string databasePath = "data/SQLiteTestSuite/bookmarkTest.sqlite";
|
||||
int bookmarkCount = 4;
|
||||
int result = -1;
|
||||
{
|
||||
boost::filesystem::remove(databasePath);
|
||||
SqliteBookmarkStorage storage(databasePath);
|
||||
storage.setup();
|
||||
|
||||
const Id categoryId = storage.addBookmarkCategory("test category");
|
||||
const Id bookmarkId = storage.addBookmark("test bookmark", "test comment", TimePoint::now().toString(), categoryId);
|
||||
|
||||
for (unsigned int i = 0; i < bookmarkCount; i++)
|
||||
{
|
||||
storage.addBookmarkedNode(bookmarkId, "test name");
|
||||
}
|
||||
|
||||
result = storage.getAllBookmarkedNodes().size();
|
||||
}
|
||||
|
||||
boost::filesystem::remove(databasePath);
|
||||
|
||||
TS_ASSERT_EQUALS(result, bookmarkCount);
|
||||
}
|
||||
|
||||
void test_remove_bookmark_also_removes_bookmarked_node()
|
||||
{
|
||||
std::string databasePath = "data/SQLiteTestSuite/bookmarkTest.sqlite";
|
||||
int bookmarkCount = 4;
|
||||
int result = -1;
|
||||
{
|
||||
boost::filesystem::remove(databasePath);
|
||||
SqliteBookmarkStorage storage(databasePath);
|
||||
storage.setup();
|
||||
|
||||
const Id categoryId = storage.addBookmarkCategory("test category");
|
||||
const Id bookmarkId = storage.addBookmark("test bookmark", "test comment", TimePoint::now().toString(), categoryId);
|
||||
const Id bookmarkedNodeId = storage.addBookmarkedNode(bookmarkId, "test name");
|
||||
|
||||
storage.removeBookmark(bookmarkId);
|
||||
|
||||
result = storage.getAllBookmarkedNodes().size();
|
||||
}
|
||||
|
||||
boost::filesystem::remove(databasePath);
|
||||
|
||||
TS_ASSERT_EQUALS(result, 0);
|
||||
}
|
||||
|
||||
void test_edit_nodeBookmark()
|
||||
{
|
||||
std::string databasePath = "data/SQLiteTestSuite/bookmarkTest.sqlite";
|
||||
|
||||
const std::string updatedName = "updated name";
|
||||
const std::string updatedComment = "updated comment";
|
||||
|
||||
StorageBookmark storageBookmark;
|
||||
{
|
||||
boost::filesystem::remove(databasePath);
|
||||
SqliteBookmarkStorage storage(databasePath);
|
||||
storage.setup();
|
||||
|
||||
const Id categoryId = storage.addBookmarkCategory("test category");
|
||||
const Id bookmarkId = storage.addBookmark("test bookmark", "test comment", TimePoint::now().toString(), categoryId);
|
||||
const Id bookmarkedNodeId = storage.addBookmarkedNode(bookmarkId, "test name");
|
||||
|
||||
storage.updateBookmark(bookmarkId, updatedName, updatedComment, categoryId);
|
||||
|
||||
storageBookmark = storage.getAllBookmarks().front();
|
||||
}
|
||||
|
||||
TS_ASSERT_EQUALS(updatedName, storageBookmark.name);
|
||||
TS_ASSERT_EQUALS(updatedComment, storageBookmark.comment);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user