| 1 | #!/usr/bin/perl |
| 2 | |
| 3 | use strict; |
| 4 | use warnings; |
| 5 | |
| 6 | use Test::More tests => 5; |
| 7 | |
| 8 | use Config::IniFiles; |
| 9 | |
| 10 | use lib "./t/lib"; |
| 11 | |
| 12 | use Config::IniFiles::TestPaths; |
| 13 | |
| 14 | my ( $ini, $value ); |
| 15 | |
| 16 | t_unlink("test07.ini"); |
| 17 | |
| 18 | # Test 1 |
| 19 | # Multiple equals in a parameter - should split on the first |
| 20 | $ini = Config::IniFiles->new( -file => t_file('test.ini') ); |
| 21 | |
| 22 | # TEST |
| 23 | is( |
| 24 | scalar( $ini->val( 'test7', 'criterion' ) ), |
| 25 | 'price <= maximum', |
| 26 | "Multiple equals in a parameter - should split on the first", |
| 27 | ); |
| 28 | |
| 29 | # Test 2 |
| 30 | # Parameters whose name is a substring of existing parameters should be loaded |
| 31 | $value = $ini->val( 'substring', 'boot' ); |
| 32 | |
| 33 | # TEST |
| 34 | is( $value, 'smarty', |
| 35 | "Parameters whose name is a substring of existing parameters should be loaded" |
| 36 | ); |
| 37 | |
| 38 | # test 3 |
| 39 | # See if default option works |
| 40 | $ini = Config::IniFiles->new( |
| 41 | -file => t_file("test.ini"), |
| 42 | -default => 'test1', |
| 43 | -nocase => 1 |
| 44 | ); |
| 45 | $ini->SetFileName( t_file("test07.ini") ); |
| 46 | $ini->SetWriteMode("0666"); |
| 47 | |
| 48 | # TEST |
| 49 | ok( defined($ini), "default option works - \$ini works." ); |
| 50 | |
| 51 | # TEST |
| 52 | is( scalar( $ini->val( 'test2', 'three' ) ), |
| 53 | 'value3', "default option works - ->val" ); |
| 54 | |
| 55 | # Test 4 |
| 56 | # Check that Config::IniFiles respects RO permission on original INI file |
| 57 | $ini->WriteConfig( t_file("test07.ini") ); |
| 58 | chmod 0444, t_file("test07.ini"); |
| 59 | |
| 60 | SKIP: |
| 61 | { |
| 62 | if ( -w t_file("test07.ini") ) |
| 63 | { |
| 64 | skip( 'RO Permissions not settable.', 1 ); |
| 65 | } |
| 66 | else |
| 67 | { |
| 68 | $ini->setval( 'test2', 'three', 'should not be here' ); |
| 69 | $value = $ini->WriteConfig( t_file("test07.ini") ); |
| 70 | warn "Value is $value!" if ( defined $value ); |
| 71 | |
| 72 | # TEST |
| 73 | ok( !defined($value), "Value is undefined." ); |
| 74 | } # end if |
| 75 | } |
| 76 | |
| 77 | # Clean up when we're done |
| 78 | t_unlink("test07.ini"); |
| 79 |