LeechCraft  0.6.70-13729-g7046a9d2a7
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  * Boost Software License - Version 1.0 - August 17th, 2003
6  *
7  * Permission is hereby granted, free of charge, to any person or organization
8  * obtaining a copy of the software and accompanying documentation covered by
9  * this license (the "Software") to use, reproduce, display, distribute,
10  * execute, and transmit the Software, and to prepare derivative works of the
11  * Software, and to permit third-parties to whom the Software is furnished to
12  * do so, all subject to the following:
13  *
14  * The copyright notices in the Software and this entire statement, including
15  * the above license grant, this restriction and the following disclaimer,
16  * must be included in all copies of the Software, in whole or in part, and
17  * all derivative works of the Software, unless such copies or derivative
18  * works are solely in the form of machine-executable object code generated by
19  * a source language processor.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
24  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
25  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  **********************************************************************/
29 
30 #include "oralfkeytest.h"
31 #include "common.h"
32 
33 QTEST_GUILESS_MAIN (LC::Util::OralFKeyTest)
34 
35 struct Student
36 {
38  QString Name_;
39 
40  static QString ClassName ()
41  {
42  return "Student";
43  }
44 
45  auto AsTuple () const
46  {
47  return std::tie (ID_, Name_);
48  }
49 };
50 
52  ID_,
53  Name_)
54 
56 
57 struct StudentInfo
58 {
59  lco::PKey<int> ID_;
61  int Age_;
62  int Year_;
63 
64  static QString ClassName ()
65  {
66  return "StudentInfo";
67  }
68 
69  auto AsTuple () const
70  {
71  return std::tie (ID_, StudentID_, Age_, Year_);
72  }
73 };
74 
76  ID_,
77  StudentID_,
78  Age_,
79  Year_)
80 
81 TOSTRING (StudentInfo)
82 
83 struct Lecturer
84 {
85  lco::PKey<int> ID_;
86  QString Name_;
87 
88  static QString ClassName ()
89  {
90  return "Lecturer";
91  }
92 
93  auto AsTuple () const
94  {
95  return std::tie (ID_, Name_);
96  }
97 };
98 
100  ID_,
101  Name_)
102 
103 TOSTRING (Lecturer)
104 
105 struct Student2Lecturer
106 {
107  lco::PKey<int> ID_;
110 
111  static QString ClassName ()
112  {
113  return "Student2Lecturer";
114  }
115 
116  auto AsTuple () const
117  {
118  return std::tie (ID_, StudentID_, LecturerID_);
119  }
120 };
121 
122 BOOST_FUSION_ADAPT_STRUCT (Student2Lecturer,
123  ID_,
124  StudentID_,
125  LecturerID_)
126 
127 TOSTRING (Student2Lecturer)
128 
129 namespace LC
130 {
131 namespace Util
132 {
133  void OralFKeyTest::testBasicFKeys ()
134  {
135  auto db = MakeDatabase ();
136 
137  auto student = Util::oral::AdaptPtr<Student, OralFactory> (db);
138  auto studentInfo = Util::oral::AdaptPtr<StudentInfo, OralFactory> (db);
139 
141  {
142  { { 0, "Student 1" }, { 0, 0, 18, 1 } },
143  { { 0, "Student 2" }, { 0, 0, 19, 1 } },
144  { { 0, "Student 3" }, { 0, 0, 19, 2 } },
145  };
146 
147  for (auto& [stud, info] : list)
148  {
149  student->Insert (stud);
150  info.StudentID_ = stud.ID_;
151  studentInfo->Insert (info);
152  }
153 
154  namespace sph = oral::sph;
155 
156  const auto& selected = student->Select (sph::f<&Student::ID_> == sph::f<&StudentInfo::StudentID_> &&
157  sph::f<&StudentInfo::Age_> > 18);
158  const QList<Student> expected { list [1].first, list [2].first };
159  QCOMPARE (selected, expected);
160  }
161 }
162 }
std::string Name_
QString Name_
QSqlDatabase MakeDatabase(const QString &name=":memory:")
Definition: common.h:112
static QString ClassName()
lco::PKey< int > ID_
BOOST_FUSION_ADAPT_STRUCT(Student, ID_, Name_) struct StudentInfo
auto AsTuple() const
Definition: constants.h:35
#define TOSTRING(n)
Definition: common.h:91