Updated documentation formatting
[lms] / ruby-lightmediascanner / lightmediascanner-unittest.rb
1 #!/usr/bin/env ruby
2
3 # Copyright (C) 2007 by Levi Bard
4
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 # @author Levi Bard <taktaktaktaktaktaktaktaktaktak@gmail.com>
20
21
22
23 require 'lightmediascanner'
24
25 if(__FILE__ == $0)
26         require 'test/unit'
27
28         # Test cases for LightMediaScanner.  You probably don't care about this.
29         class LightMediaScanner::Test < Test::Unit::TestCase
30                 include LightMediaScanner
31
32                 def test_module()
33                         assert(LightMediaScanner::constants.include?('Scanner'))
34                         assert(LightMediaScanner::constants.include?('Parser'))
35                 end
36
37                 def test_scanner_gooddata()
38                         dbPath = '/'
39                         timeout = 60000
40                         commitInterval = 1000
41
42                         lms = nil
43                         assert_nothing_raised(){ lms = Scanner.new(dbPath) }
44                         assert_equal(dbPath, lms.db_path)
45
46                         lms.timeout=timeout
47                         assert_equal(lms.timeout, timeout)
48
49                         assert(!lms.processing?)
50
51                         lms.commit_interval = commitInterval
52                         assert_equal(lms.commit_interval, commitInterval)
53
54                         assert_raise(RuntimeError){ lms.process('/') }
55                         assert_raise(RuntimeError){ lms.check('/') }
56                         assert_nothing_raised(){ lms.add_charset('ISO-8859-1') }
57                         assert_nothing_raised(){ lms.remove_charset('ISO-8859-1') }
58                         assert_raise(RuntimeError){ Parser.new(lms, 'blah') }
59                 end
60
61                 def test_scanner_baddata()
62                         dbPath = '/'
63                         timeout = 60000
64                         commitInterval = 1000
65
66                         lms = nil
67                         assert_raise(TypeError){ lms = Scanner.new(nil) }
68                         assert_nothing_raised(){ lms = Scanner.new(dbPath) }
69                         assert_equal(dbPath, lms.db_path)
70
71                         assert_raise(TypeError){ lms.timeout = 'Jared' }
72                         assert_raise(TypeError){ lms.timeout = 3.14159 }
73
74                         assert_raise(TypeError){ lms.commit_interval = 2.72 }
75                         assert_raise(TypeError){ lms.commit_interval = nil }
76
77                         assert_raise(TypeError){ lms.process(nil) }
78                         assert_raise(TypeError){ lms.process(3) }
79
80                         assert_raise(TypeError){ lms.check(lms) }
81                         assert_raise(TypeError){ lms.check(5.43) }
82
83                         assert_raise(TypeError){ lms.add_charset(nil) }
84                         assert_raise(TypeError){ lms.add_charset(42) }
85                         assert_raise(RuntimeError){ lms.add_charset('I CAN HAZ CHARSET?') }
86
87                         assert_raise(RuntimeError){ lms.remove_charset('EBCDIC') }
88                         assert_raise(TypeError){ lms.remove_charset(nil) }
89                 end
90         end
91 end