Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
VideoLAN
medialibrary
Commits
0f2184aa
Commit
0f2184aa
authored
Jan 25, 2016
by
Hugo Beauzée-Luyssen
Browse files
tests: Fix unmounting device behavior
parent
0bd3b314
Changes
3
Hide whitespace changes
Inline
Side-by-side
test/mocks/FileSystem.h
View file @
0f2184aa
...
...
@@ -69,6 +69,51 @@ struct FileSystemFactory : public factory::IFileSystem
return
dev
;
}
std
::
shared_ptr
<
Device
>
removeDevice
(
const
std
::
string
&
uuid
)
{
auto
it
=
std
::
find_if
(
begin
(
devices
),
end
(
devices
),
[
uuid
](
const
std
::
shared_ptr
<
Device
>&
d
)
{
return
d
->
uuid
()
==
uuid
;
}
);
if
(
it
==
end
(
devices
)
)
return
nullptr
;
auto
ret
=
*
it
;
devices
.
erase
(
it
);
// Now flag the mountpoint as belonging to its containing device, since it's now
// just a regular folder
auto
d
=
device
(
ret
->
mountpoint
()
);
d
->
invalidateMountpoint
(
ret
->
mountpoint
()
);
return
ret
;
}
void
unmountDevice
(
const
std
::
string
&
uuid
)
{
auto
it
=
std
::
find_if
(
begin
(
devices
),
end
(
devices
),
[
uuid
](
const
std
::
shared_ptr
<
Device
>&
d
)
{
return
d
->
uuid
()
==
uuid
;
}
);
if
(
it
==
end
(
devices
)
)
return
;
auto
d
=
*
it
;
d
->
setPresent
(
false
);
auto
mountpointDevice
=
device
(
d
->
mountpoint
()
);
mountpointDevice
->
invalidateMountpoint
(
d
->
mountpoint
()
);
}
void
remountDevice
(
const
std
::
string
&
uuid
)
{
auto
it
=
std
::
find_if
(
begin
(
devices
),
end
(
devices
),
[
uuid
](
const
std
::
shared_ptr
<
Device
>&
d
)
{
return
d
->
uuid
()
==
uuid
;
}
);
if
(
it
==
end
(
devices
)
)
return
;
auto
d
=
*
it
;
// Look for the containing device before marking the actual device back as present.
// otherwise, we will get the device mountpoint itself, instead of the device that contains
// the mountpoint
auto
mountpointDevice
=
device
(
d
->
mountpoint
()
);
d
->
setPresent
(
true
);
mountpointDevice
->
setMountpointRoot
(
d
->
mountpoint
(),
d
->
root
()
);
}
void
addDevice
(
std
::
shared_ptr
<
Device
>
dev
)
{
auto
d
=
device
(
dev
->
mountpoint
()
);
...
...
@@ -154,22 +199,6 @@ struct FileSystemFactory : public factory::IFileSystem
return
ret
;
}
std
::
shared_ptr
<
Device
>
removeDevice
(
const
std
::
string
&
uuid
)
{
auto
it
=
std
::
find_if
(
begin
(
devices
),
end
(
devices
),
[
uuid
](
const
std
::
shared_ptr
<
Device
>&
d
)
{
return
d
->
uuid
()
==
uuid
;
}
);
if
(
it
==
end
(
devices
)
)
return
nullptr
;
auto
ret
=
*
it
;
devices
.
erase
(
it
);
// Now flag the mountpoint as belonging to its containing device, since it's now
// just a regular folder
auto
d
=
device
(
ret
->
mountpoint
()
);
d
->
invalidateMountpoint
(
ret
->
mountpoint
()
);
return
ret
;
}
std
::
vector
<
std
::
shared_ptr
<
Device
>>
devices
;
};
...
...
test/mocks/filesystem/MockDirectory.cpp
View file @
0f2184aa
...
...
@@ -44,7 +44,7 @@ const std::string&Directory::path() const
return
m_path
;
}
const
std
::
vector
<
std
::
shared_ptr
<
fs
::
IFile
>
>&
Directory
::
files
()
const
const
std
::
vector
<
std
::
shared_ptr
<
fs
::
IFile
>>&
Directory
::
files
()
const
{
m_filePathes
.
clear
();
for
(
auto
&
f
:
m_files
)
...
...
@@ -52,7 +52,7 @@ const std::vector<std::shared_ptr<fs::IFile> >&Directory::files() const
return
m_filePathes
;
}
const
std
::
vector
<
std
::
shared_ptr
<
fs
::
IDirectory
>
>&
Directory
::
dirs
()
const
const
std
::
vector
<
std
::
shared_ptr
<
fs
::
IDirectory
>>&
Directory
::
dirs
()
const
{
m_dirPathes
.
clear
();
for
(
const
auto
&
d
:
m_dirs
)
...
...
test/unittest/DeviceTests.cpp
View file @
0f2184aa
...
...
@@ -146,8 +146,7 @@ TEST_F( DeviceFs, UnmountDisk )
auto
media
=
ml
->
media
(
RemovableDeviceMountpoint
+
"removablefile.mp3"
);
ASSERT_NE
(
nullptr
,
media
);
auto
device
=
std
::
static_pointer_cast
<
mock
::
Device
>
(
fsMock
->
createDevice
(
RemovableDeviceUuid
)
);
device
->
setPresent
(
false
);
fsMock
->
unmountDevice
(
RemovableDeviceUuid
);
cbMock
->
prepareForReload
();
Reload
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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