File: binary_spec.rb

package info (click to toggle)
ruby-mongo 2.21.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 14,764 kB
  • sloc: ruby: 108,806; makefile: 5; sh: 2
file content (70 lines) | stat: -rw-r--r-- 2,223 bytes parent folder | download
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
69
70
# frozen_string_literal: true
# rubocop:todo all

require 'lite_spec_helper'

describe 'Mongo::Crypt::Binding' do
  describe 'binary_t bindings' do
    require_libmongocrypt

    let(:bytes) { [104, 101, 108, 108, 111] }

    let(:bytes_pointer) do
      # FFI::MemoryPointer automatically frees memory when it goes out of scope
      p = FFI::MemoryPointer.new(bytes.size)
      p.write_array_of_type(FFI::TYPE_UINT8, :put_uint8, bytes)
    end

    after do
      Mongo::Crypt::Binding.mongocrypt_binary_destroy(binary)
    end

    describe '#mongocrypt_binary_new' do
      let(:binary) { Mongo::Crypt::Binding.mongocrypt_binary_new }

      it 'returns a pointer' do
        expect(binary).to be_a_kind_of(FFI::Pointer)
      end
    end

    describe '#mongocrypt_binary_new_from_data' do
      let(:binary) { Mongo::Crypt::Binding.mongocrypt_binary_new_from_data(bytes_pointer, bytes.length) }

      it 'returns a pointer' do
        expect(binary).to be_a_kind_of(FFI::Pointer)
      end
    end

    describe '#mongocrypt_binary_data' do
      let(:binary) { Mongo::Crypt::Binding.mongocrypt_binary_new_from_data(bytes_pointer, bytes.length) }

      it 'returns the pointer to the data' do
        expect(Mongo::Crypt::Binding.mongocrypt_binary_data(binary)).to eq(bytes_pointer)
      end
    end

    describe '#get_binary_data_direct' do
      let(:binary) { Mongo::Crypt::Binding.mongocrypt_binary_new_from_data(bytes_pointer, bytes.length) }

      it 'returns the pointer to the data' do
        expect(Mongo::Crypt::Binding.get_binary_data_direct(binary)).to eq(bytes_pointer)
      end
    end

    describe '#mongocrypt_binary_len' do
      let(:binary) { Mongo::Crypt::Binding.mongocrypt_binary_new_from_data(bytes_pointer, bytes.length) }

      it 'returns the length of the data' do
        expect(Mongo::Crypt::Binding.mongocrypt_binary_len(binary)).to eq(bytes.length)
      end
    end

    describe '#get_binary_len_direct' do
      let(:binary) { Mongo::Crypt::Binding.mongocrypt_binary_new_from_data(bytes_pointer, bytes.length) }

      it 'returns the length of the data' do
        expect(Mongo::Crypt::Binding.get_binary_len_direct(binary)).to eq(bytes.length)
      end
    end
  end
end