flash_tool 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of flash_tool might be problematic. Click here for more details.
- data/.gitignore +1 -0
- data/README.rdoc +63 -15
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/flash_tool.gemspec +28 -18
- data/lib/flash_tool.rb +76 -170
- data/lib/flash_tool/flash.rb +114 -0
- data/lib/flash_tool/flash_combine.rb +82 -0
- data/lib/flash_tool/flash_object.rb +73 -0
- data/lib/flash_tool/flash_script.rb +36 -0
- data/test/{25-1.gif → test_files/25-1.gif} +0 -0
- data/test/test_files/bad.sc +1 -0
- data/test/{bad_ext.txt → test_files/bad_ext.txt} +0 -0
- data/test/{bad_swf.swf → test_files/bad_swf.swf} +0 -0
- data/test/{jpeg.swf → test_files/jpeg.swf} +0 -0
- data/test/{liberationserif_bold.ttf → test_files/liberationserif_bold.ttf} +0 -0
- data/test/{rfxview.swf → test_files/rfxview.swf} +0 -0
- data/test/test_files/script.sc +8 -0
- data/test/{test.jpg → test_files/test.jpg} +0 -0
- data/test/{test.pdf → test_files/test.pdf} +0 -0
- data/test/{test.png → test_files/test.png} +0 -0
- data/test/{test_with_password.pdf → test_files/test_with_password.pdf} +0 -0
- data/test/{tester.swf → test_files/tester.swf} +0 -0
- data/test/test_flash_combine.rb +88 -0
- data/test/test_flash_object.rb +230 -0
- data/test/test_flash_script.rb +52 -0
- data/test/test_flash_tool.rb +47 -140
- metadata +27 -17
- data/test/test_flash_data.rb +0 -69
@@ -0,0 +1,114 @@
|
|
1
|
+
module FlashTool
|
2
|
+
|
3
|
+
|
4
|
+
class Flash
|
5
|
+
|
6
|
+
attr :input
|
7
|
+
attr :args
|
8
|
+
|
9
|
+
# Path to file
|
10
|
+
attr_reader :output_path
|
11
|
+
|
12
|
+
# Hash with informations about generated file
|
13
|
+
attr_reader :info
|
14
|
+
|
15
|
+
|
16
|
+
#
|
17
|
+
# This is basic method for generating command in swf tools
|
18
|
+
# ==Example
|
19
|
+
# something = Flash.new("document.pdf","pdf2swf")do |f|
|
20
|
+
# f.rate(24)
|
21
|
+
# f.save("outputs.swf"
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# It is much easer to use other classes
|
25
|
+
# *FlashObject - for work converting from other formats
|
26
|
+
# *FlashScirpt - for generating files from scripts
|
27
|
+
# *FlashCombine - for combining files
|
28
|
+
#
|
29
|
+
def initialize(input, command ,tempfile = nil, &block)
|
30
|
+
@args = []
|
31
|
+
@tempfile = tempfile
|
32
|
+
@input = input
|
33
|
+
@command = command
|
34
|
+
yield self if block_given?
|
35
|
+
raise FlashToolError, "File not found" unless File.exist?(input)
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
# Save swf file from documents
|
41
|
+
# This method creates and run command
|
42
|
+
# Output path can be defined in save method or in method output before
|
43
|
+
# otherwise default file name will be same as input name document with swf extension
|
44
|
+
def save(output_path=nil)
|
45
|
+
to_output_path(output_path)
|
46
|
+
run_command(@command,*@args << @input)
|
47
|
+
@info = FlashTool.flash_info(@output_path)
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
# Setting options from command
|
53
|
+
# List of commands and options can find here http://wiki.swftools.org/index.php/Main_Page
|
54
|
+
# Optins with "-" can't be executed in shorter form
|
55
|
+
#
|
56
|
+
def method_missing(symbol, *args)
|
57
|
+
@output_path = args.to_s if symbol.to_s == "output"
|
58
|
+
@args << ("--#{symbol}")
|
59
|
+
@args +=(args)
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
protected
|
64
|
+
|
65
|
+
# This method runs command
|
66
|
+
def run_command(command ,*args)
|
67
|
+
args.collect! do |arg|
|
68
|
+
# args can contain characters like '>' so we must escape them, but don't quote switches
|
69
|
+
if arg !~ /^[\-]/
|
70
|
+
"\"#{arg}\""
|
71
|
+
else
|
72
|
+
arg.to_s
|
73
|
+
end
|
74
|
+
end
|
75
|
+
command = "#{command} #{args.join(" ")}"
|
76
|
+
output = `#{command} 2>&1`
|
77
|
+
|
78
|
+
if $?.exitstatus != 0
|
79
|
+
raise FlashToolError, "SWF command (#{command.inspect}) failed: #{{:status_code => $?, :output => output}.inspect}"
|
80
|
+
else
|
81
|
+
output
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
# set output path before saveing
|
88
|
+
def to_output_path(output_path) #:nodoc:
|
89
|
+
unless @output_path
|
90
|
+
if output_path
|
91
|
+
@output_path = output_path
|
92
|
+
else
|
93
|
+
@output_path = parse_nil_path(@input)
|
94
|
+
end
|
95
|
+
@args << "--output"
|
96
|
+
@args << @output_path
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
# Parsing file name and push new exetesnion if filename is not setted
|
103
|
+
def parse_nil_path path #:nodoc:
|
104
|
+
path = path.split('.')
|
105
|
+
path.pop if path.length > 1
|
106
|
+
path.push("swf")
|
107
|
+
path.join('.')
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/flash.rb'
|
2
|
+
module FlashTool
|
3
|
+
|
4
|
+
#
|
5
|
+
# This class work with tool swfcombine it is basic http://www.swftools.org/swfcombine.html
|
6
|
+
# You can use every opticons for this command.
|
7
|
+
# For adding master and slave swf files you must use methods master and slave
|
8
|
+
# If you trying to use options
|
9
|
+
#
|
10
|
+
class FlashCombine < Flash
|
11
|
+
|
12
|
+
|
13
|
+
#
|
14
|
+
# Take two or more SWF files, and combine them into a new SWF file.
|
15
|
+
# Can be used with or without master swf file
|
16
|
+
#
|
17
|
+
# ==Use
|
18
|
+
#
|
19
|
+
# combinated_file = FlashTool::FlashCombine.new
|
20
|
+
# combinated_file.master("master.swf")
|
21
|
+
# combinated_file.slave("viewport","slave.swf") #viewport is name of frame where can be placed slave
|
22
|
+
# combinated_file.rate(24)
|
23
|
+
# combinated_file.save("merged.swf")
|
24
|
+
#
|
25
|
+
# cominated_file = FlashTool::FlashCombine.new do |f|
|
26
|
+
# f.master("master.swf")
|
27
|
+
# f.slave("viewport","slave.swf")
|
28
|
+
# f.output("merged.swf")
|
29
|
+
# f.save
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
def initialize(&block)
|
33
|
+
@args = []
|
34
|
+
@slaves = []
|
35
|
+
@command = "swfcombine"
|
36
|
+
yield self if block_given?
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# With this method you will set master swf file for combining
|
41
|
+
#
|
42
|
+
# Can be only one master file
|
43
|
+
#
|
44
|
+
# Raise FlashToolError
|
45
|
+
#
|
46
|
+
def master(file)
|
47
|
+
raise(FlashToolError, "Can be only one master swf file" ) if @master
|
48
|
+
@master = file
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# With this method you will set slave swf file for combining
|
53
|
+
#
|
54
|
+
# Can be only one master file
|
55
|
+
#
|
56
|
+
def slave(name, file)
|
57
|
+
@slaves += ["#{name}=#{file}"]
|
58
|
+
end
|
59
|
+
|
60
|
+
#
|
61
|
+
# Method save generate and run swfcombine command and generates file
|
62
|
+
# Outputh path must be setted here or with method outputh before
|
63
|
+
#
|
64
|
+
# Raise error if output_path is not set.
|
65
|
+
#
|
66
|
+
def save(output_path=nil)
|
67
|
+
raise FlashToolError, "No output file name " if !@output_path and !output_path
|
68
|
+
to_output_path(output_path)
|
69
|
+
combiner
|
70
|
+
run_command(@command,*@args)
|
71
|
+
@info = FlashTool.flash_info(@output_path)
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
private
|
76
|
+
def combiner
|
77
|
+
@args.unshift(@master, @slaves)
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/flash.rb'
|
2
|
+
module FlashTool
|
3
|
+
class FlashObject < Flash
|
4
|
+
attr_reader :type
|
5
|
+
attr :input
|
6
|
+
|
7
|
+
# Input is path file with good extesnion
|
8
|
+
# Approved formats are :
|
9
|
+
# *pdf,
|
10
|
+
# *jpeg (jpeg and jpg extension),
|
11
|
+
# *png,
|
12
|
+
# *gif,
|
13
|
+
# *fonts (ttf, afm, pfa, pfb formats) and
|
14
|
+
# *wav (wav funcionality is untested and you can often will have problems with SWFTools installation and with command wav2swf)
|
15
|
+
#
|
16
|
+
# type - is extension name string if your input file have other extension
|
17
|
+
#
|
18
|
+
# == Example
|
19
|
+
# flash = FlashOjbect.new('path_to_file', 'png')
|
20
|
+
#
|
21
|
+
# flash = FlashOjbect.new('path_to_file.jpg') do |f|
|
22
|
+
# f.quality(80)
|
23
|
+
# f.rate('24')
|
24
|
+
# f.save('outputh_path')
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# Raise exceptions
|
28
|
+
def initialize(input, type = nil, tempfile = nil, &block)
|
29
|
+
@type = type || input.split('.').last
|
30
|
+
@command = type_parser @type
|
31
|
+
super(input,@command,tempfile,&block)
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def self.from_blob(blob, ext, &block)
|
37
|
+
begin
|
38
|
+
tempfile = Tempfile.new(['flash_tool', ext.to_s])
|
39
|
+
tempfile.binmode
|
40
|
+
tempfile.write(blob)
|
41
|
+
ensure
|
42
|
+
tempfile.close if tempfile
|
43
|
+
end
|
44
|
+
|
45
|
+
return self.new(tempfile.path, ext ,tempfile, &block)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def type_parser input
|
51
|
+
case input.downcase
|
52
|
+
when "pdf"
|
53
|
+
command = "pdf2swf"
|
54
|
+
when "jpg", "jpeg"
|
55
|
+
command = "jpeg2swf"
|
56
|
+
when "png"
|
57
|
+
command = "png2swf"
|
58
|
+
when "gif"
|
59
|
+
command = "gif2swf"
|
60
|
+
when "ttf", "afm", "pfa", "pfb"
|
61
|
+
command = "font2swf"
|
62
|
+
when "wav" #TODO Test wav for converting
|
63
|
+
command = "wav2swf"
|
64
|
+
else
|
65
|
+
raise FlashToolError, "Invalid type"
|
66
|
+
end
|
67
|
+
return command
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/flash.rb'
|
2
|
+
module FlashTool
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
# Generates flash files from scripts and using swfc tool
|
7
|
+
# More about this http://wiki.swftools.org/index.php/Swfc
|
8
|
+
class FlashScript < Flash
|
9
|
+
|
10
|
+
def initialize(input, tempfile = nil, &block)
|
11
|
+
@command = "swfc"
|
12
|
+
super(input,@command,tempfile,&block)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Creates and return flash from input script
|
16
|
+
# Same as option cgi options, but don't create file
|
17
|
+
def cgi
|
18
|
+
@args << "--cgi"
|
19
|
+
run_command(@command,*@args << @input)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Creates and return flash from input script
|
23
|
+
def self.flash_data(input)
|
24
|
+
return self.new(input).cgi
|
25
|
+
end
|
26
|
+
|
27
|
+
# Creates flash from input script
|
28
|
+
def self.create(input, output)
|
29
|
+
return self.new(input).save(output)
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
end
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
stuipid test
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../lib/flash_tool.rb')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class Test_Flash_Combine < Test::Unit::TestCase
|
6
|
+
include FlashTool
|
7
|
+
CURRENT_DIR = File.dirname(File.expand_path(__FILE__)) + "/test_files/"
|
8
|
+
TEST_SWF = CURRENT_DIR + "tester.swf"
|
9
|
+
BAD_FILE = CURRENT_DIR + "bad_ext.txt"
|
10
|
+
JPG_SWF = CURRENT_DIR + "jpeg.swf"
|
11
|
+
NO_FILE = CURRENT_DIR + "jpegswf.swf"
|
12
|
+
BAD_SWF = CURRENT_DIR + "bad_swf.swf"
|
13
|
+
VIEW_SWF = CURRENT_DIR + "rfxview.swf"
|
14
|
+
|
15
|
+
def test_combine
|
16
|
+
output_file = "#{CURRENT_DIR}/merge.swf"
|
17
|
+
begin
|
18
|
+
inputs = VIEW_SWF
|
19
|
+
flash = FlashCombine.new()
|
20
|
+
flash.master(inputs)
|
21
|
+
flash.slave("viewport",TEST_SWF)
|
22
|
+
flash.save(output_file)
|
23
|
+
assert(File.exist?(output_file))
|
24
|
+
assert_kind_of(Hash, flash.info)
|
25
|
+
|
26
|
+
ensure
|
27
|
+
File.delete(output_file)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_combine_block
|
32
|
+
output_file = "#{CURRENT_DIR}/merge.swf"
|
33
|
+
begin
|
34
|
+
inputs = VIEW_SWF
|
35
|
+
flash = FlashCombine.new() do |f|
|
36
|
+
f.master(inputs)
|
37
|
+
f.slave("viewport",TEST_SWF)
|
38
|
+
f.save(output_file)
|
39
|
+
end
|
40
|
+
assert_kind_of(Hash, flash.info)
|
41
|
+
assert(File.exist?(output_file))
|
42
|
+
ensure
|
43
|
+
File.delete(output_file)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_combine_without_save
|
48
|
+
output_file = "#{CURRENT_DIR}/merge.swf"
|
49
|
+
begin
|
50
|
+
inputs = VIEW_SWF
|
51
|
+
flash = FlashCombine.new() do |f|
|
52
|
+
f.slave("viewport",TEST_SWF)
|
53
|
+
f.method_missing("local-with-filesystem")
|
54
|
+
f.method_missing("rate",50)
|
55
|
+
f.master(inputs)
|
56
|
+
f.output(output_file)
|
57
|
+
f.save()
|
58
|
+
end
|
59
|
+
assert_kind_of(Hash, flash.info)
|
60
|
+
assert(File.exist?(output_file))
|
61
|
+
ensure
|
62
|
+
File.delete(output_file)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_combine_no_output
|
67
|
+
inputs = VIEW_SWF
|
68
|
+
FlashCombine.new() do |f|
|
69
|
+
f.master(inputs)
|
70
|
+
f.slave("viewport",TEST_SWF)
|
71
|
+
f.output()
|
72
|
+
assert_raise(FlashToolError) {f.save()}
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_bad_inputs
|
77
|
+
inputs = BAD_FILE
|
78
|
+
FlashCombine.new() do |f|
|
79
|
+
f.master(inputs)
|
80
|
+
f.slave("viewport",TEST_SWF)
|
81
|
+
f.output()
|
82
|
+
assert_raise(FlashToolError) {f.save()}
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,230 @@
|
|
1
|
+
# To change this template, choose Tools | Templates
|
2
|
+
# and open the template in the editor.
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require File.join(File.dirname(__FILE__), '../lib/flash_tool.rb')
|
6
|
+
|
7
|
+
class FlashToolsTest < Test::Unit::TestCase
|
8
|
+
include FlashTool
|
9
|
+
|
10
|
+
CURRENT_DIR = File.dirname(File.expand_path(__FILE__)) + "/test_files/"
|
11
|
+
|
12
|
+
PDF_FILE = CURRENT_DIR + "test.pdf"
|
13
|
+
PDF_PASSW_PROTECTED = CURRENT_DIR + "test_with_password.pdf"
|
14
|
+
GIF_FILE = CURRENT_DIR + "25-1.gif"
|
15
|
+
FONT_FILE = CURRENT_DIR + "liberationserif_bold.ttf"
|
16
|
+
JPG_FILE = CURRENT_DIR + "test.jpg"
|
17
|
+
PNG_FILE = CURRENT_DIR + "test.png"
|
18
|
+
VIEW_SWF = CURRENT_DIR + "rfxview.swf"
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
def test_flash_object_from_blob
|
23
|
+
File.open(JPG_FILE, "rb") do |f|
|
24
|
+
flash_object = FlashObject.from_blob(f.read, 'jpg')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def test_flash_object_new
|
30
|
+
flash_object = FlashObject.new(JPG_FILE)
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Testing file type detection and creation by file type
|
35
|
+
#
|
36
|
+
#
|
37
|
+
|
38
|
+
def test_pdf_create
|
39
|
+
begin
|
40
|
+
output_file = "#{CURRENT_DIR}/test.swf"
|
41
|
+
flash_object = FlashObject.new(PDF_FILE)
|
42
|
+
flash_object.jpegquality(80)
|
43
|
+
flash_object.save(output_file)
|
44
|
+
|
45
|
+
assert(File.exist?(output_file))
|
46
|
+
ensure
|
47
|
+
File.delete(output_file)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
def test_pdf_create_with_password
|
51
|
+
output_file = "#{CURRENT_DIR}/test_password.swf"
|
52
|
+
begin
|
53
|
+
flash_object = FlashObject.new(PDF_PASSW_PROTECTED)
|
54
|
+
flash_object.jpegquality(80)
|
55
|
+
flash_object.password("test")
|
56
|
+
flash_object.save(output_file)
|
57
|
+
assert(File.exist?(output_file))
|
58
|
+
ensure
|
59
|
+
File.delete(output_file)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_pdf_create_with_password_without_save_declaration
|
64
|
+
output_file = "#{CURRENT_DIR}/test_password.swf"
|
65
|
+
begin
|
66
|
+
|
67
|
+
flash_object = FlashObject.new(PDF_PASSW_PROTECTED)
|
68
|
+
flash_object.jpegquality(80)
|
69
|
+
flash_object.password("test")
|
70
|
+
flash_object.output(output_file)
|
71
|
+
flash_object.save()
|
72
|
+
assert(File.exist?(output_file))
|
73
|
+
assert_equal output_file, flash_object.output_path
|
74
|
+
ensure
|
75
|
+
File.delete(output_file)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_font_create
|
80
|
+
output_file = "#{CURRENT_DIR}/arial.swf"
|
81
|
+
begin
|
82
|
+
flash_object = FlashObject.new(FONT_FILE)
|
83
|
+
flash_object.save(output_file)
|
84
|
+
assert(File.exist?(output_file))
|
85
|
+
ensure
|
86
|
+
File.delete(output_file)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_gif_create
|
91
|
+
output_file = "#{CURRENT_DIR}/gif.swf"
|
92
|
+
begin
|
93
|
+
flash_object = FlashObject.new(GIF_FILE)
|
94
|
+
flash_object.save(output_file)
|
95
|
+
assert(File.exist?(output_file))
|
96
|
+
ensure
|
97
|
+
File.delete(output_file)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_png_create
|
102
|
+
output_file = "#{CURRENT_DIR}/png.swf"
|
103
|
+
begin
|
104
|
+
flash_object = FlashObject.new(PNG_FILE)
|
105
|
+
flash_object.save(output_file)
|
106
|
+
assert(File.exist?(output_file))
|
107
|
+
ensure
|
108
|
+
File.delete(output_file)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_jpg_create
|
113
|
+
output_file = "#{CURRENT_DIR}/jpg.swf"
|
114
|
+
begin
|
115
|
+
flash_object = FlashObject.new(JPG_FILE)
|
116
|
+
flash_object.save(output_file)
|
117
|
+
assert(File.exist?(output_file))
|
118
|
+
ensure
|
119
|
+
File.delete(output_file)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_create_from_blob
|
124
|
+
output_file = "#{CURRENT_DIR}/jpg_blob.swf"
|
125
|
+
begin
|
126
|
+
tt = File.open(JPG_FILE, "rb")
|
127
|
+
flash_object = FlashObject.from_blob(tt.read, 'jpg')
|
128
|
+
flash_object.quality(80)
|
129
|
+
flash_object.save(output_file)
|
130
|
+
assert(File.exist?(output_file))
|
131
|
+
assert_equal output_file, flash_object.output_path
|
132
|
+
|
133
|
+
ensure
|
134
|
+
|
135
|
+
File.delete(output_file)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_create_from_blob_block
|
140
|
+
output_file = "#{CURRENT_DIR}/jpg_block.swf"
|
141
|
+
begin
|
142
|
+
|
143
|
+
tt = File.open(JPG_FILE, "rb")
|
144
|
+
flash_object = FlashObject.from_blob(tt.read, 'jpg') do |f|
|
145
|
+
f.quality(80)
|
146
|
+
f.output(output_file)
|
147
|
+
f.save()
|
148
|
+
end
|
149
|
+
assert(File.exist?(output_file))
|
150
|
+
assert_kind_of Hash, flash_object.info
|
151
|
+
assert_equal output_file, flash_object.output_path
|
152
|
+
|
153
|
+
ensure
|
154
|
+
|
155
|
+
File.delete(output_file)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_creating_viewer
|
160
|
+
output_file = "#{CURRENT_DIR}/jpg.swf"
|
161
|
+
output_file = "#{CURRENT_DIR}/test_viewer.swf"
|
162
|
+
begin
|
163
|
+
flash_object = FlashObject.new(PDF_FILE)
|
164
|
+
flash_object.jpegquality(80)
|
165
|
+
flash_object.viewer(VIEW_SWF)
|
166
|
+
flash_object.save(output_file)
|
167
|
+
assert(File.exist?(output_file))
|
168
|
+
ensure
|
169
|
+
File.delete(output_file)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
#
|
177
|
+
# Testing errors and bad types
|
178
|
+
#
|
179
|
+
|
180
|
+
def test_file_not_exist
|
181
|
+
assert_raise(FlashToolError) { flash_object = FlashObject.new("nofile.jpg") }
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_wrong_file_type
|
185
|
+
assert_raise(FlashToolError) {flash_object = FlashObject.new("bad_ext.txt")}
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
def test_block
|
190
|
+
output_file = "#{CURRENT_DIR}/jpg.swf"
|
191
|
+
begin
|
192
|
+
flash_object = FlashObject.new(JPG_FILE) do |f|
|
193
|
+
f.quality(80)
|
194
|
+
end
|
195
|
+
flash_object.save(output_file)
|
196
|
+
|
197
|
+
assert(File.exist?(output_file))
|
198
|
+
ensure
|
199
|
+
File.delete(output_file)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_info
|
204
|
+
output_file = "#{CURRENT_DIR}/jpg.swf"
|
205
|
+
begin
|
206
|
+
flash_object = FlashObject.new(JPG_FILE)
|
207
|
+
assert_equal nil, flash_object.info
|
208
|
+
flash_object.output(output_file)
|
209
|
+
assert_equal nil, flash_object.info
|
210
|
+
flash_object.save()
|
211
|
+
assert_not_equal nil, flash_object.info
|
212
|
+
|
213
|
+
ensure
|
214
|
+
File.delete(output_file)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_without_outputh_path
|
219
|
+
begin
|
220
|
+
flash_object = FlashObject.new(JPG_FILE)
|
221
|
+
flash_object.save()
|
222
|
+
assert_equal("#{CURRENT_DIR}test.swf" , flash_object.output_path)
|
223
|
+
ensure
|
224
|
+
File.delete(flash_object.output_path)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
|
229
|
+
end
|
230
|
+
|