cups 0.1.6 → 0.1.7

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.
Files changed (3) hide show
  1. data/ext/cups.c +23 -22
  2. data/test/cups_test.rb +26 -28
  3. metadata +2 -2
data/ext/cups.c CHANGED
@@ -40,7 +40,7 @@ int printer_exists(VALUE printer){
40
40
  // First call Cups#show_destinations
41
41
  VALUE dest_list = rb_funcall(rubyCups, rb_intern("show_destinations"), 0);
42
42
  // Then check the printer arg is included in the returned array...
43
- rb_ary_includes(dest_list, printer) ? 1 : 0;
43
+ return rb_ary_includes(dest_list, printer) ? 1 : 0;
44
44
  }
45
45
 
46
46
  /*
@@ -116,7 +116,7 @@ static VALUE cups_print(VALUE self)
116
116
  char *fname = RSTRING_PTR(file); // Filename
117
117
  char *title = T_STRING == TYPE(rname) ? RSTRING_PTR(rname) : "rCups";
118
118
  char *target = RSTRING_PTR(printer); // Target printer string
119
- char *url = RSTRING_PTR(url_path); // Server URL address
119
+ const char *url = RSTRING_PTR(url_path); // Server URL address
120
120
  int port = 631; // Default CUPS port
121
121
 
122
122
  VALUE job_options = rb_iv_get(self, "@job_options");
@@ -198,8 +198,9 @@ static VALUE cups_get_default(VALUE self)
198
198
  VALUE def_p = rb_str_new2(default_printer);
199
199
 
200
200
  return def_p;
201
+ } else {
202
+ return Qnil;
201
203
  }
202
- // should return nil if no default printer is found!
203
204
  }
204
205
 
205
206
  /*
@@ -336,27 +337,27 @@ static VALUE cups_job_completed(VALUE self)
336
337
 
337
338
  if (NIL_P(job_id)) {
338
339
  return Qfalse;
339
- } else {
340
- num_jobs = cupsGetJobs(&jobs, printer_arg, 1, -1); // Get jobs
341
- // job_state = IPP_JOB_COMPLETED;
340
+ }
342
341
 
343
- for (i = 0; i < num_jobs; i ++) {
344
- if (jobs[i].id == NUM2INT(job_id)) {
345
- job_state = jobs[i].state;
346
- break;
347
- }
348
-
349
- // Free job array
350
- cupsFreeJobs(num_jobs, jobs);
351
-
352
- if (job_state == IPP_JOB_COMPLETED) {
353
- return Qtrue;
354
- } else {
355
- return Qfalse;
356
- }
357
-
342
+ num_jobs = cupsGetJobs(&jobs, printer_arg, 1, -1); // Get jobs
343
+
344
+ // find our job
345
+ for (i = 0; i < num_jobs; i ++) {
346
+ if (jobs[i].id == NUM2INT(job_id)) {
347
+ job_state = jobs[i].state;
348
+ break;
358
349
  }
359
- }
350
+ }
351
+
352
+ // Free job array
353
+ cupsFreeJobs(num_jobs, jobs);
354
+
355
+ if (job_state == IPP_JOB_COMPLETED) {
356
+ return Qtrue;
357
+ } else {
358
+ return Qfalse;
359
+ }
360
+
360
361
  }
361
362
 
362
363
  /*
@@ -20,61 +20,59 @@ class CupsTest < Test::Unit::TestCase
20
20
  assert cups_destinations.is_a?(Array)
21
21
  assert_equal cups_destinations, lplist
22
22
  end
23
-
23
+
24
24
  def test_can_instantiate_print_job_object_with_correct_args
25
25
  assert_raise(ArgumentError) do
26
26
  Cups::PrintJob.new
27
27
  end
28
-
28
+
29
29
  assert_nothing_raised do
30
30
  Cups::PrintJob.new("/path", @printer)
31
- Cups::PrintJob.new("/path")
31
+ Cups::PrintJob.new("/path") if Cups.default_printer
32
32
  end
33
33
  end
34
-
34
+
35
35
  def test_job_defaults_to_default
36
36
  assert_nothing_raised do
37
- pj = Cups::PrintJob.new("/non/existent/file")
38
-
39
- assert_equal Cups.default_printer, pj.instance_variable_get(:@printer)
37
+ if Cups.default_printer
38
+ pj = Cups::PrintJob.new( "/non/existent/file" )
39
+ assert_equal Cups.default_printer, pj.instance_variable_get(:@printer)
40
+ end
40
41
  end
41
42
  end
42
-
43
+
43
44
  def test_we_cant_print_to_nonexistent_printers
44
- assert_raise(RuntimeError) do
45
+ assert_raise(ArgumentError) do
45
46
  pj = Cups::PrintJob.new("/non/existent/file", "bollocks_printer")
46
-
47
47
  assert !Cups.show_destinations.include?(pj.instance_variable_get(:@printer))
48
48
  end
49
49
  end
50
50
 
51
51
  def test_we_cant_print_nonexistent_files
52
- pj = Cups::PrintJob.new("soft_class")
53
-
52
+ pj = Cups::PrintJob.new("soft_class",@printer)
54
53
  assert_raise(RuntimeError) do
55
- pj.print
54
+ pj.print
56
55
  end
57
-
58
56
  assert_nil pj.job_id
59
57
  end
60
-
58
+
61
59
  def test_we_can_pass_args_down_as_options
62
60
  options = {:foo => 'bar'}
63
61
  pj = Cups::PrintJob.new(sample, @printer, options)
64
62
  assert_equal(options, pj.job_options)
65
63
  end
66
-
64
+
67
65
  def test_we_can_only_pass_strings_down_as_options
68
66
  options = {:foo => 'bar'}
69
67
  pj = Cups::PrintJob.new(sample, @printer, options)
70
68
  assert_raise(TypeError) { pj.print }
71
69
  end
72
-
70
+
73
71
  def test_we_can_omit_options_and_will_set_to_empty
74
72
  pj = Cups::PrintJob.new(sample, @printer)
75
73
  assert_equal({}, pj.job_options)
76
74
  end
77
-
75
+
78
76
  def test_print_job_cancellation
79
77
  pj = Cups::PrintJob.new(sample, @printer)
80
78
  pj.print
@@ -82,13 +80,13 @@ class CupsTest < Test::Unit::TestCase
82
80
  assert_equal pj.cancel, true
83
81
  assert pj.job_id.is_a?(Fixnum)
84
82
  end
85
-
83
+
86
84
  def test_all_jobs_raises_with_nonexistent_printers
87
85
  assert_raise(RuntimeError) { Cups.all_jobs(nil) }
88
86
  end
89
-
87
+
90
88
  def test_all_jobs_returns_hash
91
- assert Cups.all_jobs(Cups.default_printer).is_a?(Hash)
89
+ assert Cups.all_jobs(@printer).is_a?(Hash)
92
90
  end
93
91
 
94
92
  def test_all_jobs_hash_contains_info_hash
@@ -98,11 +96,11 @@ class CupsTest < Test::Unit::TestCase
98
96
  assert info.is_a?(Hash)
99
97
  assert info.keys.all?{|key| [:title, :format, :submitted_by, :state, :size].include?(key)}
100
98
  end
101
-
99
+
102
100
  def test_dest_list_returns_array
103
101
  assert Cups.show_destinations.is_a?(Array)
104
102
  end
105
-
103
+
106
104
  def test_dest_options_returns_hash_if_real
107
105
  assert Cups.options_for(@printer).is_a?(Hash)
108
106
  end
@@ -128,7 +126,7 @@ class CupsTest < Test::Unit::TestCase
128
126
  end
129
127
 
130
128
  def test_returns_failure_string_on_cancellation
131
- pj = Cups::PrintJob.new(blank_sample, @printer)
129
+ pj = Cups::PrintJob.new(sample, @printer)
132
130
  pj.print
133
131
 
134
132
  # assert pj.job_id == 0 # Failed jobs have an ID of zero
@@ -148,20 +146,20 @@ class CupsTest < Test::Unit::TestCase
148
146
  assert pj.state == :cancelled
149
147
  assert !pj.completed?
150
148
  end
151
-
149
+
152
150
  def test_print_job_attributes
153
- pj = Cups::PrintJob.new(sample)
151
+ pj = Cups::PrintJob.new(sample, @printer)
154
152
  [:printer, :filename, :job_id].each do |attr|
155
153
  assert pj.respond_to?(attr)
156
154
  end
157
155
  end
158
156
 
159
157
  private
160
-
158
+
161
159
  def sample
162
160
  "#{File.dirname(__FILE__)}/sample.txt"
163
161
  end
164
-
162
+
165
163
  def blank_sample
166
164
  "#{File.dirname(__FILE__)}/sample_blank.txt"
167
165
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cups
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-06-27 00:00:00.000000000 Z
15
+ date: 2013-07-14 00:00:00.000000000 Z
16
16
  dependencies: []
17
17
  description: ! ' Ruby CUPS provides a wrapper for the Common UNIX Printing System,
18
18
  allowing rubyists to perform basic tasks like printer discovery, job submission