File indexing completed on 2024-11-24 04:44:09

0001 /*
0002  * SPDX-FileCopyrightText: 2012 Christian Mollekopf <mollekopf@kolabsys.com>
0003  *
0004  * SPDX-License-Identifier: LGPL-3.0-or-later
0005  */
0006 
0007 #include "legacyformattest.h"
0008 #include "kolabformat/errorhandler.h"
0009 #include "kolabformat/xmlobject.h"
0010 #include "pimkolab_debug.h"
0011 #include "testutils.h"
0012 #include <QTest>
0013 #include <fstream>
0014 #include <sstream>
0015 
0016 void V2Test::testReadDistlistUID()
0017 {
0018     std::ifstream t((TESTFILEDIR.toStdString() + "v2/contacts/distlistWithUID.xml").c_str());
0019     std::stringstream buffer;
0020     buffer << t.rdbuf();
0021 
0022     Kolab::XMLObject xo;
0023     const Kolab::DistList distlist = xo.readDistlist(buffer.str(), Kolab::KolabV2);
0024     const auto members = distlist.members();
0025     for (const Kolab::ContactReference &contact : members) {
0026         QVERIFY(!contact.uid().empty());
0027     }
0028     QVERIFY(!Kolab::ErrorHandler::errorOccured());
0029 }
0030 
0031 void V2Test::testWriteDistlistUID()
0032 {
0033     Kolab::DistList distlist;
0034     distlist.setUid("uid");
0035     distlist.setName("name");
0036     std::vector<Kolab::ContactReference> members;
0037     members.emplace_back(Kolab::ContactReference::UidReference, "memberuid", "membername");
0038     distlist.setMembers(members);
0039 
0040     Kolab::XMLObject xo;
0041     const std::string xml = xo.writeDistlist(distlist, Kolab::KolabV2);
0042     QVERIFY(QString::fromStdString(xml).contains(QLatin1StringView("memberuid")));
0043     QVERIFY(!Kolab::ErrorHandler::errorOccured());
0044 }
0045 
0046 QTEST_MAIN(V2Test)
0047 
0048 #include "moc_legacyformattest.cpp"