forked from meganz/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile_test.cpp
More file actions
135 lines (122 loc) · 4.72 KB
/
File_test.cpp
File metadata and controls
135 lines (122 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
* (c) 2019 by Mega Limited, Wellsford, New Zealand
*
* This file is part of the MEGA SDK - Client Access Engine.
*
* Applications using the MEGA API must present a valid application key
* and comply with the the rules set forth in the Terms of Service.
*
* The MEGA SDK 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.
*
* @copyright Simplified (2-clause) BSD License.
*
* You should have received a copy of the license along with this
* program.
*/
#include <gtest/gtest.h>
#include <mega/megaclient.h>
#include <mega/megaapp.h>
#include <mega/file.h>
#include "DefaultedFileSystemAccess.h"
#include "utils.h"
#include "mega.h"
namespace
{
//class MockFileSystemAccess : public mt::DefaultedFileSystemAccess
//{
//public:
// bool unlinklocal(std::string*) override
// {
// return true;
// }
//};
void checkFiles(const mega::File& exp, const mega::File& act)
{
ASSERT_EQ(exp.name, act.name);
ASSERT_EQ(exp.localname, act.localname);
ASSERT_EQ(exp.h, act.h);
ASSERT_EQ(exp.hprivate, act.hprivate);
ASSERT_EQ(exp.hforeign, act.hforeign);
ASSERT_EQ(exp.syncxfer, act.syncxfer);
ASSERT_EQ(exp.temporaryfile, act.temporaryfile);
ASSERT_EQ(exp.privauth, act.privauth);
ASSERT_EQ(exp.pubauth, act.pubauth);
ASSERT_EQ(std::string{exp.chatauth}, std::string{act.chatauth});
ASSERT_TRUE(std::equal(exp.filekey, exp.filekey + mega::FILENODEKEYLENGTH, act.filekey));
ASSERT_EQ(exp.targetuser, act.targetuser);
ASSERT_EQ(nullptr, act.transfer);
ASSERT_EQ(static_cast<const mega::FileFingerprint&>(exp), static_cast<const mega::FileFingerprint&>(act));
}
}
TEST(File, serialize_unserialize)
{
mega::MegaApp app;
::mega::FSACCESS_CLASS fsaccess;
auto client = mt::makeClient(app, fsaccess);
mega::File file;
file.name = "foo";
file.localname = ::mega::LocalPath::fromPath(file.name, fsaccess);
file.h = 42;
file.hprivate = true;
file.hforeign = true;
file.syncxfer = true;
file.temporaryfile = true;
file.privauth = "privauth";
file.pubauth = "pubauth";
file.chatauth = new char[4]{'b', 'a', 'r', '\0'}; // owned by file
std::fill(file.filekey, file.filekey + mega::FILENODEKEYLENGTH, 'X');
file.targetuser = "targetuser";
file.transfer = new mega::Transfer{client.get(), mega::GET}; // owned by client
file.transfer->files.push_back(&file);
file.file_it = file.transfer->files.begin();
std::string d;
file.serialize(&d);
auto newFile = std::unique_ptr<mega::File>{mega::File::unserialize(&d)};
checkFiles(file, *newFile);
}
#ifndef WIN32 // data was recorded with "mock" utf-8 not the actual utf-16
TEST(File, unserialize_32bit)
{
mega::MegaApp app;
::mega::FSACCESS_CLASS fsaccess;
auto client = mt::makeClient(app, fsaccess);
mega::File file;
file.name = "foo";
file.localname = ::mega::LocalPath::fromPath(file.name, fsaccess);
file.h = 42;
file.hprivate = true;
file.hforeign = true;
file.syncxfer = true;
file.temporaryfile = true;
file.privauth = "privauth";
file.pubauth = "pubauth";
file.chatauth = new char[4]{'b', 'a', 'r', '\0'}; // owned by file
std::fill(file.filekey, file.filekey + mega::FILENODEKEYLENGTH, 'X');
file.targetuser = "targetuser";
file.transfer = new mega::Transfer{client.get(), mega::GET}; // owned by client
file.transfer->files.push_back(&file);
file.file_it = file.transfer->files.begin();
// This is the result of serialization on 32bit Windows
const std::array<unsigned char, 133> rawData = {
0x03, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff,
0xff, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00,
0x66, 0x6f, 0x6f, 0x03, 0x00, 0x66, 0x6f, 0x6f, 0x0a, 0x00, 0x74, 0x61,
0x72, 0x67, 0x65, 0x74, 0x75, 0x73, 0x65, 0x72, 0x08, 0x00, 0x70, 0x72,
0x69, 0x76, 0x61, 0x75, 0x74, 0x68, 0x07, 0x00, 0x70, 0x75, 0x62, 0x61,
0x75, 0x74, 0x68, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58,
0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58,
0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58,
0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x01, 0x01, 0x01, 0x01, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x62, 0x61,
0x72
};
std::string d(reinterpret_cast<const char*>(rawData.data()), rawData.size());
auto newFile = std::unique_ptr<mega::File>{mega::File::unserialize(&d)};
checkFiles(file, *newFile);
}
#endif