rbpdf-fruitcake0525 1.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +96 -0
  3. data/Gemfile +7 -0
  4. data/LICENSE.TXT +504 -0
  5. data/README.md +64 -0
  6. data/Rakefile +12 -0
  7. data/lib/core/rmagick.rb +93 -0
  8. data/lib/htmlcolors.rb +207 -0
  9. data/lib/rbpdf.rb +15138 -0
  10. data/lib/rbpdf/version.rb +3 -0
  11. data/lib/unicode_data.rb +18315 -0
  12. data/logo_example.png +0 -0
  13. data/rbpdf.gemspec +37 -0
  14. data/test/err_font1.rb +3 -0
  15. data/test/err_font2.rb +4 -0
  16. data/test/logo_rbpdf_8bit.gif +0 -0
  17. data/test/logo_rbpdf_8bit.jpg +0 -0
  18. data/test/logo_rbpdf_8bit.png +0 -0
  19. data/test/logo_rbpdf_8bit_alpha.gif +0 -0
  20. data/test/logo_rbpdf_mono_gray.jpg +0 -0
  21. data/test/logo_rbpdf_mono_gray.png +0 -0
  22. data/test/logo_rbpdf_mono_rgb.jpg +0 -0
  23. data/test/logo_rbpdf_mono_rgb.png +0 -0
  24. data/test/png_test_alpha.png +0 -0
  25. data/test/png_test_msk_alpha.png +0 -0
  26. data/test/png_test_non_alpha.png +0 -0
  27. data/test/rbpdf_bidi_test.rb +438 -0
  28. data/test/rbpdf_bookmark_test.rb +56 -0
  29. data/test/rbpdf_cell_test.rb +266 -0
  30. data/test/rbpdf_content_test.rb +196 -0
  31. data/test/rbpdf_css_test.rb +636 -0
  32. data/test/rbpdf_dom_test.rb +338 -0
  33. data/test/rbpdf_font_func_test.rb +41 -0
  34. data/test/rbpdf_font_style_test.rb +33 -0
  35. data/test/rbpdf_font_test.rb +291 -0
  36. data/test/rbpdf_format_test.rb +26 -0
  37. data/test/rbpdf_func_test.rb +135 -0
  38. data/test/rbpdf_html_anchor_test.rb +107 -0
  39. data/test/rbpdf_html_func_test.rb +166 -0
  40. data/test/rbpdf_html_test.rb +580 -0
  41. data/test/rbpdf_htmlcell_test.rb +64 -0
  42. data/test/rbpdf_image_rmagick_test.rb +294 -0
  43. data/test/rbpdf_image_test.rb +107 -0
  44. data/test/rbpdf_test.rb +377 -0
  45. data/test/rbpdf_transaction_test.rb +199 -0
  46. data/test/rbpdf_viewerpreferences_test.rb +37 -0
  47. data/test/rbpdf_write_test.rb +225 -0
  48. data/test/test_helper.rb +4 -0
  49. data/test_unicode.rbpdf +115 -0
  50. data/utf8test.txt +120 -0
  51. metadata +205 -0
@@ -0,0 +1,377 @@
1
+ require 'test_helper'
2
+
3
+ class RbpdfTest < Test::Unit::TestCase
4
+ class MYPDF < RBPDF
5
+ def getPageBuffer(page)
6
+ super
7
+ end
8
+ end
9
+
10
+ test "set_x potision" do
11
+ pdf = RBPDF.new
12
+ width = pdf.get_page_width
13
+
14
+ pdf.set_x(5)
15
+ x = pdf.get_x
16
+ abs_x = pdf.get_abs_x
17
+ assert_equal 5, x
18
+ assert_equal 5, abs_x
19
+
20
+ pdf.set_x(-4)
21
+ x = pdf.get_x
22
+ abs_x = pdf.get_abs_x
23
+ assert_equal width - 4, x
24
+ assert_equal width - 4, abs_x
25
+
26
+ pdf.set_rtl(true) # Right to Left
27
+
28
+ pdf.set_x(5)
29
+ x = pdf.get_x
30
+ abs_x = pdf.get_abs_x
31
+ assert_equal 5, x
32
+ assert_equal width - 5, abs_x
33
+
34
+ pdf.set_x(-4)
35
+ x = pdf.get_x
36
+ abs_x = pdf.get_abs_x
37
+ assert_equal width - 4, x
38
+ assert_equal 4, abs_x
39
+ end
40
+
41
+ test "set_y potision" do
42
+ pdf = RBPDF.new
43
+ width = pdf.get_page_width
44
+
45
+ pdf.set_left_margin(10)
46
+ pdf.set_y(20)
47
+ x = pdf.get_x
48
+ abs_x = pdf.get_abs_x
49
+ y = pdf.get_y
50
+ assert_equal 10, x
51
+ assert_equal 10, abs_x
52
+ assert_equal 20, y
53
+
54
+ pdf.set_left_margin(30)
55
+ pdf.set_y(20)
56
+ x = pdf.get_x
57
+ abs_x = pdf.get_abs_x
58
+ y = pdf.get_y
59
+ assert_equal 30, x
60
+ assert_equal 30, abs_x
61
+ assert_equal 20, y
62
+
63
+ pdf.set_rtl(true) # Right to Left
64
+
65
+ pdf.set_right_margin(10)
66
+ pdf.set_y(20)
67
+ x = pdf.get_x
68
+ abs_x = pdf.get_abs_x
69
+ y = pdf.get_y
70
+ assert_equal 10, x
71
+ assert_equal width - 10, abs_x
72
+ assert_equal 20, y
73
+
74
+ pdf.set_right_margin(30)
75
+ pdf.set_y(20)
76
+ x = pdf.get_x
77
+ abs_x = pdf.get_abs_x
78
+ y = pdf.get_y
79
+ assert_equal 30, x
80
+ assert_equal width - 30, abs_x
81
+ assert_equal 20, y
82
+ end
83
+
84
+ test "add_page potision" do
85
+ pdf = RBPDF.new
86
+ width = pdf.get_page_width
87
+
88
+ pdf.add_page
89
+ x = pdf.get_x
90
+ abs_x = pdf.get_abs_x
91
+ y = pdf.get_y
92
+ assert_in_delta 10.00125, x, 0.00001
93
+ assert_in_delta 10.00125, abs_x, 0.00001
94
+ assert_in_delta 10.00125, y, 0.00001
95
+
96
+ pdf.set_rtl(true) # Right to Left
97
+
98
+ pdf.add_page
99
+ x = pdf.get_x
100
+ abs_x = pdf.get_abs_x
101
+ y = pdf.get_y
102
+ assert_in_delta 10.00125, x, 0.00001
103
+ assert_in_delta width - 10.00125, abs_x, 0.00001
104
+ assert_in_delta 10.00125, y, 0.00001
105
+
106
+ pdf.set_page(1)
107
+ page = pdf.get_page
108
+ assert_equal 1, page
109
+ pdf.set_y(20)
110
+ y = pdf.get_y
111
+ assert_equal 20, y
112
+ pdf.add_page
113
+ y = pdf.get_y
114
+ assert_in_delta 10.00125, y, 0.00001
115
+
116
+ end
117
+
118
+ test "add_page" do
119
+ pdf = RBPDF.new
120
+
121
+ page = pdf.get_page
122
+ assert_equal 0, page
123
+ pages = pdf.get_num_pages
124
+ assert_equal 0, pages
125
+
126
+ pdf.add_page
127
+ page = pdf.get_page
128
+ assert_equal 1, page
129
+ pages = pdf.get_num_pages
130
+ assert_equal 1, pages
131
+
132
+ pdf.add_page
133
+ page = pdf.get_page
134
+ assert_equal 2, page
135
+ pages = pdf.get_num_pages
136
+ assert_equal 2, pages
137
+
138
+ pdf.set_page(1)
139
+ page = pdf.get_page
140
+ assert_equal 1, page
141
+
142
+ pdf.add_page
143
+ page = pdf.get_page
144
+ assert_equal 2, page
145
+ pages = pdf.get_num_pages
146
+ assert_equal 2, pages
147
+
148
+ pdf.add_page
149
+ page = pdf.get_page
150
+ assert_equal 3, page
151
+ pages = pdf.get_num_pages
152
+ assert_equal 3, pages
153
+
154
+ pdf.set_page(1)
155
+ page = pdf.get_page
156
+ assert_equal 1, page
157
+
158
+ pdf.last_page
159
+ page = pdf.get_page
160
+ assert_equal 3, page
161
+ pages = pdf.get_num_pages
162
+ assert_equal 3, pages
163
+ end
164
+
165
+ test "add_page set_page Under Error" do
166
+ pdf = RBPDF.new
167
+
168
+ page = pdf.get_page
169
+ assert_equal 0, page
170
+ pages = pdf.get_num_pages
171
+ assert_equal 0, pages
172
+
173
+ pdf.add_page
174
+ page = pdf.get_page
175
+ assert_equal 1, page
176
+ pages = pdf.get_num_pages
177
+ assert_equal 1, pages
178
+
179
+ assert_raise(RuntimeError) {pdf.set_page(0)} # Page under size
180
+ end
181
+
182
+ test "add_page set_page Over Error" do
183
+ pdf = RBPDF.new
184
+
185
+ page = pdf.get_page
186
+ assert_equal 0, page
187
+ pages = pdf.get_num_pages
188
+ assert_equal 0, pages
189
+
190
+ pdf.add_page
191
+ page = pdf.get_page
192
+ assert_equal 1, page
193
+ pages = pdf.get_num_pages
194
+ assert_equal 1, pages
195
+
196
+ pdf.add_page
197
+ page = pdf.get_page
198
+ assert_equal 2, page
199
+ pages = pdf.get_num_pages
200
+ assert_equal 2, pages
201
+
202
+ pdf.set_page(1)
203
+ page = pdf.get_page
204
+ assert_equal 1, page
205
+
206
+ assert_raise(RuntimeError) {pdf.set_page(3)} # Page over size
207
+ end
208
+
209
+ test "deletePage test" do
210
+ pdf = MYPDF.new
211
+
212
+ pdf.add_page
213
+ pdf.write(0, "Page 1")
214
+
215
+ page = pdf.get_page
216
+ assert_equal 1, page
217
+ pages = pdf.get_num_pages
218
+ assert_equal 1, pages
219
+
220
+ contents1 = pdf.getPageBuffer(1)
221
+
222
+ pdf.add_page
223
+ pdf.write(0, "Page 2")
224
+
225
+ page = pdf.get_page
226
+ assert_equal 2, page
227
+ pages = pdf.get_num_pages
228
+ assert_equal 2, pages
229
+
230
+ contents2 = pdf.getPageBuffer(2)
231
+
232
+ pdf.deletePage(1)
233
+ page = pdf.get_page
234
+ assert_equal 1, page
235
+ pages = pdf.get_num_pages
236
+ assert_equal 1, pages
237
+
238
+ contents3 = pdf.getPageBuffer(1)
239
+ assert_not_equal contents3, contents1
240
+ assert_equal contents3, contents2
241
+
242
+ contents4 = pdf.getPageBuffer(2)
243
+ assert_equal contents4, false
244
+ end
245
+
246
+ test "start_page_group test" do
247
+ pdf = RBPDF.new
248
+ pdf.add_page
249
+ pdf.start_page_group
250
+ pdf.start_page_group(1)
251
+ pdf.start_page_group(nil)
252
+ pdf.start_page_group('')
253
+ end
254
+
255
+ test "get_page_dimensions test" do
256
+ pdf = RBPDF.new
257
+ pdf.add_page
258
+
259
+ pagedim = pdf.get_page_dimensions
260
+ assert_equal pagedim['CropBox']['llx'], 0.0
261
+ pagedim = pdf.get_page_dimensions(1)
262
+ assert_equal pagedim['CropBox']['llx'], 0.0
263
+ pagedim = pdf.get_page_dimensions(nil)
264
+ assert_equal pagedim['CropBox']['llx'], 0.0
265
+ pagedim = pdf.get_page_dimensions('')
266
+ assert_equal pagedim['CropBox']['llx'], 0.0
267
+ end
268
+
269
+ test "Page Box A4 test 1" do
270
+ pdf = RBPDF.new
271
+ pagedim = pdf.get_page_dimensions
272
+ assert_equal pagedim['MediaBox']['llx'], 0.0
273
+ assert_equal pagedim['MediaBox']['lly'], 0.0
274
+ assert_equal pagedim['MediaBox']['urx'], 595.28
275
+ assert_equal pagedim['MediaBox']['ury'], 841.89
276
+ assert_equal pagedim['CropBox']['llx'], 0.0
277
+ assert_equal pagedim['CropBox']['lly'], 0.0
278
+ assert_equal pagedim['CropBox']['urx'], 595.28
279
+ assert_equal pagedim['CropBox']['ury'], 841.89
280
+ assert_equal pagedim['BleedBox']['llx'], 0.0
281
+ assert_equal pagedim['BleedBox']['lly'], 0.0
282
+ assert_equal pagedim['BleedBox']['urx'], 595.28
283
+ assert_equal pagedim['BleedBox']['ury'], 841.89
284
+ assert_equal pagedim['TrimBox']['llx'], 0.0
285
+ assert_equal pagedim['TrimBox']['lly'], 0.0
286
+ assert_equal pagedim['TrimBox']['urx'], 595.28
287
+ assert_equal pagedim['TrimBox']['ury'], 841.89
288
+ assert_equal pagedim['ArtBox']['llx'], 0.0
289
+ assert_equal pagedim['ArtBox']['lly'], 0.0
290
+ assert_equal pagedim['ArtBox']['urx'], 595.28
291
+ assert_equal pagedim['ArtBox']['ury'], 841.89
292
+ end
293
+
294
+ test "Page Box A4 test 2" do
295
+ format = {}
296
+ type = ['CropBox', 'BleedBox', 'TrimBox', 'ArtBox']
297
+ type.each do |type|
298
+ format[type] = {}
299
+ format[type]['llx'] = 0
300
+ format[type]['lly'] = 0
301
+ format[type]['urx'] = 210
302
+ format[type]['ury'] = 297
303
+ end
304
+
305
+ pdf = RBPDF.new('P', 'mm', format)
306
+ pagedim = pdf.get_page_dimensions
307
+ assert_equal pagedim['MediaBox']['llx'], 0.0
308
+ assert_equal pagedim['MediaBox']['lly'], 0.0
309
+ assert_in_delta pagedim['MediaBox']['urx'], 595.28, 0.1
310
+ assert_in_delta pagedim['MediaBox']['ury'], 841.89, 0.1
311
+ assert_equal pagedim['CropBox']['llx'], 0.0
312
+ assert_equal pagedim['CropBox']['lly'], 0.0
313
+ assert_in_delta pagedim['CropBox']['urx'], 595.28, 0.1
314
+ assert_in_delta pagedim['CropBox']['ury'], 841.89, 0.1
315
+ assert_equal pagedim['BleedBox']['llx'], 0.0
316
+ assert_equal pagedim['BleedBox']['lly'], 0.0
317
+ assert_in_delta pagedim['BleedBox']['urx'], 595.28, 0.1
318
+ assert_in_delta pagedim['BleedBox']['ury'], 841.89, 0.1
319
+ assert_equal pagedim['TrimBox']['llx'], 0.0
320
+ assert_equal pagedim['TrimBox']['lly'], 0.0
321
+ assert_in_delta pagedim['TrimBox']['urx'], 595.28, 0.1
322
+ assert_in_delta pagedim['TrimBox']['ury'], 841.89, 0.1
323
+ assert_equal pagedim['ArtBox']['llx'], 0.0
324
+ assert_equal pagedim['ArtBox']['lly'], 0.0
325
+ assert_in_delta pagedim['ArtBox']['urx'], 595.28, 0.1
326
+ assert_in_delta pagedim['ArtBox']['ury'], 841.89, 0.1
327
+ end
328
+
329
+ test "Page Box A4 test 3" do
330
+ format = {}
331
+ type = ['MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox']
332
+ type.each do |type|
333
+ format[type] = {}
334
+ format[type]['llx'] = 0
335
+ format[type]['lly'] = 0
336
+ format[type]['urx'] = 210
337
+ format[type]['ury'] = 297
338
+ end
339
+
340
+ pdf = RBPDF.new('P', 'mm', format)
341
+ pagedim = pdf.get_page_dimensions
342
+ assert_equal pagedim['MediaBox']['llx'], 0.0
343
+ assert_equal pagedim['MediaBox']['lly'], 0.0
344
+ assert_in_delta pagedim['MediaBox']['urx'], 595.28, 0.1
345
+ assert_in_delta pagedim['MediaBox']['ury'], 841.89, 0.1
346
+ assert_equal pagedim['CropBox']['llx'], 0.0
347
+ assert_equal pagedim['CropBox']['lly'], 0.0
348
+ assert_in_delta pagedim['CropBox']['urx'], 595.28, 0.1
349
+ assert_in_delta pagedim['CropBox']['ury'], 841.89, 0.1
350
+ assert_equal pagedim['BleedBox']['llx'], 0.0
351
+ assert_equal pagedim['BleedBox']['lly'], 0.0
352
+ assert_in_delta pagedim['BleedBox']['urx'], 595.28, 0.1
353
+ assert_in_delta pagedim['BleedBox']['ury'], 841.89, 0.1
354
+ assert_equal pagedim['TrimBox']['llx'], 0.0
355
+ assert_equal pagedim['TrimBox']['lly'], 0.0
356
+ assert_in_delta pagedim['TrimBox']['urx'], 595.28, 0.1
357
+ assert_in_delta pagedim['TrimBox']['ury'], 841.89, 0.1
358
+ assert_equal pagedim['ArtBox']['llx'], 0.0
359
+ assert_equal pagedim['ArtBox']['lly'], 0.0
360
+ assert_in_delta pagedim['ArtBox']['urx'], 595.28, 0.1
361
+ assert_in_delta pagedim['ArtBox']['ury'], 841.89, 0.1
362
+ end
363
+
364
+ test "get_break_margin test" do
365
+ pdf = RBPDF.new
366
+ pdf.add_page
367
+
368
+ b_margin = pdf.get_break_margin
369
+ assert_in_delta b_margin, 20.0, 0.1
370
+ b_margin = pdf.get_break_margin(1)
371
+ assert_in_delta b_margin, 20.0, 0.1
372
+ b_margin = pdf.get_break_margin(nil)
373
+ assert_in_delta b_margin, 20.0, 0.1
374
+ b_margin = pdf.get_break_margin('')
375
+ assert_in_delta b_margin, 20.0, 0.1
376
+ end
377
+ end
@@ -0,0 +1,199 @@
1
+ require 'test_helper'
2
+
3
+ class RbpdfTest < Test::Unit::TestCase
4
+ class MYPDF < RBPDF
5
+ def getPageBuffer(page)
6
+ super
7
+ end
8
+ end
9
+
10
+ test "Transaction write test without diskcache" do
11
+ pdf = MYPDF.new
12
+ pdf.add_page()
13
+ page = pdf.get_page
14
+
15
+ pdf.write(0, "LINE 0\n")
16
+ contents01 = pdf.getPageBuffer(page).dup
17
+
18
+ pdf.start_transaction()
19
+
20
+ pdf.write(0, "LINE 1\n")
21
+ pdf.write(0, "LINE 2\n")
22
+ contents02 = pdf.getPageBuffer(page).dup
23
+ assert_not_equal contents01, contents02
24
+
25
+ # rolls back to the last (re)start 1
26
+ pdf = pdf.rollback_transaction()
27
+ contents03 = pdf.getPageBuffer(page).dup
28
+ assert_equal contents01, contents03
29
+
30
+ pdf.start_transaction()
31
+
32
+ pdf.write(0, "LINE 3\n")
33
+ pdf.write(0, "LINE 4\n")
34
+ contents04 = pdf.getPageBuffer(page).dup
35
+ assert_not_equal contents03, contents04
36
+
37
+ # rolls back to the last (re)start 2
38
+ pdf = pdf.rollback_transaction()
39
+ contents05 = pdf.getPageBuffer(page).dup
40
+ assert_equal contents03, contents05
41
+
42
+ pdf.commit_transaction()
43
+ end
44
+
45
+ test "Transaction test with diskcache" do
46
+ pdf = MYPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
47
+ pdf.add_page()
48
+ page = pdf.get_page
49
+
50
+ pdf.write(0, "LINE 0\n")
51
+ contents01 = pdf.getPageBuffer(page).dup
52
+ cache_file1 = pdf.cache_file_length.dup
53
+
54
+ pdf.start_transaction()
55
+
56
+ pdf.write(0, "LINE 1\n")
57
+ pdf.write(0, "LINE 2\n")
58
+ cache_file2 = pdf.cache_file_length.dup
59
+ contents02 = pdf.getPageBuffer(page).dup
60
+ assert_not_equal cache_file1, cache_file2
61
+ assert_not_equal contents01, contents02
62
+
63
+ # rolls back to the last (re)start 1
64
+ pdf = pdf.rollback_transaction()
65
+
66
+ cache_file3 = pdf.cache_file_length.dup
67
+ contents03 = pdf.getPageBuffer(page).dup
68
+ assert_equal cache_file1, cache_file3
69
+ assert_equal contents01, contents03
70
+
71
+ pdf.start_transaction()
72
+
73
+ pdf.write(0, "LINE 3\n")
74
+ pdf.write(0, "LINE 4\n")
75
+ contents04 = pdf.getPageBuffer(page).dup
76
+ assert_not_equal contents03, contents04
77
+
78
+ # rolls back to the last (re)start 2
79
+ pdf = pdf.rollback_transaction()
80
+
81
+ contents05 = pdf.getPageBuffer(page).dup
82
+ assert_equal contents03, contents05
83
+ end
84
+
85
+ test "Transaction multi_cell test without diskcache" do
86
+ pdf = MYPDF.new
87
+ pdf.add_page()
88
+ page = pdf.get_page
89
+
90
+ pdf.multi_cell(50, 5, 'mult_cell 1', 0)
91
+ contents01 = pdf.getPageBuffer(page).dup
92
+
93
+ pdf.start_transaction()
94
+
95
+ pdf.multi_cell(50, 5, 'mult_cell 1', 1)
96
+ pdf.multi_cell(50, 5, 'mult_cell 2', 1)
97
+ contents02 = pdf.getPageBuffer(page).dup
98
+ assert_not_equal contents01, contents02
99
+
100
+ # rolls back to the last (re)start 1
101
+ pdf = pdf.rollback_transaction()
102
+ contents03 = pdf.getPageBuffer(page).dup
103
+ assert_equal contents01, contents03
104
+
105
+ pdf.start_transaction()
106
+
107
+ pdf.multi_cell(50, 5, 'mult_cell 3', 1)
108
+ pdf.multi_cell(50, 5, 'mult_cell 4', 1)
109
+ contents04 = pdf.getPageBuffer(page).dup
110
+ assert_not_equal contents03, contents04
111
+
112
+ # rolls back to the last (re)start 2
113
+ pdf = pdf.rollback_transaction()
114
+ contents05 = pdf.getPageBuffer(page).dup
115
+ assert_equal contents03, contents05
116
+
117
+ pdf.commit_transaction()
118
+ end
119
+
120
+ test "Transaction mult_cell test with diskcache" do
121
+ pdf = MYPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
122
+ pdf.add_page()
123
+ page = pdf.get_page
124
+
125
+ pdf.multi_cell(50, 5, 'mult_cell 0', 1)
126
+ cache_file1 = pdf.cache_file_length.dup
127
+ contents01 = pdf.getPageBuffer(page).dup
128
+
129
+ pdf.start_transaction()
130
+
131
+ pdf.multi_cell(50, 5, 'mult_cell 1', 1)
132
+ pdf.multi_cell(50, 5, 'mult_cell 2', 1)
133
+ cache_file2 = pdf.cache_file_length.dup
134
+ contents02 = pdf.getPageBuffer(page).dup
135
+ assert_not_equal cache_file1, cache_file2
136
+ assert_not_equal contents01, contents02
137
+
138
+ # rolls back to the last (re)start 1
139
+ pdf = pdf.rollback_transaction()
140
+
141
+ contents03 = pdf.getPageBuffer(page).dup
142
+ cache_file3 = pdf.cache_file_length.dup
143
+ assert_equal cache_file1, cache_file3
144
+ assert_equal contents01, contents03
145
+
146
+ pdf.start_transaction()
147
+
148
+ pdf.multi_cell(50, 5, 'mult_cell 3', 1)
149
+ pdf.multi_cell(50, 5, 'mult_cell 4', 1)
150
+ contents04 = pdf.getPageBuffer(page).dup
151
+ assert_not_equal contents03, contents04
152
+
153
+ # rolls back to the last (re)start 2
154
+ pdf = pdf.rollback_transaction()
155
+
156
+ contents05 = pdf.getPageBuffer(page).dup
157
+ assert_equal contents03, contents05
158
+ end
159
+
160
+ test "Transaction mult_cell self test with diskcache" do
161
+ pdf = MYPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
162
+ pdf.add_page()
163
+ page = pdf.get_page
164
+
165
+ pdf.multi_cell(50, 5, 'mult_cell 0', 1)
166
+ cache_file1 = pdf.cache_file_length.dup
167
+ contents01 = pdf.getPageBuffer(page).dup
168
+
169
+ pdf.start_transaction()
170
+
171
+ pdf.multi_cell(50, 5, 'mult_cell 1', 1)
172
+ pdf.multi_cell(50, 5, 'mult_cell 2', 1)
173
+ cache_file2 = pdf.cache_file_length.dup
174
+ contents02 = pdf.getPageBuffer(page).dup
175
+ assert_not_equal cache_file1, cache_file2
176
+ assert_not_equal contents01, contents02
177
+
178
+ # rolls back to the last (re)start 1
179
+ pdf.rollback_transaction(true)
180
+
181
+ contents03 = pdf.getPageBuffer(page).dup
182
+ cache_file3 = pdf.cache_file_length.dup
183
+ assert_equal cache_file1, cache_file3
184
+ assert_equal contents01, contents03
185
+
186
+ pdf.start_transaction()
187
+
188
+ pdf.multi_cell(50, 5, 'mult_cell 3', 1)
189
+ pdf.multi_cell(50, 5, 'mult_cell 4', 1)
190
+ contents04 = pdf.getPageBuffer(page).dup
191
+ assert_not_equal contents03, contents04
192
+
193
+ # rolls back to the last (re)start 2
194
+ pdf.rollback_transaction(true)
195
+
196
+ contents05 = pdf.getPageBuffer(page).dup
197
+ assert_equal contents03, contents05
198
+ end
199
+ end