~ubuntu-branches/ubuntu/wily/lua-lgi/wily-proposed

« back to all changes in this revision

Viewing changes to tests/cairo.lua

  • Committer: Package Import Robot
  • Author(s): Enrico Tassi
  • Date: 2012-06-25 13:36:04 UTC
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: package-import@ubuntu.com-20120625133604-3v03ss7t7cwdmp6z
Tags: upstream-0.7.1
ImportĀ upstreamĀ versionĀ 0.7.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
         checkv(pts[1].x, 10, 'number')
98
98
         checkv(pts[1].y, 11, 'number')
99
99
      elseif i == 2 then
100
 
         checkv(t, 'MOVE_TO', 'string')
 
100
         checkv(t, 'CURVE_TO', 'string')
101
101
         check(type(pts) == 'table' and #pts == 3)
102
102
         checkv(pts[1].x, 1, 'number')
103
103
         checkv(pts[1].y, 2, 'number')
106
106
         checkv(pts[3].x, 5, 'number')
107
107
         checkv(pts[3].y, 6, 'number')
108
108
      elseif i == 3 then
109
 
         checkv(t, 'MOVE_TO', 'string')
 
109
         checkv(t, 'CLOSE_PATH', 'string')
110
110
         check(type(pts) == 'table' and #pts == 0)
111
111
      elseif i == 4 then
 
112
         checkv(t, 'MOVE_TO', 'string')
 
113
         check(type(pts) == 'table' and #pts == 1)
 
114
         checkv(pts[1].x, 10, 'number')
 
115
         checkv(pts[1].y, 11, 'number')
 
116
      elseif i == 5 then
112
117
         checkv(t, 'LINE_TO', 'string')
113
118
         check(type(pts) == 'table' and #pts == 1)
114
119
         checkv(pts[1].x, 21, 'number')
118
123
      end
119
124
      i = i + 1
120
125
   end
 
126
   check(i == 6)
121
127
end
122
128
 
123
129
function cairo.surface_type()
135
141
   check(not cairo.RecordingSurface:is_type_of(s2))
136
142
end
137
143
 
 
144
function cairo.pattern_type()
 
145
   local cairo = lgi.cairo
 
146
   local pattern
 
147
 
 
148
   pattern = cairo.Pattern.create_rgb(1, 1, 1)
 
149
   check(cairo.SolidPattern:is_type_of(pattern))
 
150
   check(cairo.Pattern:is_type_of(pattern))
 
151
   pattern = cairo.SolidPattern(1, 1, 1)
 
152
   check(cairo.SolidPattern:is_type_of(pattern))
 
153
   pattern = cairo.SolidPattern(1, 1, 1, 1)
 
154
   check(cairo.SolidPattern:is_type_of(pattern))
 
155
 
 
156
   local surface = cairo.ImageSurface('ARGB32', 100, 100)
 
157
   pattern = cairo.Pattern.create_for_surface(surface)
 
158
   check(select(2, pattern:get_surface()) == surface)
 
159
   check(cairo.SurfacePattern:is_type_of(pattern))
 
160
   check(cairo.Pattern:is_type_of(pattern))
 
161
   pattern = cairo.SurfacePattern(surface)
 
162
   check(cairo.SurfacePattern:is_type_of(pattern))
 
163
 
 
164
   pattern = cairo.Pattern.create_linear(0, 0, 10, 10)
 
165
   check(cairo.LinearPattern:is_type_of(pattern))
 
166
   check(cairo.GradientPattern:is_type_of(pattern))
 
167
   check(cairo.Pattern:is_type_of(pattern))
 
168
   pattern = cairo.LinearPattern(0, 0, 10, 10)
 
169
   check(cairo.LinearPattern:is_type_of(pattern))
 
170
 
 
171
   pattern = cairo.Pattern.create_radial(0, 0, 5, 10, 10, 5)
 
172
   check(cairo.RadialPattern:is_type_of(pattern))
 
173
   check(cairo.GradientPattern:is_type_of(pattern))
 
174
   check(cairo.Pattern:is_type_of(pattern))
 
175
   pattern = cairo.RadialPattern(0, 0, 5, 10, 10, 5)
 
176
   check(cairo.RadialPattern:is_type_of(pattern))
 
177
 
 
178
   if cairo.version >= cairo.version_encode(1, 12, 0) then
 
179
      pattern = cairo.Pattern.create_mesh()
 
180
      check(cairo.MeshPattern:is_type_of(pattern))
 
181
      check(not cairo.GradientPattern:is_type_of(pattern))
 
182
      check(cairo.Pattern:is_type_of(pattern))
 
183
      pattern = cairo.MeshPattern()
 
184
      check(cairo.MeshPattern:is_type_of(pattern))
 
185
   end
 
186
end
 
187
 
 
188
function cairo.pattern_mesh()
 
189
   local cairo = lgi.cairo
 
190
 
 
191
   -- Mesh patterns are introduced in cairo 1.12
 
192
   if cairo.version < cairo.version_encode(1, 12, 0) then
 
193
      return
 
194
   end
 
195
 
 
196
   local mesh = cairo.Pattern.create_mesh()
 
197
   local pattern = cairo.Pattern.create_radial(1, 2, 3, 4, 5, 6)
 
198
 
 
199
   check(cairo.Pattern:is_type_of(mesh))
 
200
   check(cairo.MeshPattern:is_type_of(mesh))
 
201
 
 
202
   check(cairo.Pattern:is_type_of(pattern))
 
203
   check(not cairo.MeshPattern:is_type_of(pattern))
 
204
 
 
205
   local function check_status(status)
 
206
       checkv(status, 'SUCCESS', 'string')
 
207
   end
 
208
 
 
209
   -- Taken from cairo's pattern-getters test and slightly adapted to use all
 
210
   -- functions of the mesh pattern API
 
211
   local status, count = mesh:get_patch_count()
 
212
   check_status(status)
 
213
   checkv(count, 0, 'number')
 
214
 
 
215
   mesh:begin_patch()
 
216
   mesh:move_to(0, 0)
 
217
   mesh:line_to(0, 3)
 
218
   mesh:line_to(3, 3)
 
219
   mesh:line_to(3, 0)
 
220
   mesh:set_corner_color_rgba(0, 1, 1, 1, 1)
 
221
   mesh:end_patch()
 
222
 
 
223
   local status, count = mesh:get_patch_count()
 
224
   check_status(status)
 
225
   checkv(count, 1, 'number')
 
226
 
 
227
   for k, v in pairs({ { 1, 1 }, { 1, 2 }, { 2, 2 }, { 2, 1 } }) do
 
228
       local status, x, y = mesh:get_control_point(0, k - 1)
 
229
       check_status(status)
 
230
       checkv(x, v[1], 'number')
 
231
       checkv(y, v[2], 'number')
 
232
   end
 
233
 
 
234
   mesh:begin_patch()
 
235
   mesh:move_to(0, 0)
 
236
   mesh:line_to(1, 0)
 
237
   mesh:curve_to(1, 1, 1, 2, 0, 1)
 
238
   mesh:set_corner_color_rgb(0, 1, 1, 1)
 
239
   mesh:set_control_point(2, 0.5, 0.5)
 
240
   mesh:end_patch()
 
241
 
 
242
   local status, count = mesh:get_patch_count()
 
243
   check_status(status)
 
244
   checkv(count, 2, 'number')
 
245
 
 
246
   for k, v in pairs({ 1, 0, 0, 1 }) do
 
247
       local status, r, g, b, a = mesh:get_corner_color_rgba(1, k - 1)
 
248
       check_status(status)
 
249
       checkv(r, v, 'number')
 
250
       checkv(g, v, 'number')
 
251
       checkv(b, v, 'number')
 
252
       checkv(a, v, 'number')
 
253
   end
 
254
 
 
255
   local i = 0
 
256
   local expected = {
 
257
      { { 0, 1 }, { 0, 2 }, { 0, 3 } },
 
258
      { { 1, 3 }, { 2, 3 }, { 3, 3 } },
 
259
      { { 3, 2 }, { 3, 1 }, { 3, 0 } },
 
260
      { { 2, 0 }, { 1, 0 }, { 0, 0 } },
 
261
   }
 
262
   for t, pts in mesh:get_path(0):pairs() do
 
263
      if i == 0 then
 
264
         checkv(t, 'MOVE_TO', 'string')
 
265
         check(type(pts) == 'table' and #pts == 1)
 
266
         checkv(pts[1].x, 0, 'number')
 
267
         checkv(pts[1].y, 0, 'number')
 
268
      else
 
269
         -- Mesh patterns turn everything into curves. :-(
 
270
         checkv(t, 'CURVE_TO', 'string')
 
271
         check(type(pts) == 'table' and #pts == 3)
 
272
         for k, v in pairs(expected[i]) do
 
273
            checkv(pts[k].x, v[1], 'number')
 
274
            checkv(pts[k].y, v[2], 'number')
 
275
         end
 
276
      end
 
277
      i = i + 1
 
278
   end
 
279
   check(i == #expected + 1)
 
280
end
 
281
 
138
282
function cairo.context_transform()
139
283
   local cairo = lgi.cairo
140
284
   local surface = cairo.ImageSurface('ARGB32', 100, 100)