-rw-r--r-- | test/.gitignore | 1 | ||||
-rw-r--r-- | test/Makefile.am | 6 | ||||
-rw-r--r-- | test/idiscover.cc | 54 |
3 files changed, 60 insertions, 1 deletions
diff --git a/test/.gitignore b/test/.gitignore index 918b3c9..31ae686 100644 --- a/test/.gitignore +++ b/test/.gitignore | |||
@@ -2,3 +2,4 @@ | |||
2 | /.libs | 2 | /.libs |
3 | /test | 3 | /test |
4 | *.o | 4 | *.o |
5 | /idiscover | ||
diff --git a/test/Makefile.am b/test/Makefile.am index 0d1c0ef..b573d55 100644 --- a/test/Makefile.am +++ b/test/Makefile.am | |||
@@ -1,5 +1,6 @@ | |||
1 | noinst_PROGRAMS = test | 1 | noinst_PROGRAMS = test idiscover |
2 | 2 | ||
3 | AM_CPPFLAGS=${CPPFLAGS_DEBUG} | ||
3 | DEFAULT_INCLUDES = -I${top_builddir} | 4 | DEFAULT_INCLUDES = -I${top_builddir} |
4 | INCLUDES = -I${top_srcdir}/include/ ${KONFORKA_CFLAGS} ${LIBCURL_CPPFLAGS} | 5 | INCLUDES = -I${top_srcdir}/include/ ${KONFORKA_CFLAGS} ${LIBCURL_CPPFLAGS} |
5 | 6 | ||
@@ -10,3 +11,6 @@ EXTRA_DIST=$(addsuffix .html,$(addprefix html/, \ | |||
10 | empty head-in-body hkn-delegate hkn-server hkn in-body \ | 11 | empty head-in-body hkn-delegate hkn-server hkn in-body \ |
11 | unclosed-head spaced-links spaced-link-attrs 2rels \ | 12 | unclosed-head spaced-links spaced-link-attrs 2rels \ |
12 | )) | 13 | )) |
14 | |||
15 | idiscover_SOURCES = idiscover.cc | ||
16 | idiscover_LDADD = ${top_builddir}/lib/libopkele.la | ||
diff --git a/test/idiscover.cc b/test/idiscover.cc new file mode 100644 index 0000000..d9a7c62 --- a/dev/null +++ b/test/idiscover.cc | |||
@@ -0,0 +1,54 @@ | |||
1 | #include <iostream> | ||
2 | #include <stdexcept> | ||
3 | #include <iterator> | ||
4 | #include <algorithm> | ||
5 | using namespace std; | ||
6 | #include <opkele/exception.h> | ||
7 | #include <opkele/discovery.h> | ||
8 | |||
9 | template<typename _PDT> | ||
10 | ostream& operator<<(ostream& o,const opkele::xrd::priority_map<_PDT>& pm) { | ||
11 | for(typename opkele::xrd::priority_map<_PDT>::const_iterator i=pm.begin(); | ||
12 | i!=pm.end();++i) | ||
13 | o << ' ' << i->second << '[' << i->first << ']'; | ||
14 | return o; | ||
15 | } | ||
16 | |||
17 | ostream& operator<<(ostream& o,const opkele::xrd::service_t s) { | ||
18 | o << "{" << endl | ||
19 | << " Type: "; | ||
20 | copy(s.types.begin(),s.types.end(), | ||
21 | ostream_iterator<string>(o," ")); | ||
22 | o << endl | ||
23 | << " URI: " << s.uris << endl | ||
24 | << " LocalID: " << s.local_ids << endl | ||
25 | << " ProviderID: " << s.provider_id << endl; | ||
26 | o << "}"; | ||
27 | } | ||
28 | |||
29 | int main(int argc,char **argv) { | ||
30 | try { | ||
31 | if(argc<2) | ||
32 | throw opkele::exception(OPKELE_CP_ "Please, give me something to resolve"); | ||
33 | for(int a=1;a<argc;++a) { | ||
34 | opkele::idiscovery_t discovery(argv[a]); | ||
35 | clog | ||
36 | << "===============================================================" << endl | ||
37 | << "User-supplied ID: " << argv[a] << endl | ||
38 | << "Normalized ID: " << discovery.normalized_id << endl | ||
39 | << "Canonicalized ID: " << discovery.canonicalized_id << endl | ||
40 | << "The identity is " << (discovery.xri_identity?"":"not ") << "an i-name" << endl; | ||
41 | if(discovery.xrd.expires) | ||
42 | clog << "Information expires in " << discovery.xrd.expires-time(0) << " seconds" << endl; | ||
43 | clog << endl | ||
44 | << "CanonicalID: " << discovery.xrd.canonical_ids << endl | ||
45 | << "LocalID: " << discovery.xrd.local_ids << endl | ||
46 | << "ProviderID: " << discovery.xrd.provider_id << endl | ||
47 | << "Services: " << discovery.xrd.services << endl; | ||
48 | } | ||
49 | }catch(exception& e) { | ||
50 | cerr << "oops: " << e.what() << endl; | ||
51 | _exit(1); | ||
52 | } | ||
53 | _exit(0); | ||
54 | } | ||