~zorba-coders/zorba/bug-874679-image-module

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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
(:~
 : Simple test module for the paint functions of the image library.
 : 
 : @author Daniel Thomas
 :)
import module namespace basic = 'http://www.zorba-xquery.com/modules/image/basic';
import module namespace file = 'http://expath.org/ns/file';
import module namespace paint = 'http://www.zorba-xquery.com/modules/image/paint';
import schema namespace image = 'http://www.zorba-xquery.com/modules/image/image';

declare namespace an = "http://www.zorba-xquery.com/annotations";

declare variable $local:image-dir := fn:concat(file:dir-name(fn:static-base-uri()), "/images/");


declare variable $local:gif as xs:base64Binary := basic:create(xs:unsignedInt(100), xs:unsignedInt(100), image:imageFormat("GIF"));


(:~
 : Outputs a nice error message to the screen ...
 :
 : @param $messsage is the message to be displayed
 : @return The passed message but really very, very nicely formatted.
 :)
declare function local:error($messages as xs:string*) as xs:string* {
  "
************************************************************************
ERROR:
  Location:", file:path-to-native("."), "
  Cause:",
  $messages,
  "
************************************************************************
"
};


(:~
 : @return true if the man:draw-rectangle function works.
 :)
declare %an:nondeterministic function local:test-draw-rectangle() as xs:boolean {
    let $draw := paint:paint($local:gif, <image:rectangle><image:upperLeft><image:x>20</image:x><image:y>20</image:y></image:upperLeft><image:lowerRight><image:x>50</image:x><image:y>50</image:y></image:lowerRight></image:rectangle>)
    let $draw-ref := file:read-binary(concat($local:image-dir, "paint/rectangle.gif"))
    return basic:equals($draw, $draw-ref)
};

(:~
 : @return true if the man:draw-rectangle function works.
 :)
declare %an:nondeterministic function local:test-draw-rectangle-green() as xs:boolean {
    let $draw := paint:paint($local:gif, <image:rectangle><image:strokeColor>#00AF00</image:strokeColor><image:upperLeft><image:x>20</image:x><image:y>20</image:y></image:upperLeft><image:lowerRight><image:x>50</image:x><image:y>50</image:y></image:lowerRight></image:rectangle>)
    let $draw-ref := file:read-binary(concat($local:image-dir, "paint/rectangleGreen.gif"))
    return basic:equals($draw, $draw-ref)
};


(:~
 : @return true if the man:draw-rectangle function works.
 :)
declare %an:nondeterministic function local:test-draw-rectangle-green-red() as xs:boolean {
    let $draw := paint:paint($local:gif, <image:rectangle><image:strokeColor>#00AF00</image:strokeColor><image:fillColor>#A10000</image:fillColor><image:upperLeft><image:x>20</image:x><image:y>20</image:y></image:upperLeft><image:lowerRight><image:x>50</image:x><image:y>50</image:y></image:lowerRight></image:rectangle>)
    let $draw-ref := file:read-binary(concat($local:image-dir, "paint/rectangleGreenRed.gif"))
    return basic:equals($draw, $draw-ref)
};


(:~
 : @return true if the man:draw-rectangle function works.
 :)
declare %an:nondeterministic function local:test-draw-rectangle-anti-aliased() as xs:boolean {
    let $draw := paint:paint($local:gif, <image:rectangle><image:strokeWidth>5</image:strokeWidth><image:strokeColor>#00AF00</image:strokeColor><image:fillColor>#A10000</image:fillColor><image:antiAliasing>true</image:antiAliasing><image:upperLeft><image:x>20</image:x><image:y>20</image:y></image:upperLeft><image:lowerRight><image:x>50</image:x><image:y>50</image:y></image:lowerRight></image:rectangle>)
    let $draw-ref := file:read-binary(concat($local:image-dir, "paint/rectangleAntiAliased.gif"))
    return basic:equals($draw, $draw-ref)
};

(:~
 : @return true if the man:draw-rounded-rectangle function works.
 :)
declare %an:nondeterministic function local:test-draw-rounded-rectangle() as xs:boolean {
    let $draw := paint:paint($local:gif, <image:roundedRectangle><image:upperLeft><image:x>20</image:x><image:y>20</image:y></image:upperLeft><image:lowerRight><image:x>50</image:x><image:y>50</image:y></image:lowerRight><image:cornerWidth>10</image:cornerWidth><image:cornerHeight>10</image:cornerHeight></image:roundedRectangle>)
    let $draw-ref := file:read-binary(concat($local:image-dir, "paint/rectangleRounded.gif"))
    return basic:equals($draw, $draw-ref)
};

(:~
 : @return true if the man:draw-rounded-rectangle function works.
 :)
declare %an:nondeterministic function local:test-draw-rounded-rectangle-blue() as xs:boolean {
    let $draw := paint:paint($local:gif, <image:roundedRectangle><image:strokeColor>#0000FF</image:strokeColor><image:upperLeft><image:x>20</image:x><image:y>20</image:y></image:upperLeft><image:lowerRight><image:x>50</image:x><image:y>50</image:y></image:lowerRight><image:cornerWidth>10</image:cornerWidth><image:cornerHeight>10</image:cornerHeight></image:roundedRectangle>)
    let $draw-ref := file:read-binary(concat($local:image-dir, "paint/rectangleRoundedBlue.gif"))
    return basic:equals($draw, $draw-ref)
};


(:~
 : @return true if the man:draw-rounded-rectangle function works.
 :)
declare %an:nondeterministic function local:test-draw-rounded-rectangle-blue-green() as xs:boolean {
    let $draw := paint:paint($local:gif, <image:roundedRectangle><image:strokeColor>#0000FF</image:strokeColor><image:fillColor>#00FF00</image:fillColor><image:upperLeft><image:x>20</image:x><image:y>20</image:y></image:upperLeft><image:lowerRight><image:x>50</image:x><image:y>50</image:y></image:lowerRight><image:cornerWidth>10</image:cornerWidth><image:cornerHeight>10</image:cornerHeight></image:roundedRectangle>)
    let $draw-ref := file:read-binary(concat($local:image-dir, "paint/rectangleRoundedBlueGreen.gif"))
    return basic:equals($draw, $draw-ref)
};


(:~
 : @return true if the man:draw-rounded-rectangle function works.
 :)
declare %an:nondeterministic function local:test-draw-rounded-rectangle-anti-aliased() as xs:boolean {
    let $draw := paint:paint($local:gif, <image:roundedRectangle><image:strokeColor>#0000FF</image:strokeColor><image:fillColor>#00FF00</image:fillColor><image:antiAliasing>true</image:antiAliasing><image:upperLeft><image:x>20</image:x><image:y>20</image:y></image:upperLeft><image:lowerRight><image:x>50</image:x><image:y>50</image:y></image:lowerRight><image:cornerWidth>10</image:cornerWidth><image:cornerHeight>10</image:cornerHeight></image:roundedRectangle>)
    let $draw-ref := file:read-binary(concat($local:image-dir, "paint/rectangleRoundedAntiAliased.gif"))
    return basic:equals($draw, $draw-ref)
};


declare %an:nondeterministic %an:sequential function local:main() as xs:string* {

  let $a := local:test-draw-rectangle()
  return
    if (fn:not($a)) then
      exit returning local:error(("Drawing a rectangle on an image failed."));
    else ();
    
  let $c := local:test-draw-rectangle-green()
  return
    if (fn:not($c)) then
      exit returning local:error(("Drawing a green rectangle on an image failed."));
    else ();    
  
   
  let $e := local:test-draw-rectangle-anti-aliased()
  return
    if (fn:not($e)) then
      exit returning local:error(("Drawing a anti-aliased wide green rectangle filled with red on an image failed."));
    else ();    
   
    
  let $f := local:test-draw-rounded-rectangle()
  return
    if (fn:not($f)) then
      exit returning local:error(("Drawing a rounded rectangle on an image failed."));
    else ();    
  
      
  let $g := local:test-draw-rounded-rectangle-blue()
  return
    if (fn:not($g)) then
      exit returning local:error(("Drawing a blue rounded rectangle on an image failed."));
    else ();          
    
  let $h := local:test-draw-rounded-rectangle-blue-green()
  return
    if (fn:not($h)) then
      exit returning local:error(("Drawing a blue rounded rectangle filled with green on an image failed."));
    else ();               
           
             
  let $j := local:test-draw-rounded-rectangle-anti-aliased()
  return
    if (fn:not($j)) then
      exit returning local:error(("Drawing a blue rounded rectangle anti-aliased filled with green on an image failed."));
    else ();               
    
  (: If all went well ... make sure the world knows! :)  
  "SUCCESS"
};

local:main()