Xregistry

Check-in [024e690d87]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Raise error in readBoolEntry if value is a string and add additional tests of reading entries.
Timelines: family | ancestors | descendants | both | trunk | version-1.5.1
Files: files | file ages | folders
SHA1:024e690d8789a850150997a352c15cd3a8c2ceb3
User & Date: wbp 2016-03-19 21:15:17
Context
2016-03-20
01:17
Raise error in readBoolEntry if value retrieved is a float. check-in: 7aec519c28 user: wbp tags: trunk, version-1.5.2
2016-03-19
21:15
Raise error in readBoolEntry if value is a string and add additional tests of reading entries. check-in: 024e690d87 user: wbp tags: trunk, version-1.5.1
2016-03-11
21:50
Add appKey and vendorKey methods. check-in: 5a7b383dcf user: wbp tags: trunk, version-1.5.0
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to VERSION.

1
1.5.0
|
1
1.5.1

Changes to lib/xregistry.rb.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
..
87
88
89
90
91
92
93
94

95
96


97
98
99
100
101
102
103
#  registry, but without needing the FOX toolkit.
#
#  The original FOX registry uses the Windows registry if running under Windows,
#  and an .INI type file if running under Unix-type systems.  This class also
#  uses the Windows registry if running under Windows, but uses an SQLite3
#  database if running under a Unix-type system.
#
#  Last revised:  11-Mar-2016  Wm. Parsons
################################################################################


class Registry
  # Construct registry object; app_key and vendor_key must be string constants.
  # Regular applications SHOULD set a vendor key!
  def initialize(app_key = '', vendor_key = '')
................................................................................
    else
      @db.execute "drop table if exists \"#{section}\""
    end
  end
  alias delete_section deleteSection

  # Read a boolean registry entry from the specified section and key.  If no
  # value is found, the default value is returned.

  def readBoolEntry(section, key, default = false)
    readEntry(section, key, default ? 1 : 0) == 0 ? false : true


  end
  alias read_bool_entry readBoolEntry

  # Read an integer registry entry from the specified section and key.  If no
  # value is found, the default value is returned.
  def readIntEntry(section, key, default = 0)
    readEntry(section, key, default).to_i







|







 







|
>

|
>
>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
..
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#  registry, but without needing the FOX toolkit.
#
#  The original FOX registry uses the Windows registry if running under Windows,
#  and an .INI type file if running under Unix-type systems.  This class also
#  uses the Windows registry if running under Windows, but uses an SQLite3
#  database if running under a Unix-type system.
#
#  Last revised:  19-Mar-2016  Wm. Parsons
################################################################################


class Registry
  # Construct registry object; app_key and vendor_key must be string constants.
  # Regular applications SHOULD set a vendor key!
  def initialize(app_key = '', vendor_key = '')
................................................................................
    else
      @db.execute "drop table if exists \"#{section}\""
    end
  end
  alias delete_section deleteSection

  # Read a boolean registry entry from the specified section and key.  If no
  # value is found, the default value is returned.  A type error is
  # raised if the retrieved value is a string.
  def readBoolEntry(section, key, default = false)
    value = readEntry(section, key, default)
    raise TypeError if value.class == String
    value && value != 0
  end
  alias read_bool_entry readBoolEntry

  # Read an integer registry entry from the specified section and key.  If no
  # value is found, the default value is returned.
  def readIntEntry(section, key, default = 0)
    readEntry(section, key, default).to_i

Changes to test/test_xregistry.rb.

1
2
3
4
5
6
7
8
9
..
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
# test program for wregistry gem
# Last modified:  11-Mar-2016

require 'xregistry'
require 'test/unit'

class TestXregistry < Test::Unit::TestCase
  @@app_key    = 'testxreg'
  @@vendor_key = 'Wikareia'
................................................................................
    assert_equal(false, value)

    value = @@reg.readBoolEntry('Settings', 'bool_key1', true)
    assert_equal(true, value)

    value = @@reg.readBoolEntry('Settings', 'bool_key1', false)
    assert_equal(false, value)











  end

  # test of readIntEntry
  def test_read_int_entry
    value = @@reg.readIntEntry('Settings', 'int_key1')
    assert_equal(0, value)

    value = @@reg.readIntEntry('Settings', 'int_key1', 123)
    assert_equal(123, value)
















  end

  # test of readRealEntry
  def test_read_real_entry
    value = @@reg.readRealEntry('Settings', 'real_key1')
    assert_equal(0.0, value)

    value = @@reg.readRealEntry('Settings', 'real_key1', 12.5)
    assert_equal(12.5, value)
















  end

  # test of readStringEntry
  def test_read_string_entry
    string = @@reg.readStringEntry('Settings', 'string_key1')
    assert_equal('', string)

    string = @@reg.readStringEntry('Settings', 'string_key1', 'default value')
    assert_match(/ value/, string)












  end

  # test of writeBoolEntry
  def test_write_bool_entry
    @@reg.writeBoolEntry('Settings', 'bool_key2', true)
    value = @@reg.readBoolEntry('Settings', 'bool_key2')
    assert_equal(true, value)

|







 







>
>
>
>
>
>
>
>
>
>
>









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>









>
>
>
>
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
..
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# test program for wregistry gem
# Last modified:  19-Mar-2016

require 'xregistry'
require 'test/unit'

class TestXregistry < Test::Unit::TestCase
  @@app_key    = 'testxreg'
  @@vendor_key = 'Wikareia'
................................................................................
    assert_equal(false, value)

    value = @@reg.readBoolEntry('Settings', 'bool_key1', true)
    assert_equal(true, value)

    value = @@reg.readBoolEntry('Settings', 'bool_key1', false)
    assert_equal(false, value)

    @@reg.writeIntEntry('Settings', 'bool_key1', 2)
    value = @@reg.readBoolEntry('Settings', 'bool_key1')
    assert_equal(true, value)

    @@reg.writeRealEntry('Settings', 'bool_key1', 2.5)
    value = @@reg.readBoolEntry('Settings', 'bool_key1')
    assert_equal(true, value)

    @@reg.writeStringEntry('Settings', 'bool_key1', '2')
    assert_raise(TypeError) { @@reg.readBoolEntry('Settings', 'bool_key1') }
  end

  # test of readIntEntry
  def test_read_int_entry
    value = @@reg.readIntEntry('Settings', 'int_key1')
    assert_equal(0, value)

    value = @@reg.readIntEntry('Settings', 'int_key1', 123)
    assert_equal(123, value)

    @@reg.writeBoolEntry('Settings', 'int_key1', true)
    value = @@reg.readIntEntry('Settings', 'int_key1')
    assert_equal(1, value)

    @@reg.writeRealEntry('Settings', 'int_key1', 2.5)
    value = @@reg.readIntEntry('Settings', 'int_key1')
    assert_equal(2, value)

    @@reg.writeStringEntry('Settings', 'int_key1', '2')
    value = @@reg.readIntEntry('Settings', 'int_key1')
    assert_equal(2, value)

    @@reg.writeStringEntry('Settings', 'int_key1', 'abc')
    value = @@reg.readIntEntry('Settings', 'int_key1')
    assert_equal(0, value)
  end

  # test of readRealEntry
  def test_read_real_entry
    value = @@reg.readRealEntry('Settings', 'real_key1')
    assert_equal(0.0, value)

    value = @@reg.readRealEntry('Settings', 'real_key1', 12.5)
    assert_equal(12.5, value)

    @@reg.writeBoolEntry('Settings', 'real_key1', true)
    value = @@reg.readRealEntry('Settings', 'real_key1')
    assert_equal(1.0, value)

    @@reg.writeIntEntry('Settings', 'real_key1', 2)
    value = @@reg.readRealEntry('Settings', 'real_key1')
    assert_equal(2.0, value)

    @@reg.writeStringEntry('Settings', 'real_key1', '2.5')
    value = @@reg.readRealEntry('Settings', 'real_key1')
    assert_equal(2.5, value)

    @@reg.writeStringEntry('Settings', 'real_key1', 'abc')
    value = @@reg.readRealEntry('Settings', 'real_key1')
    assert_equal(0, value)
  end

  # test of readStringEntry
  def test_read_string_entry
    string = @@reg.readStringEntry('Settings', 'string_key1')
    assert_equal('', string)

    string = @@reg.readStringEntry('Settings', 'string_key1', 'default value')
    assert_match(/ value/, string)

    @@reg.writeBoolEntry('Settings', 'string_key1', true)
    value = @@reg.readStringEntry('Settings', 'string_key1')
    assert_equal('1', value)

    @@reg.writeIntEntry('Settings', 'string_key1', 2)
    value = @@reg.readStringEntry('Settings', 'string_key1')
    assert_equal('2', value)

    @@reg.writeRealEntry('Settings', 'string_key1', 2.5)
    value = @@reg.readStringEntry('Settings', 'string_key1')
    assert_equal('2.5', value)
  end

  # test of writeBoolEntry
  def test_write_bool_entry
    @@reg.writeBoolEntry('Settings', 'bool_key2', true)
    value = @@reg.readBoolEntry('Settings', 'bool_key2')
    assert_equal(true, value)