1 /**
2  * (c) 2019 by Mega Limited, Wellsford, New Zealand
3  *
4  * This file is part of the MEGA SDK - Client Access Engine.
5  *
6  * Applications using the MEGA API must present a valid application key
7  * and comply with the the rules set forth in the Terms of Service.
8  *
9  * The MEGA SDK is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  *
13  * @copyright Simplified (2-clause) BSD License.
14  *
15  * You should have received a copy of the license along with this
16  * program.
17  */
18 
19 #include <gtest/gtest.h>
20 
21 #include <mega/pendingcontactrequest.h>
22 
23 namespace
24 {
25 
checkPcrs(const mega::PendingContactRequest & exp,const mega::PendingContactRequest & act)26 void checkPcrs(const mega::PendingContactRequest& exp, const mega::PendingContactRequest& act)
27 {
28     ASSERT_EQ(exp.id, act.id);
29     ASSERT_EQ(exp.originatoremail, act.originatoremail);
30     ASSERT_EQ(exp.targetemail, act.targetemail);
31     ASSERT_EQ(exp.ts, act.ts);
32     ASSERT_EQ(exp.uts, act.uts);
33     ASSERT_EQ(exp.msg, act.msg);
34     ASSERT_EQ(exp.isoutgoing, act.isoutgoing);
35 }
36 
37 }
38 
TEST(PendingContactRequest,serialize_unserialize)39 TEST(PendingContactRequest, serialize_unserialize)
40 {
41     mega::PendingContactRequest pcr{1, "blah", "foo", 2, 3, "hello", true};
42 
43     std::string d;
44     ASSERT_TRUE(pcr.serialize(&d));
45 
46     auto newPcr = std::unique_ptr<mega::PendingContactRequest>{mega::PendingContactRequest::unserialize(&d)};
47     checkPcrs(pcr, *newPcr);
48 }
49 
TEST(PendingContactRequest,unserialize_32bit)50 TEST(PendingContactRequest, unserialize_32bit)
51 {
52     mega::PendingContactRequest pcr{1, "blah", "foo", 2, 3, "hello", true};
53 
54     // This is the result of serialization on 32bit Windows
55     const std::array<char, 40> rawData = {
56         0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x62, 0x6c, 0x61,
57         0x68, 0x03, 0x66, 0x6f, 0x6f, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58         0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x68, 0x65,
59         0x6c, 0x6c, 0x6f, 0x01
60     };
61     std::string d(rawData.data(), rawData.size());
62 
63     auto newPcr = std::unique_ptr<mega::PendingContactRequest>{mega::PendingContactRequest::unserialize(&d)};
64     checkPcrs(pcr, *newPcr);
65 }
66