Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Xavier Bachelot
lemonldap-ng
Commits
f1d3e947
Commit
f1d3e947
authored
Jan 09, 2016
by
Yadd
Browse files
Update File tests (utf8) (#827)
parent
fcc333e4
Changes
2
Hide whitespace changes
Inline
Side-by-side
lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf/File.pm
View file @
f1d3e947
...
...
@@ -82,12 +82,13 @@ sub store {
my
(
$self
,
$fields
)
=
@_
;
my
$mask
=
umask
;
umask
(
oct
('
0027
')
);
unless
(
open
FILE
,
"
>:encoding(UTF-8)
"
,
$self
->
_file
(
$fields
->
{
cfgNum
}
)
)
unless
(
open
FILE
,
'
>
'
,
$self
->
_file
(
$fields
->
{
cfgNum
}
)
)
{
$
Lemonldap::NG::Common::Conf::
msg
.
=
"
Open file failed: $!
\n
";
$
Lemonldap::NG::Common::Conf::
msg
=
"
Open file failed: $!
\n
";
$self
->
unlock
;
return
UNKNOWN_ERROR
;
}
binmode
(
FILE
);
print
FILE
JSON
->
new
->
canonical
(
1
)
->
encode
(
$fields
);
close
FILE
;
umask
(
$mask
);
...
...
@@ -109,6 +110,7 @@ sub load {
$f
=
encode
(
'
UTF-8
',
$f
);
eval
{
$ret
=
decode_json
(
$f
)
};
if
(
$@
)
{
print
STDERR
"
$@
\n
";
$
Lemonldap::NG::Common::Conf::
msg
.=
"
JSON fails to read file: $@
\n
";
return
undef
;
...
...
lemonldap-ng-common/t/02-Common-Conf-File.t
View file @
f1d3e947
...
...
@@ -5,7 +5,8 @@
# change 'tests => 1' to 'tests => last_test_to_print';
use
Test::
More
tests
=>
2
;
use
strict
;
use
Test::
More
;
BEGIN
{
use_ok
('
Lemonldap::NG::Common::Conf
')
}
#########################
...
...
@@ -19,9 +20,45 @@ ok(
$h
=
new
Lemonldap::NG::Common::
Conf
(
{
type
=>
'
File
',
dirName
=>
"
.
",
dirName
=>
"
t/
",
}
),
'
type => file
',
);
my
$count
=
2
;
my
@test
=
(
# simple ascii
{
cfgNum
=>
1
,
test
=>
'
ascii
'
},
# utf-8
{
cfgNum
=>
1
,
test
=>
'
Русский
'
},
# compatible utf8/latin-1 char but with different codes
{
cfgNum
=>
1
,
test
=>
'
éà
'
}
);
for
(
my
$i
=
0
;
$i
<
@test
;
$i
++
)
{
ok
(
$h
->
store
(
$test
[
$i
]
)
==
1
,
"
Test
$i
is stored
"
)
or
print
STDERR
"
$Lemonldap
::NG::Common::Conf::msg $!
";
$count
++
;
if
(
-
x
'
/usr/bin/file
'
)
{
eval
{
open
F
,
'
file t/lmConf-1.js |
';
$_
=
join
(
'',
<
F
>
);
close
F
;
ok
(
/(ascii|utf-?8)/si
,
"
File is $1 encoded
"
);
$count
++
;
};
}
my
$cfg
;
ok
(
$cfg
=
$h
->
load
(
1
),
"
Test
$i
can be read
"
)
or
print
STDERR
$
Lemonldap::NG::Common::Conf::
msg
;
ok
(
$cfg
->
{
test
}
eq
$test
[
$i
]
->
{
test
},
"
Test
$i
is restored
"
);
$count
+=
2
;
}
unlink
'
t/lmConf-1.js
';
done_testing
(
$count
);
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment