Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Education
Artikulate
Commits
4551f0f6
Commit
4551f0f6
authored
Jun 23, 2019
by
Andreas Cord-Landwehr
Browse files
Fix and test correct setting of unit parents
parent
40357fc0
Changes
5
Hide whitespace changes
Inline
Side-by-side
autotests/integrationtests/iresourcerepository_integration/test_iresourcerepository.cpp
View file @
4551f0f6
...
...
@@ -26,6 +26,8 @@
#include "core/resourcerepository.h"
#include "core/contributorrepository.h"
#include "core/language.h"
#include "core/icourse.h"
#include "core/unit.h"
#include "../src/settings.h"
void
TestIResourceRepository
::
init
()
...
...
@@ -84,6 +86,7 @@ void TestIResourceRepository::performInterfaceTests(IResourceRepository *interfa
QVERIFY
(
german
!=
nullptr
);
// ensure that German language was found
QCOMPARE
(
interface
->
courses
(
german
->
id
()).
count
(),
1
);
// there is exactly one German course
QCOMPARE
(
interface
->
courses
(
nullptr
).
count
(),
2
);
// all courses in total are 2
QVERIFY
(
interface
->
courses
().
first
()
->
units
().
size
()
>
0
);
}
QTEST_GUILESS_MAIN
(
TestIResourceRepository
)
autotests/unittests/courseresource/test_courseresource.cpp
View file @
4551f0f6
...
...
@@ -72,6 +72,7 @@ void TestCourseResource::loadCourseResource()
QVERIFY
(
course
.
language
()
!=
nullptr
);
QCOMPARE
(
course
.
language
()
->
id
(),
"de"
);
QCOMPARE
(
course
.
units
().
count
(),
1
);
QCOMPARE
(
course
.
units
().
first
()
->
course
(),
&
course
);
const
auto
unit
=
course
.
units
().
first
();
QVERIFY
(
unit
!=
nullptr
);
...
...
@@ -114,10 +115,11 @@ void TestCourseResource::unitAddAndRemoveHandling()
QSignalSpy
spyAdded
(
&
course
,
SIGNAL
(
unitAdded
()));
QCOMPARE
(
spyAboutToBeAdded
.
count
(),
0
);
QCOMPARE
(
spyAdded
.
count
(),
0
);
course
.
addUnit
(
std
::
move
(
unit
));
auto
sharedUnit
=
course
.
addUnit
(
std
::
move
(
unit
));
QCOMPARE
(
course
.
units
().
count
(),
initialUnitNumber
+
1
);
QCOMPARE
(
spyAboutToBeAdded
.
count
(),
1
);
QCOMPARE
(
spyAdded
.
count
(),
1
);
QCOMPARE
(
sharedUnit
->
course
(),
&
course
);
}
void
TestCourseResource
::
coursePropertyChanges
()
...
...
autotests/unittests/editablecourseresource/test_editablecourseresource.cpp
View file @
4551f0f6
...
...
@@ -81,6 +81,7 @@ void TestEditableCourseResource::loadCourseResource()
QVERIFY
(
course
.
language
()
!=
nullptr
);
QCOMPARE
(
course
.
language
()
->
id
(),
"de"
);
QCOMPARE
(
course
.
units
().
count
(),
1
);
QCOMPARE
(
course
.
units
().
first
()
->
course
(),
&
course
);
const
auto
unit
=
course
.
units
().
first
();
QVERIFY
(
unit
!=
nullptr
);
...
...
@@ -120,10 +121,11 @@ void TestEditableCourseResource::unitAddAndRemoveHandling()
QSignalSpy
spyAdded
(
&
course
,
SIGNAL
(
unitAdded
()));
QCOMPARE
(
spyAboutToBeAdded
.
count
(),
0
);
QCOMPARE
(
spyAdded
.
count
(),
0
);
course
.
addUnit
(
std
::
move
(
unit
));
auto
sharedUnit
=
course
.
addUnit
(
std
::
move
(
unit
));
QCOMPARE
(
course
.
units
().
count
(),
initialUnitNumber
+
1
);
QCOMPARE
(
spyAboutToBeAdded
.
count
(),
1
);
QCOMPARE
(
spyAdded
.
count
(),
1
);
QCOMPARE
(
sharedUnit
->
course
(),
&
course
);
}
void
TestEditableCourseResource
::
coursePropertyChanges
()
...
...
src/core/resources/courseresource.cpp
View file @
4551f0f6
...
...
@@ -247,6 +247,7 @@ void CourseResource::setLanguage(std::shared_ptr<Language> language)
std
::
shared_ptr
<
Unit
>
CourseResource
::
addUnit
(
std
::
unique_ptr
<
Unit
>
unit
)
{
std
::
shared_ptr
<
Unit
>
storedUnit
(
std
::
move
(
unit
));
storedUnit
->
setCourse
(
this
);
emit
unitAboutToBeAdded
(
storedUnit
,
d
->
m_units
.
count
()
-
1
);
d
->
m_units
.
append
(
storedUnit
);
emit
unitAdded
();
...
...
src/core/resources/editablecourseresource.cpp
View file @
4551f0f6
...
...
@@ -40,6 +40,11 @@ EditableCourseResource::EditableCourseResource(const QUrl &path, IResourceReposi
,
m_course
(
new
CourseResource
(
path
,
repository
))
{
QQmlEngine
::
setObjectOwnership
(
this
,
QQmlEngine
::
CppOwnership
);
for
(
auto
unit
:
m_course
->
units
())
{
unit
->
setCourse
(
this
);
}
connect
(
m_course
.
get
(),
&
ICourse
::
unitAboutToBeAdded
,
this
,
&
ICourse
::
unitAboutToBeAdded
);
connect
(
m_course
.
get
(),
&
ICourse
::
unitAdded
,
this
,
&
ICourse
::
unitAdded
);
connect
(
m_course
.
get
(),
&
CourseResource
::
idChanged
,
this
,
&
EditableCourseResource
::
idChanged
);
...
...
@@ -153,7 +158,9 @@ bool EditableCourseResource::exportCourse(const QUrl &filePath)
std
::
shared_ptr
<
Unit
>
EditableCourseResource
::
addUnit
(
std
::
unique_ptr
<
Unit
>
unit
)
{
setModified
(
true
);
return
m_course
->
addUnit
(
std
::
move
(
unit
));
auto
sharedUnit
=
m_course
->
addUnit
(
std
::
move
(
unit
));
sharedUnit
->
setCourse
(
this
);
return
sharedUnit
;
}
QVector
<
std
::
shared_ptr
<
Unit
>>
EditableCourseResource
::
units
()
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment