File: info_test.c

package info (click to toggle)
liblicense 0.8-2.1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 6,448 kB
  • ctags: 793
  • sloc: sh: 9,182; ansic: 8,249; makefile: 862; xml: 178; cpp: 111; ruby: 41; python: 39
file content (151 lines) | stat: -rw-r--r-- 4,181 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
 * Creative Commons has made the contents of this file
 * available under a CC-GNU-LGPL license:
 *
 * http://creativecommons.org/licenses/LGPL/2.1/
 *
 * A copy of the full license can be found as part of this
 * distribution in the file COPYING.
 *
 * You may use the liblicense software in accordance with the
 * terms of that license. You agree that you are solely
 * responsible for your use of the liblicense software and you
 * represent and warrant to Creative Commons that your use
 * of the liblicense software will comply with the CC-GNU-LGPL.
 *
 * Copyright 2007, Creative Commons, www.creativecommons.org.
 * Copyright 2007, Scott Shawcroft.
 * Copyright (C) 2007 Peter Miller
 */

#include "liblicense.h"

#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>

void test_get_attribute_jurisdiction() {
	char * license;
	char * j;
	license = "http://creativecommons.org/licenses/by-nd/2.0/de/";
	j = ll_get_first(ll_get_attribute(license, LL_JURISDICTION, false));
	printf("get_jurisdiction: '%s'\n",j);
	assert (strcmp(j, "http://creativecommons.org/international/de/") == 0);
	free(j);
}

void test_get_attribute_jurisdiction_localized() {
	char * license;
	char * j;
	license = "http://creativecommons.org/licenses/by-nd/2.0/de/";
	j = ll_get_first(ll_get_attribute(license, LL_JURISDICTION, true));
	printf("get_jurisdiction: '%s'\n",j);
	assert (strcmp(j, "http://creativecommons.org/international/de/") == 0);
	free(j);
}

void test_get_attribute_name_whatever_lang() {
	const char * license;
	char * name;
	license = "http://creativecommons.org/licenses/by-nd/2.0/de/";
	name = ll_get_first(ll_get_attribute(license, LL_NAME, false));
	printf("get_name: '%s'\n",name);
	assert (strcmp(name, "Recoñecemento-SenObraDerivada") == 0); /* UTF-8 */
	free(name);
}

void test_get_attribute_name_system_lang() {
	const char * license;
	char * name;
	license = "http://creativecommons.org/licenses/by-nd/2.0/de/";
	name = ll_get_first(ll_get_attribute(license, LL_NAME, true));
	printf("get_name: '%s'\n",name);
	assert (strcmp(name, "Attribution-NoDerivs") == 0); /* UTF-8 */
	free(name);
}

void test_get_version() {
	int known_good_version[] = {2,2,0};
	const char * license;
	int* version;

	license = "http://creativecommons.org/licenses/by-nd/2.0/de/";
	
	version = ll_parse_version(ll_get_first (ll_get_attribute (license, LL_VERSION, false)));
	printf("get_version: ");
	assert (ll_int_arrays_equal(version, known_good_version));
	if (version) {
		int i;
		for (i=1; i<=version[0]; ++i) {
			if (i!=1) printf(".");
			printf("%d",version[i]);
		}
		printf("\n");
		free(version);
	} else {
		printf("unversioned\n");
	}
}


int main(int argc,char** argv) {
	char * known_good_prohibits[] = {NULL};
	char * known_good_permits[] = {LL_DISTRIBUTION, LL_REPRODUCTION, NULL};
	char * known_good_requires[] = {LL_NOTICE, LL_ATTRIBUTION, NULL};
	
	ll_uri_t license;
	ll_juris_t j;
	char* name;
	ll_uri_t* p;
	int b;

        (void)argc;
        (void)argv;
	ll_init();

	license = "http://creativecommons.org/licenses/by-nd/2.0/de/";

	test_get_attribute_jurisdiction();
	test_get_attribute_jurisdiction_localized();
	test_get_attribute_name_system_lang();
	test_get_attribute_name_whatever_lang();
	test_get_version();

	p = ll_get_attribute(license, LL_PROHIBITS, false);
	printf("get_prohibits: ");
	assert (ll_lists_equal(p, known_good_prohibits));
	ll_list_print(p);
	ll_free_list(p);

	p = ll_get_attribute(license, LL_PERMITS, false);
	printf("get_permits: ");
	assert (ll_lists_equal(p, known_good_permits));
	ll_list_print(p);
	ll_free_list(p);

	p = ll_get_attribute(license, LL_REQUIRES, false);
	printf("get_requires: ");
	assert (ll_lists_equal(p, known_good_requires));
	ll_list_print(p);
	ll_free_list(p);

	b = ll_verify_uri(license);
	printf("verify_uri: %d\n",b);
	assert (b == 1);

	p = ll_get_all_licenses();
	printf("get_all_licenses: ");
	ll_list_print(p);
	assert (ll_list_contains(p, license));
	ll_free_list(p);

	p = ll_get_licenses("http://creativecommons.org/international/de/");
	printf("get_licenses: ");
	ll_list_print(p);
	assert (ll_list_contains(p, license));
	ll_free_list(p);

	ll_stop();
	return 0;
}