LeechCraft
0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
oralfkeytest.cpp
Go to the documentation of this file.
1
/**********************************************************************
2
* LeechCraft - modular cross-platform feature rich internet client.
3
* Copyright (C) 2006-2014 Georg Rudoy
4
*
5
* Distributed under the Boost Software License, Version 1.0.
6
* (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7
**********************************************************************/
8
9
#include "
oralfkeytest.h
"
10
#include "
common.h
"
11
12
QTEST_GUILESS_MAIN (
LC::Util::OralFKeyTest
)
13
14
using
LC::operator
""
_ct;
15
16
struct
Student
17
{
18
lco::PKey<int>
ID_
;
19
QString
Name_
;
20
21
constexpr
static
auto
ClassName
=
"Student"
_ct;
22
23
auto
AsTuple
()
const
24
{
25
return
std::tie (
ID_
,
Name_
);
26
}
27
};
28
29
ORAL_ADAPT_STRUCT
(
Student
,
30
ID_,
31
Name_
)
32
33
TOSTRING
(
Student
)
34
35
struct
StudentInfo
36
{
37
lco::PKey<int>
ID_;
38
lco::References<&Student::ID_>
StudentID_;
39
int
Age_;
40
int
Year_;
41
42
constexpr
static
auto
ClassName =
"StudentInfo"
_ct;
43
44
auto
AsTuple ()
const
45
{
46
return
std::tie (ID_, StudentID_, Age_, Year_);
47
}
48
};
49
50
ORAL_ADAPT_STRUCT
(StudentInfo,
51
ID_,
52
StudentID_,
53
Age_,
54
Year_)
55
56
TOSTRING
(StudentInfo)
57
58
struct
Lecturer
59
{
60
lco::PKey<int>
ID_;
61
QString
Name_
;
62
63
constexpr
static
auto
ClassName =
"Lecturer"
_ct;
64
65
auto
AsTuple ()
const
66
{
67
return
std::tie (ID_,
Name_
);
68
}
69
};
70
71
ORAL_ADAPT_STRUCT
(Lecturer,
72
ID_,
73
Name_
)
74
75
TOSTRING
(Lecturer)
76
77
struct
Student2Lecturer
78
{
79
lco::PKey<int>
ID_;
80
lco::References<&Student::ID_>
StudentID_;
81
lco::References<&Lecturer::ID_>
LecturerID_;
82
83
constexpr
static
auto
ClassName =
"Student2Lecturer"
_ct;
84
85
auto
AsTuple ()
const
86
{
87
return
std::tie (ID_, StudentID_, LecturerID_);
88
}
89
};
90
91
ORAL_ADAPT_STRUCT
(Student2Lecturer,
92
ID_,
93
StudentID_,
94
LecturerID_)
95
96
TOSTRING
(Student2Lecturer)
97
98
namespace
LC
99
{
100
namespace
Util
101
{
102
void
OralFKeyTest::testBasicFKeys ()
103
{
104
auto
db =
MakeDatabase
();
105
106
auto
student =
Util::oral::AdaptPtr<Student, OralFactory>
(db);
107
auto
studentInfo =
Util::oral::AdaptPtr<StudentInfo, OralFactory>
(db);
108
109
QList<QPair<Student, StudentInfo>
> list
110
{
111
{ { 0,
"Student 1"
}, { 0, 0, 18, 1 } },
112
{ { 0,
"Student 2"
}, { 0, 0, 19, 1 } },
113
{ { 0,
"Student 3"
}, { 0, 0, 19, 2 } },
114
};
115
116
for
(
auto
& [stud, info] : list)
117
{
118
student->Insert (stud);
119
info.StudentID_ = stud.ID_;
120
studentInfo->Insert (info);
121
}
122
123
namespace
sph = oral::sph;
124
125
const
auto
& selected = student->Select (
sph::f<&Student::ID_>
==
sph::f<&StudentInfo::StudentID_>
&&
126
sph::f<&StudentInfo::Age_>
> 18);
127
const
QList<Student>
expected { list [1].first, list [2].first };
128
QCOMPARE (selected, expected);
129
}
130
}
131
}
LC::Util::OralFKeyTest
Definition
oralfkeytest.h:18
QList
Definition
ianrulesstorage.h:14
common.h
TOSTRING
#define TOSTRING(n)
Definition
common.h:52
Name_
std::string Name_
Definition
desktopparser.cpp:23
LC::Util::oral::sph::f
constexpr detail::ExprTree< detail::ExprType::LeafStaticPlaceholder, detail::MemberPtrs< Ptr > > f
Definition
oral.h:951
LC::Util::oral::AdaptPtr
ObjectInfo_ptr< T > AdaptPtr(const QSqlDatabase &db)
Definition
oral.h:1662
LC::Util::MakeDatabase
QSqlDatabase MakeDatabase(const QString &name=":memory:")
Definition
common.h:73
LC
Definition
constants.h:15
ORAL_ADAPT_STRUCT
#define ORAL_ADAPT_STRUCT(sname,...)
Definition
oral.h:52
oralfkeytest.h
LC::Util::oral::PKey
Definition
oraltypes.h:67
LC::Util::oral::References
Definition
oraltypes.h:109
Student
Definition
oralfkeytest.cpp:17
Student::ClassName
static constexpr auto ClassName
Definition
oralfkeytest.cpp:21
Student::AsTuple
auto AsTuple() const
Definition
oralfkeytest.cpp:23
Student::Name_
QString Name_
Definition
oralfkeytest.cpp:19
Student::ID_
lco::PKey< int > ID_
Definition
oralfkeytest.cpp:18
src
util
db
tests
oralfkeytest.cpp
Generated by
1.12.0