[gnote] Add test for NoteManager



commit ee96ba235173511590c625aacc2aca6884a633bf
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sun Apr 27 18:47:47 2014 +0300

    Add test for NoteManager

 .gitignore                   |    1 +
 src/Makefile.am              |   11 +++++-
 src/test/notemanagertest.cpp |   46 +++++++++++++++++++++++++
 src/test/testnote.cpp        |   42 +++++++++++++++++++++++
 src/test/testnote.hpp        |   38 +++++++++++++++++++++
 src/test/testnotemanager.cpp |   49 +++++++++++++++++++++++++++
 src/test/testnotemanager.hpp |   36 ++++++++++++++++++++
 src/test/testtagmanager.cpp  |   76 ++++++++++++++++++++++++++++++++++++++++++
 src/test/testtagmanager.hpp  |   41 ++++++++++++++++++++++
 9 files changed, 338 insertions(+), 2 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index c749a90..32cf5a7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -73,6 +73,7 @@ src/gnote
 src/gnote-applet
 src/libgnote.a
 src/notetest
+src/notemanagertest
 src/stringtest
 src/trietest
 src/uritest
diff --git a/src/Makefile.am b/src/Makefile.am
index dad281c..a24b165 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -28,9 +28,9 @@ GNOTE_LIBS = libgnote.la $(LIBGNOTE_LIBS)
 lib_LTLIBRARIES = libgnote.la
 bin_PROGRAMS = gnote
 check_PROGRAMS = trietest stringtest notetest dttest uritest filestest \
-       fileinfotest xmlreadertest
+       fileinfotest xmlreadertest notemanagertest
 TESTS = trietest stringtest notetest dttest uritest filestest \
-       fileinfotest xmlreadertest
+       fileinfotest xmlreadertest notemanagertest
 
 
 trietest_SOURCES = test/trietest.cpp
@@ -57,6 +57,13 @@ xmlreadertest_LDADD = libgnote.la @LIBXML_LIBS@
 notetest_SOURCES = test/notetest.cpp
 notetest_LDADD =  $(GNOTE_LIBS) -lX11
 
+notemanagertest_SOURCES = test/notemanagertest.cpp \
+       test/testnote.cpp test/testnote.hpp \
+       test/testnotemanager.cpp test/testnotemanager.hpp \
+       test/testtagmanager.cpp test/testtagmanager.hpp \
+       $(NULL)
+notemanagertest_LDADD = $(GNOTE_LIBS)
+
 
 SUBDIRS += dbus
 DBUS_SOURCES=remotecontrolproxy.hpp remotecontrolproxy.cpp \
diff --git a/src/test/notemanagertest.cpp b/src/test/notemanagertest.cpp
new file mode 100644
index 0000000..71b5d0b
--- /dev/null
+++ b/src/test/notemanagertest.cpp
@@ -0,0 +1,46 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2014 Aurimas Cernius
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <boost/test/minimal.hpp>
+
+#include "testnotemanager.hpp"
+#include "testtagmanager.hpp"
+
+
+int test_main(int /*argc*/, char ** /*argv*/)
+{
+  char notes_dir_tmpl[] = "/tmp/gnotetestnotesXXXXXX";
+  char *notes_dir = g_mkdtemp(notes_dir_tmpl);
+  BOOST_CHECK(notes_dir != NULL);
+
+  new test::TagManager;
+  test::NoteManager manager(notes_dir);
+  manager.create();
+  manager.create();
+  gnote::NoteBase::Ptr test_note = manager.create("test note");
+  BOOST_CHECK(test_note != 0);
+  // 3 notes + template note
+  BOOST_CHECK(manager.get_notes().size() == 4);
+  BOOST_CHECK(manager.find("test note") == test_note);
+  BOOST_CHECK(manager.find_by_uri(test_note->uri()) == test_note);
+
+  return 0;
+}
+
diff --git a/src/test/testnote.cpp b/src/test/testnote.cpp
new file mode 100644
index 0000000..22e2ae4
--- /dev/null
+++ b/src/test/testnote.cpp
@@ -0,0 +1,42 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2014 Aurimas Cernius
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "testnote.hpp"
+
+namespace test {
+
+Note::Note(gnote::NoteData *_data, const Glib::ustring & filepath, gnote::NoteManagerBase & manager_)
+  : gnote::NoteBase(_data, filepath, manager_)
+  , m_data_synchronizer(_data)
+{
+}
+
+const gnote::NoteDataBufferSynchronizerBase & Note::data_synchronizer() const
+{
+  return m_data_synchronizer;
+}
+
+gnote::NoteDataBufferSynchronizerBase & Note::data_synchronizer()
+{
+  return m_data_synchronizer;
+}
+
+}
+
diff --git a/src/test/testnote.hpp b/src/test/testnote.hpp
new file mode 100644
index 0000000..ecbfa99
--- /dev/null
+++ b/src/test/testnote.hpp
@@ -0,0 +1,38 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2014 Aurimas Cernius
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "notebase.hpp"
+
+namespace test {
+
+class Note
+  : public gnote::NoteBase
+{
+public:
+  Note(gnote::NoteData *_data, const Glib::ustring & filepath, gnote::NoteManagerBase & manager);
+protected:
+  virtual const gnote::NoteDataBufferSynchronizerBase & data_synchronizer() const;
+  virtual gnote::NoteDataBufferSynchronizerBase & data_synchronizer();
+private:
+  gnote::NoteDataBufferSynchronizerBase m_data_synchronizer;
+};
+
+}
+
diff --git a/src/test/testnotemanager.cpp b/src/test/testnotemanager.cpp
new file mode 100644
index 0000000..dd96014
--- /dev/null
+++ b/src/test/testnotemanager.cpp
@@ -0,0 +1,49 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2014 Aurimas Cernius
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "testnote.hpp"
+#include "testnotemanager.hpp"
+
+namespace test {
+
+NoteManager::NoteManager(const Glib::ustring & notesdir)
+  : gnote::NoteManagerBase(notesdir)
+{
+  std::string backup = notesdir + "/Backup";
+  _common_init(notesdir, backup);
+}
+
+gnote::NoteBase::Ptr NoteManager::note_create_new(const Glib::ustring & title, const Glib::ustring & 
file_name)
+{
+  gnote::NoteData *note_data = new gnote::NoteData(gnote::NoteBase::url_from_path(file_name));
+  note_data->title() = title;
+  sharp::DateTime date(sharp::DateTime::now());
+  note_data->create_date() = date;
+  note_data->set_change_date(date);
+
+  return Note::Ptr(new Note(note_data, file_name, *this));
+}
+
+gnote::NoteBase::Ptr NoteManager::note_load(const Glib::ustring & file_name)
+{
+  return gnote::NoteBase::Ptr();
+}
+
+}
+
diff --git a/src/test/testnotemanager.hpp b/src/test/testnotemanager.hpp
new file mode 100644
index 0000000..3875862
--- /dev/null
+++ b/src/test/testnotemanager.hpp
@@ -0,0 +1,36 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2014 Aurimas Cernius
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "base/macros.hpp"
+#include "notemanagerbase.hpp"
+
+
+namespace test {
+
+class NoteManager
+  : public gnote::NoteManagerBase
+{
+public:
+  explicit NoteManager(const Glib::ustring & notes_dir);
+protected:
+  virtual gnote::NoteBase::Ptr note_create_new(const Glib::ustring & title, const Glib::ustring & file_name) 
override;
+  virtual gnote::NoteBase::Ptr note_load(const Glib::ustring & file_name) override;
+};
+
+}
diff --git a/src/test/testtagmanager.cpp b/src/test/testtagmanager.cpp
new file mode 100644
index 0000000..80d5518
--- /dev/null
+++ b/src/test/testtagmanager.cpp
@@ -0,0 +1,76 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2014 Aurimas Cernius
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "testtagmanager.hpp"
+
+namespace test {
+
+gnote::Tag::Ptr TagManager::get_tag(const std::string & tag_name) const
+{
+  std::map<std::string, gnote::Tag::Ptr>::const_iterator iter = m_tags.find(tag_name);
+  if(iter != m_tags.end()) {
+    return iter->second;
+  }
+  return gnote::Tag::Ptr();
+}
+
+gnote::Tag::Ptr TagManager::get_or_create_tag(const std::string & tag_name)
+{
+  std::map<std::string, gnote::Tag::Ptr>::iterator iter = m_tags.find(tag_name);
+  if(iter != m_tags.end()) {
+    return iter->second;
+  }
+  gnote::Tag::Ptr tag = gnote::Tag::Ptr(new gnote::Tag(tag_name));
+  m_tags[tag_name] = tag;
+  return tag;
+}
+
+gnote::Tag::Ptr TagManager::get_system_tag(const std::string & name) const
+{
+  return get_tag("SYSTEM:" + name);
+}
+
+gnote::Tag::Ptr TagManager::get_or_create_system_tag(const std::string & name)
+{
+  return get_or_create_tag("SYSTEM:" + name);
+}
+
+void TagManager::remove_tag(const gnote::Tag::Ptr & tag)
+{
+  for(std::map<std::string, gnote::Tag::Ptr>::iterator iter = m_tags.begin();
+      iter != m_tags.end(); ++iter) {
+    if(iter->second == tag) {
+      m_tags.erase(iter);
+      break;
+    }
+  }
+}
+
+void TagManager::all_tags(std::list<gnote::Tag::Ptr> & list) const
+{
+  list.clear();
+  for(std::map<std::string, gnote::Tag::Ptr>::const_iterator iter = m_tags.begin();
+      iter != m_tags.end(); ++iter) {
+    list.push_back(iter->second);
+  }
+}
+
+}
+
diff --git a/src/test/testtagmanager.hpp b/src/test/testtagmanager.hpp
new file mode 100644
index 0000000..29885f4
--- /dev/null
+++ b/src/test/testtagmanager.hpp
@@ -0,0 +1,41 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2014 Aurimas Cernius
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "base/macros.hpp"
+#include "itagmanager.hpp"
+
+namespace test {
+
+class TagManager
+  : public gnote::ITagManager
+{
+public:
+  virtual gnote::Tag::Ptr get_tag(const std::string & tag_name) const override;
+  virtual gnote::Tag::Ptr get_or_create_tag(const std::string &) override;
+  virtual gnote::Tag::Ptr get_system_tag(const std::string & tag_name) const override;
+  virtual gnote::Tag::Ptr get_or_create_system_tag(const std::string & name) override;
+  virtual void remove_tag(const gnote::Tag::Ptr & tag) override;
+  virtual void all_tags(std::list<gnote::Tag::Ptr> &) const override;
+private:
+  std::map<std::string, gnote::Tag::Ptr> m_tags;
+};
+
+}
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]