* configure.in (rb_cv_broken_glibc_ia64_erfc): renamed from
[ruby-svn.git] / test / test_pstore.rb
blob678ffa4a629a1b5090aa2f8b22e49a5b39defbe0
1 require 'test/unit'
2 require 'pstore'
4 class PStoreTest < Test::Unit::TestCase
5   def setup
6     @pstore_file = "pstore.tmp.#{Process.pid}"
7     @pstore = PStore.new(@pstore_file)
8   end
10   def teardown
11     File.unlink(@pstore_file) rescue nil
12   end
14   def test_opening_new_file_in_readonly_mode_should_result_in_empty_values
15     @pstore.transaction(true) do
16       assert_nil @pstore[:foo]
17       assert_nil @pstore[:bar]
18     end
19   end
20   
21   def test_opening_new_file_in_readwrite_mode_should_result_in_empty_values
22     @pstore.transaction do
23       assert_nil @pstore[:foo]
24       assert_nil @pstore[:bar]
25     end
26   end
27   
28   def test_data_should_be_loaded_correctly_when_in_readonly_mode
29     @pstore.transaction do
30       @pstore[:foo] = "bar"
31     end
32     @pstore.transaction(true) do
33       assert_equal "bar", @pstore[:foo]
34     end
35   end
36   
37   def test_data_should_be_loaded_correctly_when_in_readwrite_mode
38     @pstore.transaction do
39       @pstore[:foo] = "bar"
40     end
41     @pstore.transaction do
42       assert_equal "bar", @pstore[:foo]
43     end
44   end
45   
46   def test_changes_after_commit_are_discarded
47     @pstore.transaction do
48       @pstore[:foo] = "bar"
49       @pstore.commit
50       @pstore[:foo] = "baz"
51     end
52     @pstore.transaction(true) do
53       assert_equal "bar", @pstore[:foo]
54     end
55   end
56   
57   def test_changes_are_not_written_on_abort
58     @pstore.transaction do
59       @pstore[:foo] = "bar"
60       @pstore.abort
61     end
62     @pstore.transaction(true) do
63       assert_nil @pstore[:foo]
64     end
65   end
66   
67   def test_writing_inside_readonly_transaction_raises_error
68     assert_raise(PStore::Error) do
69       @pstore.transaction(true) do
70         @pstore[:foo] = "bar"
71       end
72     end
73   end
74 end