Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / ACEXML / tests / NamespaceSupport_Test.cpp
blobfde26a7767ba55e292f120bef4ba8cd69f09fe1e
1 #include "ACEXML/common/NamespaceSupport.h"
2 #include "ace/OS_main.h"
4 int ACE_TMAIN (int, ACE_TCHAR *[])
6 ACEXML_NamespaceSupport xmlns;
7 if (xmlns.init() == -1)
9 ACE_DEBUG ((LM_DEBUG,
10 ACE_TEXT ("Error in initializing namespace support.")));
11 return 1;
13 xmlns.pushContext();
14 xmlns.declarePrefix(ACE_TEXT (""),
15 ACE_TEXT ("http://www.w3.org/1999/xhtml"));
16 xmlns.declarePrefix(ACE_TEXT ("dc"),
17 ACE_TEXT ("http://www.purl.org/dc#"));
18 xmlns.declarePrefix(ACE_TEXT ("xc"),
19 ACE_TEXT ("http://www.purl.org/dc#"));
21 const ACEXML_Char *lName, *uri;
22 const ACEXML_Char *n1 = ACE_TEXT ("p");
24 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("*** Checking processName:\n")));
25 if (xmlns.processName (n1, uri, lName, 0) != 0)
26 ACE_DEBUG ((LM_ERROR,
27 ACE_TEXT ("Fail to resolve namespace name %s\n"),
28 n1));
29 else
30 ACE_DEBUG ((LM_DEBUG,
31 ACE_TEXT ("Namespace URI: %s\nLocal name: %s\nRaw name: %s\n"),
32 uri, lName, n1));
34 const ACEXML_Char *n2 = ACE_TEXT ("dc:title");
35 if (xmlns.processName(n2, uri, lName, 0) != 0)
36 ACE_DEBUG ((LM_ERROR,
37 ACE_TEXT ("Fail to resolve namespace name %S\n"),
38 n2));
39 else
40 ACE_DEBUG ((LM_DEBUG,
41 ACE_TEXT ("Namespace URI: %s\nLocal name: %s\nRaw name: %s\n"),
42 uri, lName, n2));
44 const ACEXML_Char *n3 = ACE_TEXT ("xml:title");
45 if (xmlns.processName(n3, uri, lName, 0) != 0)
46 ACE_DEBUG ((LM_ERROR,
47 ACE_TEXT ("Fail to resolve namespace name %S\n"),
48 n3));
49 else
50 ACE_DEBUG ((LM_DEBUG,
51 ACE_TEXT ("Namespace URI: %s\nLocal name: %s\nRaw name: %s\n"),
52 uri, lName, n3));
54 ACE_DEBUG ((LM_DEBUG,
55 ACE_TEXT ("\n*** Checking getDeclaredPrefixes\n")));
57 ACEXML_STR_LIST prefixes;
58 if (xmlns.getDeclaredPrefixes (prefixes) != 0)
59 ACE_DEBUG ((LM_ERROR,
60 ACE_TEXT ("Fail to get a list of declared prefixes\n")));
61 else
63 ACEXML_STR_LIST::ITERATOR iter = prefixes.begin ();
64 const ACEXML_Char **prefix = 0;
66 for (; iter.next (prefix);iter.advance ())
67 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("prefix: \"%s\"\n"), *prefix));
70 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n*** Checking getPrefix\n")));
71 const ACEXML_Char *prefix = 0;
73 if ((prefix = xmlns.getPrefix (ACE_TEXT ("http://www.purl.org/dc#"))) == 0)
74 ACE_DEBUG ((LM_ERROR,
75 ACE_TEXT ("Fail to get prefix of http://www.purl.org/dc#\n")));
76 else
77 ACE_DEBUG ((LM_DEBUG,
78 ACE_TEXT ("Prefix of http://www.purl.org/dc# is %s\n"),
79 prefix));
81 if ((prefix = xmlns.getPrefix (ACE_TEXT ("http://www.w3.org/1999/xhtml"))) == 0)
82 ACE_DEBUG ((LM_DEBUG,
83 ACE_TEXT ("Fail to get prefix of http://www.w3.org/1999/xhtml which is okay\n")));
84 else
85 ACE_DEBUG ((LM_ERROR,
86 ACE_TEXT ("ERROR: Prefix of http://www.w3.org/1999/xhtml is %s\n"),
87 prefix));
89 if ((prefix = xmlns.getPrefix (ACE_TEXT ("http://www.w3.org/XML/1998/namespace"))) == 0)
90 ACE_DEBUG ((LM_ERROR,
91 ACE_TEXT ("Fail to get prefix of http://www.w3.org/XML/1998/namespace\n")));
92 else
93 ACE_DEBUG ((LM_DEBUG,
94 ACE_TEXT ("Prefix of http://www.w3.org/XML/1998/namespace is %s\n"),
95 prefix));
97 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n*** Checking getPrefixes with known URI\n")));
98 prefixes.reset ();
100 if (xmlns.getPrefixes (ACE_TEXT ("http://www.purl.org/dc#"), prefixes) != 0)
101 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Fail to getPrefixes based on known URI\n")));
102 else
104 ACEXML_STR_LIST::ITERATOR iter = prefixes.begin ();
105 const ACEXML_Char **prefix = 0;
107 for (; iter.next (prefix);iter.advance ())
108 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("prefix: \"%s\"\n"), *prefix));
111 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n*** Checking getPrefixes\n")));
112 prefixes.reset ();
114 if (xmlns.getPrefixes (prefixes) != 0)
115 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Fail to getPrefixes\n")));
116 else
118 ACEXML_STR_LIST::ITERATOR iter = prefixes.begin ();
119 const ACEXML_Char **prefix = 0;
121 for (; iter.next (prefix);iter.advance ())
122 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("prefix: \"%s\"\n"), *prefix));
125 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n*** Checking getURI\n")));
126 const ACEXML_Char *URI = 0;
128 if ((URI = xmlns.getURI (ACE_TEXT ("dc"))) == 0)
129 ACE_DEBUG((LM_ERROR, ACE_TEXT ("Fail to get URI for \"dc\"\n")));
130 else
131 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("URI for \"dc\" is %s\n"), URI));
132 if ((URI = xmlns.getURI (ACE_TEXT ("xc"))) == 0)
133 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Fail to get URI for \"xc\"\n")));
134 else
135 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("URI for \"xc\" is %s\n"), URI));
136 if ((URI = xmlns.getURI (ACE_TEXT ("xml"))) == 0)
137 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Fail to get URI for \"xml\"\n")));
138 else
139 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("URI for \"xml\" is %s\n"), URI));
140 if ((URI = xmlns.getURI (ACE_TEXT (""))) == 0)
141 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Fail to get default namespace URI\n")));
142 else
143 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("URI for default namespace is %s\n"), URI));
145 xmlns.popContext();
147 return 0;