Simplify test case creation
authorHenning Rogge <henning.rogge@fkie.fraunhofer.de>
Fri, 18 May 2018 08:09:25 +0000 (10:09 +0200)
committerHenning Rogge <henning.rogge@fkie.fraunhofer.de>
Fri, 18 May 2018 08:09:25 +0000 (10:09 +0200)
CMakeListsGlobal.cmake
cmake/create_test.cmake [new file with mode: 0644]
include/oonf/base/os_vif.h
include/oonf/libcommon/netaddr.h
src/libcore/CMakeLists.txt
src/tests/CMakeLists.txt

index 708d9e1..4168059 100644 (file)
@@ -36,6 +36,9 @@ include (${CMAKE_CURRENT_LIST_DIR}/cmake/lib_config.cmake)
 # include compiler flags
 include (${CMAKE_CURRENT_LIST_DIR}/cmake/cc_flags.cmake)
 
+# helper for test case creation
+include (${CMAKE_CURRENT_LIST_DIR}/cmake/create_test.cmake)
+
 ########################################
 #### get repository tag and version ####
 ########################################
diff --git a/cmake/create_test.cmake b/cmake/create_test.cmake
new file mode 100644 (file)
index 0000000..0e41e23
--- /dev/null
@@ -0,0 +1,22 @@
+function (oonf_create_test executable source libraries)
+    # create executable
+    ADD_EXECUTABLE(${executable} ${source})
+
+    add_dependencies(build_tests ${executable})
+
+    TARGET_LINK_LIBRARIES(${executable} ${libraries})
+    TARGET_LINK_LIBRARIES(${executable} static_cunit)
+
+    # link regex for windows and android
+    IF (WIN32 OR ANDROID)
+        TARGET_LINK_LIBRARIES(${executable} oonf_regex)
+    ENDIF(WIN32 OR ANDROID)
+
+    # link extra win32 libs
+    IF(WIN32)
+        SET_TARGET_PROPERTIES(${executable} PROPERTIES ENABLE_EXPORTS true)
+        TARGET_LINK_LIBRARIES(${executable} ws2_32 iphlpapi)
+    ENDIF(WIN32)
+
+    ADD_TEST(NAME ${executable} COMMAND ${executable})
+endfunction (oonf_create_test)
index d98f49f..64fe188 100644 (file)
@@ -111,4 +111,14 @@ os_vif_get(const char *name) {
   return avl_find_element(os_vif_get_tree(), name, vif, _vif_node);
 }
 
+/**
+ * Tests if a virtual interface has been initialized
+ * @param vif pointer to virtual interface state
+ * @return true if initialized, false otherwise
+ */
+static INLINE bool
+os_vif_is_active(struct os_vif *vif) {
+  return avl_is_node_added(&vif->_vif_node);
+}
+
 #endif /* OS_VIF_H_ */
index 47cbdcf..805ae47 100644 (file)
@@ -270,6 +270,15 @@ netaddr_is_host(const struct netaddr *addr) {
 }
 
 /**
+ * @param addr network address
+ * @return true if address is a MAC48 multicast
+ */
+static INLINE bool
+netaddr_is_mac48_multicast(const struct netaddr *addr) {
+  return addr->_type == AF_MAC48 && ((addr->_addr[0] & 0x01) == 0x01);
+}
+
+/**
  * Converts a netaddr object into a string.
  * Prefix will be added if necessary.
  * @param dst target buffer
index 2264146..083da52 100644 (file)
@@ -34,7 +34,7 @@ ENDIF(LINUX)
 
 SET(linkto_internal oonf_libcommon oonf_libconfig)
 
-oonf_create_library("libcore" "${OONF_CORE_SRCS}" "${OONF_CORE_INCLUDES}" "${linkto_internal}" "rt")
+oonf_create_library("libcore" "${OONF_CORE_SRCS}" "${OONF_CORE_INCLUDES}" "${linkto_internal}" "${CMAKE_DL_LIBS}")
 
 # remove git commit cache entry
 UNSET (OONF_LIB_GIT CACHE)
index bf6e4a0..fa3c78c 100644 (file)
@@ -1,29 +1,3 @@
-# add test directories
-include_directories(.)
-
-function (oonf_create_test executable source libraries)
-    # create executable
-    ADD_EXECUTABLE(${executable} ${source})
-
-    add_dependencies(build_tests ${executable})
-
-    TARGET_LINK_LIBRARIES(${executable} ${libraries})
-    TARGET_LINK_LIBRARIES(${executable} static_cunit)
-
-    # link regex for windows and android
-    IF (WIN32 OR ANDROID)
-        TARGET_LINK_LIBRARIES(${executable} oonf_regex)
-    ENDIF(WIN32 OR ANDROID)
-
-    # link extra win32 libs
-    IF(WIN32)
-        SET_TARGET_PROPERTIES(${executable} PROPERTIES ENABLE_EXPORTS true)
-        TARGET_LINK_LIBRARIES(${executable} ws2_32 iphlpapi)
-    ENDIF(WIN32)
-
-    ADD_TEST(NAME ${executable} COMMAND ${executable})
-endfunction (oonf_create_test)
-
 add_subdirectory(cunit)
 add_subdirectory(common)
 add_subdirectory(config)