Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-1.1
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc-1.1
Commits
27bee6c9
Commit
27bee6c9
authored
Mar 23, 2008
by
Filippo Carone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more unit test and functions for media list
parent
974a399a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
31 deletions
+102
-31
bindings/java/core/src/main/java/org/videolan/jvlc/MediaList.java
.../java/core/src/main/java/org/videolan/jvlc/MediaList.java
+61
-18
bindings/java/core/src/test/java/org/videolan/jvlc/MediaListTest.java
...a/core/src/test/java/org/videolan/jvlc/MediaListTest.java
+41
-13
No files found.
bindings/java/core/src/main/java/org/videolan/jvlc/MediaList.java
View file @
27bee6c9
...
...
@@ -54,12 +54,18 @@ public class MediaList
eventManager
=
jvlc
.
getLibvlc
().
libvlc_media_list_event_manager
(
instance
,
exception
);
}
public
void
addMedia
(
String
media
)
/**
* @param mrl The media resource locator to add to the media list.
*/
public
void
addMedia
(
String
mrl
)
{
MediaDescriptor
descriptor
=
new
MediaDescriptor
(
jvlc
,
m
edia
);
MediaDescriptor
descriptor
=
new
MediaDescriptor
(
jvlc
,
m
rl
);
addMedia
(
descriptor
);
}
/**
* @param descriptor The media descriptor to add to the media list.
*/
public
void
addMedia
(
MediaDescriptor
descriptor
)
{
if
(
items
.
contains
(
descriptor
.
getMrl
()))
...
...
@@ -71,27 +77,47 @@ public class MediaList
jvlc
.
getLibvlc
().
libvlc_media_list_add_media_descriptor
(
instance
,
descriptor
.
getInstance
(),
exception
);
}
public
int
itemsCount
()
/**
* @return The current number of items in the media list.
*/
public
int
size
()
{
libvlc_exception_t
exception
=
new
libvlc_exception_t
();
return
jvlc
.
getLibvlc
().
libvlc_media_list_count
(
instance
,
exception
);
}
/**
* @param descriptor The media descriptor to get the index of.
* @return The index of the media descriptor, or -1 if not found.
*/
public
int
indexOf
(
MediaDescriptor
descriptor
)
{
libvlc_exception_t
exception
=
new
libvlc_exception_t
();
return
jvlc
.
getLibvlc
().
libvlc_media_list_index_of_item
(
instance
,
descriptor
.
getInstance
(),
exception
);
}
/**
* @param index The index of the media descriptor to get.
* @return The media descriptor at the given index.
* @throws IndexOutOfBoundsException if index is bigger than size() or < 0, or there are no items in the media_list.
*/
public
MediaDescriptor
getMediaDescriptorAtIndex
(
int
index
)
{
libvlc_exception_t
exception
=
new
libvlc_exception_t
();
if
(
size
()
==
0
)
{
throw
new
IndexOutOfBoundsException
();
}
if
(
index
<
0
||
index
>
size
())
{
throw
new
IndexOutOfBoundsException
();
}
LibVlcMediaDescriptor
descriptor
=
jvlc
.
getLibvlc
().
libvlc_media_list_item_at_index
(
instance
,
index
,
exception
);
return
new
MediaDescriptor
(
jvlc
,
descriptor
);
}
/**
* @param index The index of the media to remove
* @param index The index of the media to remove
.
* @return True if the media was successfully removed, false otherwise.
*/
public
boolean
removeMedia
(
int
index
)
...
...
@@ -107,7 +133,7 @@ public class MediaList
}
/**
* @param media The media descriptor mrl
* @param media The media descriptor mrl
.
*/
public
boolean
removeMedia
(
String
mrl
)
{
...
...
@@ -118,7 +144,36 @@ public class MediaList
}
return
removeMedia
(
index
);
}
/**
* @param mediaDescriptor The media descriptor to remove.
*/
public
boolean
removeMedia
(
MediaDescriptor
mediaDescriptor
)
{
String
mrl
=
mediaDescriptor
.
getMrl
();
int
index
=
items
.
indexOf
(
mrl
);
if
(
index
==
-
1
)
{
return
false
;
}
return
removeMedia
(
index
);
}
/**
* Removes all items from the media list.
*/
public
void
clear
()
{
for
(
int
i
=
0
;
i
<
size
();
i
++)
{
removeMedia
(
i
);
}
}
/**
* @param descriptor The media descriptor to insert.
* @param index The index of the inserted media descriptor.
*/
public
void
insertMediaDescriptor
(
MediaDescriptor
descriptor
,
int
index
)
{
libvlc_exception_t
exception
=
new
libvlc_exception_t
();
...
...
@@ -146,18 +201,6 @@ public class MediaList
return
instance
;
}
/**
* @param mediaDescriptor
*/
public
boolean
removeMedia
(
MediaDescriptor
mediaDescriptor
)
{
String
mrl
=
mediaDescriptor
.
getMrl
();
int
index
=
items
.
indexOf
(
mrl
);
if
(
index
==
-
1
)
{
return
false
;
}
return
removeMedia
(
index
);
}
}
bindings/java/core/src/test/java/org/videolan/jvlc/MediaListTest.java
View file @
27bee6c9
...
...
@@ -48,7 +48,7 @@ public class MediaListTest
{
MediaList
mlist
=
new
MediaList
(
jvlc
);
mlist
.
addMedia
(
mrl
);
Assert
.
assertEquals
(
1
,
mlist
.
itemsCount
());
Assert
.
assertEquals
(
1
,
mlist
.
size
());
}
@Test
...
...
@@ -56,13 +56,13 @@ public class MediaListTest
{
MediaList
mlist
=
new
MediaList
(
jvlc
);
mlist
.
addMedia
(
mrl
);
Assert
.
assertEquals
(
1
,
mlist
.
itemsCount
());
Assert
.
assertEquals
(
1
,
mlist
.
size
());
mlist
.
addMedia
(
mrl
);
Assert
.
assertEquals
(
1
,
mlist
.
itemsCount
());
Assert
.
assertEquals
(
1
,
mlist
.
size
());
mlist
.
addMedia
(
new
MediaDescriptor
(
jvlc
,
mrl
));
Assert
.
assertEquals
(
1
,
mlist
.
itemsCount
());
Assert
.
assertEquals
(
1
,
mlist
.
size
());
mlist
.
addMedia
(
"non-existing"
);
Assert
.
assertEquals
(
2
,
mlist
.
itemsCount
());
Assert
.
assertEquals
(
2
,
mlist
.
size
());
}
@Test
...
...
@@ -70,9 +70,9 @@ public class MediaListTest
{
MediaList
mlist
=
new
MediaList
(
jvlc
);
mlist
.
addMedia
(
mrl
);
Assert
.
assertEquals
(
1
,
mlist
.
itemsCount
());
Assert
.
assertEquals
(
1
,
mlist
.
size
());
mlist
.
removeMedia
(
0
);
Assert
.
assertEquals
(
0
,
mlist
.
itemsCount
());
Assert
.
assertEquals
(
0
,
mlist
.
size
());
}
@Test
...
...
@@ -80,25 +80,25 @@ public class MediaListTest
{
MediaList
mlist
=
new
MediaList
(
jvlc
);
mlist
.
addMedia
(
mrl
);
Assert
.
assertEquals
(
1
,
mlist
.
itemsCount
());
Assert
.
assertEquals
(
1
,
mlist
.
size
());
mlist
.
removeMedia
(
0
);
Assert
.
assertEquals
(
0
,
mlist
.
itemsCount
());
Assert
.
assertEquals
(
0
,
mlist
.
size
());
mlist
.
addMedia
(
mrl
);
mlist
.
removeMedia
(
0
);
Assert
.
assertEquals
(
0
,
mlist
.
itemsCount
());
Assert
.
assertEquals
(
0
,
mlist
.
size
());
mlist
.
addMedia
(
new
MediaDescriptor
(
jvlc
,
mrl
));
mlist
.
removeMedia
(
0
);
Assert
.
assertEquals
(
0
,
mlist
.
itemsCount
());
Assert
.
assertEquals
(
0
,
mlist
.
size
());
mlist
.
addMedia
(
new
MediaDescriptor
(
jvlc
,
mrl
));
mlist
.
removeMedia
(
mrl
);
Assert
.
assertEquals
(
0
,
mlist
.
itemsCount
());
Assert
.
assertEquals
(
0
,
mlist
.
size
());
mlist
.
addMedia
(
new
MediaDescriptor
(
jvlc
,
mrl
));
mlist
.
removeMedia
(
new
MediaDescriptor
(
jvlc
,
mrl
));
Assert
.
assertEquals
(
0
,
mlist
.
itemsCount
());
Assert
.
assertEquals
(
0
,
mlist
.
size
());
}
@Test
...
...
@@ -109,5 +109,33 @@ public class MediaListTest
Assert
.
assertFalse
(
result
);
}
@Test
public
void
mediaListIndexOfNonExistingMediaDescriptor
()
{
MediaList
mlist
=
new
MediaList
(
jvlc
);
MediaDescriptor
md
=
new
MediaDescriptor
(
jvlc
,
"dummy"
);
int
result
=
mlist
.
indexOf
(
md
);
Assert
.
assertEquals
(-
1
,
result
);
}
@Test
(
expected
=
IndexOutOfBoundsException
.
class
)
public
void
mediaListGetMediaDesciptorAtInvalidIndex
()
{
MediaList
mlist
=
new
MediaList
(
jvlc
);
mlist
.
getMediaDescriptorAtIndex
(
5
);
}
@Test
(
expected
=
IndexOutOfBoundsException
.
class
)
public
void
mediaListGetMediaDesciptorAtInvalidIndex2
()
{
MediaList
mlist
=
new
MediaList
(
jvlc
);
mlist
.
getMediaDescriptorAtIndex
(-
5
);
}
@Test
(
expected
=
IndexOutOfBoundsException
.
class
)
public
void
mediaListGetMediaDesciptorAtInvalidIndex3
()
{
MediaList
mlist
=
new
MediaList
(
jvlc
);
mlist
.
getMediaDescriptorAtIndex
(
0
);
}
}
Write
Preview
Markdown
is supported
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