Skip to content

Commit

Permalink
Merge pull request #125 from mvidner/two-return-values
Browse files Browse the repository at this point in the history
Test two OUT arguments
  • Loading branch information
mvidner committed Mar 21, 2023
2 parents 4c51ecc + cf78e6f commit 2ae2b7e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
35 changes: 35 additions & 0 deletions spec/proxy_object_interface_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env rspec
# frozen_string_literal: true

require_relative "spec_helper"
require "dbus"

describe DBus::ProxyObjectInterface do
# TODO: tag tests that need a service, eg "needs-service"
# TODO: maybe remove this and rely on a packaged tool
around(:each) do |example|
with_private_bus do
with_service_by_activation(&example)
end
end

let(:bus) { DBus::ASessionBus.new }

context "when calling org.ruby.service" do
let(:svc) { bus["org.ruby.service"] }

# This is white box testing, knowing the implementation
# A better way would be structuring it according to the D-Bus Spec
# Or testing the service side doing the right thing? (What if our bugs cancel out)
describe "#define_method_from_descriptor" do
it "can call a method with multiple OUT arguments" do
obj = svc["/org/ruby/MyInstance"]
ifc = obj["org.ruby.SampleInterface"]

even, odd = ifc.EvenOdd([3, 1, 4, 1, 5, 9, 2, 6])
expect(even).to eq [4, 2, 6]
expect(odd).to eq [3, 1, 1, 5, 9]
end
end
end
end
6 changes: 6 additions & 0 deletions spec/service_newapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ def initialize(path)
[coords]
end

# Two OUT arguments
dbus_method :EvenOdd, "in numbers:ai, out even:ai, out odd:ai" do |numbers|
even, odd = numbers.partition(&:even?)
[even, odd]
end

# Properties:
# ReadMe:string, returns "READ ME" at first, then what WriteMe received
# WriteMe:string
Expand Down

0 comments on commit 2ae2b7e

Please sign in to comment.