Repository navigation
Expand file tree
/
Copy pathtest_structuralcontext.cpp
More file actions
78 lines (66 loc) · 2.76 KB
/
Copy pathtest_structuralcontext.cpp
File metadata and controls
78 lines (66 loc) · 2.76 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
#include <cassert>
#include <ref/utils/StructuralContext.hpp>
#include "../examples/company.hpp"
#include <iostream>
#include <set>
#include <algorithm>
using namespace ref;
using namespace std;
int main(int argc, char **argv)
{
auto companyDesc =
example::Company::getClassDescriptorInstance();
auto departmentDesc =
example::Department::getClassDescriptorInstance();
auto employeeDesc =
example::Employee::getClassDescriptorInstance();
const StructuralContext ctx(companyDesc);
// getRootClass and getAllClasses
{
assert(ctx.getRootClass() == companyDesc);
assert(ctx.getAllClasses().size() == 4);
const set<string> expected = {"ref::ModelClass", "example::Department",
"example::Employee", "example::Company"};
const auto allClasses = ctx.getAllClasses();
set<string> fqns;
for (auto d: allClasses)
{
fqns.insert(d->getFqn());
}
assert(fqns == expected);
}
// References
{
assert(ctx.getIncomingReferences(companyDesc).size() == 0);
assert(ctx.getIncomingReferences(departmentDesc).size() == 1);
assert(ctx.getIncomingReferences(employeeDesc).size() == 2);
assert(ctx.getAllIncomingReferences(companyDesc).size() == 0);
assert(ctx.getAllIncomingReferences(departmentDesc).size() == 1);
assert(ctx.getAllIncomingReferences(employeeDesc).size() == 2);
assert(ctx.getOutgoingReferences(companyDesc).size() == 1);
assert(ctx.getOutgoingReferences(departmentDesc).size() == 1);
assert(ctx.getOutgoingReferences(employeeDesc).size() == 1);
assert(ctx.getAllOutgoingReferences(companyDesc).size() == 1);
assert(ctx.getAllOutgoingReferences(departmentDesc).size() == 1);
assert(ctx.getAllOutgoingReferences(employeeDesc).size() == 1);
auto empInRefs = ctx.getIncomingReferences(employeeDesc);
for (const auto& it: empInRefs)
{
assert(it.referencedClassDesc == employeeDesc);
}
assert(empInRefs[0].classDesc == departmentDesc);
assert(empInRefs[0].featureDesc ==
departmentDesc->getFeatureDescriptor("Employees"));
assert(empInRefs[1].classDesc == employeeDesc);
assert(empInRefs[1].featureDesc ==
employeeDesc->getFeatureDescriptor("Manager"));
// isReference
assert(
ctx.isReference(departmentDesc->getFeatureDescriptor("Employees")));
assert(!ctx.isReference(departmentDesc->getFeatureDescriptor("Name")));
assert(
ctx.isReference(companyDesc->getFeatureDescriptor("Departments")));
assert(!ctx.isReference(companyDesc->getFeatureDescriptor("Name")));
}
return 0;
}