[odb-users] Unit-testing odb::result<MyClassTable>
boris at codesynthesis.com
Fri Jan 26 08:53:21 EST 2018
Javier Gutierrez <javier.gutierrez at web.de> writes:
> first of all thank you very much for the great job.
Thanks, I am glad you are enjoying it.
> I am in the process of unit-testing a function that calls a method that
> returns odb::result<MyClassTable>.
> So basically what I want is to mock that method and to return instead my own
> version of an odb::result object pointing to a couple of made-up
> MyClassTable objects.
> I have tried to create my own version of odb::result by inheriting from the
> template odb::view_result_impl, but can't figure out how to go further.
You would need to implement its virtual interface to load objects from,
say, a vector instead of the database:
load (object_type&, bool fetch = true) = 0;
load_id () = 0;
next () = 0;
cache () = 0;
size () = 0;
> I analyzed the possibility to return std::vector instead of odb::result and
> to convert from odb::result to std::vector in the real method, but obviously
> that's an overkill..
Yes, if I were to go this direction, then I would make my code accept a
container template rather than odb::result<> so that I can call it either
with that or std::vector<>. The iteration interface in odb::result<> is
intentionally std-compatible to allow such generic code.
More information about the odb-users