File: test_annotations.rb

package info (click to toggle)
origami-pdf 2.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,484 kB
  • sloc: ruby: 17,883; makefile: 8
file content (68 lines) | stat: -rw-r--r-- 2,033 bytes parent folder | download | duplicates (3)
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
require 'minitest/autorun'
require 'stringio'

class TestAnnotations < Minitest::Test
    def setup
        @target = PDF.new
        @page = Page.new
        @action = Action::JavaScript["app.alert(null);"]
        @output = StringIO.new

        @types = [ 
            Annotation::Circle, Annotation::Square,
            Annotation::Text, Annotation::Link,
            Annotation::FileAttachment, Annotation::Screen,
            Annotation::Sound, Annotation::Widget::CheckBox,
            Annotation::Widget::Radio, Annotation::Widget::Text,
            Annotation::Widget::ComboBox, Annotation::Widget::ListBox,
            Annotation::Widget::Signature
        ]
    end

    def test_annotations
        @target.append_page @page

        annotations = @types.map(&:new)
        annotations.each do |annotation|
            @page.add_annotation(annotation)
        end

        @page.each_annotation do |annotation|
            assert_kind_of Annotation, annotation

            assert annotations.include?(annotation)
        end

        assert_equal @page.annotations.size, annotations.size

        @target.save(@output)
    end

    def test_annotation_actions
        screen = Annotation::Screen.new

        @page.add_annotation screen

        screen.onMouseOver @action
        screen.onMouseOut @action
        screen.onMouseDown @action
        screen.onMouseUp @action
        screen.onFocus @action
        screen.onBlur @action
        screen.onPageOpen @action
        screen.onPageClose @action
        screen.onPageVisible @action
        screen.onPageInvisible @action

        assert_equal screen.AA.E, @action
        assert_equal screen.AA.X, @action
        assert_equal screen.AA.D, @action
        assert_equal screen.AA.U, @action
        assert_equal screen.AA.Fo, @action
        assert_equal screen.AA.Bl, @action
        assert_equal screen.AA.PO, @action
        assert_equal screen.AA.PC, @action
        assert_equal screen.AA.PV, @action
        assert_equal screen.AA.PI, @action
    end
end