Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-solvers
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Patrick Jaap
dune-solvers
Commits
83db8cea
Commit
83db8cea
authored
7 years ago
by
Jonathan Youett
Browse files
Options
Downloads
Patches
Plain Diff
Tests for wrap_own_share
Code by Carsten Graeser
parent
a9fff592
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dune/solvers/test/CMakeLists.txt
+1
-0
1 addition, 0 deletions
dune/solvers/test/CMakeLists.txt
dune/solvers/test/wrapownsharetest.cc
+138
-0
138 additions, 0 deletions
dune/solvers/test/wrapownsharetest.cc
with
139 additions
and
0 deletions
dune/solvers/test/CMakeLists.txt
+
1
−
0
View file @
83db8cea
...
...
@@ -8,6 +8,7 @@ dune_add_test(SOURCES genericvectortoolstest.cc)
dune_add_test
(
SOURCES lowrankoperatortest.cc
)
dune_add_test
(
SOURCES nulloperatortest.cc
)
dune_add_test
(
SOURCES sumoperatortest.cc
)
dune_add_test
(
SOURCES wrapownsharetest.cc
)
if
(
HAVE_IPOPT
)
dune_add_test
(
SOURCES quadraticipoptsolvertest.cc
)
...
...
This diff is collapsed.
Click to expand it.
dune/solvers/test/wrapownsharetest.cc
0 → 100644
+
138
−
0
View file @
83db8cea
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#include
<config.h>
#include
<iostream>
#include
<sstream>
#include
<memory>
#include
<dune/solvers/common/wrapownshare.hh>
class
Foo
{
public:
Foo
(
std
::
size_t
counter
)
:
counter_
(
counter
)
{}
Foo
()
:
counter_
(
0
)
{}
Foo
(
Foo
&&
other
)
:
counter_
(
other
.
counter
())
{
std
::
cout
<<
"move"
<<
std
::
endl
;
}
Foo
(
const
Foo
&
other
)
:
counter_
(
other
.
counter
()
+
1
)
{
std
::
cout
<<
"copy"
<<
std
::
endl
;
}
std
::
size_t
counter
()
const
{
return
counter_
;
}
virtual
std
::
string
name
()
const
{
return
"Foo"
;
}
virtual
std
::
string
str
()
const
{
std
::
stringstream
s
;
s
<<
name
()
<<
":"
<<
counter
();
return
s
.
str
();
}
protected
:
std
::
size_t
counter_
;
};
class
Bar
:
public
Foo
{
public:
using
Foo
::
Foo
;
virtual
std
::
string
name
()
const
{
return
"Bar"
;
}
};
template
<
class
Impl
>
bool
doTests
()
{
// wrap non-const Impl&
{
Impl
foo
(
0
);
auto
foo_p
=
Dune
::
Solvers
::
wrap_own_share
<
Foo
>
(
foo
);
std
::
cout
<<
foo
.
str
()
<<
" "
<<
foo_p
->
str
()
<<
std
::
endl
;
if
(
foo
.
counter
()
!=
foo_p
->
counter
())
return
false
;
}
// wrap const Foo&
{
const
Impl
foo
(
0
);
auto
foo_p
=
Dune
::
Solvers
::
wrap_own_share
<
const
Foo
>
(
foo
);
std
::
cout
<<
foo
.
str
()
<<
" "
<<
foo_p
->
str
()
<<
std
::
endl
;
if
(
foo
.
counter
()
!=
foo_p
->
counter
())
return
false
;
}
// own Foo&& as Foo
{
auto
foo_p
=
Dune
::
Solvers
::
wrap_own_share
<
Foo
>
(
Impl
());
std
::
cout
<<
foo_p
->
str
()
<<
std
::
endl
;
if
(
foo_p
->
counter
()
!=
std
::
size_t
(
0
))
return
false
;
}
// own Foo&& as const Foo
{
auto
foo_p
=
Dune
::
Solvers
::
wrap_own_share
<
const
Foo
>
(
Impl
());
std
::
cout
<<
foo_p
->
str
()
<<
std
::
endl
;
if
(
foo_p
->
counter
()
!=
std
::
size_t
(
0
))
return
false
;
}
// share shared_ptr to Foo as Foo
{
auto
foo
=
std
::
make_shared
<
Impl
>
();
auto
foo_p
=
Dune
::
Solvers
::
wrap_own_share
<
Foo
>
(
foo
);
std
::
cout
<<
foo
->
str
()
<<
" "
<<
foo_p
->
str
()
<<
std
::
endl
;
if
(
foo
->
counter
()
!=
foo_p
->
counter
())
return
false
;
}
// share shared_ptr to Foo as const Foo
{
auto
foo
=
std
::
make_shared
<
Impl
>
();
auto
foo_p
=
Dune
::
Solvers
::
wrap_own_share
<
const
Foo
>
(
foo
);
std
::
cout
<<
foo
->
str
()
<<
" "
<<
foo_p
->
str
()
<<
std
::
endl
;
if
(
foo
->
counter
()
!=
foo_p
->
counter
())
return
false
;
}
// share shared_ptr to const Foo as const Foo
{
auto
foo
=
std
::
make_shared
<
const
Impl
>
();
auto
foo_p
=
Dune
::
Solvers
::
wrap_own_share
<
const
Foo
>
(
foo
);
std
::
cout
<<
foo
->
str
()
<<
" "
<<
foo_p
->
str
()
<<
std
::
endl
;
if
(
foo
->
counter
()
!=
foo_p
->
counter
())
return
false
;
}
return
true
;
}
int
main
()
{
std
::
cout
<<
"Testing with Foo"
<<
std
::
endl
;
bool
successful
=
doTests
<
Foo
>
();
std
::
cout
<<
"Testing with Bar"
<<
std
::
endl
;
successful
&=
doTests
<
Bar
>
();
return
!
successful
;
}
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