aboutsummaryrefslogtreecommitdiffstats
path: root/test/fileop_test_unit_memory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/fileop_test_unit_memory.cpp')
-rw-r--r--test/fileop_test_unit_memory.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/fileop_test_unit_memory.cpp b/test/fileop_test_unit_memory.cpp
new file mode 100644
index 0000000..4ebe22b
--- /dev/null
+++ b/test/fileop_test_unit_memory.cpp
@@ -0,0 +1,36 @@
+/**
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * @file fileop_test_unit_memory.cpp
+ * @brief Unit test fot fileop.c
+ */
+#include <gtest/gtest.h>
+#include "mock/syscall_io_mock.hpp"
+#include "mock/memory_mock.hpp"
+
+// Test Terget files ---------------------------------------
+extern "C" {
+#define malloc(X) unittest_malloc(X)
+#include "../lib/fileop.c"
+#undef malloc
+}
+// Test Terget files ---------------------------------------
+using namespace ::testing;
+
+struct fileop_test_unit_memory_test : Test, SyscallIOMockBase, MemoryMockBase {};
+
+//--------------------------------------------------------------------------------------------------------
+TEST_F(fileop_test_unit_memory_test, unit_test_refop_new_file_write__open_error)
+{
+ int ret = -1;
+ refop_handle_t handle = (refop_handle_t)calloc(1,sizeof(struct refop_halndle));
+ uint8_t *dmybuf = (uint8_t*)calloc(1, refop_get_config_data_size_limit());
+
+ EXPECT_CALL(sysiom, unlink(_)).WillOnce(SetErrnoAndReturn(ENOENT, -1));
+ EXPECT_CALL(memorym, malloc(_)).WillOnce(Return(NULL));
+ ret = refop_new_file_write(handle, dmybuf, refop_get_config_data_size_limit());
+ ASSERT_EQ(-1, ret);
+
+ free(dmybuf);
+ free(handle);
+}