Bladeren bron

Add POSIX read API to core module

- provide POSIX read API interface
- implement API interface
- provide POSIX read API mock
Patrick-Christopher Mattulat 1 jaar geleden
bovenliggende
commit
2150228fdc

+ 14 - 3
CMakeLists.txt

@@ -145,9 +145,20 @@ set(SOURCE_FILES_BOXING
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/boxing/Long.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/boxing/String.cpp)
 
-set(SOURCE_FILES_CORE
-        ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/core/Class.cpp
-        ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/core/Version.cpp)
+if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU OR
+        ${CMAKE_CXX_COMPILER_ID} STREQUAL Clang OR
+        ${CMAKE_CXX_COMPILER_ID} STREQUAL AppleClang)
+    set(SOURCE_FILES_CORE
+            ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/core/api/io/PosixReader.cpp
+            ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/core/Class.cpp
+            ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/core/Version.cpp)
+endif()
+
+if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
+    set(SOURCE_FILES_CORE
+            ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/core/Class.cpp
+            ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/core/Version.cpp)
+endif()
 
 set(SOURCE_FILES_ENCODING
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/encoding/Base64.cpp)

+ 28 - 0
include/ls_std/core/api/io/PosixReader.hpp

@@ -0,0 +1,28 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2022-12-16
+ * Changed:         2022-12-16
+ *
+ * */
+
+#ifndef LS_STD_POSIX_READER_HPP
+#define LS_STD_POSIX_READER_HPP
+
+#include <ls_std/core/interface/IPosixReader.hpp>
+
+namespace ls::std::core::api
+{
+  class PosixReader : public ls::std::core::interface_type::IPosixReader
+  {
+    public:
+
+      PosixReader() = default;
+      ~PosixReader() override = default;
+
+      size_t read(int _unixFileDescriptor, void* _buffer, size_t _size) override;
+  };
+}
+
+#endif

+ 27 - 0
include/ls_std/core/interface/IPosixReader.hpp

@@ -0,0 +1,27 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2022-12-15
+ * Changed:         2022-12-16
+ *
+ * */
+
+#ifndef LS_STD_I_POSIX_READER_HPP
+#define LS_STD_I_POSIX_READER_HPP
+
+#include <unistd.h>
+
+namespace ls::std::core::interface_type
+{
+  class IPosixReader
+  {
+    public:
+
+      virtual ~IPosixReader() = default;
+
+      virtual size_t read(int _unixFileDescriptor, void* _buffer, size_t _size) = 0;
+  };
+}
+
+#endif

+ 5 - 1
include/ls_std/ls_std_core.hpp

@@ -3,13 +3,17 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2022-05-13
- * Changed:         2022-12-12
+ * Changed:         2022-12-16
  *
  * */
 
 #ifndef LS_STD_LS_STD_CORE_HPP
 #define LS_STD_LS_STD_CORE_HPP
 
+#if defined(unix) || defined(__APPLE__)
+#include <ls_std/core/api/io/PosixReader.hpp>
+#endif
+
 #include <ls_std/core/exception/EventNotHandledException.hpp>
 #include <ls_std/core/exception/EventNotSubscribedException.hpp>
 #include <ls_std/core/exception/FileNotFoundException.hpp>

+ 15 - 0
source/ls_std/core/api/io/PosixReader.cpp

@@ -0,0 +1,15 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2022-12-16
+ * Changed:         2022-12-16
+ *
+ * */
+
+#include <ls_std/core/api/io/PosixReader.hpp>
+
+size_t ls::std::core::api::PosixReader::read(int _unixFileDescriptor, void *_buffer, size_t _size)
+{
+  return ::read(_unixFileDescriptor, _buffer, _size);
+}

+ 29 - 0
test/classes/core/api/io/MockPosixReader.hpp

@@ -0,0 +1,29 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2022-12-16
+ * Changed:         2022-12-16
+ *
+ * */
+
+#ifndef LS_STD_MOCK_POSIX_READER_HPP
+#define LS_STD_MOCK_POSIX_READER_HPP
+
+#include <ls_std/ls_std_core.hpp>
+#include <gmock/gmock.h>
+
+namespace ls_std_core_test
+{
+  class MockPosixReader : public ls::std::core::interface_type::IPosixReader
+  {
+    public:
+
+      MockPosixReader() = default;
+      ~MockPosixReader() override = default;
+
+      MOCK_METHOD(size_t, read, (int _unixFileDescriptor, void* _buffer, size_t _size), (override));
+  };
+}
+
+#endif

+ 3 - 1
test/ls_std_core_test.hpp

@@ -3,13 +3,15 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2022-05-16
- * Changed:         2022-05-16
+ * Changed:         2022-12-16
  *
  * */
 
 #ifndef LS_STD_LS_STD_CORE_TEST_HPP
 #define LS_STD_LS_STD_CORE_TEST_HPP
 
+#include <classes/core/api/io/MockPosixReader.hpp>
+
 #include <classes/base/ClassWrapper.hpp>
 
 #endif