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
12QTEST_GUILESS_MAIN (LC::Util::OralFKeyTest)
13
14using LC::operator""_ct;
15
16struct Student
17{
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
30 ID_,
31 Name_)
32
34
35struct StudentInfo
36{
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
50ORAL_ADAPT_STRUCT (StudentInfo,
51 ID_,
52 StudentID_,
53 Age_,
54 Year_)
55
56TOSTRING (StudentInfo)
57
58struct Lecturer
59{
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
72 ID_,
73 Name_)
74
75TOSTRING (Lecturer)
76
77struct Student2Lecturer
78{
82
83 constexpr static auto ClassName = "Student2Lecturer"_ct;
84
85 auto AsTuple () const
86 {
87 return std::tie (ID_, StudentID_, LecturerID_);
88 }
89};
90
91ORAL_ADAPT_STRUCT (Student2Lecturer,
92 ID_,
93 StudentID_,
94 LecturerID_)
95
96TOSTRING (Student2Lecturer)
97
98namespace LC
99{
100namespace Util
101{
102 void OralFKeyTest::testBasicFKeys ()
103 {
104 auto db = MakeDatabase ();
105
108
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_> &&
127 const QList<Student> expected { list [1].first, list [2].first };
128 QCOMPARE (selected, expected);
129 }
130}
131}
#define TOSTRING(n)
Definition common.h:52
std::string Name_
constexpr detail::ExprTree< detail::ExprType::LeafStaticPlaceholder, detail::MemberPtrs< Ptr > > f
Definition oral.h:951
ObjectInfo_ptr< T > AdaptPtr(const QSqlDatabase &db)
Definition oral.h:1662
QSqlDatabase MakeDatabase(const QString &name=":memory:")
Definition common.h:73
Definition constants.h:15
#define ORAL_ADAPT_STRUCT(sname,...)
Definition oral.h:52
static constexpr auto ClassName
auto AsTuple() const
QString Name_
lco::PKey< int > ID_