]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
unit-tests: Match in and outbound SPIs in SA asserts
authorTobias Brunner <tobias@strongswan.org>
Wed, 18 May 2016 15:15:12 +0000 (17:15 +0200)
committerTobias Brunner <tobias@strongswan.org>
Fri, 17 Jun 2016 16:48:02 +0000 (18:48 +0200)
Since we use unique sequential SPIs that should be OK.

src/libcharon/tests/utils/sa_asserts.h

index 80e390ee39d3110880b4786ef1dafb95d7487daf..9faa2ff080c142e2f2ac42033ede5e43cd44beec 100644 (file)
 })
 
 /**
- * Check if the CHILD_SA with the given inbound SPI is in the expected state.
+ * Check if the CHILD_SA with the given SPI is in the expected state.
  */
 #define assert_child_sa_state(ike_sa, spi, state) \
 ({ \
        typeof(ike_sa) _sa = ike_sa; \
        typeof(spi) _spi = spi; \
        typeof(state) _state = state; \
-       child_sa_t *_child = _sa->get_child_sa(_sa, PROTO_ESP, _spi, TRUE); \
+       child_sa_t *_child = _sa->get_child_sa(_sa, PROTO_ESP, _spi, TRUE) ?: \
+                                                _sa->get_child_sa(_sa, PROTO_ESP, _spi, FALSE); \
        test_assert_msg(_child, "CHILD_SA with SPI %.8x does not exist", \
                                        ntohl(_spi)); \
        test_assert_msg(_state == _child->get_state(_child), "%N != %N", \
                                        child_sa_state_names, _child->get_state(_child)); \
 })
 
+/**
+ * Assert that the CHILD_SA with the given inbound SPI does not exist.
+ */
+#define assert_child_sa_not_exists(ike_sa, spi) \
+({ \
+       typeof(ike_sa) _sa = ike_sa; \
+       typeof(spi) _spi = spi; \
+       child_sa_t *_child = _sa->get_child_sa(_sa, PROTO_ESP, _spi, TRUE) ?: \
+                                                _sa->get_child_sa(_sa, PROTO_ESP, _spi, FALSE); \
+       test_assert_msg(!_child, "CHILD_SA with SPI %.8x exists", ntohl(_spi)); \
+})
+
 #endif /** SA_ASSERTS_H_ @}*/