From 709d35a0e3624046ba00429d50dfd33d8bbc9d9c Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Tue, 17 Jul 2018 17:13:09 +0100
Subject: Add unit test for missing bookmark responses

Test-Information:
Without the recent fix for missing bookmark results, tests crash,
on master they pass

Change-Id: Iab2d55d6d60e5926485d31f4dd63a117a9d12aee

diff --git a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
index 7469d64..954dd2f 100644
--- a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
+++ b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
@@ -177,6 +177,9 @@ class ChatsManagerTest : public CppUnit::TestFixture {
     CPPUNIT_TEST(testAutoJoinBookmarksAndChattables);
     CPPUNIT_TEST(testJoinNoAutojoinBookmark);
     CPPUNIT_TEST(testJoinAndBookmarkMUC);
+    CPPUNIT_TEST(testReceivingNoBookmarks);
+    CPPUNIT_TEST(testReceivingNullBookmarks);
+    CPPUNIT_TEST(testReceivingBookmarksError);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -1691,6 +1694,41 @@ public:
         stanzaChannel_->onIQReceived(response);
     }
 
+    void testReceivingNoBookmarks() {
+        auto bookmarkRequest = std::dynamic_pointer_cast<IQ>(stanzaChannel_->sentStanzas[0]);
+        auto response = IQ::createResult(
+            bookmarkRequest->getFrom(),
+            bookmarkRequest->getTo(),
+            bookmarkRequest->getID(),
+            std::make_shared<PrivateStorage>()
+        );
+        stanzaChannel_->onIQReceived(response);
+    }
+
+    void testReceivingNullBookmarks() {
+        auto bookmarkRequest = std::dynamic_pointer_cast<IQ>(stanzaChannel_->sentStanzas[0]);
+        auto response = IQ::createResult(
+            bookmarkRequest->getFrom(),
+            bookmarkRequest->getTo(),
+            bookmarkRequest->getID(),
+            nullptr
+        );
+        stanzaChannel_->onIQReceived(response);
+    }
+
+    void testReceivingBookmarksError() {
+        auto bookmarkRequest = std::dynamic_pointer_cast<IQ>(stanzaChannel_->sentStanzas[0]);
+        auto response = IQ::createError(
+            bookmarkRequest->getFrom(),
+            bookmarkRequest->getTo(),
+            bookmarkRequest->getID(),
+            ErrorPayload::Condition::ServiceUnavailable,
+            ErrorPayload::Type::Cancel,
+            nullptr
+        );
+        stanzaChannel_->onIQReceived(response);
+    }
+
     void testReceivingBookmarksWithFullJID() {
         auto bookmarkRequest = std::dynamic_pointer_cast<IQ>(stanzaChannel_->sentStanzas[0]);
         auto response = IQ::createResult(
diff --git a/Swiften/MUC/MUCBookmarkManager.cpp b/Swiften/MUC/MUCBookmarkManager.cpp
index da021ad..8a7854d 100644
--- a/Swiften/MUC/MUCBookmarkManager.cpp
+++ b/Swiften/MUC/MUCBookmarkManager.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
  * All rights reserved.
  * See the COPYING file for more information.
  */
-- 
cgit v0.10.2-6-g49f6