File: doi_test.c

package info (click to toggle)
bibutils 7.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,040 kB
  • sloc: ansic: 112,579; sh: 462; makefile: 42
file content (120 lines) | stat: -rw-r--r-- 2,719 bytes parent folder | download | duplicates (2)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * doi_test.c
 *
 * Copyright (c) 2016-2021
 *
 * Source code released under the GPL version 2
 *
 */
#include <stdio.h>
#include <stdlib.h>
#include "url.h"

char progname[] = "doi_test";

typedef struct test_t {
	char *s;
	int expected;
} test_t;

int
test_is_doi( void )
{
	test_t tests[] = {
		{ "10.1021/",            0 },
		{ "00.0000/",            0 },
		{ "00,0000/",            -1 },
		{ "doi:99.9999/",        4 },
		{ "doi: 99.9999/",       5 },
		{ "doi: DOI: 99.9999/",  10 },
		{ "http://www.test.com", -1 },
	};
	int ntests = sizeof( tests ) / sizeof( tests[0] );
	int failed = 0;
	int found;
	int i;

	for ( i=0; i<ntests; ++i ) {
		found = is_doi( tests[i].s );
		if ( found != tests[i].expected ) {
			printf( "%s: Error is_doi( '%s' ) returned %d, expected %d\n", progname, tests[i].s, found, tests[i].expected );
			failed++;
		}
	}
	return failed;
}

int
test_is_uri_remote_scheme( void )
{
	test_t tests[] = {
		{ "This is a note",           -1 },
		{ "doi:99.9999/",             -1 },
		{ "git://www.git.com",        4 },
		{ "ftp://www.ftp.com",        4 },
		{ "gopher://www.gopher.com",  7 },
		{ "arXiv:10121",              -1 },
		{ "pubmed:121211",            -1 },
		{ "http://www.test.com",      5 },
		{ "https://www.test.com",     6 },
	};
	int ntests = sizeof( tests ) / sizeof( tests[0] );
	int failed = 0;
	int found;
	int i;

	for ( i=0; i<ntests; ++i ) {
		found = is_uri_remote_scheme( tests[i].s );
		if ( found != tests[i].expected ) {
			printf( "%s: Error is_uri_remote_scheme( '%s' ) returned %d, expected %d\n", progname, tests[i].s, found, tests[i].expected );
			failed++;
		}
	}
	return failed;
}

int
test_is_embedded_link( void )
{
	test_t tests[] = {
		{ "This is a note",           0 },
		{ "doi:99.9999/",             1 },
		{ "git://www.git.com",        1 },
		{ "ftp://www.ftp.com",        1 },
		{ "gopher://www.gopher.com",  1 },
		{ "arXiv:10121",              1 },
		{ "pubmed:121211",            1 },
		{ "http://www.test.com",      1 },
		{ "https://www.test.com",     1 },
	};
	int ntests = sizeof( tests ) / sizeof( tests[0] );
	int failed = 0;
	int found;
	int i;

	for ( i=0; i<ntests; ++i ) {
		found = is_embedded_link( tests[i].s );
		if ( found != tests[i].expected ) {
			printf( "%s: Error is_embedded_link( '%s' ) returned %d, expected %d\n", progname, tests[i].s, found, tests[i].expected );
			failed++;
		}
	}
	return failed;
}


int
main( int argc, char *argv[] )
{
	int failed = 0;
	failed += test_is_doi();
	failed += test_is_uri_remote_scheme();
	failed += test_is_embedded_link();
	if ( !failed ) {
		printf( "%s: PASSED\n", progname );
		return EXIT_SUCCESS;
	} else {
		printf( "%s: FAILED\n", progname );
		return EXIT_FAILURE;
	}
}