LeechCraft  0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
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 {
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 
35 struct StudentInfo
36 {
37  lco::PKey<int> ID_;
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 
72  ID_,
73  Name_)
74 
75 TOSTRING (Lecturer)
76 
77 struct Student2Lecturer
78 {
79  lco::PKey<int> ID_;
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 
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 }
std::string Name_
ORAL_ADAPT_STRUCT(Student, ID_, Name_) struct StudentInfo
QString Name_
QSqlDatabase MakeDatabase(const QString &name=":memory:")
Definition: common.h:73
lco::PKey< int > ID_
static constexpr auto ClassName
auto AsTuple() const
#define TOSTRING(n)
Definition: common.h:52