2 #ifndef SEEN_EXTRACT_URI_TEST_H
3 #define SEEN_EXTRACT_URI_TEST_H
5 #include <cxxtest/TestSuite.h>
7 #include "extract-uri.h"
9 class ExtractURITest : public CxxTest::TestSuite
10 {
11 public:
12 void checkOne( char const* str, char const* expected )
13 {
14 gchar* result = extract_uri( str );
15 TS_ASSERT_EQUALS( ( result == NULL ), ( expected == NULL ) );
16 if ( result && expected ) {
17 TS_ASSERT_EQUALS( std::string(result), std::string(expected) );
18 } else if ( result ) {
19 TS_FAIL( std::string("Expected null, found (") + result + ")" );
20 } else if ( expected ) {
21 TS_FAIL( std::string("Expected (") + expected + "), found null" );
22 }
23 g_free( result );
24 }
26 void testBase()
27 {
28 char const* cases[][2] = {
29 { "url(#foo)", "#foo" },
30 { "url foo ", NULL },
31 { "url", NULL },
32 { "url ", NULL },
33 { "url()", NULL },
34 { "url ( ) ", NULL },
35 { "url foo bar ", NULL },
36 };
38 for ( size_t i = 0; i < G_N_ELEMENTS(cases); i++ )
39 {
40 checkOne( cases[i][0], cases[i][1] );
41 }
42 }
44 void testWithTrailing()
45 {
46 char const* cases[][2] = {
47 { "url(#foo) bar", "#foo" },
48 { "url() bar", NULL },
49 { "url ( ) bar ", NULL }
50 };
52 for ( size_t i = 0; i < G_N_ELEMENTS(cases); i++ )
53 {
54 checkOne( cases[i][0], cases[i][1] );
55 }
56 }
58 void testQuoted()
59 {
60 char const* cases[][2] = {
61 { "url('#foo')", "#foo" },
62 { "url(\"#foo\")", "#foo" },
63 { "url('#f o o')", "#f o o" },
64 { "url(\"#f o o\")", "#f o o" },
65 { "url('#fo\"o')", "#fo\"o" },
66 { "url(\"#fo'o\")", "#fo'o" },
67 };
69 for ( size_t i = 0; i < G_N_ELEMENTS(cases); i++ )
70 {
71 checkOne( cases[i][0], cases[i][1] );
72 }
73 }
75 };
77 #endif // SEEN_EXTRACT_URI_TEST_H
79 /*
80 Local Variables:
81 mode:c++
82 c-file-style:"stroustrup"
83 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
84 indent-tabs-mode:nil
85 fill-column:99
86 End:
87 */
88 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :