Commit Graph

120 Commits

Author SHA1 Message Date
Gudmundur Adalsteinsson
99d98dd217 Improved enum flags operators and tests 2019-05-09 22:33:49 +00:00
Simon Giesecke
9a60ad3fc8
Apply suggestions from code review
Co-Authored-By: gummif <ofpgummi@yahoo.com>
2019-05-08 21:37:14 +00:00
Gudmundur Adalsteinsson
3d4be814e8 Problem: send/recv functions lack type-safety
Solution: Add functions taking buffers and enum class flags
2019-05-05 22:05:47 +00:00
Gudmundur Adalsteinsson
c6a3529cd1 Problem: No type-safe alternatives when polling or needing a reference to a socket
Solution: Introduce a socket_ref that is a non-owning nullable reference to a socket
2019-04-19 22:10:26 +00:00
Simon Giesecke
b0ac8acd60
Merge pull request #315 from gummif/gfa/test-warnings
Problem: Compiler warnings in tests
2019-04-15 11:54:05 +02:00
Simon Giesecke
961bb4fb46
Merge pull request #313 from gummif/gfa/socket-ctor
Problem: socket_t can not be default constructed
2019-04-15 10:58:45 +02:00
Gudmundur Adalsteinsson
c2e595bc69 Problem: Compiler warning in tests
Solution: Fix some compiler warnings
2019-04-14 21:34:15 +00:00
Gudmundur Adalsteinsson
4ceabb37b6 Problem: socket_t can not be default constructed
Solution: Provide a default constructor
2019-04-14 12:21:30 +00:00
Gudmundur Adalsteinsson
16f16eeaad Problem: message_t lacks empty() function
Solution: Add function and qualify with nodiscard like std types
2019-04-04 17:55:27 +00:00
Simon Giesecke
d1e7c538cc
Merge pull request #303 from gummif/gfa/swap
Problem: Missing swap functions
2019-04-04 14:51:10 +02:00
Simon Giesecke
5c69a36b95
Merge pull request #304 from gummif/gfa/monitor-move
Problem: monitor_t incorrectly deletes socket_t move assignment operator
2019-04-04 09:15:55 +02:00
Gudmundur Adalsteinsson
b6a07be512 Problem: monitor_t incorrectly deletes socket_t move assignment operator
Solution: Implement a move assignment operator for monitor_t
2019-04-03 14:04:58 +00:00
Gudmundur Adalsteinsson
72f0e1bcba Problem: message_t move and copy are mutating but take const
Solution: Deprecate old functions and add overloads taking non-const
references
2019-04-03 13:56:11 +00:00
Gudmundur Adalsteinsson
83b91c8b7e Problem: Missing swap functions
Solution: Implement for socket_t, context_t, message_t and poller_t
Additionally remove dependency on <functional> by refactoring poller_t
and remove unused <unordered_map> include.
2019-04-03 13:23:17 +00:00
Gudmundur Adalsteinsson
1eedfaf9a5 Problem: proxy is not typesafe
Solution: Add overloads to proxy and proxy_steerable taking socket_t
objects
2019-03-31 22:30:10 +00:00
trya
a91522f65e Unit tests for message_t::get()
Testing ZMQ_SHARED property only, since other properties (ZMQ_MORE and
ZMQ_SRCFD) depend on socket operations.
2019-03-14 14:25:50 +01:00
Simon Giesecke
4043617afe Problem: test cases for error behaviour of (active_)poller_t failing with libzmq 4.3.x
Solution: adapt test cases to changed behaviour
2019-02-04 15:25:35 +01:00
Pawel Kurdybacha
6982fb7017 Problem #268: CTest output without tests details
Solution: Added integration with CTest to existing unit test framework
based on Catch. ctest -v returns list of run tests now.

Changes:

* downloading and using Catch cmake modules that `unit_tests
--list-test-names-only` for add_test internally
2019-01-23 08:48:11 +00:00
Pawel Kurdybacha
6a6aebb845 Problem #284: test pthread link error with with gcc
Solution: Use Threads cmake module as suggested in this thread:
https://cmake.org/pipermail/cmake/2016-February/062729.html

I was able to reproduce with gcc 8.2.1 and cmake 3.13.2.
2019-01-22 20:55:06 +00:00
Pawel Kurdybacha
ae15964907 Problem: Dependency on googletest framework
Currently cppzmq as relatively simple and header only library depends on rather
complex unit test framework googletest.
Current issues:
- Googletest requires downloading and building it every time on travis
as cache support is limited there
- Googletest build is signifficant with comparison to cppzmq unittests
total runtime

Solution: Port existing tests to Catch - header only C++ framework and
gain ~20% build speed up on travis.

Why Catch?
It is well know C++ header only testing framework. It works well, it is
being kept up to date and maintainers seem to pay attention to
community's comments and issues.
We can not use Catch2 currently as we still support pre-C++11 compilers.
2018-10-17 15:22:07 +01:00
tangfu
5af24314c3 add front and back (#269)
* add front and back

i'll get the last message in some situations,but have to do like this :
```
multimsg msgs;
auto msg = msgs[msgs.size() - 1];
func(msg.size());
auto *msg = msgs.end() - 1;
```
but, std::queue have some method 'front' and 'back'. so maybe i can simply do this ? :
```
multimsg msgs;
auto msg = msgs.back();
```

* add test for front and back
2018-10-17 08:41:21 +01:00
Simon Giesecke
120c7ae3f2 Problem: no test case for previously existing send functionality
Solution: added test case
2018-08-21 13:50:02 +02:00
Simon Giesecke
ab09f5da98 Problem: addition of new single-argument message_t introduces ambiguity when calling e.g. socket_t::send
Solution: make single-argument constructor explicit
2018-08-21 13:50:02 +02:00
Joseph Artsimovich
751f27d635 Add support for RADIO/DISH sockets if draft API is enabled
This commit introduces new socket_type enumeration values as well
as the following supporting functions:

socket_t::join()
socket_t::leave()
message_t::group()
message_t::set_group()
2018-07-13 16:01:15 +03:00
Pawel Kurdybacha
57454dff4b Problem: monitor_t tests not event driven
Solution: instead of waiting for fixed amount of time for events, react
as soon as events are triggered.

- Total running time of unittest reduced 10x (from ~300ms to 30ms).
- Reduced code duplication by reusing testutil's constructs.
2018-07-05 00:23:31 +01:00
Simon Giesecke
58ffef7190 Problem: no tests for monitor_t::abort
Solution: add a test and fix implementation of monitor_t::abort to make it usable
2018-06-05 17:27:32 +02:00
Simon Giesecke
ec63fb3485 Problem: no test case for zmq::monitor_t::init
Solution: added test case
2018-06-05 17:27:28 +02:00
Pawel Kurdybacha
9a7a85703c Problem: Coverage with coveralls not working
Solution: Enable coveralls for one linux build target and fix coveralls
configuration.
2018-06-03 19:09:44 +01:00
Simon Giesecke
7023764834
Merge pull request #235 from Tulon/master
Add message_t::routing_id() and set_routing_id()
2018-05-20 09:25:20 +02:00
Pawel Kurdybacha
099bcfc4a4 Problem: cppzmq build broken with C++11 compiler and git cloned repo.
Default build, ./ci_build.sh without any arguments, which causes to run
with draft disabled, does not work properly for git cloned repository and
C++11 compiler.

Two issues:
1. For git cloned repository ENABLE_DRAFTS is ON by default but libzmq
compiled build without drafts .Travis did not catch that because default build
runs on non C++11 compiler.
2. testutil.hpp does not build because of missing draft guards.

Solution 1: Remove check for presence of .git for enabling draft API as it
is confusing to use with ENABLE_DRAFTS flag and there should be only one
explicit way to enable draft build.

Solution 2: add missing draft guards in testutil.hpp for server/client
socket in use there.

Solution 3: add extra Travis build covering C++11 compiler and non
draft enabled build.
2018-05-20 07:53:56 +01:00
Joseph Artsimovich
d4374cbebe Add message_t::routing_id() and set_routing_id()
Setting a routing id is necessary when sending a message through a
ZMQ_SERVER socket. See [1] for more details.

[1] http://api.zeromq.org/4-2:zmq-socket#toc5
2018-05-19 08:44:41 +03:00
Pawel Kurdybacha
a5578a6f25 Problem: libzmq 4.2.0 cmake build broken
It seems that there is a bug in libzmq 4.2.0 cmake configs that prevents
linking to it without installing.

Solution: disable libzmq 4.2.0 for cmake builds
2018-05-13 15:30:56 +01:00
Pawel Kurdybacha
3dc20bb05a Problem: libzmq builds with tests
libzmq build with default settings now which build all the tests and
performance tools. This is not required for cppzmq build and slows down
it only.

Solution: disable tests build for libzmq and make it release only.
2018-05-13 15:30:56 +01:00
Pawel Kurdybacha
ff3c221516 Problem: whitespace style too restrictive.
For header only library like cppzmq, whitespace style inherited from
libzmq is too restrictive.

Solution: relaxing whitespace before parens from always to in control
statements only, increased max column width from 80 to 85 and removing
requirement of whitespace after template keyword.
2018-05-12 17:28:28 +01:00
Pawel Kurdybacha
5031278f18 Problem: project files do not follow clang-format 2018-05-11 20:29:15 +01:00
Simon Giesecke
421d66c97e Problem: redundant assertion
Solution: removed redundant assertion
2018-05-11 12:31:17 +02:00
Simon Giesecke
762b0131e8 Problem: no tests for poller_t
Solution: add tests
2018-05-11 12:31:17 +02:00
Simon Giesecke
ee1cc9a791 Problem: unnecessary heap allocations for test subject
Solution: change to local variables
2018-05-11 11:33:54 +02:00
Simon Giesecke
882f5e844c Problem: extra abstraction layer type poller_t is in zmq.hpp
Solution: move to zmq_addon.hpp, rename to active_poller_t, and rename base_poller_t to poller_t
2018-05-11 11:33:53 +02:00
Simon Giesecke
dc996cd2ec Problem: zmq_addon header contains tests (with a syntax error)
Solution: convert to googletest based test, and fix syntax error
2018-05-11 11:33:53 +02:00
Simon Giesecke
89d9db7366 Problem: move poller tests are unspecific
Solution: remove redundant assertions (tested elsewhere), and add assertion behaviour of calling wait on moved-from poller
2018-05-11 11:02:59 +02:00
Simon Giesecke
bf47be0a0c Problem: poller_t adds an abstraction layer on zmq_poller_*
Solution: extract base_poller_t from poller_t, which provides a direct mapping of zmq_poller_* to C++ only
2018-05-11 11:02:27 +02:00
Pawel Kurdybacha
33025bf0e6 Problem: client/server socket types not defined.
Solution: Add ZMQ_CLIENT and ZMQ_SERVER to socket_type enum.
Update some of draft guarded unit tests to use them.
2018-05-11 06:41:53 +01:00
Pawel Kurdybacha
625a0ebb41 Unit tests for poller's move operations 2018-05-09 05:57:44 +01:00
Pawel Kurdybacha
559d373da3 Add back size method, add empty for completeness
As disscussed on #219 PR bringing back `size` method and adding `empty`
for completeness.
2018-05-09 05:44:11 +01:00
Pawel Kurdybacha
faf6671d38 Problem: poller can segfault when modified from registered handler. (#219)
* Problem: poller can segfault when modified from registred handler.

It is possible that a user would like to add/remove sockets from
handlers. As handlers and poll items might be removed while not
being processed yet - we have a segfault situation.
Provided unit test `remove_from_handler` demonstrates the problem.

Solution: Modify internal poll item data structure only after processing
of events is finished.

Please not that events processing path performance remains the same when there are
no modification (add/remove) to the poller (no rebuild) - main real use case.

As an effect of changes `size()` method has been removed as it does not
represent any meaningful information anymore. There are active and pending
(waiting for rebuild) poll items so two different sizes. User can
easily track on their side number of registered sockets if original size
information is needed.

`wait` method returns number of processed sockets now. It might be
useful information to a user for no extra cost.
2018-05-03 21:10:05 +01:00
Pawel Kurdybacha
131d2ec487 Problem: googletest is also installed into install destination
Building and installing cppzmq brings googletest build artifacts to the
installation destination as well. For example someone building cppzmq
with:
```
cmake -DCMAKE_INSTALL_PREFIX=mydest .
cmake --build --target install
```
gets googletest headers and libraries in `mydest`.

Solution: remove googletest from install target
2018-04-29 12:57:32 +01:00
Pawel Kurdybacha
94e0fb0bc3 Problem: deprecated poller's method in draft API
We have a deprecated method `add` in poller that contradicts purpose of a draft
API where it can change without deprecation period.

Solution: remove the method so we do not to maintain it anymore.
2018-04-26 19:50:14 +01:00
Pawel Kurdybacha
3fcd58d3f0 Problem: poller_t simple modify test case missing 2018-04-24 21:21:55 +01:00
Pawel Kurdybacha
85e05b0c88 Problem: poller_t does not support modify
Solution: Added `modify` method based on `zmq_poller_modify` and test cases
covering it.
Reduced code duplication in existing test cases by introducing
`client_server_setup` helper struct.
2018-04-24 21:16:01 +01:00
Pawel Kurdybacha
c55379d6e2 Problem: poller_t's deprecated add might throw std::bad_function_call
Issue is reproducible in deprecated add method with empty handler
followed by wait that kicks in (covered by provided unit test).

I would prefer we remove this method completely as maintaining something
that we consider `deprecated` is unnecessary in `draft` API.
2018-04-20 06:16:04 +01:00
Pawel Kurdybacha
810b87c021 Problem: poller_t invalid behaviour on invalid sockets
On adding invalid socket (e.g. after move) there was exception thrown
but leaving modified and unconsistent internal state.
Besides that there was no possibility to remove a socket that was moved
into.

Solutions: check for socket validity (added operator bool) and changed
internal unordered_map "handlers" to operator on zmq internal pointers.

Added two test cases covering the issues.
2018-04-18 07:00:41 +01:00
Pawel Kurdybacha
fdc145a09e Problem: Windows build broken because of multiple issues (#204)
* Problem: Windows build broken because of multiple issues

Windows issues:
* missing includes files
  Solution: added missing <memory> and <unordered_map>
  Here <map> was replaced with <unordered_map> as there is no need for
  sorted map.
* googletest fails because deprecation warning causing errors.
  Solution: D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING option added.
* googletest fails because by default, new Visual Studio projects
  link the C runtimes dynamically but Google Test links them statically.
  Solution: gtest_force_shared_crt=ON option added.

Besides that adding appveyor.yml configuration to add Windows build to
CI in order to prevent accidental Windows build breakage.
For now only Debug configuration as Release requires more time to figure
out.

* Problem: Windows build takes too long

Solution: disabling tests and perf tools

* Problem: Windows unit_tests executable not finding lizmq dll.

Solution: copy libzmq dll to build bin directory.

* Problem: Windows build fails because wrong test path provided
2018-04-17 09:29:47 +01:00
Simon Giesecke
4d0418750e Problem: no tests for move-assignment
Solution: added test cases
2018-04-13 11:35:00 -04:00
Simon Giesecke
438bad28e6 Problem: insufficient test cases for operator==
Solution: added test cases
2018-04-13 11:24:36 -04:00
Simon Giesecke
799c89cb09 Problem: several test cases mixed in message.constructors
Solution: split up into test cases for various ctors and equality operators
2018-04-13 11:20:07 -04:00
Pawel Kurdybacha
f518a648ef Problem: extended initializer lists only available in C++11 2018-04-14 14:06:32 +01:00
Pawel Kurdybacha
6caa5d19d3 Problem: message_t should be easier to construct
* Added overload constructor (c++11 only) taking iteratable object.
  It would be easier to use std::string, std::array etc to construct
  a message now. Making it a draft for now in case it is too greedy
  and needs to be more specialize.
* Added equal and not euqal operator to message_t as a recommended
  and expected way of comparing objects in C++.
* deprecated C style equal method as operator== should be used instead
  (point above).
* Added message_t test covering all available message_t's constructors
2018-04-14 12:13:44 +01:00
Pawel Kurdybacha
40c55018b2 Problem: create_destroy test not assigned properly 2018-04-13 17:38:51 +01:00
Pawel Kurdybacha
8353e8460f Problem: non consistent whitespace formatting
* Converted tabs to to 4 spaces to be consistend with the rest of the
code
* Stripped white spaces from the end of lines
2018-04-13 17:35:41 +01:00
Simon Giesecke
5b1ab44264 Problem: insufficient tests for poller_t, bad usability since caller of add must store function object
Solution: added tests, added size() method, added add deprecated overload with former signature, changed new add signature to accept handler by value
2018-04-13 16:24:46 +02:00
Pawel Kurdybacha
1975818171 Problem: poller's handler not aware of event type. (#200)
* Problem: Poller's handler not aware of event type.

It was possible to register a handler for more than one event types but
impossible to distinguish which event is being handled.
Now events are passed to a handler.

Besides that some other changes:
* new test covering changes in the poller
* modified existing tests to cover changes in the poller
* defined handler_t in poller_t scope for more convinient use
  and simpler code
* helper loopback binder to be re-used in tests

* Problem: CMake build fails on Windows

Issue #199

It seems that with GCC on Linux <array> is implicitly included
by one of stl includes already in zmq.hpp but it breaks on Windows
with Visual Studio.

Adding explicit include for array.

Can not verify right now but this change is a good practice
so creating a pull request.

* Poller: array include not between C++11 guards
2018-04-09 08:22:31 +01:00
Pawel Kurdybacha
18f8035ba8 Problem: poller_t does not have great test coverage
@sigiesec's recent commits with gtests and basics tests for zmq
types (thanks for that!) makes it too convinient to not add some more tests.

* Adding some simple tests for poller_t
* Stripped whitespaces from poller implementation.
2018-04-07 23:00:10 +01:00
Simon Giesecke
cc5f4050dc Problem: no build/tests with DRAFT
Solution: added initial test case
2018-04-03 18:41:44 +02:00
Simon Giesecke
83f854869a Problem: no tests for socket_t ctor accepting enum socket_type
Solution: added test case
2018-04-03 18:41:44 +02:00
Simon Giesecke
1616c0fad2 Problem: test file not correctly named
Solution: move and split example_add.cpp
2018-04-03 18:41:44 +02:00
Simon Giesecke
63f81e40d6 Problem: code coverage not working
Solution: build tests within cppzmq build, and add separate demo
2018-04-03 18:41:32 +02:00
Simon Giesecke
b737b9f1de Problem: no test cases
Solution: added a few initial test cases
2018-04-02 14:13:05 +02:00
Simon Giesecke
07b583a99a Problem: test not using cppzmq
Solution: add dependency on cppzmq
2018-03-29 18:46:04 +02:00
Simon Giesecke
968473cdba Problem: no test infrastructure
Solution: integrate googletest, with non-cppzmq test case for a start
2018-03-29 18:11:28 +02:00