-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMBDocTestMain.cpp
More file actions
88 lines (86 loc) · 3 KB
/
Copy pathMBDocTestMain.cpp
File metadata and controls
88 lines (86 loc) · 3 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
#include "MBDoc.h"
#include <iostream>
std::vector<std::string> TestLinkResolving()
{
std::vector<std::string> ReturnValue;
MBError ParseError;
MBDoc::DocumentBuild LinkResolveBuild = MBDoc::DocumentBuild::ParseDocumentBuild("LinkResolution/LinkResolve.json",ParseError);
if(!ParseError)
{
ReturnValue.push_back("Error in testing link resolving: Error parsing LinkResolve.json: "+ParseError.ErrorMessage);
return(ReturnValue);
}
MBDoc::DocumentFilesystem LinkResolveFilesystem;
//ParseError = MBDoc::DocumentFilesystem::CreateDocumentFilesystem(LinkResolveBuild,LinkResolveFilesystem);
//Current Dir and PathToResolve
std::vector<std::pair<std::string,std::string>> TruePairs =
{
{"/Top2.mbd","Top1.mbd"},
{"/Top2.mbd","Top1.mbd#Top1 Top"},
{"/Top2.mbd","Top1.mbd#Top1 Sub"},
{"/Top2.mbd","Top1.mbd#Top1 SubSub"},
{"/Top2.mbd","#Top2 Top"},
{"/Top2.mbd","#Top2 Sub"},
{"/Top2.mbd","#Top2 SubSub"},
};
std::vector<std::pair<std::string,std::string>> FalsePairs
{
{"/Top2.mbd","Top3.mbd"},
};
for(auto const& Pair : TruePairs)
{
ParseError = MBError(true);
MBDoc::DocumentPath DocPath = MBDoc::DocumentPath::ParsePath(Pair.first,ParseError);
if(!ParseError)
{
ReturnValue.push_back("Error parsing path \""+Pair.first+"\": "+ParseError.ErrorMessage);
ParseError = MBError(true);
continue;
}
LinkResolveFilesystem.ResolveReference(DocPath,Pair.second,ParseError);
if(!ParseError)
{
ReturnValue.push_back("Error resolving path \""+Pair.second+"\" in document \""+Pair.first+"\": "+ParseError.ErrorMessage);
ParseError = MBError(true);
}
}
for(auto const& Pair : FalsePairs)
{
ParseError = MBError(true);
MBDoc::DocumentPath DocPath = MBDoc::DocumentPath::ParsePath(Pair.first,ParseError);
if(!ParseError)
{
ReturnValue.push_back("Error parsing path \""+Pair.first+"\": "+ParseError.ErrorMessage);
ParseError = MBError(true);
continue;
}
LinkResolveFilesystem.ResolveReference(DocPath,Pair.second,ParseError);
if(ParseError)
{
ReturnValue.push_back("Incorrect path \""+Pair.second+"\" resolved in document \""+Pair.first+"\": "+ParseError.ErrorMessage);
ParseError = MBError(true);
}
}
return(ReturnValue);
}
//Assumes that it's run in the Test subdirectory
int main(int argc,const char** argv)
{
bool ErrorOccured = false;
std::vector<std::vector<std::string>(*)()> Tests = {TestLinkResolving};
for(auto const& Test : Tests)
{
std::vector<std::string> NewErrors = Test();
for(std::string& Error : NewErrors)
{
ErrorOccured = true;
std::cout<<Error<<"\n";
}
}
std::cout.flush();
if(ErrorOccured)
{
return(1);
}
return(0);
}