LeechCraft  0.6.70-15082-g543737046d
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 struct Student
15 {
16  lco::PKey<int> ID_;
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 
36 struct StudentInfo
37 {
38  lco::PKey<int> ID_;
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 
60 TOSTRING (StudentInfo)
61 
62 struct Lecturer
63 {
64  lco::PKey<int> ID_;
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 
82 TOSTRING (Lecturer)
83 
84 struct Student2Lecturer
85 {
86  lco::PKey<int> ID_;
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 
101 BOOST_FUSION_ADAPT_STRUCT (Student2Lecturer,
102  ID_,
103  StudentID_,
104  LecturerID_)
105 
106 TOSTRING (Student2Lecturer)
107 
108 namespace LC
109 {
110 namespace 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 }
QList
Definition: ianrulesstorage.h:14
LC::Util::MakeDatabase
QSqlDatabase MakeDatabase(const QString &name=":memory:")
Definition: common.h:73
LC::Util::oral::References
Definition: oraltypes.h:130
common.h
Student
Definition: oralfkeytest.cpp:14
TOSTRING
#define TOSTRING(n)
Definition: common.h:52
LC::Util::oral::PKey< int >
BOOST_FUSION_ADAPT_STRUCT
BOOST_FUSION_ADAPT_STRUCT(Student, ID_, Name_) struct StudentInfo
Definition: oralfkeytest.cpp:30
LC
Definition: constants.h:14
LC::Util::OralFKeyTest
Definition: oralfkeytest.h:29
oralfkeytest.h
Name_
std::string Name_
Definition: desktopparser.cpp:35