1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
/*
* blogc: A blog compiler.
* Copyright (C) 2014-2017 Rafael G. Martins <rafael@rafaelmartins.eng.br>
*
* This program can be distributed under the terms of the BSD License.
* See the file LICENSE.
*/
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include <unistd.h>
#include "../../src/blogc-runserver/mime.h"
int
__wrap_access(const char *pathname, int mode)
{
assert_string_equal(pathname, mock_type(const char*));
assert_int_equal(mode, F_OK);
return mock_type(int);
}
static void
test_guess_content_type(void **state)
{
assert_string_equal(br_mime_guess_content_type("foo.html"), "text/html");
assert_string_equal(br_mime_guess_content_type("foo.jpg"), "image/jpeg");
assert_string_equal(br_mime_guess_content_type("foo.mp4"), "video/mp4");
assert_string_equal(br_mime_guess_content_type("foo.bola"), "application/octet-stream");
}
static void
test_guess_index(void **state)
{
char *t;
will_return(__wrap_access, "dir/index.html");
will_return(__wrap_access, 0);
t = br_mime_guess_index("dir");
assert_string_equal(t, "dir/index.html");
free(t);
will_return(__wrap_access, "dir/index.html");
will_return(__wrap_access, 1);
will_return(__wrap_access, "dir/index.htm");
will_return(__wrap_access, 0);
t = br_mime_guess_index("dir");
assert_string_equal(t, "dir/index.htm");
free(t);
will_return(__wrap_access, "dir/index.html");
will_return(__wrap_access, 1);
will_return(__wrap_access, "dir/index.htm");
will_return(__wrap_access, 1);
will_return(__wrap_access, "dir/index.shtml");
will_return(__wrap_access, 1);
will_return(__wrap_access, "dir/index.xml");
will_return(__wrap_access, 1);
will_return(__wrap_access, "dir/index.txt");
will_return(__wrap_access, 1);
will_return(__wrap_access, "dir/index.xhtml");
will_return(__wrap_access, 0);
t = br_mime_guess_index("dir");
assert_string_equal(t, "dir/index.xhtml");
free(t);
will_return(__wrap_access, "dir/index.html");
will_return(__wrap_access, 1);
will_return(__wrap_access, "dir/index.htm");
will_return(__wrap_access, 1);
will_return(__wrap_access, "dir/index.shtml");
will_return(__wrap_access, 1);
will_return(__wrap_access, "dir/index.xml");
will_return(__wrap_access, 1);
will_return(__wrap_access, "dir/index.txt");
will_return(__wrap_access, 1);
will_return(__wrap_access, "dir/index.xhtml");
will_return(__wrap_access, 1);
assert_null(br_mime_guess_index("dir"));
}
int
main(void)
{
const UnitTest tests[] = {
unit_test(test_guess_content_type),
unit_test(test_guess_index),
};
return run_tests(tests);
}
|