LeechCraft 0.6.70-14794-g33744ae6ce
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
12QTEST_GUILESS_MAIN (LC::Util::OralFKeyTest)
13
14struct Student
15{
17 QString Name_;
18
19 static QString ClassName ()
20 {
21 return "Student";
22 }
23
24 auto AsTuple () const
25 {
26 return std::tie (ID_, Name_);
27 }
28};
29
31 ID_,
32 Name_)
33
35
36struct StudentInfo
37{
40 int Age_;
41 int Year_;
42
43 static QString ClassName ()
44 {
45 return "StudentInfo";
46 }
47
48 auto AsTuple () const
49 {
50 return std::tie (ID_, StudentID_, Age_, Year_);
51 }
52};
53
55 ID_,
56 StudentID_,
57 Age_,
58 Year_)
59
60TOSTRING (StudentInfo)
61
62struct Lecturer
63{
65 QString Name_;
66
67 static QString ClassName ()
68 {
69 return "Lecturer";
70 }
71
72 auto AsTuple () const
73 {
74 return std::tie (ID_, Name_);
75 }
76};
77
79 ID_,
80 Name_)
81
82TOSTRING (Lecturer)
83
84struct Student2Lecturer
85{
89
90 static QString ClassName ()
91 {
92 return "Student2Lecturer";
93 }
94
95 auto AsTuple () const
96 {
97 return std::tie (ID_, StudentID_, LecturerID_);
98 }
99};
100
102 ID_,
103 StudentID_,
104 LecturerID_)
105
106TOSTRING (Student2Lecturer)
107
108namespace LC
109{
110namespace Util
111{
112 void OralFKeyTest::testBasicFKeys ()
113 {
114 auto db = MakeDatabase ();
115
116 auto student = Util::oral::AdaptPtr<Student, OralFactory> (db);
117 auto studentInfo = Util::oral::AdaptPtr<StudentInfo, OralFactory> (db);
118
120 {
121 { { 0, "Student 1" }, { 0, 0, 18, 1 } },
122 { { 0, "Student 2" }, { 0, 0, 19, 1 } },
123 { { 0, "Student 3" }, { 0, 0, 19, 2 } },
124 };
125
126 for (auto& [stud, info] : list)
127 {
128 student->Insert (stud);
129 info.StudentID_ = stud.ID_;
130 studentInfo->Insert (info);
131 }
132
133 namespace sph = oral::sph;
134
135 const auto& selected = student->Select (sph::f<&Student::ID_> == sph::f<&StudentInfo::StudentID_> &&
136 sph::f<&StudentInfo::Age_> > 18);
137 const QList<Student> expected { list [1].first, list [2].first };
138 QCOMPARE (selected, expected);
139 }
140}
141}
#define TOSTRING(n)
Definition: common.h:52
std::string Name_
QSqlDatabase MakeDatabase(const QString &name=":memory:")
Definition: common.h:73
Definition: constants.h:15
BOOST_FUSION_ADAPT_STRUCT(Student, ID_, Name_) struct StudentInfo
static QString ClassName()
auto AsTuple() const
QString Name_
lco::PKey< int > ID_