Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openstructure
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
schwede
openstructure
Commits
3de39d3e
Commit
3de39d3e
authored
12 years ago
by
Valerio Mariani
Browse files
Options
Downloads
Patches
Plain Diff
Unit tests for the Path class
parent
c05586c9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/base/src/path.cc
+12
-0
12 additions, 0 deletions
modules/base/src/path.cc
modules/base/tests/test_path.cc
+124
-0
124 additions, 0 deletions
modules/base/tests/test_path.cc
with
136 additions
and
0 deletions
modules/base/src/path.cc
+
12
−
0
View file @
3de39d3e
...
...
@@ -18,8 +18,13 @@
#include
<ost/path.hh>
#include
<ost/string_ref.hh>
#ifdef WIN32
// Insert Windows code here
#else
#include
<sys/param.h>
#include
<unistd.h>
#endif
namespace
ost
{
...
...
@@ -74,6 +79,11 @@ String Path::GetExtension() const
return
(
filename_sr_split
.
rbegin
())
->
str
();
}
#ifdef WIN32
// Insert Windows Code Here
#else
String
Path
::
GetAbsolutePath
()
const
{
if
(
path_
[
0
]
==
OST_DIRECTORY_SEPARATOR
)
{
...
...
@@ -105,4 +115,6 @@ bool Path::IsWritable() const
return
false
;
}
#endif
}
// ost
This diff is collapsed.
Click to expand it.
modules/base/tests/test_path.cc
0 → 100644
+
124
−
0
View file @
3de39d3e
//------------------------------------------------------------------------------
// This file is part of the OpenStructure project <www.openstructure.org>
//
// Copyright (C) 2008-2011 by the OpenStructure authors
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 3.0 of the License, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//------------------------------------------------------------------------------
/*
Author: Valerio Mariani
*/
#define BOOST_TEST_DYN_LINK
#include
<boost/test/unit_test.hpp>
#include
<boost/test/auto_unit_test.hpp>
#include
<ost/path.hh>
#include
<sys/stat.h>
#include
<iostream>
#include
<fstream>
using
namespace
ost
;
BOOST_AUTO_TEST_SUITE
(
base
);
BOOST_AUTO_TEST_CASE
(
test_constructors_and_implicit_conversion
)
{
Path
test_path
(
"path"
);
String
impl_conv
(
test_path
);
BOOST_CHECK
(
impl_conv
==
"path"
);
}
BOOST_AUTO_TEST_CASE
(
test_operators
)
{
String
fullpath_base
(
"this"
);
fullpath_base
+=
OST_DIRECTORY_SEPARATOR
;
fullpath_base
+=
"is"
;
String
fullpath_end
(
"test"
);
fullpath_end
+=
OST_DIRECTORY_SEPARATOR
;
fullpath_end
+=
"path"
;
String
full_path1
=
fullpath_base
;
full_path1
+=
OST_DIRECTORY_SEPARATOR
;
full_path1
+=
"a"
;
full_path1
+=
OST_DIRECTORY_SEPARATOR
;
full_path1
+=
fullpath_end
;
String
full_path2
=
fullpath_base
;
full_path2
+=
OST_DIRECTORY_SEPARATOR
;
full_path2
+=
"another"
;
full_path2
+=
OST_DIRECTORY_SEPARATOR
;
full_path2
+=
fullpath_end
;
Path
test_path1
(
"this"
);
test_path1
/
"is"
/
"a"
/
"test"
/
"path"
;
BOOST_CHECK
(
test_path1
.
GetFullPath
()
==
full_path1
);
Path
test_path2b
(
"is"
);
Path
test_path2c
(
"another"
);
Path
test_path2d
(
"test"
);
Path
test_path2e
(
"path"
);
Path
test_path2
(
"this"
);
test_path2
/
test_path2b
/
test_path2c
/
test_path2d
/
test_path2e
;
BOOST_CHECK
(
test_path2
.
GetFullPath
()
==
full_path2
);
}
BOOST_AUTO_TEST_CASE
(
test_path_disassembling_operators
)
{
Path
test_path
(
""
);
test_path
/
"etc"
/
"rc.d"
/
"rc.conf"
;
String
dirname
(
""
);
dirname
+=
OST_DIRECTORY_SEPARATOR
;
dirname
+=
"etc"
;
dirname
+=
OST_DIRECTORY_SEPARATOR
;
dirname
+=
"rc.d"
;
dirname
+=
OST_DIRECTORY_SEPARATOR
;
BOOST_CHECK
(
test_path
.
GetDirName
()
==
dirname
);
BOOST_CHECK
(
test_path
.
GetFileName
()
==
"rc.conf"
);
BOOST_CHECK
(
test_path
.
GetExtension
()
==
"conf"
);
Path
test_path2
(
"etc"
);
test_path2
/
"rc.d"
/
""
;
String
dirname2
(
"etc"
);
dirname2
+=
OST_DIRECTORY_SEPARATOR
;
dirname2
+=
"rc.d"
;
dirname2
+=
OST_DIRECTORY_SEPARATOR
;
BOOST_CHECK
(
test_path2
.
GetDirName
()
==
dirname2
);
BOOST_CHECK
(
test_path2
.
GetFileName
()
==
""
);
BOOST_CHECK
(
test_path2
.
GetExtension
()
==
""
);
}
BOOST_AUTO_TEST_CASE
(
test_existence_and_accessibility
)
{
std
::
ofstream
filestr
;
Path
filename
(
"testfiles"
);
filename
/
"path_test_file.txt"
;
Path
test_path
(
"testfiles"
);
test_path
/
"path_test_file.txt"
;
BOOST_CHECK
(
test_path
.
Exists
()
==
false
);
filestr
.
open
(
filename
.
GetFullPath
().
c_str
());
filestr
<<
"This file is created by the unitest for the Path class"
<<
std
::
endl
;
filestr
.
close
();
BOOST_CHECK
(
test_path
.
Exists
()
==
true
);
BOOST_CHECK
(
test_path
.
IsWritable
()
==
true
);
#ifdef WIN32
// Put windows code here
#else
chmod
(
test_path
.
GetFullPath
().
c_str
(),
S_IRUSR
|
S_IRGRP
|
S_IROTH
);
BOOST_CHECK
(
test_path
.
IsWritable
()
==
false
);
chmod
(
test_path
.
GetFullPath
().
c_str
(),
S_IRUSR
|
S_IWUSR
|
S_IRGRP
|
S_IROTH
);
#endif
}
BOOST_AUTO_TEST_SUITE_END
();
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment