Skip to content

Commit

Permalink
100% coverage for detectors/cache.d
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeSlave committed Jul 16, 2016
1 parent 8a3c10c commit 4ae5ece
Show file tree
Hide file tree
Showing 19 changed files with 109 additions and 22 deletions.
12 changes: 11 additions & 1 deletion source/mime/database.d
Expand Up @@ -359,7 +359,17 @@ unittest

//testing literal
assert(database.mimeTypeForFileName("liblist.gam"));
assert(database.mimeTypeForFileName("GNUmakefile"));
assert(database.mimeTypeForFileName("makefile"));

//testing discard glob
assert(!database.mimeTypeForFileName("GNUmakefile"));
assert(!database.detector.mimeTypeForFileName("GNUmakefile"));

assert(!database.mimeTypeForFileName("file.qvm3"));
assert(!database.detector.mimeTypeForFileName("file.qvm3"));

assert(!database.mimeTypeForFileName("model01.sequence"));
assert(!database.detector.mimeTypeForFileName("model01.sequence"));

//testing discard magic
assert(!database.mimeTypeForData("PAK"));
Expand Down
1 change: 1 addition & 0 deletions test/.gitignore
@@ -0,0 +1 @@
update-mime-database
1 change: 1 addition & 0 deletions test/discard/generic-icons
@@ -0,0 +1 @@
application/x-hlmdl-sequence:application-x-hlmdl
5 changes: 4 additions & 1 deletion test/discard/globs
@@ -1,4 +1,7 @@
# This file was automatically generated by the
# update-mime-database command. DO NOT EDIT!
text/x-gnumakefile:gnumakefile
application/x-hlmdl-sequence:**[0123456789][0123456789].sequence
text/x-makefile:gnumakefile
application/java-multimedia-file:*.jmf
text/x-othermakefile:makefile
application/x-qvm:*.qvm3
5 changes: 4 additions & 1 deletion test/discard/globs2
@@ -1,4 +1,7 @@
# This file was automatically generated by the
# update-mime-database command. DO NOT EDIT!
50:text/x-gnumakefile:gnumakefile
50:application/x-hlmdl-sequence:**[0123456789][0123456789].sequence
50:text/x-makefile:gnumakefile
50:application/java-multimedia-file:*.jmf
50:text/x-othermakefile:makefile
50:application/x-qvm:*.qvm3
Binary file modified test/discard/mime.cache
Binary file not shown.
16 changes: 15 additions & 1 deletion test/discard/packages/discard.xml
Expand Up @@ -10,7 +10,12 @@
<comment>Java multimedia file</comment>
<glob pattern="*.jmf"/>
</mime-type>
<mime-type type="text/x-gnumakefile">
<mime-type type="text/x-othermakefile">
<comment>Makefile</comment>
<sub-class-of type="text/plain"/>
<glob pattern="makefile"/>
</mime-type>
<mime-type type="text/x-makefile">
<comment>Makefile</comment>
<sub-class-of type="text/plain"/>
<glob pattern="GNUmakefile"/>
Expand All @@ -27,4 +32,13 @@
<match value="IDS2" type="string" offset="0"/>
</magic>
</mime-type>
<mime-type type="application/x-hlmdl-sequence">
<comment>Half-Life model sequence</comment>
<generic-icon name="application-x-hlmdl"/>
<glob pattern="**[0123456789][0123456789].sequence"/>
</mime-type>
<mime-type type="application/x-qvm">
<comment>Quake III virtual machine bytecode</comment>
<glob pattern="*.qvm3"/>
</mime-type>
</mime-info>
3 changes: 2 additions & 1 deletion test/discard/subclasses
@@ -1 +1,2 @@
text/x-gnumakefile text/plain
text/x-othermakefile text/plain
text/x-makefile text/plain
5 changes: 4 additions & 1 deletion test/discard/types
@@ -1,5 +1,8 @@
application/java-multimedia-file
application/x-hlmdl-sequence
application/x-otherpak
application/x-pak
application/x-qvm
image/x-somesprite
text/x-gnumakefile
text/x-makefile
text/x-othermakefile
2 changes: 1 addition & 1 deletion test/discard/version
@@ -1 +1 @@
1.3
1.6
12 changes: 7 additions & 5 deletions test/mime/globs
@@ -1,16 +1,19 @@
# This file was automatically generated by the
# update-mime-database command. DO NOT EDIT!
text/x-makefile:__NOGLOBS__
application/x-hlmdl-sequence:__NOGLOBS__
application/x-qvm:__NOGLOBS__
image/x-sprite32:*.spr32
application/x-pak:pak*.pak
application/x-iqm:*.iqm
text/x-q3shader:*.shader
application/x-general-long-glob:general*_long_glob
image/x-sprite32:*.sp2
image/x-q2sprite:*.sp2
application/x-general-long-glob:general*_long_glob
image/x-qsprite:*.spr
image/x-sprite32:*.spr
image/x-hlsprite:*.spr
text/x-ent:*.ent
application/x-pak:pak*.pak
application/x-wad:*.wad
application/x-wad2:*.wad
application/x-wad3:*.wad
Expand All @@ -28,15 +31,14 @@ application/x-mdl:*.mdl
application/x-rmf:*.rmf
application/x-md2:*.md2
application/x-md3:*.md3
application/x-md4:*.md4
application/x-lmp:*.lmp
application/x-md4:*.md4
application/x-qvm:*.qvm
text/x-liblist:liblist.gam
application/x-jmf:*.jmf
image/x-vtf:*.vtf
application/x-gcf:*.gcf
image/x-vtf:*.vtf
text/x-qcsrc:*.qc
text/x-makefile:gnumakefile
text/x-qchdr:*.qh
application/x-general-glob:general*glob
application/x-vmf:*.vmf
Expand Down
14 changes: 8 additions & 6 deletions test/mime/globs2
@@ -1,18 +1,21 @@
# This file was automatically generated by the
# update-mime-database command. DO NOT EDIT!
0:text/x-makefile:__NOGLOBS__
0:application/x-hlmdl-sequence:__NOGLOBS__
0:application/x-qvm:__NOGLOBS__
50:image/x-sprite32:*.spr32
50:application/x-pak:pak*.pak:cs
50:application/x-pak:pak*.pak
50:application/x-iqm:*.iqm
50:text/x-q3shader:*.shader:cs
50:text/x-q3shader:*.shader
50:application/x-general-long-glob:general*_long_glob
50:image/x-sprite32:*.sp2
50:image/x-q2sprite:*.sp2
50:application/x-general-long-glob:general*_long_glob
50:image/x-qsprite:*.spr
50:image/x-sprite32:*.spr
50:image/x-hlsprite:*.spr
50:text/x-ent:*.ent
50:application/x-pak:pak*.pak:cs
50:application/x-pak:pak*.pak
50:application/x-wad:*.wad
50:application/x-wad2:*.wad
50:application/x-wad3:*.wad
Expand All @@ -30,15 +33,14 @@
50:application/x-rmf:*.rmf
50:application/x-md2:*.md2
50:application/x-md3:*.md3
50:application/x-md4:*.md4
50:application/x-lmp:*.lmp
50:application/x-md4:*.md4
50:application/x-qvm:*.qvm
50:text/x-liblist:liblist.gam
50:application/x-jmf:*.jmf
50:image/x-vtf:*.vtf
50:application/x-gcf:*.gcf
50:image/x-vtf:*.vtf
50:text/x-qcsrc:*.qc
50:text/x-makefile:gnumakefile
50:text/x-qchdr:*.qh
50:application/x-general-glob:general*glob
50:application/x-vmf:*.vmf
Expand Down
Binary file modified test/mime/mime.cache
Binary file not shown.
2 changes: 1 addition & 1 deletion test/mime/packages/base.xml
Expand Up @@ -16,7 +16,7 @@
<comment>Makefile</comment>
<sub-class-of type="text/plain"/>
<glob pattern="makefile"/>
<glob pattern="GNUmakefile"/>
<glob-deleteall/>
</mime-type>
<mime-type type="x-content/image-dcf">
<comment>digital photos</comment>
Expand Down
2 changes: 2 additions & 0 deletions test/mime/packages/quake-hl.xml
Expand Up @@ -207,6 +207,7 @@
</match>
</magic>
<glob pattern="*[0123456789][0123456789].mdl"/>
<glob-deleteall/>
</mime-type>

<mime-type type="application/x-hl2mdl">
Expand Down Expand Up @@ -315,6 +316,7 @@
<match value="0x12721445" type="little32" offset="0"/>
</magic>
<glob pattern="*.qvm"/>
<glob-deleteall/>
</mime-type>

</mime-info>
2 changes: 1 addition & 1 deletion test/mime/version
@@ -1 +1 @@
1.3
1.6
3 changes: 3 additions & 0 deletions test/note.txt
@@ -0,0 +1,3 @@
update-mime-database from shared-mime-info 1.6 has bugs with writing the number of literal and glob patterns.
These tests use patched version to make 100% coverage of mime/detectors/cache.d possible.
Patch is provided as update-mime-database.c.patch file.
42 changes: 42 additions & 0 deletions test/update-mime-database.c.patch
@@ -0,0 +1,42 @@
2372a2373,2396
> typedef struct
> {
> GetValueFunc *get_value;
> gpointer data;
> guint count;
>
> } CountData;
>
> static void
> count_map_entry (gpointer key,
> gpointer data)
> {
> CountData *count_data = (CountData *)data;
> gchar **values;
>
> values = (* count_data->get_value) (count_data->data, key);
> count_data->count += g_strv_length (values) / 3;
> g_strfreev (values);
> }
>
> static gchar **
> get_glob_list_value (gpointer data,
> gchar *key);
>
2384a2409,2410
> CountData count_data;
> guint count;
2394c2420,2430
< if (!write_card32 (cache, keys->len))
---
> if (get_value == &get_glob_list_value) {
> count_data.count = 0;
> count_data.data = map;
> count_data.get_value = get_value;
> g_ptr_array_foreach (keys, count_map_entry, &count_data);
> count = count_data.count;
> } else {
> count = keys->len;
> }
>
> if (!write_card32 (cache, count))
4 changes: 2 additions & 2 deletions test/update.sh
@@ -1,5 +1,5 @@

DIRNAME=$(dirname -- $(readlink -f -- $0))
export XDG_DATA_HOME=$DIRNAME
update-mime-database $DIRNAME/mime
update-mime-database $DIRNAME/discard
$DIRNAME/update-mime-database $DIRNAME/mime
$DIRNAME/update-mime-database $DIRNAME/discard

0 comments on commit 4ae5ece

Please sign in to comment.