[gnote: 2/21] Add test for SyncManager



commit d5601c95bd7e3d7fdb227c9f30f8e1e9297f56d3
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sun Sep 14 14:38:06 2014 +0300

    Add test for SyncManager
    
    Still incomplete

 .gitignore                   |    1 +
 src/Makefile.am              |   19 +++++++++-
 src/test/syncmanagertest.cpp |   77 +++++++++++++++++++++++++++++++++++++++
 src/test/testsyncaddin.cpp   |   83 ++++++++++++++++++++++++++++++++++++++++++
 src/test/testsyncaddin.hpp   |   53 +++++++++++++++++++++++++++
 src/test/testsyncmanager.cpp |   70 +++++++++++++++++++++++++++++++++++
 src/test/testsyncmanager.hpp |   48 ++++++++++++++++++++++++
 7 files changed, 349 insertions(+), 2 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 0b9c14c..5e8a6fa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -82,6 +82,7 @@ src/libgnote.a
 src/notetest
 src/notemanagertest
 src/stringtest
+src/syncmanagertest
 src/trietest
 src/uritest
 src/xmlreadertest
diff --git a/src/Makefile.am b/src/Makefile.am
index 537ffa1..a8a5b29 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -28,9 +28,11 @@ GNOTE_LIBS = libgnote.la $(LIBGNOTE_LIBS)
 lib_LTLIBRARIES = libgnote.la
 bin_PROGRAMS = gnote
 check_PROGRAMS = trietest stringtest notetest dttest uritest filestest \
-       fileinfotest xmlreadertest notemanagertest gnotesyncclienttest
+       fileinfotest xmlreadertest notemanagertest gnotesyncclienttest \
+       syncmanagertest
 TESTS = trietest stringtest notetest dttest uritest filestest \
-       fileinfotest xmlreadertest notemanagertest gnotesyncclienttest
+       fileinfotest xmlreadertest notemanagertest gnotesyncclienttest \
+       syncmanagertest
 
 
 trietest_SOURCES = test/trietest.cpp
@@ -73,6 +75,19 @@ gnotesyncclienttest_SOURCES = test/gnotesyncclienttest.cpp \
        $(NULL)
 gnotesyncclienttest_LDADD = $(GNOTE_LIBS)
 
+syncmanagertest_SOURCES = test/syncmanagertest.cpp \
+       test/testnote.cpp test/testnote.hpp \
+       test/testnotemanager.cpp test/testnotemanager.hpp \
+       test/testsyncaddin.cpp test/testsyncaddin.hpp \
+       test/testsyncclient.cpp test/testsyncclient.hpp \
+       test/testsyncmanager.cpp test/testsyncmanager.hpp \
+       test/testtagmanager.cpp test/testtagmanager.hpp \
+       synchronization/gnotesyncclient.hpp synchronization/gnotesyncclient.cpp \
+       synchronization/silentui.hpp synchronization/silentui.cpp \
+       synchronization/syncmanager.hpp synchronization/syncmanager.cpp \
+       $(NULL)
+syncmanagertest_LDADD = $(GNOTE_LIBS)
+
 
 SUBDIRS += dbus
 DBUS_SOURCES=remotecontrolproxy.hpp remotecontrolproxy.cpp \
diff --git a/src/test/syncmanagertest.cpp b/src/test/syncmanagertest.cpp
new file mode 100644
index 0000000..ae8d5f1
--- /dev/null
+++ b/src/test/syncmanagertest.cpp
@@ -0,0 +1,77 @@
+/*
+ * 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 <cstdio>
+#include <iostream>
+
+#include <boost/format.hpp>
+#include <boost/test/minimal.hpp>
+#include <glib/gstdio.h>
+
+#include "notemanager.hpp"
+#include "testnotemanager.hpp"
+#include "testsyncmanager.hpp"
+#include "testtagmanager.hpp"
+#include "synchronization/silentui.hpp"
+
+using namespace gnote;
+
+
+void create_note(test::NoteManager & manager, const std::string & title, const std::string & body)
+{
+  std::string content = str(boost::format("<note-content><note-title>%1%</note-title>\n\n%2%</note-content>")
+                            % title % body);
+  manager.create(title, content);
+}
+
+int test_main(int /*argc*/, char ** /*argv*/)
+{
+  char notes_dir_tmpl[] = "/tmp/gnotetestnotesXXXXXX";
+  char notes_dir_tmpl2[] = "/tmp/gnotetestnotesXXXXXX";
+  char *notes_dir = g_mkdtemp(notes_dir_tmpl);
+  BOOST_CHECK(notes_dir != NULL);
+  char *notes_dir2 = g_mkdtemp(notes_dir_tmpl2);
+  BOOST_CHECK(notes_dir2 != NULL);
+  std::string notesdir = std::string(notes_dir) + "/notes";
+  std::string notesdir2 = std::string(notes_dir2) + "/notes";
+  std::string syncdir = std::string(notes_dir) + "/sync";
+  if(g_mkdir(syncdir.c_str(), 0x755)) {
+    std::cerr << "Failed to create test directory: " << syncdir << std::endl;
+    return 1;
+  }
+  std::string manifest = std::string(notes_dir) + "/manifest.xml";
+
+  new test::TagManager;
+  test::NoteManager manager1(notes_dir);
+  create_note(manager1, "note1", "content1");
+  create_note(manager1, "note2", "content2");
+  create_note(manager1, "note3", "content3");
+
+  test::NoteManager manager2(notesdir2);
+
+  test::SyncManager sync_manager1(manager1);
+  test::SyncManager sync_manager2(manager2);
+  test::SyncClient::Ptr sync_client1 = 
dynamic_pointer_cast<test::SyncClient>(sync_manager1.get_client(manifest));
+  gnote::sync::SilentUI::Ptr sync_ui = gnote::sync::SilentUI::create(manager1);
+  //sync_manager1.perform_synchronization(sync_ui); //TODO: fails, return proper server from test SyncAddin
+
+  return 0;
+}
+
diff --git a/src/test/testsyncaddin.cpp b/src/test/testsyncaddin.cpp
new file mode 100644
index 0000000..3110d0e
--- /dev/null
+++ b/src/test/testsyncaddin.cpp
@@ -0,0 +1,83 @@
+/*
+ * 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 "testsyncaddin.hpp"
+
+
+namespace test {
+
+gnote::sync::SyncServer::Ptr SyncAddin::create_sync_server()
+{
+  return gnote::sync::SyncServer::Ptr();
+}
+
+void SyncAddin::post_sync_cleanup()
+{
+}
+
+Gtk::Widget *SyncAddin::create_preferences_control(EventHandler /*requiredPrefChanged*/)
+{
+  return NULL;
+}
+
+bool SyncAddin::save_configuration()
+{
+  return true;
+}
+
+void SyncAddin::reset_configuration()
+{
+}
+
+bool SyncAddin::is_configured()
+{
+  return true;
+}
+
+std::string SyncAddin::name()
+{
+  return "test";
+}
+
+std::string SyncAddin::id()
+{
+  return "test";
+}
+
+bool SyncAddin::is_supported()
+{
+  return true;
+}
+
+void SyncAddin::initialize()
+{
+}
+
+void SyncAddin::shutdown()
+{
+}
+
+bool SyncAddin::initialized()
+{
+  return true;
+}
+
+
+}
diff --git a/src/test/testsyncaddin.hpp b/src/test/testsyncaddin.hpp
new file mode 100644
index 0000000..d4e4edc
--- /dev/null
+++ b/src/test/testsyncaddin.hpp
@@ -0,0 +1,53 @@
+/*
+ * 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/>.
+ */
+
+
+#ifndef _TESTSYNCADDIN_HPP_
+#define _TESTSYNCADDIN_HPP_
+
+
+#include "base/macros.hpp"
+#include "synchronization/syncserviceaddin.hpp"
+
+
+namespace test {
+
+class SyncAddin
+  : public gnote::sync::SyncServiceAddin
+{
+public:
+  virtual gnote::sync::SyncServer::Ptr create_sync_server() override;
+  virtual void post_sync_cleanup() override;
+  virtual Gtk::Widget *create_preferences_control(EventHandler requiredPrefChanged) override;
+  virtual bool save_configuration() override;
+  virtual void reset_configuration() override;
+  virtual bool is_configured() override;
+  virtual std::string name() override;
+  virtual std::string id() override;
+  virtual bool is_supported() override;
+  virtual void initialize() override;
+  virtual void shutdown() override;
+  virtual bool initialized() override;
+};
+
+}
+
+
+#endif
+
diff --git a/src/test/testsyncmanager.cpp b/src/test/testsyncmanager.cpp
new file mode 100644
index 0000000..c240dfa
--- /dev/null
+++ b/src/test/testsyncmanager.cpp
@@ -0,0 +1,70 @@
+/*
+ * 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 "testsyncaddin.hpp"
+#include "testsyncmanager.hpp"
+
+namespace test {
+
+SyncManager::SyncManager(gnote::NoteManagerBase & manager)
+  : gnote::sync::SyncManager(manager)
+{
+  m_client = gnote::sync::SyncClient::Ptr(new test::SyncClient(manager));
+}
+
+test::SyncClient::Ptr SyncManager::get_client(const std::string & manifest)
+{
+  SyncClient::Ptr client = dynamic_pointer_cast<SyncClient>(m_client);
+  client->set_manifest_path(manifest);
+  client->reparse();
+  return client;
+}
+
+void SyncManager::reset_client()
+{
+}
+
+void SyncManager::perform_synchronization(const gnote::sync::SyncUI::Ptr & sync_ui)
+{
+  m_sync_ui = sync_ui;
+  synchronization_thread();
+}
+
+void SyncManager::resolve_conflict(gnote::sync::SyncTitleConflictResolution resolution)
+{
+}
+
+bool SyncManager::synchronized_note_xml_matches(const std::string & noteXml1, const std::string & noteXml2)
+{
+  return false;
+}
+
+gnote::sync::SyncServiceAddin *SyncManager::get_sync_service_addin(const std::string & sync_service_id)
+{
+  return new SyncAddin();
+}
+
+gnote::sync::SyncServiceAddin *SyncManager::get_configured_sync_service()
+{
+  return get_sync_service_addin("");
+}
+
+}
+
diff --git a/src/test/testsyncmanager.hpp b/src/test/testsyncmanager.hpp
new file mode 100644
index 0000000..8c7e8bb
--- /dev/null
+++ b/src/test/testsyncmanager.hpp
@@ -0,0 +1,48 @@
+/*
+ * 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/>.
+ */
+
+
+#ifndef _TEST_TESTSYNCMANAGER_HPP_
+#define _TEST_TESTSYNCMANAGER_HPP_
+
+#include "base/macros.hpp"
+#include "synchronization/syncmanager.hpp"
+#include "testsyncclient.hpp"
+
+
+namespace test {
+
+class SyncManager
+  : public gnote::sync::SyncManager
+{
+public:
+  SyncManager(gnote::NoteManagerBase&);
+  virtual void reset_client() override;
+  virtual void perform_synchronization(const gnote::sync::SyncUI::Ptr & sync_ui) override;
+  virtual void resolve_conflict(gnote::sync::SyncTitleConflictResolution resolution) override;
+  virtual bool synchronized_note_xml_matches(const std::string & noteXml1, const std::string & noteXml2) 
override;
+  virtual gnote::sync::SyncServiceAddin *get_sync_service_addin(const std::string & sync_service_id) 
override;
+  virtual gnote::sync::SyncServiceAddin *get_configured_sync_service() override;
+  test::SyncClient::Ptr get_client(const std::string & manifest);
+};
+
+}
+
+#endif
+


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