gir_ffi-gnome_keyring 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog.md ADDED
@@ -0,0 +1,3 @@
1
+ ### 0.0.1 / 2013-08-03
2
+
3
+ * Initial release
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # GirFFI-GnomeKeyring
2
+
3
+ GirFFI-based bindings for GnomeKeyring
4
+
5
+ [![Build Status](https://secure.travis-ci.org/mvz/gir_ffi-gnome_keyring.png)](http://travis-ci.org/mvz/gir-ffi-gnome_keyring)
6
+
7
+ ## Features
8
+
9
+ * Auto-generated bindings using GObject introspection.
10
+ * Adds overrides for introspection data bugs.
11
+
12
+ ## Install
13
+
14
+ gem install gir_ffi-gnome_keyring
15
+
16
+ ## License
17
+
18
+ Copyright © 2013 Matijs van Zuijlen
19
+
20
+ GirFFI-GnomeKeyring is free software, distributed under the terms of the GNU
21
+ Lesser General Public License, version 2.1 or later. See the file
22
+ COPYING.LIB for more information.
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'rake/clean'
2
+ import 'tasks/test.rake'
3
+ import 'tasks/yardoc.rake'
4
+
5
+ task :default => 'test'
@@ -0,0 +1,57 @@
1
+ require 'gir_ffi'
2
+
3
+ GirFFI.setup 'GnomeKeyring'
4
+
5
+ require 'gir_ffi-gnome_keyring/attribute'
6
+ require 'gir_ffi-gnome_keyring/attribute_list'
7
+ require 'gir_ffi-gnome_keyring/found'
8
+
9
+ module GnomeKeyring
10
+ setup_method :find_items_sync
11
+ setup_method :item_create_sync
12
+ setup_method :item_get_attributes_sync
13
+ setup_method :item_set_attributes_sync
14
+
15
+ class << self
16
+ remove_method :find_items_sync
17
+ remove_method :item_create_sync
18
+ remove_method :item_set_attributes_sync
19
+ remove_method :item_get_attributes_sync
20
+ end
21
+
22
+ def self.find_items_sync(type, attributes)
23
+ _v2 = GnomeKeyring::AttributeList.from(attributes)
24
+ _v3 = GirFFI::InOutPointer.for(:glist)
25
+ _v4 = GnomeKeyring::Lib.gnome_keyring_find_items_sync(type, _v2, _v3)
26
+ _v5 = GLib::List.wrap(GnomeKeyring::Found, _v3.to_value)
27
+ return [_v4, _v5]
28
+ end
29
+
30
+ def self.item_create_sync(keyring, type, display_name, attributes, secret,
31
+ update_if_exists)
32
+ _v1 = GirFFI::InPointer.from(:utf8, keyring)
33
+ _v3 = GirFFI::InPointer.from(:utf8, display_name)
34
+ _v4 = GnomeKeyring::AttributeList.from(attributes)
35
+ _v5 = GirFFI::InPointer.from(:utf8, secret)
36
+ _v7 = GirFFI::InOutPointer.for(:guint32)
37
+ _v8 = GnomeKeyring::Lib.gnome_keyring_item_create_sync(_v1, type, _v3, _v4,
38
+ _v5,
39
+ update_if_exists,
40
+ _v7)
41
+ return [_v8, _v7.to_value]
42
+ end
43
+
44
+ def self.item_get_attributes_sync(keyring, id)
45
+ _v1 = GirFFI::InPointer.from(:utf8, keyring)
46
+ _v3 = GirFFI::InOutPointer.for(:struct)
47
+ _v4 = GnomeKeyring::Lib.gnome_keyring_item_get_attributes_sync(_v1, id, _v3)
48
+ attributes = GnomeKeyring::AttributeList.wrap(_v3.to_value)
49
+ return [_v4, attributes]
50
+ end
51
+
52
+ def self.item_set_attributes_sync(keyring, id, attributes)
53
+ _v1 = GirFFI::InPointer.from(:utf8, keyring)
54
+ _v3 = GnomeKeyring::AttributeList.from(attributes)
55
+ GnomeKeyring::Lib.gnome_keyring_item_set_attributes_sync(_v1, id, _v3)
56
+ end
57
+ end
@@ -0,0 +1,16 @@
1
+ module GnomeKeyring
2
+ load_class :Attribute
3
+
4
+ class Attribute
5
+ setup_method 'list_new'
6
+ setup_method 'list_append_string'
7
+ setup_method 'list_append_uint32'
8
+
9
+ private_class_method :list_new,
10
+ :list_append_string,
11
+ :list_append_uint32,
12
+ :list_copy,
13
+ :list_free,
14
+ :list_to_glist
15
+ end
16
+ end
@@ -0,0 +1,46 @@
1
+ require 'gir_ffi-gnome_keyring/attribute'
2
+
3
+ module GnomeKeyring
4
+ class AttributeList < GLib::Array
5
+ def self.new
6
+ ptr = GnomeKeyring::Lib.gnome_keyring_attribute_list_new
7
+ wrap(ptr)
8
+ end
9
+
10
+ def self.wrap ptr
11
+ super GnomeKeyring::Attribute, ptr
12
+ end
13
+
14
+ def self.from it
15
+ case it
16
+ when self then it
17
+ when FFI::Pointer then wrap it
18
+ else self.new.tap {|arr| arr.append_vals it }
19
+ end
20
+ end
21
+
22
+ # FIXME: Remove once GLib::Array#index has been fixed
23
+ def index idx
24
+ ptr = @struct[:data] + idx * get_element_size
25
+ GnomeKeyring::Attribute.wrap(ptr)
26
+ end
27
+
28
+ def append_string name, value
29
+ _v2 = GirFFI::InPointer.from(:utf8, name)
30
+ _v3 = GirFFI::InPointer.from(:utf8, value)
31
+ GnomeKeyring::Lib.gnome_keyring_attribute_list_append_string self, _v2, _v3
32
+ end
33
+
34
+ def append_uint32 name, value
35
+ _v2 = GirFFI::InPointer.from(:utf8, name)
36
+ GnomeKeyring::Lib.gnome_keyring_attribute_list_append_uint32 self, _v2, value
37
+ end
38
+
39
+ private
40
+
41
+ # FIXME: Private method override. Bad.
42
+ def check_element_size_match
43
+ true
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,17 @@
1
+ require 'gir_ffi-gnome_keyring/attribute_list'
2
+
3
+ module GnomeKeyring
4
+ load_class :Found
5
+
6
+ class Found
7
+ def attributes
8
+ struct = GnomeKeyring::Found::Struct.new(@struct.to_ptr)
9
+ GnomeKeyring::AttributeList.wrap(struct[:attributes])
10
+ end
11
+
12
+ def attributes=(value)
13
+ struct = GnomeKeyring::Found::Struct.new(@struct.to_ptr)
14
+ struct[:attributes] = GnomeKeyring::AttributeList.from(value)
15
+ end
16
+ end
17
+ end
data/tasks/test.rake ADDED
@@ -0,0 +1,19 @@
1
+ require 'rake/testtask'
2
+
3
+ namespace :test do
4
+
5
+ Rake::TestTask.new(:unit) do |t|
6
+ t.libs = ['lib']
7
+ t.test_files = FileList['test/unit/**/*_test.rb']
8
+ t.ruby_opts += ["-w -Itest"]
9
+ end
10
+
11
+ Rake::TestTask.new(:integration) do |t|
12
+ t.libs = ['lib']
13
+ t.test_files = FileList['test/integration/*_test.rb']
14
+ t.ruby_opts += ["-w -Itest"]
15
+ end
16
+ end
17
+
18
+ desc 'Run unit and integration tests'
19
+ task :test => ['test:unit', 'test:integration']
data/tasks/yardoc.rake ADDED
@@ -0,0 +1,9 @@
1
+ begin
2
+ require 'yard'
3
+
4
+ YARD::Rake::YardocTask.new do |t|
5
+ t.files = ['lib/**/*.rb']
6
+ t.options = ['--private', '--protected', '--readme', 'README.md']
7
+ end
8
+ rescue LoadError
9
+ end
@@ -0,0 +1,5 @@
1
+ require 'minitest/autorun'
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+
5
+ require 'gir_ffi-gnome_keyring'
@@ -0,0 +1,66 @@
1
+ require 'test_helper'
2
+
3
+ describe GnomeKeyring::AttributeList do
4
+ it "descends from GLib::Array" do
5
+ GnomeKeyring::AttributeList.ancestors.must_include GLib::Array
6
+ end
7
+
8
+ describe ".new" do
9
+ it "takes no arguments" do
10
+ GnomeKeyring::AttributeList.new
11
+ pass
12
+ end
13
+ end
14
+
15
+ describe ".wrap" do
16
+ it "wraps its argument in an AttributeList object" do
17
+ orig = GnomeKeyring::AttributeList.new
18
+ copy = GnomeKeyring::AttributeList.wrap(orig.to_ptr)
19
+ copy.to_ptr.must_equal orig.to_ptr
20
+ end
21
+ end
22
+
23
+ describe ".from" do
24
+ it "wraps its argument's pointer in an AttributeList object" do
25
+ orig = GnomeKeyring::AttributeList.new
26
+ copy = GnomeKeyring::AttributeList.from(orig)
27
+ copy.to_ptr.must_equal orig.to_ptr
28
+ end
29
+
30
+ it "wraps an empty array" do
31
+ attr = GnomeKeyring::AttributeList.from([])
32
+ attr.to_a.must_equal []
33
+ end
34
+
35
+ it "wraps an array of Attribute" do
36
+ att = GnomeKeyring::Attribute.new
37
+ att.name = 'foo'
38
+ attr = GnomeKeyring::AttributeList.from([att])
39
+ arr = attr.to_a
40
+ arr.length.must_equal 1
41
+ arr.first.name.must_equal 'foo'
42
+ end
43
+ end
44
+
45
+ describe "#append_string" do
46
+ it "appends a string attribute" do
47
+ list = GnomeKeyring::AttributeList.new
48
+ list.append_string 'foo', 'bar'
49
+ attr = list.index(0)
50
+ attr.name.must_equal 'foo'
51
+ attr.get_string.must_equal 'bar'
52
+ attr.type.must_equal :string
53
+ end
54
+ end
55
+
56
+ describe "#append_uint32" do
57
+ it "appends a uint32 attribute" do
58
+ list = GnomeKeyring::AttributeList.new
59
+ list.append_uint32 'baz', 42
60
+ attr = list.index(0)
61
+ attr.name.must_equal 'baz'
62
+ attr.get_uint32.must_equal 42
63
+ attr.type.must_equal :uint32
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+
3
+ describe GnomeKeyring::Attribute do
4
+ describe ".list_new" do
5
+ it "is private" do
6
+ proc { GnomeKeyring::Attribute.list_new }.must_raise NoMethodError
7
+ end
8
+ end
9
+
10
+ describe ".list_append_string" do
11
+ it "is private" do
12
+ proc { GnomeKeyring::Attribute.list_append_string }.must_raise NoMethodError
13
+ end
14
+ end
15
+
16
+ describe ".list_append_uint32" do
17
+ it "is private" do
18
+ proc { GnomeKeyring::Attribute.list_append_uint32 }.must_raise NoMethodError
19
+ end
20
+ end
21
+
22
+ describe ".list_copy" do
23
+ it "is private" do
24
+ proc { GnomeKeyring::Attribute.list_copy }.must_raise NoMethodError
25
+ end
26
+ end
27
+
28
+ describe ".list_free" do
29
+ it "is private" do
30
+ proc { GnomeKeyring::Attribute.list_free }.must_raise NoMethodError
31
+ end
32
+ end
33
+
34
+ describe ".list_to_glist" do
35
+ it "is private" do
36
+ proc { GnomeKeyring::Attribute.list_to_glist }.must_raise NoMethodError
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+
3
+ describe GnomeKeyring::Found do
4
+ let(:instance) { GnomeKeyring::Found.new }
5
+
6
+ describe "#attributes" do
7
+ it "returns nil by default" do
8
+ attrs = instance.attributes
9
+ attrs.must_be_nil
10
+ end
11
+
12
+ it "returns an assigned AttributeList" do
13
+ attrs = GnomeKeyring::AttributeList.new
14
+ struct = GnomeKeyring::Found::Struct.new(instance.to_ptr)
15
+ struct[:attributes] = attrs.to_ptr
16
+
17
+ result = instance.attributes
18
+ result.must_be_instance_of GnomeKeyring::AttributeList
19
+ result.to_ptr.must_equal attrs.to_ptr
20
+ end
21
+ end
22
+
23
+ describe "#attributes=" do
24
+ it "assigns its argument to the correct struct member" do
25
+ attrs = GnomeKeyring::AttributeList.new
26
+ instance.attributes = attrs
27
+ struct = GnomeKeyring::Found::Struct.new(instance.to_ptr)
28
+ result = struct[:attributes]
29
+ result.must_equal attrs.to_ptr
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,80 @@
1
+ require 'test_helper'
2
+
3
+ describe GnomeKeyring do
4
+ describe ".find_items_sync" do
5
+ it "calls Lib.gnome_keyring_find_items_sync with the correct values" do
6
+ body = lambda { |type, attrs, listptr|
7
+ type.must_equal :generic_secret
8
+ attrs.must_be_instance_of GnomeKeyring::AttributeList
9
+ listptr.must_be_instance_of GirFFI::InOutPointer
10
+ :ok
11
+ }
12
+
13
+ GnomeKeyring::Lib.stub :gnome_keyring_find_items_sync, body do
14
+ code, list = GnomeKeyring.find_items_sync :generic_secret, []
15
+ code.must_equal :ok
16
+ list.must_be_nil
17
+ end
18
+ end
19
+ end
20
+
21
+ describe ".item_create_sync" do
22
+ it "calls Lib.gnome_keyring_item_create_sync with the correct values" do
23
+ body = lambda { |keyring, type, display_name, attributes, secret, update_if_exists, item_id|
24
+ GirFFI::ArgHelper.ptr_to_utf8(keyring).must_equal "foo"
25
+ type.must_equal :generic_secret
26
+ GirFFI::ArgHelper.ptr_to_utf8(display_name).must_equal "bar"
27
+ attributes.must_be_instance_of GnomeKeyring::AttributeList
28
+ GirFFI::ArgHelper.ptr_to_utf8(secret).must_equal "secret-name"
29
+ update_if_exists.must_equal false
30
+
31
+ item_id.write_int32 42
32
+ :ok
33
+ }
34
+
35
+ GnomeKeyring::Lib.stub :gnome_keyring_item_create_sync, body do
36
+ code, id = GnomeKeyring.item_create_sync("foo",
37
+ :generic_secret,
38
+ "bar",
39
+ [],
40
+ "secret-name",
41
+ false)
42
+ code.must_equal :ok
43
+ id.must_equal 42
44
+ end
45
+ end
46
+ end
47
+
48
+ describe ".item_get_attributes_sync" do
49
+ it "calls Lib.gnome_keyring_item_get_attributes_sync with the correct values" do
50
+ body = lambda { |keyring, id, attributes|
51
+ GirFFI::ArgHelper.ptr_to_utf8(keyring).must_equal "foo"
52
+ id.must_equal 42
53
+ attributes.must_be_instance_of GirFFI::InOutPointer
54
+ :ok
55
+ }
56
+
57
+ GnomeKeyring::Lib.stub :gnome_keyring_item_get_attributes_sync, body do
58
+ code, list = GnomeKeyring.item_get_attributes_sync "foo", 42
59
+ code.must_equal :ok
60
+ list.must_be_nil
61
+ end
62
+ end
63
+ end
64
+
65
+ describe ".item_set_attributes_sync" do
66
+ it "calls Lib.gnome_keyring_item_set_attributes_sync with the correct values" do
67
+ body = lambda { |keyring, id, attributes|
68
+ GirFFI::ArgHelper.ptr_to_utf8(keyring).must_equal "foo"
69
+ id.must_equal 42
70
+ attributes.must_be_instance_of GnomeKeyring::AttributeList
71
+ :ok
72
+ }
73
+
74
+ GnomeKeyring::Lib.stub :gnome_keyring_item_set_attributes_sync, body do
75
+ result = GnomeKeyring.item_set_attributes_sync "foo", 42, []
76
+ result.must_equal :ok
77
+ end
78
+ end
79
+ end
80
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gir_ffi-gnome_keyring
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matijs van Zuijlen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: gir_ffi
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.6.5
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.6.5
30
+ - !ruby/object:Gem::Dependency
31
+ name: minitest
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '5.0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '5.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 10.1.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 10.1.0
62
+ description:
63
+ email:
64
+ - matijs@matijs.net
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files:
68
+ - README.md
69
+ - Changelog.md
70
+ files:
71
+ - lib/gir_ffi-gnome_keyring.rb
72
+ - lib/gir_ffi-gnome_keyring/attribute.rb
73
+ - lib/gir_ffi-gnome_keyring/attribute_list.rb
74
+ - lib/gir_ffi-gnome_keyring/found.rb
75
+ - test/test_helper.rb
76
+ - test/unit/gir_ffi-gnome_keyring_test.rb
77
+ - test/unit/gir_ffi-gnome_keyring/found_test.rb
78
+ - test/unit/gir_ffi-gnome_keyring/attribute_list_test.rb
79
+ - test/unit/gir_ffi-gnome_keyring/attribute_test.rb
80
+ - tasks/yardoc.rake
81
+ - tasks/test.rake
82
+ - Changelog.md
83
+ - README.md
84
+ - Rakefile
85
+ homepage: http://www.github.com/mvz/gir_ffi-gnome_keyring
86
+ licenses: []
87
+ post_install_message:
88
+ rdoc_options:
89
+ - --main
90
+ - README.md
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 1.8.23
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: GirFFI-based binding to GnomeKeyring
111
+ test_files:
112
+ - test/test_helper.rb
113
+ - test/unit/gir_ffi-gnome_keyring/attribute_list_test.rb
114
+ - test/unit/gir_ffi-gnome_keyring/attribute_test.rb
115
+ - test/unit/gir_ffi-gnome_keyring/found_test.rb
116
+ - test/unit/gir_ffi-gnome_keyring_test.rb
117
+ has_rdoc: